Orfeo Toolbox  4.0
otbLabelMapToGISTableFilter.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 __otbLabelMapToGISTableFilter_txx
19 #define __otbLabelMapToGISTableFilter_txx
20 
22 #include "itkProgressReporter.h"
23 
24 namespace otb {
25 
26 template<class TLabelMap, class TGISTable>
29 {
30  m_InputGISConnection = InputGISConnectionType::New();
31  m_DropExistingGISTable = false;
32  //default value of the gis table name
33  m_GISTableName = "labelmap_to_gis_table";
34 }
35 
36 template<class TLabelMap, class TGISTable>
37 void
40 {
41 // Process object is not const-correct so the const_cast is required here
43  const_cast<InputLabelMapType *>(input));
44 }
45 
46 template<class TLabelMap, class TGISTable>
47 void
49 ::SetInput(unsigned int idx, const InputLabelMapType *input)
50 {
51  // Process object is not const-correct so the const_cast is required here
53  const_cast<InputLabelMapType *>(input));
54 }
55 
56 template<class TLabelMap, class TGISTable>
60 {
61  if (this->GetNumberOfInputs() < 1)
62  {
63  return 0;
64  }
65 
66  return static_cast<const TLabelMap *>
68 }
69 
70 template<class TLabelMap, class TGISTable>
73 ::GetInput(unsigned int idx)
74 {
75  return static_cast<const TLabelMap *>
76  (this->itk::ProcessObject::GetInput(idx));
77 }
78 
79 template<class TLabelMap, class TGISTable>
80 void
83 { /*
84  // call the superclass' implementation of this method
85  Superclass::GenerateInputRequestedRegion();
86 
87  // We need all the input.
88  InputImagePointer input = const_cast<InputImageType *>(this->GetInput());
89  if ( !input )
90  { return; }
91  input->SetRequestedRegion( input->GetLargestPossibleRegion() ); */
92 }
93 
94 /*Distance: 5.19615
95  -> Test EXIT SUCCESS.
96 template<class TInputImage, class TLabelMap >
97 void
98 LabelMapToLabelMapFilter<TInputImage, TLabelMap>
99 ::EnlargeOutputRequestedRegion(DataObject *)
100 {
101  this->GetOutput()
102  ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() );
103 }
104 */
105 
106 template<class TLabelMap, class TGISTable>
107 void
110 {
111 
112  // Allocate the output
113  this->AllocateOutputs();
114  //std::cout << "before GetOutput" << std::endl;
115  OutputGISTableType * output = this->GetOutput();
116  //std::cout << "after GetOutput" << std::endl;
117  const InputLabelMapType * input = this->GetInput();
118 
119  //Set the filter's Postgres connection
120  output->SetConnection (this->GetInputGISConnection ());
121 
122  //Connection to the database
123  output->GetConnection()->ConnectToDB();
124 
125  //Name of the table is set automatically to "vector_data_to_gis"
126  output->SetTableName (this->GetGISTableName());
127 
128  //Create the PostgreSQL table
129  output->CreateTable(m_DropExistingGISTable);
130  FunctorType functor;
131 // SimplifyFunctorType simplifyFunctor;
132 // simplifyFunctor.SetTolerance (0.0);
133 //
134 // CloseFunctorType closeFunctor;
135 
136  CorrectFunctorType correctFunctor;
137  // Lets begin by declaring the iterator for the objects in the image.
138  typename InputLabelMapType::LabelObjectContainerType::const_iterator it;
139  // And get the object container to reuse it later
140  const typename InputLabelMapType::LabelObjectContainerType& labelObjectContainer = input->GetLabelObjectContainer();
141  for (it = labelObjectContainer.begin(); it != labelObjectContainer.end(); ++it)
142  {
143  // the label is there if we need it, but it can also be found at labelObject->GetLabel().
144  // const PType & label = it->first;
145 
146  // the label object
147  LabelObjectType * labelObject = it->second;
148  PolygonPointerType polygon = functor(labelObject);
150  std::ostringstream oss;
151  oss << labelObject->GetLabel();
152  //std::cout << "label : " << oss.str() << std::endl;
153  //std::cout << "polygon : " << polygon << std::endl;
154 
155  //Simply polygon (erase aligned points)
156 // PolygonPointerType simplifyPolygon = simplifyFunctor(polygon);
157  //std::cout << "simplify polygon : " << simplifyPolygon << std::endl;
158 
159  //Close polygon if necessary
160 // PolygonPointerType closePolygon = closeFunctor(simplifyPolygon);
161  PolygonPointerType correctPolygon = correctFunctor(polygon);
162  //std::cout << "simplify polygon : " << closePolygon << std::endl;
163 
164  this->GetOutput()->InsertPolygons(static_cast<typename TGISTable::PolygonConstPointerType> (
165  correctPolygon),
166  static_cast<typename TGISTable::PolygonListConstPointerType> (0), oss.str());
167  //Add polygon to the gis table
168  }
169 
170 }
171 
172 template<class TLabelMap, class TGISTable>
173 void
175 ::PrintSelf(std::ostream& os, itk::Indent indent) const
176 {
177  Superclass::PrintSelf(os, indent);
178  //this->GetInputGISConnection()->PrintSelf (os, indent);
179 /*
180  os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl;
181  */
182 }
183 
184 } // end namespace otb
185 #endif

Generated at Sat Mar 8 2014 16:04:12 for Orfeo Toolbox with doxygen 1.8.3.1