18 #ifndef __otbPolygonListToRCC8GraphFilter_txx
19 #define __otbPolygonListToRCC8GraphFilter_txx
29 template <
class TPolygonList,
class TOutputGraph>
33 this->SetNumberOfRequiredInputs(1);
34 m_Optimisation =
false;
35 m_UseInverted =
false;
40 template <
class TPolygonList,
class TOutputGraph>
45 template <
class TPolygonList,
class TOutputGraph>
52 const_cast<PolygonListType *>(input));
55 template <
class TPolygonList,
class TOutputGraph>
60 if (this->GetNumberOfInputs() < 1)
65 return static_cast<const TPolygonList *
>
69 template <
class TPolygonList,
class TOutputGraph>
74 return m_Accumulator[val];
77 template <
class TPolygonList,
class TOutputGraph>
82 unsigned int result = 0;
83 for (
unsigned int i = 0; i < 8; ++i)
85 result += m_Accumulator[i];
90 template <
class TPolygonList,
class TOutputGraph>
100 m_Accumulator[4] = 0;
101 m_Accumulator[5] = 0;
102 m_Accumulator[6] = 0;
103 m_Accumulator[7] = 0;
107 const int knowledge[8][8]
109 { {-3, -2, -2, -2, 0, -2, 0, 0}, {-1, -3, -2, -3, -1, -3, 0, 1}, {-1, -1, -3, -3, -1, -3, -1, 2}, { 0, -1, -2, -3, -3, 5, -1, 3}, {-1, -1, -1, -3, -1, -3, 6, 4}, { 0, 0, -2, 5, -2, 5, -3, 5}, {-1, -1, -1, -1, 6, -3, 6, 6}, { 0, 1, 2, 3, 4, 5, 6, 7}
121 int value = knowledge[r1][r2];
128 else if (value == -1)
133 else if (value == -2)
147 template <
class TPolygonList,
class TOutputGraph>
155 this->BeforeThreadedGenerateData();
163 m_EdgesPerThread =
EdgeMapVectorType(this->GetNumberOfThreads(), defaultEdgeMap);
166 this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads());
167 this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str);
170 this->GetMultiThreader()->SingleMethodExecute();
174 this->AfterThreadedGenerateData();
177 template <
class TPolygonList,
class TOutputGraph>
187 graph->SetNumberOfVertices(inputPtr->Size());
191 unsigned int nbVertices = 0;
193 typedef typename PolygonListType::ConstIterator PolygonListConstIteratorType;
196 for (PolygonListConstIteratorType it = inputPtr->Begin();
197 it != inputPtr->End(); ++it)
202 vertex->SetPath(it.Get());
206 unsigned int segIndex = 1;
208 while (segIndex < m_SegmentationRanges.size() &&
209 (nbVertices < m_SegmentationRanges[segIndex - 1] || nbVertices >= m_SegmentationRanges[segIndex]))
214 vertex->SetSegmentationLevel(segIndex - 1);
217 graph->SetVertex(nbVertices, vertex);
223 template <
class TPolygonList,
class TOutputGraph>
238 unsigned int nbVertices = graph->GetNumberOfVertices();
241 otbMsgDevMacro(<<
"Adjacency matrix size: " << nbVertices * nbVertices);
246 unsigned int count = 0;
253 if ((count >= startIndex) && (count < stopIndex))
263 calc->SetPolygon1(vIt1.
Get()->GetPath());
264 calc->SetPolygon2(vIt2.
Get()->GetPath());
279 while (!inIt1.IsAtEnd() && (know.first != FULL))
281 betweenIndex = inIt1.GetSourceIndex();
283 bool edgeFound =
false;
284 while (!inIt2.IsAtEnd() && (know.first != FULL))
288 if (inIt2.GetSourceIndex() == betweenIndex)
294 know = GetKnowledge(invert[inIt1.GetValue()], inIt2.GetValue());
295 calc->SetLevel1APrioriKnowledge(know.first == LEVEL_1);
296 calc->SetLevel3APrioriKnowledge(know.first == LEVEL_3);
306 know = GetKnowledge(invert[inIt1.GetValue()],
OTB_RCC8_DC);
307 calc->SetLevel1APrioriKnowledge(know.first == LEVEL_1);
308 calc->SetLevel3APrioriKnowledge(know.first == LEVEL_3);
314 if (know.first == FULL)
324 value = calc->GetValue();
332 value = calc->GetValue();
334 m_Accumulator[value] += 1;
335 m_Accumulator[invert[value]] += 1;
368 template <
class TPolygonList,
class TOutputGraph>
381 for (
typename EdgeMapVectorType::iterator vIt = m_EdgesPerThread.begin();
382 vIt != m_EdgesPerThread.end(); ++vIt)
384 for (
typename EdgeMapType::iterator mIt = (*vIt).begin();
385 mIt != (*vIt).end(); ++mIt)
387 globalEdgeMap[mIt->first] = mIt->second;
392 for (
typename EdgeMapType::iterator mIt = globalEdgeMap.begin();
393 mIt != globalEdgeMap.end(); ++mIt)
395 graph->AddEdge(mIt->first.first, mIt->first.second, mIt->second);
403 template <
class TPolygonList,
class TOutputGraph>
409 int threadId, threadCount;
410 unsigned int total, start, stop;
416 total = str->
Filter->GetOutput()->GetNumberOfVertices();
418 if (threadId < static_cast<int>(total))
423 static_cast<unsigned int>(vcl_floor(total *
424 vcl_sqrt(static_cast<double>(threadId) /
425 static_cast<double>(threadCount)) + 0.5));
427 static_cast<unsigned int>(vcl_floor(total *
428 vcl_sqrt(static_cast<double>(threadId +
429 1) / static_cast<double>(threadCount)) + 0.5));
430 if (stop > total) stop = total;
436 str->
Filter->ThreadedGenerateData(start, stop, threadId);
449 template <
class TPolygonList,
class TOutputGraph>
454 Superclass::PrintSelf(os, indent);