Skip to content

Commit

Permalink
COMP: Transform API updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jun 4, 2024
1 parent 656b2cc commit eced041
Show file tree
Hide file tree
Showing 10 changed files with 857 additions and 850 deletions.
27 changes: 11 additions & 16 deletions include/itkGridTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GridTransform : public Transform<double, 2, 2>
typedef Transform<double, 2, 2> Superclass;

// Base inverse transform type:
typedef Superclass::InverseTransformType InverseTransformType;
typedef Superclass InverseTransformType;
typedef SmartPointer<InverseTransformType> InverseTransformPointer;

// RTTI:
Expand Down Expand Up @@ -233,8 +233,8 @@ class GridTransform : public Transform<double, 2, 2>
}

// virtual:
unsigned int
GetNumberOfParameters() const
Superclass::NumberOfParametersType
GetNumberOfParameters() const override
{
return 2 * transform_.grid_.mesh_.size();
}
Expand All @@ -255,7 +255,6 @@ class GridTransform : public Transform<double, 2, 2>
transform_ = transform;
GetParameters();
GetFixedParameters();
this->m_Jacobian.SetSize(2, GetNumberOfParameters());
this->m_FixedParameters[0] = is_inverse ? 1.0 : 0.0;
}

Expand All @@ -266,9 +265,8 @@ class GridTransform : public Transform<double, 2, 2>
return this->m_FixedParameters[0] != 0.0;
}

// virtual:
const JacobianType &
GetJacobian(const InputPointType & point) const
void
ComputeJacobianWithRespectToParameters(const InputPointType & point, JacobianType & jacobian) const override
{
// FIXME: 20061227 -- this function was written and not tested:

Expand All @@ -281,26 +279,23 @@ class GridTransform : public Transform<double, 2, 2>

unsigned int idx[3];
double jac[12];
this->m_Jacobian.SetSize(2, GetNumberOfParameters());
this->m_Jacobian.Fill(0.0);
jacobian.SetSize(2, GetNumberOfParameters());
jacobian.Fill(0.0);
if (transform_.jacobian(point, idx, jac))
{
for (unsigned int i = 0; i < 3; i++)
{
unsigned int addr = idx[i] * 2;
this->m_Jacobian(0, addr) = Su * jac[i * 2];
this->m_Jacobian(0, addr + 1) = Su * jac[i * 2 + 1];
this->m_Jacobian(1, addr) = Sv * jac[i * 2 + 6];
this->m_Jacobian(1, addr + 1) = Sv * jac[i * 2 + 7];
jacobian(0, addr) = Su * jac[i * 2];
jacobian(0, addr + 1) = Su * jac[i * 2 + 1];
jacobian(1, addr) = Sv * jac[i * 2 + 6];
jacobian(1, addr + 1) = Sv * jac[i * 2 + 7];
}
}

return this->m_Jacobian;
}

protected:
GridTransform()
: Superclass(2, 0)
{
this->m_FixedParameters.SetSize(7);

Expand Down
34 changes: 16 additions & 18 deletions include/itkIRCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ extern const char * g_Version;
//
typedef itk::Size<2>::SizeValueType image_size_value_t;

//----------------------------------------------------------------
// array2d
//
#define array2d(T) std::vector<std::vector<T>>

//----------------------------------------------------------------
// mask_t
//
Expand Down Expand Up @@ -1415,7 +1410,7 @@ template <class T>
std::vector<typename itk::ImageRegionConstIteratorWithIndex<T>>
DivideROIAmongThreads(typename T::ConstPointer fi,
typename T::RegionType roi,
int num_Threads = boost::thread::hardware_concurrency())
int num_Threads = std::thread::hardware_concurrency())
{
typedef typename itk::ImageRegionConstIteratorWithIndex<T> itex_t;
typedef typename T::IndexType index_t;
Expand Down Expand Up @@ -1487,7 +1482,7 @@ template <class T>
std::vector<typename itk::ImageRegionIteratorWithIndex<T>>
DivideROIAmongThreads(typename T::Pointer fi,
typename T::RegionType roi,
int num_Threads = boost::thread::hardware_concurrency())
int num_Threads = std::thread::hardware_concurrency())
{
typedef typename itk::ImageRegionIteratorWithIndex<T> itex_t;
typedef typename T::IndexType index_t;
Expand Down Expand Up @@ -2003,7 +1998,7 @@ my_metric_mt(double & area,
const mask_t * mi_mask,

const TInterpolator * mi_interpolator,
int num_Threads = boost::thread::hardware_concurrency())
int num_Threads = std::thread::hardware_concurrency())
{
// return my_metric(area, fi, mi, fi_to_mi, fi_mask, mi_mask, mi_interpolator);

Expand Down Expand Up @@ -3699,7 +3694,7 @@ make_mosaic(const typename IMG::SpacingType & mosaic_sp,
typename IMG::PixelType background = 255.0,

bool dont_allocate = false,
const int num_threads = boost::thread::hardware_concurrency())
const int num_threads = std::thread::hardware_concurrency())
{
// NOTE: for backwards compatibility we do not assemble the mosaic mask:
const bool assemble_mosaic_mask = false;
Expand Down Expand Up @@ -4626,7 +4621,7 @@ make_mask(const mask_t::SpacingType & mosaic_sp,
const std::vector<bool> & omit,
const std::vector<typename transform_t::ConstPointer> & transform,
const std::vector<mask_t::ConstPointer> & image_mask,
unsigned int num_threads = boost::thread::hardware_concurrency())
unsigned int num_threads = std::thread::hardware_concurrency())
{
return make_mask_mt<transform_t>(num_threads, mosaic_sp, num_images, omit, transform, image_mask);
}
Expand All @@ -4640,7 +4635,7 @@ template <class transform_t>
mask_t::Pointer
make_mask(const std::vector<typename transform_t::ConstPointer> & transform,
const std::vector<typename mask_t::ConstPointer> & image_mask,
unsigned int num_threads = boost::thread::hardware_concurrency())
unsigned int num_threads = std::thread::hardware_concurrency())
{
const unsigned int num_images = transform.size();
return make_mask<transform_t>(
Expand Down Expand Up @@ -5159,8 +5154,8 @@ save_rgb(const char * fn_save,
inline static translate_transform_t::Pointer
inverse(const translate_transform_t * transform)
{
translate_transform_t::Pointer inv = NULL;
if (transform != NULL)
translate_transform_t::Pointer inv;
if (transform != nullptr)
{
inv = translate_transform_t::New();
inv->SetOffset(neg(transform->GetOffset()));
Expand Down Expand Up @@ -6300,8 +6295,9 @@ approx_transform(const pnt2d_t & tile_min,
const unsigned int version = 1,
const bool refine = false)
{
base_transform_t::Pointer inverse = forward->GetInverse();
assert(inverse.GetPointer() != NULL);
base_transform_t::Pointer inverse;
forward->GetInverse(inverse);
assert(inverse.GetPointer() != nullptr);

// calculate the shift:
pnt2d_t center =
Expand Down Expand Up @@ -6434,8 +6430,9 @@ solve_for_transform(const pnt2d_t & tile_min,
const unsigned int version = 1,
const bool refine = false)
{
base_transform_t::Pointer tile_to_mosaic = mosaic_to_tile_0->GetInverse();
assert(tile_to_mosaic.GetPointer() != NULL);
base_transform_t::Pointer tile_to_mosaic;
mosaic_to_tile_0->GetInverse(tile_to_mosaic);
assert(tile_to_mosaic.GetPointer() != nullptr);

// calculate the shift:
pnt2d_t center =
Expand Down Expand Up @@ -6467,7 +6464,8 @@ solve_for_transform(const T * tile,
const unsigned int version = 1,
const bool refine = false)
{
base_transform_t::Pointer tile_to_mosaic = mosaic_to_tile_0->GetInverse();
base_transform_t::Pointer tile_to_mosaic;
mosaic_to_tile_0->GetInverse(tile_to_mosaic);
assert(tile_to_mosaic.GetPointer() != NULL);

typename T::SizeType sz = tile->GetLargestPossibleRegion().GetSize();
Expand Down
Loading

0 comments on commit eced041

Please sign in to comment.