18 #ifndef itkShapeLabelObject_h
19 #define itkShapeLabelObject_h
42 template <
typename TLabel,
unsigned int VImageDimension>
64 static constexpr
unsigned int ImageDimension = VImageDimension;
70 using typename Superclass::LineType;
72 using typename Superclass::LengthType;
74 using typename Superclass::AttributeType;
77 static constexpr AttributeType NUMBER_OF_PIXELS = 100;
82 static constexpr AttributeType PHYSICAL_SIZE = 101;
87 static constexpr AttributeType CENTROID = 104;
89 static constexpr AttributeType BOUNDING_BOX = 105;
97 static constexpr AttributeType NUMBER_OF_PIXELS_ON_BORDER = 106;
106 static constexpr AttributeType PERIMETER_ON_BORDER = 107;
111 static constexpr AttributeType FERET_DIAMETER = 108;
114 static constexpr AttributeType PRINCIPAL_MOMENTS = 109;
117 static constexpr AttributeType PRINCIPAL_AXES = 110;
122 static constexpr AttributeType ELONGATION = 111;
125 static constexpr AttributeType PERIMETER = 112;
127 static constexpr AttributeType ROUNDNESS = 113;
132 static constexpr AttributeType EQUIVALENT_SPHERICAL_RADIUS = 114;
137 static constexpr AttributeType EQUIVALENT_SPHERICAL_PERIMETER = 115;
142 static constexpr AttributeType EQUIVALENT_ELLIPSOID_DIAMETER = 116;
144 static constexpr AttributeType FLATNESS = 117;
146 static constexpr AttributeType PERIMETER_ON_BORDER_RATIO = 118;
151 static constexpr AttributeType ORIENTED_BOUNDING_BOX_ORIGIN = 119;
161 static constexpr AttributeType ORIENTED_BOUNDING_BOX_SIZE = 120;
166 if (s ==
"NumberOfPixels")
168 return NUMBER_OF_PIXELS;
170 else if (s ==
"PhysicalSize")
172 return PHYSICAL_SIZE;
174 else if (s ==
"Centroid")
178 else if (s ==
"BoundingBox")
182 else if (s ==
"NumberOfPixelsOnBorder")
184 return NUMBER_OF_PIXELS_ON_BORDER;
186 else if (s ==
"PerimeterOnBorder")
188 return PERIMETER_ON_BORDER;
190 else if (s ==
"FeretDiameter")
192 return FERET_DIAMETER;
194 else if (s ==
"PrincipalMoments")
196 return PRINCIPAL_MOMENTS;
198 else if (s ==
"PrincipalAxes")
200 return PRINCIPAL_AXES;
202 else if (s ==
"Elongation")
206 else if (s ==
"Perimeter")
210 else if (s ==
"Roundness")
214 else if (s ==
"EquivalentSphericalRadius")
216 return EQUIVALENT_SPHERICAL_RADIUS;
218 else if (s ==
"EquivalentSphericalPerimeter")
220 return EQUIVALENT_SPHERICAL_PERIMETER;
222 else if (s ==
"EquivalentEllipsoidDiameter")
224 return EQUIVALENT_ELLIPSOID_DIAMETER;
226 else if (s ==
"Flatness")
230 else if (s ==
"PerimeterOnBorderRatio")
232 return PERIMETER_ON_BORDER_RATIO;
234 else if (s ==
"OrientedBoundingBoxOrigin")
236 return ORIENTED_BOUNDING_BOX_ORIGIN;
238 else if (s ==
"OrientedBoundingBoxSize")
240 return ORIENTED_BOUNDING_BOX_SIZE;
243 return Superclass::GetAttributeFromName(s);
252 case NUMBER_OF_PIXELS:
253 name =
"NumberOfPixels";
256 name =
"PhysicalSize";
262 name =
"BoundingBox";
264 case NUMBER_OF_PIXELS_ON_BORDER:
265 name =
"NumberOfPixelsOnBorder";
267 case PERIMETER_ON_BORDER:
268 name =
"PerimeterOnBorder";
271 name =
"FeretDiameter";
273 case PRINCIPAL_MOMENTS:
274 name =
"PrincipalMoments";
277 name =
"PrincipalAxes";
288 case EQUIVALENT_SPHERICAL_RADIUS:
289 name =
"EquivalentSphericalRadius";
291 case EQUIVALENT_SPHERICAL_PERIMETER:
292 name =
"EquivalentSphericalPerimeter";
294 case EQUIVALENT_ELLIPSOID_DIAMETER:
295 name =
"EquivalentEllipsoidDiameter";
300 case PERIMETER_ON_BORDER_RATIO:
301 name =
"PerimeterOnBorderRatio";
303 case ORIENTED_BOUNDING_BOX_ORIGIN:
304 name =
"OrientedBoundingBoxOrigin";
306 case ORIENTED_BOUNDING_BOX_SIZE:
307 name =
"OrientedBoundingBoxSize";
311 name = Superclass::GetNameFromAttribute(a);
339 return m_BoundingBox;
351 return m_PhysicalSize;
363 return m_NumberOfPixels;
369 m_NumberOfPixels = v;
381 m_Centroid = centroid;
387 return m_NumberOfPixelsOnBorder;
393 m_NumberOfPixelsOnBorder = v;
399 return m_PerimeterOnBorder;
405 m_PerimeterOnBorder = v;
411 return m_FeretDiameter;
423 return m_PrincipalMoments;
429 m_PrincipalMoments = v;
435 return m_PrincipalAxes;
483 return m_EquivalentSphericalRadius;
489 m_EquivalentSphericalRadius = v;
495 return m_EquivalentSphericalPerimeter;
501 m_EquivalentSphericalPerimeter = v;
507 return m_EquivalentEllipsoidDiameter;
513 m_EquivalentEllipsoidDiameter = v;
531 return m_PerimeterOnBorderRatio;
537 m_PerimeterOnBorderRatio = v;
540 const OrientedBoundingBoxPointType &
543 return m_OrientedBoundingBoxOrigin;
549 m_OrientedBoundingBoxOrigin = v;
552 const OrientedBoundingBoxSizeType &
555 return m_OrientedBoundingBoxSize;
561 m_OrientedBoundingBoxSize = v;
571 return m_BoundingBox;
577 const OrientedBoundingBoxDirectionType &
580 return this->GetPrincipalAxes();
593 OrientedBoundingBoxVerticesType
596 const MatrixType obbToPhysical(this->GetOrientedBoundingBoxDirection().GetTranspose());
605 for (
unsigned int i = 0; i < OrientedBoundingBoxVerticesType::Length; ++i)
607 constexpr
unsigned int msb = 1 << (ImageDimension - 1);
609 for (
unsigned int j = 0; j < ImageDimension; ++j)
613 offset[j] = m_OrientedBoundingBoxSize[j];
620 vertices[i] = m_OrientedBoundingBoxOrigin + obbToPhysical * offset;
637 for (
unsigned int i = 0; i < VImageDimension; ++i)
639 offset[i] = m_Centroid[i];
640 for (
unsigned int j = 0; j < VImageDimension; ++j)
642 matrix[j][i] = m_PrincipalAxes[i][j];
649 result->SetMatrix(matrix);
650 result->SetOffset(offset);
659 AffineTransformPointer
664 for (
unsigned int i = 0; i < VImageDimension; ++i)
666 offset[i] = m_Centroid[i];
667 for (
unsigned int j = 0; j < VImageDimension; ++j)
669 matrix[j][i] = m_PrincipalAxes[i][j];
675 result->SetMatrix(matrix);
676 result->SetOffset(offset);
679 result->GetInverse(inverse);
684 template <
typename TSourceLabelObject>
688 Superclass::template CopyAttributesFrom<TSourceLabelObject>(src);
690 m_BoundingBox = src->GetBoundingBox();
691 m_NumberOfPixels = src->GetNumberOfPixels();
692 m_PhysicalSize = src->GetPhysicalSize();
693 m_Centroid = src->GetCentroid();
694 m_NumberOfPixelsOnBorder = src->GetNumberOfPixelsOnBorder();
695 m_PerimeterOnBorder = src->GetPerimeterOnBorder();
696 m_FeretDiameter = src->GetFeretDiameter();
697 m_PrincipalMoments = src->GetPrincipalMoments();
698 m_PrincipalAxes = src->GetPrincipalAxes();
699 m_Elongation = src->GetElongation();
700 m_Perimeter = src->GetPerimeter();
701 m_Roundness = src->GetRoundness();
702 m_EquivalentSphericalRadius = src->GetEquivalentSphericalRadius();
703 m_EquivalentSphericalPerimeter = src->GetEquivalentSphericalPerimeter();
704 m_EquivalentEllipsoidDiameter = src->GetEquivalentEllipsoidDiameter();
705 m_Flatness = src->GetFlatness();
706 m_PerimeterOnBorderRatio = src->GetPerimeterOnBorderRatio();
707 m_OrientedBoundingBoxOrigin = src->GetOrientedBoundingBoxOrigin();
708 m_OrientedBoundingBoxSize = src->GetOrientedBoundingBoxSize();
711 template <
typename TSourceLabelObject>
715 itkAssertOrThrowMacro((src !=
nullptr),
"Null Pointer");
716 this->
template CopyLinesFrom<TSourceLabelObject>(src);
717 this->
template CopyAttributesFrom<TSourceLabelObject>(src);
723 m_NumberOfPixels = 0;
726 m_NumberOfPixelsOnBorder = 0;
727 m_PerimeterOnBorder = 0;
729 m_PrincipalMoments.Fill(0);
730 m_PrincipalAxes.Fill(0);
734 m_EquivalentSphericalRadius = 0;
735 m_EquivalentSphericalPerimeter = 0;
736 m_EquivalentEllipsoidDiameter.Fill(0);
738 m_PerimeterOnBorderRatio = 0;
739 m_OrientedBoundingBoxSize.Fill(0);
740 m_OrientedBoundingBoxOrigin.Fill(0);
746 Superclass::PrintSelf(os, indent);
748 os << indent <<
"BoundingBox: " << m_BoundingBox << std::endl;
752 os << indent <<
"PhysicalSize: " << m_PhysicalSize << std::endl;
755 os << indent <<
"NumberOfPixelsOnBorder: "
757 os << indent <<
"PerimeterOnBorder: " << m_PerimeterOnBorder << std::endl;
758 os << indent <<
"FeretDiameter: " << m_FeretDiameter << std::endl;
759 os << indent <<
"PrincipalMoments: " << m_PrincipalMoments << std::endl;
760 os << indent <<
"PrincipalAxes: " << std::endl << m_PrincipalAxes;
761 os << indent <<
"Elongation: " << m_Elongation << std::endl;
762 os << indent <<
"Perimeter: " << m_Perimeter << std::endl;
763 os << indent <<
"Roundness: " << m_Roundness << std::endl;
764 os << indent <<
"EquivalentSphericalRadius: " << m_EquivalentSphericalRadius << std::endl;
765 os << indent <<
"EquivalentSphericalPerimeter: " << m_EquivalentSphericalPerimeter << std::endl;
766 os << indent <<
"EquivalentEllipsoidDiameter: " << m_EquivalentEllipsoidDiameter << std::endl;
767 os << indent <<
"Flatness: " << m_Flatness << std::endl;
768 os << indent <<
"PerimeterOnBorderRatio: " << m_PerimeterOnBorderRatio << std::endl;
769 os << indent <<
"OrientedBoundingBoxSize: "
772 os << indent <<
"OrientedBoundingBoxOrigin: "
780 double m_PhysicalSize{};
783 double m_PerimeterOnBorder{};
784 double m_FeretDiameter{};
787 double m_Elongation{};
788 double m_Perimeter{};
789 double m_Roundness{};
790 double m_EquivalentSphericalRadius{};
791 double m_EquivalentSphericalPerimeter{};
794 double m_PerimeterOnBorderRatio{};