21 #ifndef otbImageFittingPolygonListFilter_hxx
22 #define otbImageFittingPolygonListFilter_hxx
26 #include "itkImageRegionConstIteratorWithIndex.h"
33 template <
class TPath,
class TImage>
36 this->SetNumberOfRequiredInputs(2);
37 this->SetNumberOfRequiredInputs(2);
39 m_NumberOfIterations = 1;
43 template <
class TPath,
class TImage>
46 this->itk::ProcessObject::SetNthInput(1,
const_cast<ImageType*
>(image));
49 template <
class TPath,
class TImage>
52 if (this->GetNumberOfInputs() < 1)
56 return static_cast<const ImageType*
>(this->itk::ProcessObject::GetInput(1));
62 template <
class TPath,
class TImage>
70 typename ImageType::RegionType regionLargest = inputImagePtr->GetLargestPossibleRegion();
72 typedef itk::ImageRegionConstIteratorWithIndex<ImageType> NeighborhoodIteratorType;
74 typename ImageType::SizeType size;
75 size[0] = 2 * m_Radius + 1;
76 size[1] = 2 * m_Radius + 1;
77 typename ImageType::RegionType region;
79 typename ImageType::IndexType start;
83 while (it != inputPtr->
End())
86 if (polygon->GetVertexList()->Size() > 2)
88 for (
unsigned int iteration = 0; iteration < m_NumberOfIterations; ++iteration)
99 while (vertexIt != polygon->GetVertexList()->End())
107 start[0] =
static_cast<long int>(currentPoint[0] - m_Radius);
108 start[1] =
static_cast<long int>(currentPoint[1] - m_Radius);
109 region.SetIndex(start);
110 region.Crop(inputImagePtr->GetLargestPossibleRegion());
112 NeighborhoodIteratorType nIt(inputImagePtr, region);
113 double maxValue = 0.0;
116 while (!nIt.IsAtEnd())
118 if (regionLargest.IsInside(nIt.GetIndex()))
121 double currentValue = computeValue(inputImagePtr, middlePoint, previousPoint, nextPoint);
122 if (currentValue > maxValue)
124 maxValue = currentValue;
125 maxPoint = middlePoint;
130 currentPoint = maxPoint;
131 newPolygon->AddVertex(maxPoint);
136 previousPoint = currentPoint;
137 currentPoint = nextPoint;
146 start[0] =
static_cast<long int>(currentPoint[0] - m_Radius);
147 start[1] =
static_cast<long int>(currentPoint[1] - m_Radius);
148 region.SetIndex(start);
151 NeighborhoodIteratorType nIt(inputImagePtr, region);
152 double maxValue = 0.0;
156 while (!nIt.IsAtEnd())
158 if (regionLargest.IsInside(nIt.GetIndex()))
161 double currentValue = computeValue(inputImagePtr, middlePoint, previousPoint, nextPoint);
162 if (currentValue > maxValue)
164 maxValue = currentValue;
165 maxPoint = middlePoint;
170 currentPoint = maxPoint;
171 newPolygon->AddVertex(maxPoint);
175 previousPoint = currentPoint;
176 currentPoint = firstPoint;
177 vertexIt = newPolygon->GetVertexList()->Begin();
178 nextPoint = vertexIt.Value();
185 start[0] =
static_cast<long int>(currentPoint[0] - m_Radius);
186 start[1] =
static_cast<long int>(currentPoint[1] - m_Radius);
187 region.SetIndex(start);
189 NeighborhoodIteratorType nIt(inputImagePtr, region);
190 double maxValue = 0.0;
193 while (!nIt.IsAtEnd())
195 if (regionLargest.IsInside(nIt.GetIndex()))
198 double currentValue = computeValue(inputImagePtr, middlePoint, previousPoint, nextPoint);
199 if (currentValue > maxValue)
201 maxValue = currentValue;
202 maxPoint = middlePoint;
207 currentPoint = maxPoint;
208 newPolygon->AddVertex(maxPoint);
212 polygon = newPolygon;
222 template <
class TPath,
class TImage>
226 typedef typename ImageType::IndexType IndexType;
227 IndexType middleIndex;
228 IndexType previousIndex;
230 middleIndex[0] =
static_cast<long int>(middlePoint[0]);
231 middleIndex[1] =
static_cast<long int>(middlePoint[1]);
232 previousIndex[0] =
static_cast<long int>(previousPoint[0]);
233 previousIndex[1] =
static_cast<long int>(previousPoint[1]);
234 nextIndex[0] =
static_cast<long int>(nextPoint[0]);
235 nextIndex[1] =
static_cast<long int>(nextPoint[1]);
236 double currentValue = 0.0;
237 unsigned int count = 0;
240 while (!itLineFirst.IsAtEnd())
242 currentValue += itLineFirst.Get();
249 while (!itLineSecond.IsAtEnd())
251 currentValue += itLineSecond.Get();
256 return currentValue / count;
262 template <
class TPath,
class TImage>
265 Superclass::PrintSelf(os, indent);