18 #ifndef __itkPolygonSpatialObject_txx
19 #define __itkPolygonSpatialObject_txx
27 template <
unsigned int TDimension >
32 if (Self::ObjectDimension == 2)
41 typename PointListType::const_iterator it = points.begin();
42 typename PointListType::const_iterator itend = points.end();
45 for(i = 0; i < 3; i++)
47 max[i] = NumericTraits<double>::NonpositiveMin();
48 min[i] = NumericTraits<double>::max();
53 for(i = 0; i < 3; i++)
55 if(min[i] > curpoint[i]) min[i] = curpoint[i];
56 if(max[i] < curpoint[i]) max[i] = curpoint[i];
60 if(min[0] == max[0] && min[1] != max[1] && min[2] != max[2])
64 else if(min[0] != max[0] && min[1] == max[1] && min[2] != max[2])
68 else if(min[0] != max[0] && min[1] != max[1] && min[2] == max[2])
79 template <
unsigned int TDimension >
85 typename PointListType::const_iterator it = points.begin();
86 typename PointListType::const_iterator itend = points.end();
88 return (*it).GetPosition() == (*itend).GetPosition();
91 template <
unsigned int TDimension >
96 return (this->GetPoints()).size();
99 template <
unsigned int TDimension >
105 typename PointListType::const_iterator it = points.begin();
106 typename PointListType::const_iterator itend = points.end();
107 double distance = NumericTraits<double>::max();
113 "PolygonSpatialObject: ClosestPoint called using an empty point list");
118 closestPoint.Fill(0.0);
122 = (*it).GetPosition();
124 if(curdistance < distance)
126 closestPoint = (*it).GetPosition();
127 distance = curdistance;
134 template <
unsigned int TDimension >
145 int numpoints = this->NumberOfPoints();
151 switch(this->Plane())
168 typename PointListType::const_iterator it = points.begin();
170 for(
int i = 0; i < numpoints; i++)
175 if(i == numpoints - 1)
181 b = (*it).GetPosition();
189 area += a[X] * b[Y] - a[Y] * b[X];
192 return area < 0.0 ? -area : area;
195 template <
unsigned int TDimension >
200 return m_Thickness * this->MeasureArea();
203 template <
unsigned int TDimension >
208 double perimeter = 0.0;
209 int numpoints = this->NumberOfPoints();
216 typename PointListType::const_iterator it = points.begin();
219 for(
int i = 0; i < numpoints; i++)
224 if(i == numpoints - 1)
230 b = (*it).GetPosition();
238 double curdistance = a.EuclideanDistanceTo(b);
239 perimeter += curdistance;
244 template <
unsigned int TDimension >
251 typename PointListType::iterator it = points.begin();
252 typename PointListType::iterator itend = points.end();
263 if(curpos == pointToDelete)
273 template <
unsigned int TDimension >
280 this->GetPoints().push_back(newPoint);
284 template <
unsigned int TDimension >
291 typename PointListType::iterator it = points.begin();
292 typename PointListType::iterator itend = points.end();
295 this->AddPoint(pointToAdd);
306 typename PointListType::iterator after = it;
310 points.insert(after,1,newPoint);
318 template <
unsigned int TDimension >
323 if (oldpoint == newPoint)
328 typename PointListType::iterator it = points.begin();
329 typename PointListType::iterator itend = points.end();
332 this->AddPoint(newPoint);
341 if(curpos == oldpoint)
343 typename PointListType::iterator after = it;
347 points.insert(after,1,newBlobPoint);
356 template <
unsigned int TDimension >
362 typename PointListType::iterator it = points.begin();
363 typename PointListType::iterator itend = points.end();
364 typename PointListType::iterator first;
365 typename PointListType::iterator last;
377 if(curpos == startPoint)
384 else if(foundcount > 0 && curpos == endPoint)
400 points.erase(first,points.erase(last));
404 template <
unsigned int TDimension >
409 return this->IsInside(point, 0,
NULL);
412 template <
unsigned int TDimension >
417 int numpoints = this->NumberOfPoints();
423 switch( this->Plane() )
440 if( !this->SetInternalInverseTransformToWorldToIndexTransform() )
446 this->GetInternalInverseTransform()->TransformPoint(point);
449 typename PointListType::const_iterator it = points.begin();
450 typename PointListType::const_iterator itend = points.end();
457 if( this->IsClosed() )
462 bool oddNodes =
false;
467 for(
int i = 0; i < numpoints; i++)
469 node1 = (*it).GetPosition();
471 if(i == numpoints - 1)
477 node2 = (*it).GetPosition();
480 const double x = transformedPoint[X];
481 const double y = transformedPoint[Y];
483 if((node1[Y] < y && node2[Y] >= y) ||
484 (node2[Y] < y && node1[Y] >= y))
486 if( node1[X] + (y - node1[Y])/
487 (node2[Y] - node1[Y]) * (node2[X] - node1[X]) < x )
489 oddNodes = !oddNodes;
497 template <
unsigned int TDimension >
502 Superclass::PrintSelf( os, indent );
503 os << indent << m_Thickness << std::endl;