/usr/include/InsightToolkit/Review/itkShapeLabelObject.h is in libinsighttoolkit3-dev 3.20.1+git20120521-6build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkShapeLabelObject.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkShapeLabelObject_h
#define __itkShapeLabelObject_h
#include "itkLabelObject.h"
#include "itkLabelMap.h"
#include "itkAffineTransform.h"
#include "itkMatrix.h"
namespace itk
{
/** \class ShapeLabelObject
* \brief A Label object to store the common attributes related to the shape of the object
*
* ShapeLabelObject stores the common attributes related to the shape of the object
*
* \author Gaetan Lehmann. Biologie du Developpement et de la Reproduction, INRA de Jouy-en-Josas, France.
*
* This implementation was taken from the Insight Journal paper:
* http://hdl.handle.net/1926/584 or
* http://www.insight-journal.org/browse/publication/176
*
* \ingroup DataRepresentation
*/
template < class TLabel, unsigned int VImageDimension >
class ITK_EXPORT ShapeLabelObject : public LabelObject< TLabel, VImageDimension >
{
public:
/** Standard class typedefs */
typedef ShapeLabelObject Self;
typedef LabelObject< TLabel, VImageDimension > Superclass;
typedef typename Superclass::LabelObjectType LabelObjectType;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
typedef WeakPointer<const Self> ConstWeakPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(ShapeLabelObject, LabelObject);
typedef LabelMap< Self > LabelMapType;
itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
typedef typename Superclass::IndexType IndexType;
typedef TLabel LabelType;
typedef typename Superclass::LineType LineType;
typedef typename Superclass::LengthType LengthType;
typedef typename Superclass::LineContainerType LineContainerType;
typedef typename Superclass::AttributeType AttributeType;
itkStaticConstMacro(SIZE, AttributeType, 100);
itkStaticConstMacro(PHYSICAL_SIZE, AttributeType, 101);
itkStaticConstMacro(REGION_ELONGATION, AttributeType, 102);
itkStaticConstMacro(SIZE_REGION_RATIO, AttributeType, 103);
itkStaticConstMacro(CENTROID, AttributeType, 104);
itkStaticConstMacro(REGION, AttributeType, 105);
itkStaticConstMacro(SIZE_ON_BORDER, AttributeType, 106);
itkStaticConstMacro(PHYSICAL_SIZE_ON_BORDER, AttributeType, 107);
itkStaticConstMacro(FERET_DIAMETER, AttributeType, 108);
itkStaticConstMacro(BINARY_PRINCIPAL_MOMENTS, AttributeType, 109);
itkStaticConstMacro(BINARY_PRINCIPAL_AXES, AttributeType, 110);
itkStaticConstMacro(BINARY_ELONGATION, AttributeType, 111);
itkStaticConstMacro(PERIMETER, AttributeType, 112);
itkStaticConstMacro(ROUNDNESS, AttributeType, 113);
itkStaticConstMacro(EQUIVALENT_RADIUS, AttributeType, 114);
itkStaticConstMacro(EQUIVALENT_PERIMETER, AttributeType, 115);
itkStaticConstMacro(EQUIVALENT_ELLIPSOID_RADIUS, AttributeType, 116);
itkStaticConstMacro(BINARY_FLATNESS, AttributeType, 117);
static AttributeType GetAttributeFromName( const std::string & s )
{
if( s == "Size" )
{
return SIZE;
}
else if( s == "PhysicalSize" )
{
return PHYSICAL_SIZE;
}
else if( s == "RegionElongation" )
{
return REGION_ELONGATION;
}
else if( s == "SizeRegionRatio" )
{
return SIZE_REGION_RATIO;
}
else if( s == "Centroid" )
{
return CENTROID;
}
else if( s == "Region" )
{
return REGION;
}
else if( s == "SizeOnBorder" )
{
return SIZE_ON_BORDER;
}
else if( s == "PhysicalSizeOnBorder" )
{
return PHYSICAL_SIZE_ON_BORDER;
}
else if( s == "FeretDiameter" )
{
return FERET_DIAMETER;
}
else if( s == "BinaryPrincipalMoments" )
{
return BINARY_PRINCIPAL_MOMENTS;
}
else if( s == "BinaryPrincipalAxes" )
{
return BINARY_PRINCIPAL_AXES;
}
else if( s == "BinaryElongation" )
{
return BINARY_ELONGATION;
}
else if( s == "Perimeter" )
{
return PERIMETER;
}
else if( s == "Roundness" )
{
return ROUNDNESS;
}
else if( s == "EquivalentRadius" )
{
return EQUIVALENT_RADIUS;
}
else if( s == "EquivalentPerimeter" )
{
return EQUIVALENT_PERIMETER;
}
else if( s == "EquivalentEllipsoidSize" )
{
return EQUIVALENT_ELLIPSOID_RADIUS;
}
else if( s == "BinaryFlatness" )
{
return BINARY_FLATNESS;
}
// can't recognize the name
return Superclass::GetAttributeFromName( s );
}
static std::string GetNameFromAttribute( const AttributeType & a )
{
switch( a )
{
case SIZE:
return "Size";
break;
case PHYSICAL_SIZE:
return "PhysicalSize";
break;
case REGION_ELONGATION:
return "RegionElongation";
break;
case SIZE_REGION_RATIO:
return "SizeRegionRatio";
break;
case CENTROID:
return "Centroid";
case REGION:
return "Region";
break;
case SIZE_ON_BORDER:
return "SizeOnBorder";
break;
case PHYSICAL_SIZE_ON_BORDER:
return "PhysicalSizeOnBorder";
break;
case FERET_DIAMETER:
return "FeretDiameter";
break;
case BINARY_PRINCIPAL_MOMENTS:
return "BinaryPrincipalMoments";
break;
case BINARY_PRINCIPAL_AXES:
return "BinaryPrincipalAxes";
break;
case BINARY_ELONGATION:
return "BinaryElongation";
break;
case PERIMETER:
return "Perimeter";
break;
case ROUNDNESS:
return "Roundness";
break;
case EQUIVALENT_RADIUS:
return "EquivalentRadius";
break;
case EQUIVALENT_PERIMETER:
return "EquivalentPerimeter";
break;
case EQUIVALENT_ELLIPSOID_RADIUS:
return "EquivalentEllipsoidSize";
break;
case BINARY_FLATNESS:
return "BinaryFlatness";
break;
}
// can't recognize the name
return Superclass::GetNameFromAttribute( a );
}
typedef ImageRegion< VImageDimension > RegionType;
typedef Point<double, VImageDimension> CentroidType;
typedef Matrix< double, VImageDimension, VImageDimension > MatrixType;
typedef Vector< double, VImageDimension > VectorType;
const RegionType & GetRegion() const
{
return m_Region;
}
void SetRegion( const RegionType & v )
{
m_Region = v;
}
const double & GetPhysicalSize() const
{
return m_PhysicalSize;
}
void SetPhysicalSize( const double & v )
{
m_PhysicalSize = v;
}
const unsigned long & GetSize() const
{
return m_Size;
}
void SetSize( const unsigned long & v )
{
m_Size = v;
}
const CentroidType & GetCentroid() const
{
return m_Centroid;
}
void SetCentroid( const CentroidType & centroid )
{
m_Centroid = centroid;
}
const double & GetRegionElongation() const
{
return m_RegionElongation;
}
void SetRegionElongation( const double & v )
{
m_RegionElongation = v;
}
const double & GetSizeRegionRatio() const
{
return m_SizeRegionRatio;
}
void SetSizeRegionRatio( const double & v )
{
m_SizeRegionRatio = v;
}
const unsigned long & GetSizeOnBorder() const
{
return m_SizeOnBorder;
}
void SetSizeOnBorder( const unsigned long & v )
{
m_SizeOnBorder = v;
}
const double & GetPhysicalSizeOnBorder() const
{
return m_PhysicalSizeOnBorder;
}
void SetPhysicalSizeOnBorder( const double & v )
{
m_PhysicalSizeOnBorder = v;
}
const double & GetFeretDiameter() const
{
return m_FeretDiameter;
}
void SetFeretDiameter( const double & v )
{
m_FeretDiameter = v;
}
const VectorType & GetBinaryPrincipalMoments() const
{
return m_BinaryPrincipalMoments;
}
void SetBinaryPrincipalMoments( const VectorType & v )
{
m_BinaryPrincipalMoments = v;
}
const MatrixType & GetBinaryPrincipalAxes() const
{
return m_BinaryPrincipalAxes;
}
void SetBinaryPrincipalAxes( const MatrixType & v )
{
m_BinaryPrincipalAxes = v;
}
const double & GetBinaryElongation() const
{
return m_BinaryElongation;
}
void SetBinaryElongation( const double & v )
{
m_BinaryElongation = v;
}
const double & GetPerimeter() const
{
return m_Perimeter;
}
void SetPerimeter( const double & v )
{
m_Perimeter = v;
}
const double & GetRoundness() const
{
return m_Roundness;
}
void SetRoundness( const double & v )
{
m_Roundness = v;
}
const double & GetEquivalentRadius() const
{
return m_EquivalentRadius;
}
void SetEquivalentRadius( const double & v )
{
m_EquivalentRadius = v;
}
const double & GetEquivalentPerimeter() const
{
return m_EquivalentPerimeter;
}
void SetEquivalentPerimeter( const double & v )
{
m_EquivalentPerimeter = v;
}
const VectorType & GetEquivalentEllipsoidSize() const
{
return m_EquivalentEllipsoidSize;
}
void SetEquivalentEllipsoidSize( const VectorType & v )
{
m_EquivalentEllipsoidSize = v;
}
const double & GetBinaryFlatness() const
{
return m_BinaryFlatness;
}
void SetBinaryFlatness( const double & v )
{
m_BinaryFlatness = v;
}
// some helper methods - not really required, but really useful!
/** Affine transform for mapping to and from principal axis */
typedef AffineTransform<double,VImageDimension> AffineTransformType;
typedef typename AffineTransformType::Pointer AffineTransformPointer;
/** Get the affine transform from principal axes to physical axes
* This method returns an affine transform which transforms from
* the principal axes coordinate system to physical coordinates. */
AffineTransformPointer GetBinaryPrincipalAxesToPhysicalAxesTransform() const
{
typename AffineTransformType::MatrixType matrix;
typename AffineTransformType::OffsetType offset;
for (unsigned int i = 0; i < VImageDimension; i++)
{
offset[i] = m_Centroid[i];
for (unsigned int j = 0; j < VImageDimension; j++)
{
matrix[j][i] = m_BinaryPrincipalAxes[i][j]; // Note the transposition
}
}
AffineTransformPointer result = AffineTransformType::New();
result->SetMatrix(matrix);
result->SetOffset(offset);
return result;
}
/** Get the affine transform from physical axes to principal axes
* This method returns an affine transform which transforms from
* the physical coordinate system to the principal axes coordinate
* system. */
AffineTransformPointer GetPhysicalAxesToBinaryPrincipalAxesTransform(void) const
{
typename AffineTransformType::MatrixType matrix;
typename AffineTransformType::OffsetType offset;
for (unsigned int i = 0; i < VImageDimension; i++)
{
offset[i] = m_Centroid[i];
for (unsigned int j = 0; j < VImageDimension; j++)
{
matrix[j][i] = m_BinaryPrincipalAxes[i][j]; // Note the transposition
}
}
AffineTransformPointer result = AffineTransformType::New();
result->SetMatrix(matrix);
result->SetOffset(offset);
AffineTransformPointer inverse = AffineTransformType::New();
result->GetInverse(inverse);
return inverse;
}
virtual void CopyAttributesFrom( const LabelObjectType * lo )
{
Superclass::CopyAttributesFrom( lo );
// copy the data of the current type if possible
const Self * src = dynamic_cast<const Self *>( lo );
if( src == NULL )
{
return;
}
m_Region = src->m_Region;
m_Size = src->m_Size;
m_PhysicalSize = src->m_PhysicalSize;
m_Centroid = src->m_Centroid;
m_RegionElongation = src->m_RegionElongation;
m_SizeRegionRatio = src->m_SizeRegionRatio;
m_SizeOnBorder = src->m_SizeOnBorder;
m_PhysicalSizeOnBorder = src->m_PhysicalSizeOnBorder;
m_FeretDiameter = src->m_FeretDiameter;
m_BinaryPrincipalMoments = src->m_BinaryPrincipalMoments;
m_BinaryPrincipalAxes = src->m_BinaryPrincipalAxes;
m_BinaryElongation = src->m_BinaryElongation;
m_Perimeter = src->m_Perimeter;
m_Roundness = src->m_Roundness;
m_EquivalentRadius = src->m_EquivalentRadius;
m_EquivalentPerimeter = src->m_EquivalentPerimeter;
m_EquivalentEllipsoidSize = src->m_EquivalentEllipsoidSize;
m_BinaryFlatness = src->m_BinaryFlatness;
}
protected:
ShapeLabelObject()
{
m_Size = 0;
m_PhysicalSize = 0;
m_Centroid.Fill(0);
m_RegionElongation = 0;
m_SizeRegionRatio = 0;
m_SizeOnBorder = false;
m_PhysicalSizeOnBorder = 0;
m_FeretDiameter = false;
m_BinaryPrincipalMoments.Fill(0);
m_BinaryPrincipalAxes.Fill(0);
m_BinaryElongation = 0;
m_Perimeter = 0;
m_Roundness = 0;
m_EquivalentRadius = 0;
m_EquivalentPerimeter = 0;
m_EquivalentEllipsoidSize.Fill(0);
m_BinaryFlatness = 0;
}
void PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf( os, indent );
os << indent << "Centroid: " << m_Centroid << std::endl;
os << indent << "Region: ";
m_Region.Print( os, indent );
os << indent << "PhysicalSize: " << m_PhysicalSize << std::endl;
os << indent << "Size: " << m_Size << std::endl;
os << indent << "RegionElongation: " << m_RegionElongation << std::endl;
os << indent << "SizeRegionRatio: " << m_SizeRegionRatio << std::endl;
os << indent << "SizeOnBorder: " << m_SizeOnBorder << std::endl;
os << indent << "PhysicalSizeOnBorder: " << m_PhysicalSizeOnBorder << std::endl;
os << indent << "FeretDiameter: " << m_FeretDiameter << std::endl;
os << indent << "BinaryPrincipalMoments: " << m_BinaryPrincipalMoments << std::endl;
os << indent << "BinaryPrincipalAxes: " << std::endl << m_BinaryPrincipalAxes;
os << indent << "BinaryElongation: " << m_BinaryElongation << std::endl;
os << indent << "BinaryFlatness: " << m_BinaryFlatness << std::endl;
os << indent << "Perimeter: " << m_Perimeter << std::endl;
os << indent << "Roundness: " << m_Roundness << std::endl;
os << indent << "EquivalentRadius: " << m_EquivalentRadius << std::endl;
os << indent << "EquivalentPerimeter: " << m_EquivalentPerimeter << std::endl;
os << indent << "EquivalentEllipsoidSize: " << m_EquivalentEllipsoidSize << std::endl;
}
private:
ShapeLabelObject(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
RegionType m_Region;
unsigned long m_Size;
double m_PhysicalSize;
CentroidType m_Centroid;
double m_RegionElongation;
double m_SizeRegionRatio;
unsigned long m_SizeOnBorder;
double m_PhysicalSizeOnBorder;
double m_FeretDiameter;
VectorType m_BinaryPrincipalMoments;
MatrixType m_BinaryPrincipalAxes;
double m_BinaryElongation;
double m_Perimeter;
double m_Roundness;
double m_EquivalentRadius;
double m_EquivalentPerimeter;
VectorType m_EquivalentEllipsoidSize;
double m_BinaryFlatness;
};
} // end namespace itk
#endif
|