ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkShapeLabelObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkShapeLabelObject_h
19 #define itkShapeLabelObject_h
20 
21 #include "itkLabelObject.h"
22 #include "itkLabelMap.h"
23 #include "itkAffineTransform.h"
24 
25 namespace itk
26 {
41 template< typename TLabel, unsigned int VImageDimension >
42 class ShapeLabelObject:public LabelObject< TLabel, VImageDimension >
43 {
44 public:
52 
54  itkNewMacro(Self);
55 
57  itkTypeMacro(ShapeLabelObject, LabelObject);
58 
60 
61  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
62 
63  typedef typename Superclass::IndexType IndexType;
64 
65  typedef TLabel LabelType;
66 
67  typedef typename Superclass::LineType LineType;
68 
70 
72 
74  itkStaticConstMacro(NUMBER_OF_PIXELS, AttributeType, 100);
75 
79  itkStaticConstMacro(PHYSICAL_SIZE, AttributeType, 101);
80 
84  itkStaticConstMacro(CENTROID, AttributeType, 104);
85 
86  itkStaticConstMacro(BOUNDING_BOX, AttributeType, 105);
87 
94  itkStaticConstMacro(NUMBER_OF_PIXELS_ON_BORDER, AttributeType, 106);
95 
103  itkStaticConstMacro(PERIMETER_ON_BORDER, AttributeType, 107);
104 
108  itkStaticConstMacro(FERET_DIAMETER, AttributeType, 108);
109 
111  itkStaticConstMacro(PRINCIPAL_MOMENTS, AttributeType, 109);
112 
114  itkStaticConstMacro(PRINCIPAL_AXES, AttributeType, 110);
115 
119  itkStaticConstMacro(ELONGATION, AttributeType, 111);
120 
122  itkStaticConstMacro(PERIMETER, AttributeType, 112);
123 
124  itkStaticConstMacro(ROUNDNESS, AttributeType, 113);
125 
129  itkStaticConstMacro(EQUIVALENT_SPHERICAL_RADIUS, AttributeType, 114);
130 
134  itkStaticConstMacro(EQUIVALENT_SPHERICAL_PERIMETER, AttributeType, 115);
135 
139  itkStaticConstMacro(EQUIVALENT_ELLIPSOID_DIAMETER, AttributeType, 116);
140 
141  itkStaticConstMacro(FLATNESS, AttributeType, 117);
142 
143  itkStaticConstMacro(PERIMETER_ON_BORDER_RATIO, AttributeType, 118);
144 
145  static AttributeType GetAttributeFromName(const std::string & s)
146  {
147  if ( s == "NumberOfPixels" )
148  {
149  return NUMBER_OF_PIXELS;
150  }
151  else if ( s == "PhysicalSize" )
152  {
153  return PHYSICAL_SIZE;
154  }
155  else if ( s == "Centroid" )
156  {
157  return CENTROID;
158  }
159  else if ( s == "BoundingBox" )
160  {
161  return BOUNDING_BOX;
162  }
163  else if ( s == "NumberOfPixelsOnBorder" )
164  {
166  }
167  else if ( s == "PerimeterOnBorder" )
168  {
169  return PERIMETER_ON_BORDER;
170  }
171  else if ( s == "FeretDiameter" )
172  {
173  return FERET_DIAMETER;
174  }
175  else if ( s == "PrincipalMoments" )
176  {
177  return PRINCIPAL_MOMENTS;
178  }
179  else if ( s == "PrincipalAxes" )
180  {
181  return PRINCIPAL_AXES;
182  }
183  else if ( s == "Elongation" )
184  {
185  return ELONGATION;
186  }
187  else if ( s == "Perimeter" )
188  {
189  return PERIMETER;
190  }
191  else if ( s == "Roundness" )
192  {
193  return ROUNDNESS;
194  }
195  else if ( s == "EquivalentSphericalRadius" )
196  {
198  }
199  else if ( s == "EquivalentSphericalPerimeter" )
200  {
202  }
203  else if ( s == "EquivalentEllipsoidDiameter" )
204  {
206  }
207  else if ( s == "Flatness" )
208  {
209  return FLATNESS;
210  }
211  else if ( s == "PerimeterOnBorderRatio" )
212  {
214  }
215  // can't recognize the name
217  }
218 
219  static std::string GetNameFromAttribute(const AttributeType & a)
220  {
221  std::string name;
222  switch ( a )
223  {
224  case NUMBER_OF_PIXELS:
225  name = "NumberOfPixels";
226  break;
227  case PHYSICAL_SIZE:
228  name = "PhysicalSize";
229  break;
230  case CENTROID:
231  name = "Centroid";
232  break;
233  case BOUNDING_BOX:
234  name = "BoundingBox";
235  break;
237  name = "NumberOfPixelsOnBorder";
238  break;
239  case PERIMETER_ON_BORDER:
240  name = "PerimeterOnBorder";
241  break;
242  case FERET_DIAMETER:
243  name = "FeretDiameter";
244  break;
245  case PRINCIPAL_MOMENTS:
246  name = "PrincipalMoments";
247  break;
248  case PRINCIPAL_AXES:
249  name = "PrincipalAxes";
250  break;
251  case ELONGATION:
252  name = "Elongation";
253  break;
254  case PERIMETER:
255  name = "Perimeter";
256  break;
257  case ROUNDNESS:
258  name = "Roundness";
259  break;
261  name = "EquivalentSphericalRadius";
262  break;
264  name = "EquivalentSphericalPerimeter";
265  break;
267  name = "EquivalentEllipsoidDiameter";
268  break;
269  case FLATNESS:
270  name = "Flatness";
271  break;
273  name = "PerimeterOnBorderRatio";
274  break;
275  default:
276  // can't recognize the name
278  break;
279  }
280  return name;
281  }
282 
284 
286 
288 
290 
291  const RegionType & GetBoundingBox() const
292  {
293  return m_BoundingBox;
294  }
295 
296  void SetBoundingBox(const RegionType & v)
297  {
298  m_BoundingBox = v;
299  }
300 
301  const double & GetPhysicalSize() const
302  {
303  return m_PhysicalSize;
304  }
305 
306  void SetPhysicalSize(const double & v)
307  {
308  m_PhysicalSize = v;
309  }
310 
312  {
313  return m_NumberOfPixels;
314  }
315 
317  {
318  m_NumberOfPixels = v;
319  }
320 
321  const CentroidType & GetCentroid() const
322  {
323  return m_Centroid;
324  }
325 
326  void SetCentroid(const CentroidType & centroid)
327  {
328  m_Centroid = centroid;
329  }
330 
332  {
334  }
335 
337  {
339  }
340 
341  const double & GetPerimeterOnBorder() const
342  {
343  return m_PerimeterOnBorder;
344  }
345 
346  void SetPerimeterOnBorder(const double & v)
347  {
349  }
350 
351  const double & GetFeretDiameter() const
352  {
353  return m_FeretDiameter;
354  }
355 
356  void SetFeretDiameter(const double & v)
357  {
358  m_FeretDiameter = v;
359  }
360 
362  {
363  return m_PrincipalMoments;
364  }
365 
367  {
368  m_PrincipalMoments = v;
369  }
370 
371  const MatrixType & GetPrincipalAxes() const
372  {
373  return m_PrincipalAxes;
374  }
375 
376  void SetPrincipalAxes(const MatrixType & v)
377  {
378  m_PrincipalAxes = v;
379  }
380 
381  const double & GetElongation() const
382  {
383  return m_Elongation;
384  }
385 
386  void SetElongation(const double & v)
387  {
388  m_Elongation = v;
389  }
390 
391  const double & GetPerimeter() const
392  {
393  return m_Perimeter;
394  }
395 
396  void SetPerimeter(const double & v)
397  {
398  m_Perimeter = v;
399  }
400 
401  const double & GetRoundness() const
402  {
403  return m_Roundness;
404  }
405 
406  void SetRoundness(const double & v)
407  {
408  m_Roundness = v;
409  }
410 
411  const double & GetEquivalentSphericalRadius() const
412  {
414  }
415 
416  void SetEquivalentSphericalRadius(const double & v)
417  {
419  }
420 
421  const double & GetEquivalentSphericalPerimeter() const
422  {
424  }
425 
426  void SetEquivalentSphericalPerimeter(const double & v)
427  {
429  }
430 
432  {
434  }
435 
437  {
439  }
440 
441  const double & GetFlatness() const
442  {
443  return m_Flatness;
444  }
445 
446  void SetFlatness(const double & v)
447  {
448  m_Flatness = v;
449  }
450 
451  const double & GetPerimeterOnBorderRatio() const
452  {
454  }
455 
456  void SetPerimeterOnBorderRatio(const double & v)
457  {
459  }
460 
461  // some helper methods - not really required, but really useful!
462 
466 
471  {
472  typename AffineTransformType::MatrixType matrix;
473  typename AffineTransformType::OffsetType offset;
474  for ( unsigned int i = 0; i < VImageDimension; i++ )
475  {
476  offset[i] = m_Centroid[i];
477  for ( unsigned int j = 0; j < VImageDimension; j++ )
478  {
479  matrix[j][i] = m_PrincipalAxes[i][j]; // Note the transposition
480  }
481  }
483 
485 
486  result->SetMatrix(matrix);
487  result->SetOffset(offset);
488 
489  return result;
490  }
491 
497  {
498  typename AffineTransformType::MatrixType matrix;
499  typename AffineTransformType::OffsetType offset;
500  for ( unsigned int i = 0; i < VImageDimension; i++ )
501  {
502  offset[i] = m_Centroid[i];
503  for ( unsigned int j = 0; j < VImageDimension; j++ )
504  {
505  matrix[j][i] = m_PrincipalAxes[i][j]; // Note the transposition
506  }
507  }
509 
511  result->SetMatrix(matrix);
512  result->SetOffset(offset);
513 
515  result->GetInverse(inverse);
516 
517  return inverse;
518  }
519 
520  template< typename TSourceLabelObject >
521  void CopyAttributesFrom( const TSourceLabelObject * src )
522  {
523  Superclass::template CopyAttributesFrom<TSourceLabelObject>(src);
524 
525  m_BoundingBox = src->GetBoundingBox();
526  m_NumberOfPixels = src->GetNumberOfPixels();
527  m_PhysicalSize = src->GetPhysicalSize();
528  m_Centroid = src->GetCentroid();
529  m_NumberOfPixelsOnBorder = src->GetNumberOfPixelsOnBorder();
530  m_PerimeterOnBorder = src->GetPerimeterOnBorder();
531  m_FeretDiameter = src->GetFeretDiameter();
532  m_PrincipalMoments = src->GetPrincipalMoments();
533  m_PrincipalAxes = src->GetPrincipalAxes();
534  m_Elongation = src->GetElongation();
535  m_Perimeter = src->GetPerimeter();
536  m_Roundness = src->GetRoundness();
537  m_EquivalentSphericalRadius = src->GetEquivalentSphericalRadius();
538  m_EquivalentSphericalPerimeter = src->GetEquivalentSphericalPerimeter();
539  m_EquivalentEllipsoidDiameter = src->GetEquivalentEllipsoidDiameter();
540  m_Flatness = src->GetFlatness();
541  m_PerimeterOnBorderRatio = src->GetPerimeterOnBorderRatio();
542  }
543 
544  template< typename TSourceLabelObject >
545  void CopyAllFrom(const TSourceLabelObject *src)
546  {
547  itkAssertOrThrowMacro ( ( src != ITK_NULLPTR ), "Null Pointer" );
548  this->template CopyLinesFrom<TSourceLabelObject>( src );
549  this->template CopyAttributesFrom<TSourceLabelObject>( src );
550  }
551 
552 protected:
554  {
555  m_NumberOfPixels = 0;
556  m_PhysicalSize = 0;
557  m_Centroid.Fill(0);
560  m_FeretDiameter = 0;
563  m_Elongation = 0;
564  m_Perimeter = 0;
565  m_Roundness = 0;
569  m_Flatness = 0;
571  }
572 
573  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
574  {
575  Superclass::PrintSelf(os, indent);
576 
577  os << indent << "NumberOfPixels: " << m_NumberOfPixels << std::endl;
578  os << indent << "PhysicalSize: " << m_PhysicalSize << std::endl;
579  os << indent << "Perimeter: " << m_Perimeter << std::endl;
580  os << indent << "NumberOfPixelsOnBorder: " << m_NumberOfPixelsOnBorder << std::endl;
581  os << indent << "PerimeterOnBorder: " << m_PerimeterOnBorder << std::endl;
582  os << indent << "PerimeterOnBorderRatio: " << m_PerimeterOnBorderRatio << std::endl;
583  os << indent << "Elongation: " << m_Elongation << std::endl;
584  os << indent << "Flatness: " << m_Flatness << std::endl;
585  os << indent << "Roundness: " << m_Roundness << std::endl;
586  os << indent << "Centroid: " << m_Centroid << std::endl;
587  os << indent << "BoundingBox: ";
588  m_BoundingBox.Print(os, indent);
589  os << indent << "EquivalentSphericalRadius: " << m_EquivalentSphericalRadius << std::endl;
590  os << indent << "EquivalentSphericalPerimeter: " << m_EquivalentSphericalPerimeter << std::endl;
591  os << indent << "EquivalentEllipsoidDiameter: " << m_EquivalentEllipsoidDiameter << std::endl;
592  os << indent << "PrincipalMoments: " << m_PrincipalMoments << std::endl;
593  os << indent << "PrincipalAxes: " << std::endl << m_PrincipalAxes;
594  os << indent << "FeretDiameter: " << m_FeretDiameter << std::endl;
595  }
596 
597 private:
598  ShapeLabelObject(const Self &) ITK_DELETE_FUNCTION;
599  void operator=(const Self &) ITK_DELETE_FUNCTION;
600 
610  double m_Elongation;
611  double m_Perimeter;
612  double m_Roundness;
616  double m_Flatness;
618 };
619 } // end namespace itk
620 
621 #endif
void SetPerimeter(const double &v)
Superclass::MatrixType MatrixType
Matrix< double, VImageDimension, VImageDimension > MatrixType
static const AttributeType PRINCIPAL_MOMENTS
Light weight base class for most itk classes.
static const AttributeType FERET_DIAMETER
void SetPhysicalSize(const double &v)
WeakPointer< const Self > ConstWeakPointer
Vector< double, VImageDimension > VectorType
Superclass::LengthType LengthType
Superclass::LabelObjectType LabelObjectType
static Pointer New()
Point< double, VImageDimension > CentroidType
void SetEquivalentEllipsoidDiameter(const VectorType &v)
static const AttributeType BOUNDING_BOX
const double & GetRoundness() const
void SetElongation(const double &v)
void SetCentroid(const CentroidType &centroid)
void SetEquivalentSphericalRadius(const double &v)
void SetBoundingBox(const RegionType &v)
static const unsigned int ImageDimension
void SetFlatness(const double &v)
An image region represents a structured region of data.
static const AttributeType PHYSICAL_SIZE
static AttributeType GetAttributeFromName(const std::string &s)
virtual void Print(std::ostream &os, Indent indent=0) const
LabelMap< Self > LabelMapType
static const AttributeType NUMBER_OF_PIXELS_ON_BORDER
void SetEquivalentSphericalPerimeter(const double &v)
static const AttributeType FLATNESS
SizeValueType m_NumberOfPixelsOnBorder
static const AttributeType PERIMETER_ON_BORDER_RATIO
Implements a weak reference to an object.
static const AttributeType CENTROID
const double & GetFlatness() const
LabelObjectLine< VImageDimension > LineType
void Fill(const ValueType &)
static const AttributeType NUMBER_OF_PIXELS
static const AttributeType EQUIVALENT_SPHERICAL_RADIUS
unsigned int AttributeType
static const AttributeType PRINCIPAL_AXES
Index< VImageDimension > IndexType
static std::string GetNameFromAttribute(const AttributeType &a)
void PrintSelf(std::ostream &os, Indent indent) const override
void SetNumberOfPixels(const SizeValueType &v)
Superclass::IndexType IndexType
void SetNumberOfPixelsOnBorder(const SizeValueType &v)
const double & GetPhysicalSize() const
void CopyAttributesFrom(const TSourceLabelObject *src)
LineType::LengthType LengthType
const CentroidType & GetCentroid() const
ImageRegion< VImageDimension > RegionType
LabelObject< TLabel, VImageDimension > Superclass
void SetRoundness(const double &v)
static const AttributeType EQUIVALENT_ELLIPSOID_DIAMETER
const VectorType & GetPrincipalMoments() const
Superclass::AttributeType AttributeType
Superclass::LineType LineType
AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform(void) const
virtual void PrintSelf(std::ostream &os, Indent indent) const override
static AttributeType GetAttributeFromName(const std::string &s)
const double & GetEquivalentSphericalPerimeter() const
const MatrixType & GetPrincipalAxes() const
A Label object to store the common attributes related to the shape of the object. ...
const double & GetFeretDiameter() const
const SizeValueType & GetNumberOfPixels() const
static const AttributeType PERIMETER
AffineTransformType::Pointer AffineTransformPointer
void SetPerimeterOnBorderRatio(const double &v)
const double & GetPerimeter() const
const double & GetEquivalentSphericalRadius() const
const VectorType & GetEquivalentEllipsoidDiameter() const
const double & GetPerimeterOnBorder() const
Superclass::OffsetType OffsetType
itk::SizeValueType SizeValueType
static const AttributeType PERIMETER_ON_BORDER
const double & GetElongation() const
The base class for the representation of an labeled binary object in an image.
static const AttributeType ROUNDNESS
const RegionType & GetBoundingBox() const
SmartPointer< const Self > ConstPointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void Fill(const T &value)
Definition: itkMatrix.h:185
VectorType m_EquivalentEllipsoidDiameter
void SetPrincipalMoments(const VectorType &v)
Templated n-dimensional image to store labeled objects.
Definition: itkLabelMap.h:70
void SetFeretDiameter(const double &v)
void SetPerimeterOnBorder(const double &v)
const SizeValueType & GetNumberOfPixelsOnBorder() const
void SetPrincipalAxes(const MatrixType &v)
const double & GetPerimeterOnBorderRatio() const
AffineTransform< double, VImageDimension > AffineTransformType
static std::string GetNameFromAttribute(const AttributeType &a)
static const AttributeType EQUIVALENT_SPHERICAL_PERIMETER
void CopyAllFrom(const TSourceLabelObject *src)
AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const
SmartPointer< Self > Pointer
static const AttributeType ELONGATION