Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Documentation/ITK5MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ ObjectSpace. For example, the `IsInside( point )` function has been replaced b
`IsInsideInWorldSpace( point )` functions.

As implied above, the changes to SpatialObject are extensive. They include the following:
* Replace use of ComputeMyBoundingBox() with Update();
* Replace use of ComputeObjectToWorldTransform() with Update();
* Eliminate IndexToX transforms. SpatialObjects exist purely in physical space coordinates
* Eliminate vnl TreeNode usage. SpatialObjects now track their transforms, parents, and children directly.
* Eliminate AffineGeometryFrame
Expand All @@ -350,7 +352,22 @@ As implied above, the changes to SpatialObject are extensive. They include the
* `RemoveChild()` and `RemoveAllChildren()` fixed to remove all pointers to / from those children to / from the tree
* Helper functions simplify the specification of `IsInsideInObjectSpace()`, `ValueAtInObjectSpace()`, and other computations that potentially traverse an SO tree.
* Derived classes typically only need to implement `IsInsideInObjectSpace()` and `ComputeMyBoundingBoxInObjectSpace()` member functions. Logic for `ValueAtInObjectSpace()`, `IsInsideInWorldSpace()` and such is improved.
* `ImageMaskSpatialObject::GetAxisAlignedBoundingBoxRegion()` was removed. `GetMyBoundingBoxInObjectSpace()` or `GetMyBoundingBoxInWorldSpace()` should be used instead. If an region in IndexSpace is needed, then consider ITK's LabelMap classes and the [LabelImageToShapelLabelMapFilter](https://itk.org/Doxygen/html/classitk_1_1LabelImageToShapeLabelMapFilter.html).
* `ImageMaskSpatialObject::GetAxisAlignedBoundingBoxRegion()` was removed. `GetMyBoundingBoxInObjectSpace()` or `GetMyBoundingBoxInWorldSpace()` should be used instead. If a region in IndexSpace is needed, then consider ITK's LabelMap classes and the [LabelImageToShapelLabelMapFilter](https://itk.org/Doxygen/html/classitk_1_1LabelImageToShapeLabelMapFilter.html).
```
//REPLACE typename FixedImageType::RegionType roiRegion = roiMask->GetAxisAlignedBoundingBoxRegion();
using LabelType = unsigned char;
using ShapeLabelObjectType = itk::ShapeLabelObject< LabelType, Dimension >;
using LabelMapType = itk::LabelMap< ShapeLabelObjectType >;

using LI2SLMFType = itk::LabelImageToShapeLabelMapFilter<FixedImageType,LabelMapType >;
typename LI2SLMFType::Pointer i2l = LI2SLMFType::New();
i2l->SetInput(roiImage);
i2l->Update();
LabelMapType *labelMap = i2l->GetOutput();
const typename LabelMapType::SizeValueType numLabelObjects = labelMap->GetNumberOfLabelObjects();
ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(1);
typename FixedImageType::RegionType roiRegion = labelObject->GetBoundingBox();
```

Class changes
-------------
Expand Down
6 changes: 3 additions & 3 deletions Examples/RegistrationITKv3/ModelToImageRegistration1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ int main( int argc, char *argv[] )
offset[ 1 ] = 40.0;

ellipse1->GetObjectToParentTransform()->SetOffset(offset);
ellipse1->ComputeObjectToWorldTransform();
ellipse1->Update();

offset[ 0 ] = 40.0;
offset[ 1 ] = 150.0;
ellipse2->GetObjectToParentTransform()->SetOffset(offset);
ellipse2->ComputeObjectToWorldTransform();
ellipse2->Update();

offset[ 0 ] = 150.0;
offset[ 1 ] = 150.0;
ellipse3->GetObjectToParentTransform()->SetOffset(offset);
ellipse3->ComputeObjectToWorldTransform();
ellipse3->Update();
// Software Guide : EndCodeSnippet


Expand Down
6 changes: 3 additions & 3 deletions Examples/RegistrationITKv4/ModelToImageRegistration1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,17 @@ int main( int argc, char *argv[] )
offset[ 1 ] = 40.0;

ellipse1->GetModifiableObjectToParentTransform()->SetOffset(offset);
ellipse1->ComputeObjectToWorldTransform();
ellipse1->Update();

offset[ 0 ] = 40.0;
offset[ 1 ] = 150.0;
ellipse2->GetModifiableObjectToParentTransform()->SetOffset(offset);
ellipse2->ComputeObjectToWorldTransform();
ellipse2->Update();

offset[ 0 ] = 150.0;
offset[ 1 ] = 150.0;
ellipse3->GetModifiableObjectToParentTransform()->SetOffset(offset);
ellipse3->ComputeObjectToWorldTransform();
ellipse3->Update();
// Software Guide : EndCodeSnippet


Expand Down
2 changes: 1 addition & 1 deletion Examples/SpatialObjects/GroupSpatialObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main( int , char *[] )
GroupType::VectorType offset;
offset.Fill(10);
myGroup->GetModifiableObjectToParentTransform()->SetOffset(offset);
myGroup->ComputeObjectToWorldTransform();
myGroup->Update();
// Software Guide : EndCodeSnippet

// Software Guide : BeginLatex
Expand Down
8 changes: 4 additions & 4 deletions Examples/SpatialObjects/SpatialObjectTransforms.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// Several member functions and variables are available to every SpatialObject
// so that they can readily access the WorldSpace in which they exist:
//
// * ComputeObjectToWorldTransform: Composes its ObjectToParentTransform
// * ProtectedComputeObjectToWorldTransform: Composes its ObjectToParentTransform
// with its parent's cached ObjectToObjectToWorldTransform, to determine the
// transform from the object's ObjectSpace to WorldSpace. This transform is
// always invertible. This call will cause all children objects to also
Expand All @@ -60,7 +60,7 @@
// function must be manually called by users.
//
// * GetObjectToWorldTransform: Returns the cached ObjectToWorldTransform.
// It is the user's responsibility to call ComputeObjectToWorldTransform when
// It is the user's responsibility to call ProtectedComputeObjectToWorldTransform when
// necessary, prior to calling GetObjectToWorldTransform, otherwise the
// returned transform may be "stale."
//
Expand Down Expand Up @@ -138,7 +138,7 @@ int main( int , char *[] )
// Software Guide : BeginLatex
//
// To realize the previous operations on the transformations, we should
// invoke the \code{ComputeObjectToWorldTransform()} that recomputes all
// invoke the \code{ProtectedComputeObjectToWorldTransform()} that recomputes all
// dependent transformations.
//
// By calling this function on object1, it will also descend to its children,
Expand All @@ -147,7 +147,7 @@ int main( int , char *[] )
// Software Guide : EndLatex

// Software Guide : BeginCodeSnippet
object1->ComputeObjectToWorldTransform();
object1->Update();
// Software Guide : EndCodeSnippet


Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/SpatialObjects/include/itkArrowSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class ITK_TEMPLATE_EXPORT ArrowSpatialObject:
/** Get the length of the arrow */
itkGetConstReferenceMacro(LengthInObjectSpace, double);

/** Compute the Object bounding box */
bool ComputeMyBoundingBox() const override;

/** Returns true if the point is inside the line, false otherwise. */
bool IsInsideInObjectSpace(const PointType & point, unsigned int depth=0,
const std::string & name="") const override;
Expand All @@ -87,6 +84,9 @@ class ITK_TEMPLATE_EXPORT ArrowSpatialObject:

protected:

/** Compute the Object bounding box */
void ProtectedComputeMyBoundingBox() const override;

ArrowSpatialObject();
~ArrowSpatialObject() override = default;

Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/SpatialObjects/include/itkArrowSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ ArrowSpatialObject< TDimension >

/** Compute the bounding box */
template< unsigned int TDimension >
bool
void
ArrowSpatialObject< TDimension >
::ComputeMyBoundingBox() const
::ProtectedComputeMyBoundingBox() const
{
itkDebugMacro("Computing Rectangle bounding box");

PointType pnt = this->GetPositionInObjectSpace();

this->GetModifiableMyBoundingBoxInObjectSpace()->SetMinimum(pnt);
this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum(pnt);

return true;
}

/** Check if a given point is on the arrow */
Expand Down
5 changes: 3 additions & 2 deletions Modules/Core/SpatialObjects/include/itkBoxSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ class ITK_TEMPLATE_EXPORT BoxSpatialObject:
bool IsInsideInObjectSpace(const PointType & point, unsigned int depth = 0,
const std::string & name = "" ) const override;

protected:

/** Get the boundaries of a specific object. This function needs to
* be called every time one of the object's components is
* changed. */
bool ComputeMyBoundingBox() const override;
void ProtectedComputeMyBoundingBox() const override;

protected:
BoxSpatialObject();
~BoxSpatialObject() override = default;

Expand Down
8 changes: 3 additions & 5 deletions Modules/Core/SpatialObjects/include/itkBoxSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BoxSpatialObject< TDimension >
m_SizeInObjectSpace.Fill(1);
m_PositionInObjectSpace.Fill(0);

this->ComputeMyBoundingBox();
this->Update();
}

/** Test whether a point is inside or outside the object */
Expand Down Expand Up @@ -62,9 +62,9 @@ BoxSpatialObject< TDimension >

/** Compute the bounds of the box */
template< unsigned int TDimension >
bool
void
BoxSpatialObject< TDimension >
::ComputeMyBoundingBox() const
::ProtectedComputeMyBoundingBox() const
{
itkDebugMacro("Computing BoxSpatialObject bounding box");

Expand All @@ -80,8 +80,6 @@ BoxSpatialObject< TDimension >
this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum(pnt1);
this->GetModifiableMyBoundingBoxInObjectSpace()->ConsiderPoint(pnt2);
this->GetModifiableMyBoundingBoxInObjectSpace()->ComputeBoundingBox();

return true;
}

/** InternalClone */
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/SpatialObjects/include/itkEllipseSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ class ITK_TEMPLATE_EXPORT EllipseSpatialObject:
bool IsInsideInObjectSpace(const PointType & point, unsigned int depth=0,
const std::string & name="" ) const override;

protected:
/** Get the boundaries of a specific object. This function needs to
* be called every time one of the object's components is
* changed. */
bool ComputeMyBoundingBox() const override;
void ProtectedComputeMyBoundingBox() const override;

protected:
EllipseSpatialObject();
~EllipseSpatialObject() override = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ EllipseSpatialObject< TDimension >

/** Compute the bounds of the ellipse */
template< unsigned int TDimension >
bool
void
EllipseSpatialObject< TDimension >
::ComputeMyBoundingBox() const
::ProtectedComputeMyBoundingBox() const
{
itkDebugMacro("Computing ellipse bounding box");

Expand All @@ -118,8 +118,6 @@ EllipseSpatialObject< TDimension >
this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum(pnt1);
this->GetModifiableMyBoundingBoxInObjectSpace()->ConsiderPoint(pnt2);
this->GetModifiableMyBoundingBoxInObjectSpace()->ComputeBoundingBox();

return true;
}

/** InternalClone */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ class ITK_TEMPLATE_EXPORT GaussianSpatialObject:
bool IsInsideInObjectSpace(const PointType & point, unsigned int depth = 0,
const std::string & name = "") const override;

/** This function needs to be called every time one of the object's
* components is changed. */
bool ComputeMyBoundingBox() const override;

/** Returns the value of the Gaussian at the given point. */
bool ValueAtInObjectSpace(const PointType & point, double & value,
unsigned int depth = 0, const std::string & name = "") const override;
Expand All @@ -101,6 +97,10 @@ class ITK_TEMPLATE_EXPORT GaussianSpatialObject:
typename EllipseSpatialObject< TDimension >::Pointer GetEllipsoid() const;

protected:
/** This function needs to be called every time one of the object's
* components is changed. */
void ProtectedComputeMyBoundingBox() const override;

GaussianSpatialObject();
~GaussianSpatialObject() override = default;

Expand Down
10 changes: 4 additions & 6 deletions Modules/Core/SpatialObjects/include/itkGaussianSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GaussianSpatialObject< TDimension >
m_SigmaInObjectSpace = 1.0;
m_Maximum = 1.0;

this->ComputeMyBoundingBox();
this->Update();
}

/** The z-score is the root mean square of the z-scores along
Expand Down Expand Up @@ -109,9 +109,9 @@ GaussianSpatialObject< TDimension >
/** Compute the bounds of the Gaussian (as determined by the
* specified radius). */
template< unsigned int TDimension >
bool
void
GaussianSpatialObject< TDimension >
::ComputeMyBoundingBox() const
::ProtectedComputeMyBoundingBox() const
{
itkDebugMacro("Computing Guassian bounding box");

Expand All @@ -127,8 +127,6 @@ GaussianSpatialObject< TDimension >
this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum(pnt1);
this->GetModifiableMyBoundingBoxInObjectSpace()->ConsiderPoint(pnt2);
this->GetModifiableMyBoundingBoxInObjectSpace()->ComputeBoundingBox();

return true;
}

/** Returns the value at one point. */
Expand Down Expand Up @@ -179,7 +177,7 @@ GaussianSpatialObject< TDimension >
ellipse->GetModifiableObjectToWorldTransform()->SetParameters(
this->GetObjectToWorldTransform()->GetParameters() );

ellipse->ComputeMyBoundingBox();
ellipse->Update();

return ellipse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ class ITK_TEMPLATE_EXPORT ImageMaskSpatialObject:
bool IsInsideInObjectSpace(const PointType & point, unsigned int depth=0,
const std::string & name="") const override;

protected:
/** Get the boundaries of a specific object. This function needs to
* be called every time one of the object's components is
* changed. */
bool ComputeMyBoundingBox() const override;
void ProtectedComputeMyBoundingBox() const override;

protected:
ImageMaskSpatialObject();
~ImageMaskSpatialObject() override = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ ImageMaskSpatialObject< TDimension, TPixel >
}

template< unsigned int TDimension, typename TPixel >
bool
void
ImageMaskSpatialObject< TDimension, TPixel >
::ComputeMyBoundingBox() const
::ProtectedComputeMyBoundingBox() const
{
using IteratorType = ImageRegionConstIteratorWithIndex< ImageType >;
IteratorType it( this->GetImage(),
Expand Down Expand Up @@ -131,16 +131,14 @@ ImageMaskSpatialObject< TDimension, TPixel >
if( first )
{
tmpPoint.Fill(
NumericTraits< typename BoundingBoxType::PointType::ValueType >::
ZeroValue() );
NumericTraits< typename BoundingBoxType::PointType::ValueType >::ZeroValue() );

this->GetModifiableMyBoundingBoxInObjectSpace()->SetMinimum( tmpPoint );
this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum( tmpPoint );

return false;
// NOT AN EXCEPTION!!!, used to return false, but never checked
// itkExceptionMacro(<< "ImageMask bounding box computation failed.")
}

return true;
}

/** InternalClone */
Expand Down
5 changes: 2 additions & 3 deletions Modules/Core/SpatialObjects/include/itkImageSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ class ITK_TEMPLATE_EXPORT ImageSpatialObject:
/** Get a pointer to the image currently attached to the object. */
const ImageType * GetImage() const;

/** Compute the boundaries of the image spatial object. */
bool ComputeMyBoundingBox() const override;

/** Returns true if the point is inside, false otherwise. */
bool IsInsideInObjectSpace(const PointType & point, unsigned int depth=0,
const std::string & name = "") const override;
Expand Down Expand Up @@ -112,6 +109,8 @@ class ITK_TEMPLATE_EXPORT ImageSpatialObject:
itkGetConstMacro(Interpolator, InterpolatorType *);

protected:
/** Compute the boundaries of the image spatial object. */
void ProtectedComputeMyBoundingBox() const override;

ImageSpatialObject();
~ImageSpatialObject() override;
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/SpatialObjects/include/itkImageSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ ImageSpatialObject< TDimension, PixelType >

/** Compute the bounds of the image */
template< unsigned int TDimension, typename PixelType >
bool
void
ImageSpatialObject< TDimension, PixelType >
::ComputeMyBoundingBox() const
::ProtectedComputeMyBoundingBox() const
{
itkDebugMacro("Computing ImageSpatialObject bounding box");

Expand All @@ -153,8 +153,6 @@ ImageSpatialObject< TDimension, PixelType >
this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum(pnt1);
this->GetModifiableMyBoundingBoxInObjectSpace()->ConsiderPoint(pnt2);
this->GetModifiableMyBoundingBoxInObjectSpace()->ComputeBoundingBox();

return true;
}


Expand Down
Loading