21 #ifndef otbVectorDataToRandomLineGenerator_hxx
22 #define otbVectorDataToRandomLineGenerator_hxx
30 template <
class TVectorData>
33 this->SetNumberOfRequiredInputs(1);
34 this->SetNumberOfRequiredOutputs(1);
40 template <
class TVectorData>
43 this->Superclass::PrintSelf(os, indent);
44 os << indent <<
"Required Number of Output Line: " << m_NumberOfOutputLine << std::endl;
47 template <
class TVectorData>
50 this->Superclass::SetNthInput(0,
const_cast<VectorDataType*
>(vectorData));
53 template <
class TVectorData>
56 return static_cast<const VectorDataType*
>(this->Superclass::GetInput(0));
59 template <
class TVectorData>
66 RegionType generatorRegion = node->GetPolygonExteriorRing()->GetBoundingRegion();
67 typename RegionType::SizeType generatorRegionSize = generatorRegion.GetSize();
68 typename RegionType::IndexType generatorRegionIndex = generatorRegion.GetIndex();
74 for (
unsigned int dim = 0; dim < 2; ++dim)
76 rangeMin[dim] = generatorRegionIndex[dim];
77 rangeMax[dim] = generatorRegionIndex[dim] + generatorRegionSize[dim];
80 unsigned int nbPoint = this->m_RandomSizeGenerator->GetUniformVariate(this->GetMinLineSize(), this->GetMaxLineSize());
85 for (
unsigned int dim = 0; dim < 2; ++dim)
87 candidate[dim] = this->m_RandomGenerator->GetUniformVariate(rangeMin[dim], rangeMax[dim]);
90 if (node->GetPolygonExteriorRing()->IsInside(candidate))
93 point[0] = candidate[0];
94 point[1] = candidate[1];
95 vPoint.push_back(point);
102 template <
class TVectorData>
105 this->GetOutput()->SetMetaDataDictionary(this->GetInput()->GetMetaDataDictionary());
108 typename DataNodeType::Pointer root = this->GetOutput()->GetDataTree()->GetRoot()->Get();
110 typename DataNodeType::Pointer document = DataNodeType::New();
113 this->GetOutput(0)->GetDataTree()->Add(document, root);
116 typename VectorDataType::ConstPointer vectorData =
static_cast<const VectorDataType*
>(this->GetInput());
119 itVector.GoToBegin();
120 while (!itVector.IsAtEnd())
122 if (itVector.Get()->IsPolygonFeature())
125 for (
unsigned int i = 0; i < this->GetNumberOfOutputLine(); ++i)
127 typename DataNodeType::Pointer currentGeometry = DataNodeType::New();
128 currentGeometry->SetNodeId(this->GetNextID());
130 typename LineType::Pointer line = LineType::New();
131 currentGeometry->SetLine(line);
133 for (
typename PointVectorType::const_iterator it = vPoints.begin(); it != vPoints.end(); ++it)
136 vertex[0] = (*it)[0];
137 vertex[1] = (*it)[1];
138 currentGeometry->GetLine()->AddVertex(vertex);
140 this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document);