OTB  6.7.0
Orfeo Toolbox
otbVectorDataProperties.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 
22 #ifndef otbVectorDataProperties_hxx
23 #define otbVectorDataProperties_hxx
24 
26 #include <algorithm>
27 
28 namespace otb
29 {
30 
31 template <class TVectorData>
34 {
35  for (unsigned int i = 0; i < VectorDataDimension; ++i)
36  {
37  if ((m_BoundingRegion.GetOrigin(i) != itk::NumericTraits<Type>::ZeroValue()) ||
38  (m_BoundingRegion.GetSize(i) != itk::NumericTraits<Type>::ZeroValue())) return false;
39  }
40  return true;
41 }
45 template <class TVectorData>
46 void
48 ::AddRegion(const RegionType& region)
49 {
50 // std::cout << "add region: " << region << std::endl;
51  if (this->IsBoundingRegionNull())
52  {
53  m_BoundingRegion = region;
54  }
55  else
56  {
57  Type index;
58  for (unsigned int i = 0; i < VectorDataDimension; ++i)
59  {
60  index = std::min (m_BoundingRegion.GetOrigin(i), region.GetOrigin(i));
61  m_BoundingRegion.SetSize(i,
62  std::max (m_BoundingRegion.GetOrigin(i) + m_BoundingRegion.GetSize(i),
63  region.GetOrigin(i) + region.GetSize(
64  i)) - index);
65  m_BoundingRegion.SetOrigin(i, index);
66  }
67  }
68 }
69 
73 template <class TVectorData>
74 void
77 {
78 
80  IndexType index;
81  SizeType size;
84  m_BoundingRegion.SetIndex(index);
85  m_BoundingRegion.SetSize(size);
87 
89  InternalTreeNodeType * inputRoot = const_cast<InternalTreeNodeType *>(m_VectorDataObject->GetDataTree()->GetRoot());
90  ProcessNode(inputRoot);
91 }
93 
94 template<class TVectorData>
95 void
98 {
99  // Get the children list from the input node
100  ChildrenListType children = source->GetChildrenList();
101 
102  // For each child
103  for (typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
104  {
105  // Copy input DataNode info
106  DataNodePointerType dataNode = (*it)->Get();
107 
108  switch (dataNode->GetNodeType())
109  {
110  case otb::ROOT:
111  {
112  ProcessNode((*it));
113  break;
114  }
115  case otb::DOCUMENT:
116  {
117  ProcessNode((*it));
118  break;
119  }
120  case otb::FOLDER:
121  {
122  ProcessNode((*it));
123  break;
124  }
125  case FEATURE_POINT:
126  {
127 // otbGenericMsgDebugMacro(<<"Insert Point from vectorData");
128  IndexType start;
129  for (unsigned int i = 0; i < VectorDataDimension; ++i)
130  {
131  start[i] = dataNode->GetPoint()[i];
132  }
133 
134  SizeType size;
136  RegionType region;
137  region.SetSize(size);
138  region.SetIndex(start);
139  this->AddRegion(region);
140  break;
141  }
142  case otb::FEATURE_LINE:
143  {
144  this->AddRegion(dataNode->GetLine()->GetBoundingRegion());
145  break;
146  }
147  case FEATURE_POLYGON:
148  {
149  //otbGenericMsgDebugMacro(<<"Insert polygons from vectorData");
150  this->AddRegion(dataNode->GetPolygonExteriorRing()->GetBoundingRegion());
151  break;
152  }
153  case FEATURE_MULTIPOINT:
154  {
155  itkExceptionMacro(
156  <<
157  "This type (FEATURE_MULTIPOINT) is not handle (yet), please request for it");
158  break;
159  }
160  case FEATURE_MULTILINE:
161  {
162  itkExceptionMacro(
163  << "This type (FEATURE_MULTILINE) is not handle (yet), please request for it");
164  break;
165  }
167  {
168  itkExceptionMacro(
169  <<
170  "This type (FEATURE_MULTIPOLYGON) is not handle (yet), please request for it");
171  break;
172  }
173  case FEATURE_COLLECTION:
174  {
175  itkExceptionMacro(
176  <<
177  "This type (FEATURE_COLLECTION) is not handle (yet), please request for it");
178  break;
179  }
180  }
181  }
182 }
183 
184 template<class TVectorData>
185 void
187 ::PrintSelf(std::ostream& os, itk::Indent indent) const
188 {
189  Superclass::PrintSelf(os, indent);
190  os << indent << "Properties VectorData: " << m_VectorDataObject << std::endl;
191  os << indent << "Properties Bounding Region: " << m_BoundingRegion << std::endl;
192 }
193 
194 } // End namespace otb
195 
196 #endif
void ProcessNode(InternalTreeNodeType *source)
static T ZeroValue()
InternalTreeNodeType::ChildrenListType ChildrenListType
VectorDataType::DataTreeType::TreeNodeType InternalTreeNodeType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
RegionType::IndexType IndexType
PolygonType::RegionType RegionType
void AddRegion(const RegionType &region)
DataNodeType::Pointer DataNodePointerType