Orfeo Toolbox  4.0
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.
98 
99  while ( !it.IsAtEnd() )
100  {
102  const LabelObjectType * labelObject = it.GetLabelObject();
103 
105  typename PolygonType::Pointer polygon = functor(const_cast <LabelObjectType *> (labelObject));
106 
108  PolygonPointerType correctPolygon = correctFunctor(polygon);
109  DataNodePointerType node = DataNodeType::New();
110  node->SetNodeType(otb::FEATURE_POLYGON);
111 
113  std::ostringstream oss;
114  oss << labelObject->GetLabel();
115  node->SetNodeId(oss.str());
116  //TODO hole in the polygon are not handle yet by the functor
117  node->SetPolygonExteriorRing(correctPolygon);
118 
120  std::map<std::string, std::string> fields = m_FieldsFunctor(const_cast <LabelObjectType *> (labelObject));
121  std::map<std::string, std::string>::const_iterator it2;
122  for ( it2 = fields.begin(); it2 != fields.end(); ++it2 )
123  {
124  node->SetFieldAsString(it2->first, it2->second);
125  }
126 
128  output->GetDataTree()->Add(node, folder1);
129  ++it;
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 Sat Mar 8 2014 16:04:34 for Orfeo Toolbox with doxygen 1.8.3.1