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()->GetRoot();
110 typename DataNodeType::Pointer document = DataNodeType::New();
113 this->GetOutput(0)->Add(document, root);
116 typename VectorDataType::ConstPointer vectorData =
static_cast<const VectorDataType*
>(this->GetInput());
118 auto itVectorPair = vectorData->GetIteratorPair();
119 auto currentIt = itVectorPair.first;
120 while (currentIt != itVectorPair.second)
122 if (vectorData->Get(currentIt)->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);
132 PointVectorType vPoints = RandomPointsGenerator(vectorData->Get(currentIt));
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)->Add(currentGeometry, document);
RandomGeneratorType::Pointer m_RandomSizeGenerator
std::vector< PointType > PointVectorType
VectorDataToRandomLineGenerator()
PointVectorType RandomPointsGenerator(DataNodeType *node)
VectorDataType::DataNodeType DataNodeType
DataNodeType::LineType::VertexType VertexType
DataNodeType::PolygonType::RegionType RegionType
TVectorData VectorDataType
void SetInput(const VectorDataType *)
void GenerateData(void) override
DataNodeType::PointType PointType
const VectorDataType * GetInput() const
void PrintSelf(std::ostream &os, itk::Indent indent) const override
RandomGeneratorType::Pointer m_RandomGenerator
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.