Orfeo Toolbox  3.16
otbLabelMapToVectorDataFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbLabelMapToVectorDataFilter_txx
19 #define __otbLabelMapToVectorDataFilter_txx
20 
22 
23 namespace otb {
24 
25 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
28 { /*
29  m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); */
30 }
31 
32 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
33 void
36 {
37 // Process object is not const-correct so the const_cast is required here
39  const_cast<InputLabelMapType *>(input));
40 }
41 
42 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
43 void
45 ::SetInput(unsigned int idx, const InputLabelMapType *input)
46 {
47  // Process object is not const-correct so the const_cast is required here
49  const_cast<InputLabelMapType *>(input));
50 }
51 
52 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
56 {
57  if (this->GetNumberOfInputs() < 1)
58  {
59  return 0;
60  }
61 
62  return static_cast<const TLabelMap *>
64 }
65 
66 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
69 ::GetInput(unsigned int idx)
70 {
71  return static_cast<const TLabelMap *>
72  (this->itk::ProcessObject::GetInput(idx));
73 }
74 
75 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
76 void
79 {
80  OutputVectorDataType * output = this->GetOutput();
81  const InputLabelMapType * input = this->GetInput();
82 
83  FunctorType functor;
84  CorrectFunctorType correctFunctor;
85 
87  DataNodePointerType document = DataNodeType::New();
88  DataNodePointerType folder1 = DataNodeType::New();
89 
90  document->SetNodeType(DOCUMENT);
91  folder1->SetNodeType(FOLDER);
92  DataNodePointerType root = output->GetDataTree()->GetRoot()->Get();
93  output->GetDataTree()->Add(document, root);
94  output->GetDataTree()->Add(folder1, document);
95 
96  // Lets begin by declaring the iterator for the objects in the image.
97  typename InputLabelMapType::LabelObjectContainerType::const_iterator it;
98  // And get the object container to reuse it later
99  const typename InputLabelMapType::LabelObjectContainerType& labelObjectContainer = input->GetLabelObjectContainer();
100  for (it = labelObjectContainer.begin(); it != labelObjectContainer.end(); ++it)
101  {
103  LabelObjectType * labelObject = it->second;
104 
106  typename PolygonType::Pointer polygon = functor(labelObject);
107 
109  PolygonPointerType correctPolygon = correctFunctor(polygon);
110  DataNodePointerType node = DataNodeType::New();
111  node->SetNodeType(otb::FEATURE_POLYGON);
112 
114  std::ostringstream oss;
115  oss << labelObject->GetLabel();
116  node->SetNodeId(oss.str());
117  //TODO hole in the polygon are not handle yet by the functor
118  node->SetPolygonExteriorRing(correctPolygon);
119 
121  std::map<std::string, std::string> fields = m_FieldsFunctor(labelObject);
122  std::map<std::string, std::string>::const_iterator it;
123  for ( it = fields.begin(); it != fields.end(); ++it )
124  {
125  node->SetFieldAsString(it->first, it->second);
126  }
127 
129  output->GetDataTree()->Add(node, folder1);
130  }
131 }
132 
133 template<class TLabelMap, class TVectorData, class TFieldsFunctor>
134 void
136 ::PrintSelf(std::ostream& os, itk::Indent indent) const
137 {
138  Superclass::PrintSelf(os, indent);
139 }
140 
141 } // end namespace otb
142 #endif

Generated at Sun May 19 2013 00:34:53 for Orfeo Toolbox with doxygen 1.8.3.1