Medical image analysis toolkit providing algorithms for segmentation, registration, and processing of medical images
—
ITK's spatial objects framework provides geometric primitives and spatial representations for modeling anatomical structures. These objects can be combined, transformed, and queried for geometric analysis and visualization.
Base class for all spatial objects.
template<unsigned int TDimension>
class SpatialObject : public DataObject
{
public:
typedef SpatialObject Self;
typedef DataObject Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth = 0, char * name = ITK_NULLPTR) const;
virtual bool IsInside(const PointType & point) const;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth = 0, char * name = ITK_NULLPTR) const;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth = 0, char * name = ITK_NULLPTR) const;
// Bounding box
virtual const BoundingBoxType * GetBoundingBox() const;
virtual bool ComputeLocalBoundingBox() const;
// Transform operations
void SetObjectToParentTransform(TransformType * transform);
itkGetConstObjectMacro(ObjectToParentTransform, TransformType);
void SetObjectToWorldTransform(TransformType * transform);
itkGetConstObjectMacro(ObjectToWorldTransform, TransformType);
// Hierarchy management
void SetChildren(ChildrenListType & children);
ChildrenListType * GetChildren(unsigned int depth = 0, char * name = ITK_NULLPTR);
const ChildrenListType & GetConstChildren(unsigned int depth = 0, char * name = ITK_NULLPTR) const;
void AddSpatialObject(Self * pointer);
void RemoveSpatialObject(Self * object);
// Object properties
void SetId(int id);
itkGetConstMacro(Id, int);
void SetParentId(int parentId);
itkGetConstMacro(ParentId, int);
// Type information
virtual const char * GetSpatialObjectTypeAsString() const;
// Depth and tree operations
unsigned int GetMaximumDepth() const;
void SetMaximumDepth(unsigned int depth);
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
virtual void ComputeObjectToWorldTransform();
};Container for grouping multiple spatial objects.
template<unsigned int TDimension>
class GroupSpatialObject : public SpatialObject<TDimension>
{
public:
typedef GroupSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Overridden spatial queries - delegates to children
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "GroupSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Elliptical spatial object.
template<unsigned int TDimension>
class EllipseSpatialObject : public SpatialObject<TDimension>
{
public:
typedef EllipseSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Ellipse parameters
void SetRadius(double radius);
void SetRadius(const ArrayType & radii);
itkGetConstReferenceMacro(Radius, ArrayType);
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "EllipseSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Box (rectangular parallelepiped) spatial object.
template<unsigned int TDimension>
class BoxSpatialObject : public SpatialObject<TDimension>
{
public:
typedef BoxSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Box parameters
void SetSize(const SizeType & size);
itkGetConstReferenceMacro(Size, SizeType);
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "BoxSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Cylindrical spatial object.
template<unsigned int TDimension>
class CylinderSpatialObject : public SpatialObject<TDimension>
{
public:
typedef CylinderSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Cylinder parameters
void SetRadius(double radius);
itkGetConstMacro(Radius, double);
void SetHeight(double height);
itkGetConstMacro(Height, double);
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "CylinderSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Represents tubular structures like blood vessels.
template<unsigned int TDimension>
class TubeSpatialObject : public SpatialObject<TDimension>
{
public:
typedef TubeSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Tube point management
typedef TubeSpatialObjectPoint<TDimension> TubePointType;
typedef std::vector<TubePointType> PointListType;
void SetPoints(const PointListType & points);
const PointListType & GetPoints() const;
PointListType & GetPoints();
// Point access
const TubePointType * GetPoint(IdentifierType id) const;
TubePointType * GetPoint(IdentifierType id);
SizeValueType GetNumberOfPoints() const;
// Tube properties
void SetEndType(unsigned int endType);
itkGetConstMacro(EndType, unsigned int);
void SetRoot(bool root);
itkGetConstMacro(Root, bool);
void SetArtery(bool artery);
itkGetConstMacro(Artery, bool);
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "TubeSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Specialized tube for blood vessel representation.
template<unsigned int TDimension>
class VesselTubeSpatialObject : public TubeSpatialObject<TDimension>
{
public:
typedef VesselTubeSpatialObject Self;
typedef TubeSpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Vessel-specific point type
typedef VesselTubeSpatialObjectPoint<TDimension> VesselTubePointType;
typedef std::vector<VesselTubePointType> VesselTubePointListType;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "VesselTubeSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Diffusion tensor imaging tube representation.
template<unsigned int TDimension>
class DTITubeSpatialObject : public TubeSpatialObject<TDimension>
{
public:
typedef DTITubeSpatialObject Self;
typedef TubeSpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// DTI-specific point type
typedef DTITubeSpatialObjectPoint<TDimension> DTITubePointType;
typedef std::vector<DTITubePointType> DTITubePointListType;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "DTITubeSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Represents anatomical landmarks.
template<unsigned int TDimension>
class LandmarkSpatialObject : public SpatialObject<TDimension>
{
public:
typedef LandmarkSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Landmark point management
typedef SpatialObjectPoint<TDimension> LandmarkPointType;
typedef std::vector<LandmarkPointType> PointListType;
void SetPoints(const PointListType & points);
const PointListType & GetPoints() const;
PointListType & GetPoints();
// Point access
const LandmarkPointType * GetPoint(IdentifierType id) const;
LandmarkPointType * GetPoint(IdentifierType id);
SizeValueType GetNumberOfPoints() const;
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "LandmarkSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Represents line segments and polylines.
template<unsigned int TDimension>
class LineSpatialObject : public SpatialObject<TDimension>
{
public:
typedef LineSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Line point management
typedef LineSpatialObjectPoint<TDimension> LinePointType;
typedef std::vector<LinePointType> PointListType;
void SetPoints(const PointListType & points);
const PointListType & GetPoints() const;
PointListType & GetPoints();
// Point access
const LinePointType * GetPoint(IdentifierType id) const;
LinePointType * GetPoint(IdentifierType id);
SizeValueType GetNumberOfPoints() const;
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "LineSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Wraps an image as a spatial object.
template<unsigned int TDimension, typename TPixelType>
class ImageSpatialObject : public SpatialObject<TDimension>
{
public:
typedef ImageSpatialObject Self;
typedef SpatialObject<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Image access
typedef Image<TPixelType, TDimension> ImageType;
typedef typename ImageType::Pointer ImagePointer;
typedef typename ImageType::ConstPointer ImageConstPointer;
void SetImage(const ImageType * image);
ImageType * GetImage();
const ImageType * GetImage() const;
// Spatial queries
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool IsEvaluableAt(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Slice access (for 3D images)
const ImageType * GetSlice(unsigned int dimension, unsigned int slicePosition) const;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "ImageSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Binary mask spatial object.
template<unsigned int TDimension>
class ImageMaskSpatialObject : public ImageSpatialObject<TDimension, unsigned char>
{
public:
typedef ImageMaskSpatialObject Self;
typedef ImageSpatialObject<TDimension, unsigned char> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Spatial queries override for binary masks
virtual bool IsInside(const PointType & point, unsigned int depth, char * name) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value, unsigned int depth, char * name) const ITK_OVERRIDE;
// Type identification
virtual const char * GetSpatialObjectTypeAsString() const ITK_OVERRIDE { return "ImageMaskSpatialObject"; }
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Base class for spatial object points.
template<unsigned int TPointDimension>
class SpatialObjectPoint
{
public:
typedef SpatialObjectPoint Self;
typedef Point<double, TPointDimension> PointType;
typedef Vector<double, TPointDimension> VectorType;
typedef CovariantVector<double, TPointDimension> CovariantVectorType;
// Constructors
SpatialObjectPoint();
virtual ~SpatialObjectPoint();
SpatialObjectPoint(const Self & other);
const Self & operator=(const Self & other);
// Position access
const PointType & GetPosition() const;
void SetPosition(const PointType & newPosition);
void SetPosition(double x0);
void SetPosition(double x0, double x1);
void SetPosition(double x0, double x1, double x2);
// Color
void SetColor(double red, double green, double blue, double alpha = 1);
void SetColor(const ColorType & color);
const ColorType & GetColor() const;
// Identification
void SetID(int id);
int GetID() const;
// Selection
void SetSelected(bool selected);
bool GetSelected() const;
// Printing
virtual void PrintSelf(std::ostream & os, Indent indent) const;
protected:
PointType m_Position;
ColorType m_Color;
int m_ID;
bool m_Selected;
};Point type for tube spatial objects.
template<unsigned int TPointDimension>
class TubeSpatialObjectPoint : public SpatialObjectPoint<TPointDimension>
{
public:
typedef TubeSpatialObjectPoint Self;
typedef SpatialObjectPoint<TPointDimension> Superclass;
// Constructors
TubeSpatialObjectPoint();
virtual ~TubeSpatialObjectPoint();
TubeSpatialObjectPoint(const Self & other);
const Self & operator=(const Self & other);
// Radius
void SetRadius(double radius);
double GetRadius() const;
// Medialness
void SetMedialness(double medialness);
double GetMedialness() const;
// Ridgeness
void SetRidgeness(double ridgeness);
double GetRidgeness() const;
// Branchness
void SetBranchness(double branchness);
double GetBranchness() const;
// Mark
void SetMark(bool mark);
bool GetMark() const;
// Tangent
const VectorType & GetTangent() const;
void SetTangent(const VectorType & tangent);
void SetTangent(double t0, double t1);
void SetTangent(double t0, double t1, double t2);
// Normal vectors
const CovariantVectorType & GetNormal1() const;
void SetNormal1(const CovariantVectorType & normal);
void SetNormal1(double n0, double n1);
void SetNormal1(double n0, double n1, double n2);
const CovariantVectorType & GetNormal2() const;
void SetNormal2(const CovariantVectorType & normal);
void SetNormal2(double n0, double n1);
void SetNormal2(double n0, double n1, double n2);
// Printing
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
protected:
double m_Radius;
double m_Medialness;
double m_Ridgeness;
double m_Branchness;
bool m_Mark;
VectorType m_Tangent;
CovariantVectorType m_Normal1;
CovariantVectorType m_Normal2;
};// Create an ellipse spatial object
typedef itk::EllipseSpatialObject<3> EllipseType;
EllipseType::Pointer ellipse = EllipseType::New();
// Set ellipse parameters
EllipseType::ArrayType radii;
radii[0] = 10.0; // X radius
radii[1] = 5.0; // Y radius
radii[2] = 3.0; // Z radius
ellipse->SetRadius(radii);
// Create transform to position ellipse
typedef itk::AffineTransform<double, 3> TransformType;
TransformType::Pointer transform = TransformType::New();
TransformType::OutputVectorType translation;
translation[0] = 50.0;
translation[1] = 50.0;
translation[2] = 50.0;
transform->Translate(translation);
ellipse->SetObjectToParentTransform(transform);
// Test if points are inside
EllipseType::PointType testPoint;
testPoint[0] = 52.0;
testPoint[1] = 48.0;
testPoint[2] = 51.0;
if (ellipse->IsInside(testPoint)) {
std::cout << "Point is inside ellipse" << std::endl;
}// Create vessel tube spatial object
typedef itk::VesselTubeSpatialObject<3> VesselTubeType;
VesselTubeType::Pointer vesselTube = VesselTubeType::New();
// Create vessel points
typedef VesselTubeType::VesselTubePointType VesselPointType;
typedef VesselTubeType::VesselTubePointListType PointListType;
PointListType pointList;
// Add centerline points with radii
for (int i = 0; i < 10; ++i) {
VesselPointType point;
point.SetPosition(i * 2.0, 0.0, 0.0); // Along X axis
point.SetRadius(1.0 + 0.1 * i); // Increasing radius
point.SetMedialness(0.8);
point.SetRidgeness(0.7);
pointList.push_back(point);
}
vesselTube->SetPoints(pointList);
vesselTube->SetArtery(true);
vesselTube->SetRoot(true);
std::cout << "Vessel tube has " << vesselTube->GetNumberOfPoints() << " points" << std::endl;// Create group to contain multiple objects
typedef itk::GroupSpatialObject<3> GroupType;
GroupType::Pointer group = GroupType::New();
// Create multiple objects
typedef itk::BoxSpatialObject<3> BoxType;
BoxType::Pointer box1 = BoxType::New();
BoxType::Pointer box2 = BoxType::New();
// Configure boxes
BoxType::SizeType size;
size[0] = 10.0; size[1] = 10.0; size[2] = 10.0;
box1->SetSize(size);
box2->SetSize(size);
// Position boxes
TransformType::Pointer transform1 = TransformType::New();
TransformType::Pointer transform2 = TransformType::New();
TransformType::OutputVectorType translation1, translation2;
translation1.Fill(0.0);
translation2[0] = 15.0; translation2[1] = 0.0; translation2[2] = 0.0;
transform1->Translate(translation1);
transform2->Translate(translation2);
box1->SetObjectToParentTransform(transform1);
box2->SetObjectToParentTransform(transform2);
// Add to group
group->AddSpatialObject(box1);
group->AddSpatialObject(box2);
// Test spatial queries on group
GroupType::PointType queryPoint;
queryPoint[0] = 5.0; queryPoint[1] = 5.0; queryPoint[2] = 5.0;
if (group->IsInside(queryPoint)) {
std::cout << "Point is inside one of the boxes in the group" << std::endl;
}// Common spatial object instantiations
typedef SpatialObject<2> SpatialObject2D;
typedef SpatialObject<3> SpatialObject3D;
typedef GroupSpatialObject<2> GroupSpatialObject2D;
typedef GroupSpatialObject<3> GroupSpatialObject3D;
typedef EllipseSpatialObject<2> EllipseSpatialObject2D;
typedef EllipseSpatialObject<3> EllipseSpatialObject3D;
typedef BoxSpatialObject<2> BoxSpatialObject2D;
typedef BoxSpatialObject<3> BoxSpatialObject3D;
typedef CylinderSpatialObject<3> CylinderSpatialObject3D;
typedef TubeSpatialObject<2> TubeSpatialObject2D;
typedef TubeSpatialObject<3> TubeSpatialObject3D;
typedef VesselTubeSpatialObject<2> VesselTubeSpatialObject2D;
typedef VesselTubeSpatialObject<3> VesselTubeSpatialObject3D;
typedef DTITubeSpatialObject<3> DTITubeSpatialObject3D;
typedef LandmarkSpatialObject<2> LandmarkSpatialObject2D;
typedef LandmarkSpatialObject<3> LandmarkSpatialObject3D;
typedef LineSpatialObject<2> LineSpatialObject2D;
typedef LineSpatialObject<3> LineSpatialObject3D;
typedef ImageSpatialObject<2, unsigned char> BinaryImageSpatialObject2D;
typedef ImageSpatialObject<3, unsigned char> BinaryImageSpatialObject3D;
typedef ImageSpatialObject<2, float> FloatImageSpatialObject2D;
typedef ImageSpatialObject<3, float> FloatImageSpatialObject3D;
// Point types
typedef SpatialObjectPoint<2> SpatialObjectPoint2D;
typedef SpatialObjectPoint<3> SpatialObjectPoint3D;
typedef TubeSpatialObjectPoint<2> TubeSpatialObjectPoint2D;
typedef TubeSpatialObjectPoint<3> TubeSpatialObjectPoint3D;
typedef VesselTubeSpatialObjectPoint<2> VesselTubeSpatialObjectPoint2D;
typedef VesselTubeSpatialObjectPoint<3> VesselTubeSpatialObjectPoint3D;
// Container types
typedef std::vector<SpatialObjectPoint2D> PointList2D;
typedef std::vector<SpatialObjectPoint3D> PointList3D;
typedef std::list<SpatialObject2D::Pointer> ChildrenList2D;
typedef std::list<SpatialObject3D::Pointer> ChildrenList3D;
// Color type
typedef RGBAPixel<float> ColorType;
// Transform types
typedef AffineTransform<double, 2> AffineTransform2D;
typedef AffineTransform<double, 3> AffineTransform3D;
// Bounding box types
typedef BoundingBox<PointIdentifier, 2, double> BoundingBox2D;
typedef BoundingBox<PointIdentifier, 3, double> BoundingBox3D;ITK's spatial objects framework provides a comprehensive system for geometric modeling and spatial analysis, enabling representation of complex anatomical structures and their relationships in medical imaging applications.
Install with Tessl CLI
npx tessl i tessl/cmake-itk