18 #ifndef __otbImageFittingPolygonListFilter_txx
19 #define __otbImageFittingPolygonListFilter_txx
31 template <
class TPath,
class TImage>
35 this->SetNumberOfRequiredInputs(2);
36 this->SetNumberOfInputs(2);
38 m_NumberOfIterations = 1;
41 template <
class TPath,
class TImage>
49 template <
class TPath,
class TImage>
55 if (this->GetNumberOfInputs() < 1)
65 template <
class TPath,
class TImage>
75 typename ImageType::RegionType regionLargest = inputImagePtr->GetLargestPossibleRegion();
79 typename ImageType::SizeType size;
80 size[0] = 2 * m_Radius + 1;
81 size[1] = 2 * m_Radius + 1;
82 typename ImageType::RegionType region;
84 typename ImageType::IndexType start;
88 while (it != inputPtr->
End())
91 if (polygon->GetVertexList()->Size() > 2)
93 for (
unsigned int iteration = 0; iteration < m_NumberOfIterations; ++iteration)
104 while (vertexIt != polygon->GetVertexList()->End())
112 start[0] =
static_cast<long int>(currentPoint[0] - m_Radius);
113 start[1] =
static_cast<long int>(currentPoint[1] - m_Radius);
114 region.SetIndex(start);
115 region.Crop(inputImagePtr->GetLargestPossibleRegion());
117 NeighborhoodIteratorType nIt(inputImagePtr, region);
118 double maxValue = 0.0;
121 while (!nIt.IsAtEnd())
123 if (regionLargest.IsInside(nIt.GetIndex()))
126 double currentValue = computeValue(inputImagePtr, middlePoint, previousPoint, nextPoint);
127 if (currentValue > maxValue)
129 maxValue = currentValue;
130 maxPoint = middlePoint;
135 currentPoint = maxPoint;
136 newPolygon->AddVertex(maxPoint);
141 previousPoint = currentPoint;
142 currentPoint = nextPoint;
152 start[0] =
static_cast<long int>(currentPoint[0] - m_Radius);
153 start[1] =
static_cast<long int>(currentPoint[1] - m_Radius);
154 region.SetIndex(start);
156 NeighborhoodIteratorType nIt(inputImagePtr, region);
157 double maxValue = 0.0;
161 while (!nIt.IsAtEnd())
163 if (regionLargest.IsInside(nIt.GetIndex()))
166 double currentValue = computeValue(inputImagePtr, middlePoint, previousPoint, nextPoint);
167 if (currentValue > maxValue)
169 maxValue = currentValue;
170 maxPoint = middlePoint;
175 currentPoint = maxPoint;
176 newPolygon->AddVertex(maxPoint);
180 previousPoint = currentPoint;
181 currentPoint = firstPoint;
182 vertexIt = newPolygon->GetVertexList()->Begin();
183 nextPoint = vertexIt.Value();
190 start[0] =
static_cast<long int>(currentPoint[0] - m_Radius);
191 start[1] =
static_cast<long int>(currentPoint[1] - m_Radius);
192 region.SetIndex(start);
194 NeighborhoodIteratorType nIt(inputImagePtr, region);
195 double maxValue = 0.0;
198 while (!nIt.IsAtEnd())
200 if (regionLargest.IsInside(nIt.GetIndex()))
203 double currentValue = computeValue(inputImagePtr, middlePoint, previousPoint, nextPoint);
204 if (currentValue > maxValue)
206 maxValue = currentValue;
207 maxPoint = middlePoint;
212 currentPoint = maxPoint;
213 newPolygon->AddVertex(maxPoint);
217 polygon = newPolygon;
227 template <
class TPath,
class TImage>
233 typedef typename ImageType::IndexType IndexType;
234 IndexType middleIndex;
235 IndexType previousIndex;
237 middleIndex[0] =
static_cast<long int>(middlePoint[0]);
238 middleIndex[1] =
static_cast<long int>(middlePoint[1]);
239 previousIndex[0] =
static_cast<long int>(previousPoint[0]);
240 previousIndex[1] =
static_cast<long int>(previousPoint[1]);
241 nextIndex[0] =
static_cast<long int>(nextPoint[0]);
242 nextIndex[1] =
static_cast<long int>(nextPoint[1]);
243 double currentValue = 0.0;
244 unsigned int count = 0;
249 currentValue += itLineFirst.
Get();
256 while (!itLineSecond.
IsAtEnd())
258 currentValue += itLineSecond.
Get();
263 return currentValue / count;
269 template <
class TPath,
class TImage>
274 Superclass::PrintSelf(os, indent);