OTB  9.0.0
Orfeo Toolbox
otbLabelMapToVectorDataFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbLabelMapToVectorDataFilter_hxx
22 #define otbLabelMapToVectorDataFilter_hxx
23 
25 
26 namespace otb
27 {
28 
29 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
31 { /*
32  m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); */
33 }
34 
35 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
37 {
38  // Process object is not const-correct so the const_cast is required here
39  this->itk::ProcessObject::SetNthInput(0, const_cast<InputLabelMapType*>(input));
40 }
41 
42 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
44 {
45  // Process object is not const-correct so the const_cast is required here
46  this->itk::ProcessObject::SetNthInput(idx, const_cast<InputLabelMapType*>(input));
47 }
48 
49 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
52 {
53  if (this->GetNumberOfInputs() < 1)
54  {
55  return nullptr;
56  }
57 
58  return static_cast<const TLabelMap*>(this->itk::ProcessObject::GetInput(0));
59 }
60 
61 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
64 {
65  return static_cast<const TLabelMap*>(this->itk::ProcessObject::GetInput(idx));
66 }
67 
68 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
70 {
71  OutputVectorDataType* output = this->GetOutput();
72  const InputLabelMapType* input = this->GetInput();
73 
74  FunctorType functor;
75  CorrectFunctorType correctFunctor;
76 
78  DataNodePointerType document = DataNodeType::New();
79  DataNodePointerType folder1 = DataNodeType::New();
81 
82  document->SetNodeType(DOCUMENT);
83  folder1->SetNodeType(FOLDER);
84  DataNodePointerType root = output->GetDataTree()->GetRoot()->Get();
85  output->GetDataTree()->Add(document, root);
86  output->GetDataTree()->Add(folder1, document);
87 
88  // Lets begin by declaring the iterator for the objects in the image.
90 
91  while (!it.IsAtEnd())
92  {
94  const LabelObjectType* labelObject = it.GetLabelObject();
95 
97  typename PolygonType::Pointer polygon = functor(const_cast<LabelObjectType*>(labelObject));
98 
100  PolygonPointerType correctPolygon = correctFunctor(polygon);
101  DataNodePointerType node = DataNodeType::New();
102  node->SetNodeType(otb::FEATURE_POLYGON);
104 
106  std::ostringstream oss;
107  oss << labelObject->GetLabel();
108  node->SetNodeId(oss.str());
109  // TODO hole in the polygon are not handle yet by the functor
110  node->SetPolygonExteriorRing(correctPolygon);
112 
114  std::map<std::string, std::string> fields = m_FieldsFunctor(const_cast<LabelObjectType*>(labelObject));
115  std::map<std::string, std::string>::const_iterator it2;
116  for (it2 = fields.begin(); it2 != fields.end(); ++it2)
117  {
118  node->SetFieldAsString(it2->first, it2->second);
119  }
121 
123  output->GetDataTree()->Add(node, folder1);
124  ++it;
125  }
126 }
127 
128 template <class TLabelMap, class TVectorData, class TFieldsFunctor>
130 {
131  Superclass::PrintSelf(os, indent);
132 }
133 
134 } // end namespace otb
135 #endif
otb::LabelMapToVectorDataFilter::GetInput
const InputLabelMapType * GetInput(void)
Definition: otbLabelMapToVectorDataFilter.hxx:51
otb::LabelMapToVectorDataFilter::SetInput
virtual void SetInput(const InputLabelMapType *input)
Definition: otbLabelMapToVectorDataFilter.hxx:36
otb::Functor::LabelObjectToPolygonFunctor
This class vectorizes a LabelObject to a Polygon.
Definition: otbLabelObjectToPolygonFunctor.h:62
otb::LabelMapToVectorDataFilter::LabelMapToVectorDataFilter
LabelMapToVectorDataFilter()
Definition: otbLabelMapToVectorDataFilter.hxx:30
otb::DOCUMENT
@ DOCUMENT
Definition: otbDataNode.h:41
otb::LabelMapToVectorDataFilter::OutputVectorDataType
TVectorData OutputVectorDataType
Definition: otbLabelMapToVectorDataFilter.h:69
otb::LabelMapToVectorDataFilter::LabelObjectType
InputLabelMapType::LabelObjectType LabelObjectType
Definition: otbLabelMapToVectorDataFilter.h:75
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LabelMapToVectorDataFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbLabelMapToVectorDataFilter.hxx:129
otb::FOLDER
@ FOLDER
Definition: otbDataNode.h:42
otb::LabelMapToVectorDataFilter::PolygonPointerType
PolygonType::Pointer PolygonPointerType
Definition: otbLabelMapToVectorDataFilter.h:81
otb::LabelMapToVectorDataFilter::GenerateData
void GenerateData() override
Definition: otbLabelMapToVectorDataFilter.hxx:69
otb::LabelMapToVectorDataFilter::DataNodePointerType
DataNodeType::Pointer DataNodePointerType
Definition: otbLabelMapToVectorDataFilter.h:79
otb::CorrectPolygonFunctor
This filter simplify and close the input polygon, making the last point equal to the first one.
Definition: otbCorrectPolygonFunctor.h:42
otb::FEATURE_POLYGON
@ FEATURE_POLYGON
Definition: otbDataNode.h:45
otb::LabelMapToVectorDataFilter::InputLabelMapType
TLabelMap InputLabelMapType
Definition: otbLabelMapToVectorDataFilter.h:68
otbLabelMapToVectorDataFilter.h
otb::LabelMapToVectorDataFilter::ConstIteratorType
InputLabelMapType::ConstIterator ConstIteratorType
Definition: otbLabelMapToVectorDataFilter.h:77