OTB  10.0.0
Orfeo Toolbox
otbVectorDataProperties.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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>
33 {
34  for (unsigned int i = 0; i < VectorDataDimension; ++i)
35  {
36  if ((m_BoundingRegion.GetOrigin(i) != itk::NumericTraits<Type>::ZeroValue()) || (m_BoundingRegion.GetSize(i) != itk::NumericTraits<Type>::ZeroValue()))
37  return false;
38  }
39  return true;
40 }
44 template <class TVectorData>
46 {
47  // std::cout << "add region: " << region << std::endl;
48  if (this->IsBoundingRegionNull())
49  {
50  m_BoundingRegion = region;
51  }
52  else
53  {
54  Type index;
55  for (unsigned int i = 0; i < VectorDataDimension; ++i)
56  {
57  index = std::min(m_BoundingRegion.GetOrigin(i), region.GetOrigin(i));
58  m_BoundingRegion.SetSize(i, std::max(m_BoundingRegion.GetOrigin(i) + m_BoundingRegion.GetSize(i), region.GetOrigin(i) + region.GetSize(i)) - index);
59  m_BoundingRegion.SetOrigin(i, index);
60  }
61  }
62 }
63 
67 template <class TVectorData>
69 {
70 
72  IndexType index;
73  SizeType size;
74  index.Fill(itk::NumericTraits<Type>::ZeroValue());
75  size.Fill(itk::NumericTraits<Type>::ZeroValue());
76  m_BoundingRegion.SetIndex(index);
77  m_BoundingRegion.SetSize(size);
79 
81  ProcessNode(m_VectorDataObject,m_VectorDataObject->GetRoot());
82 }
83 
84 template <class TVectorData>
86 {
87  // Get the children list from the input node
88  ChildrenListType children = inputVdata->GetChildrenList(source);
89 
90  // For each child
91  for (typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
92  {
93  // Copy input DataNode info
94  DataNodePointerType dataNode = (*it);
95 
96  switch (dataNode->GetNodeType())
97  {
98  case otb::ROOT:
99  {
100  //ProcessNode(inputVdata,(*it));
101  break;
102  }
103  case otb::DOCUMENT:
104  {
105  ProcessNode(inputVdata,(*it));
106  break;
107  }
108  case otb::FOLDER:
109  {
110  ProcessNode(inputVdata,(*it));
111  break;
112  }
113  case FEATURE_POINT:
114  {
115  // otbGenericMsgDebugMacro(<<"Insert Point from vectorData");
116  IndexType start;
117  for (unsigned int i = 0; i < VectorDataDimension; ++i)
118  {
119  start[i] = dataNode->GetPoint()[i];
120  }
121 
122  SizeType size;
123  size.Fill(itk::NumericTraits<Type>::ZeroValue());
124  RegionType region;
125  region.SetSize(size);
126  region.SetIndex(start);
127  this->AddRegion(region);
128  break;
129  }
130  case otb::FEATURE_LINE:
131  {
132  this->AddRegion(dataNode->GetLine()->GetBoundingRegion());
133  break;
134  }
135  case FEATURE_POLYGON:
136  {
137  // otbGenericMsgDebugMacro(<<"Insert polygons from vectorData");
138  this->AddRegion(dataNode->GetPolygonExteriorRing()->GetBoundingRegion());
139  break;
140  }
141  case FEATURE_MULTIPOINT:
142  {
143  itkExceptionMacro(<< "This type (FEATURE_MULTIPOINT) is not handle (yet), please request for it");
144  break;
145  }
146  case FEATURE_MULTILINE:
147  {
148  itkExceptionMacro(<< "This type (FEATURE_MULTILINE) is not handle (yet), please request for it");
149  break;
150  }
152  {
153  itkExceptionMacro(<< "This type (FEATURE_MULTIPOLYGON) is not handle (yet), please request for it");
154  break;
155  }
156  case FEATURE_COLLECTION:
157  {
158  itkExceptionMacro(<< "This type (FEATURE_COLLECTION) is not handle (yet), please request for it");
159  break;
160  }
161  }
162  }
163 }
164 
165 template <class TVectorData>
166 void VectorDataProperties<TVectorData>::PrintSelf(std::ostream& os, itk::Indent indent) const
167 {
168  Superclass::PrintSelf(os, indent);
169  os << indent << "Properties VectorData: " << m_VectorDataObject << std::endl;
170  os << indent << "Properties Bounding Region: " << m_BoundingRegion << std::endl;
171 }
172 
173 } // End namespace otb
174 
175 #endif
VectorDataType::ChildrenListType ChildrenListType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void ProcessNode(VectorDataType *inputVdata, DataNodePointerType source)
void AddRegion(const RegionType &region)
PolygonType::RegionType RegionType
RegionType::IndexType IndexType
DataNodeType::Pointer DataNodePointerType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
@ FEATURE_POLYGON
Definition: otbDataNode.h:45
@ FEATURE_MULTIPOINT
Definition: otbDataNode.h:46
@ FEATURE_MULTIPOLYGON
Definition: otbDataNode.h:48
@ FOLDER
Definition: otbDataNode.h:42
@ FEATURE_MULTILINE
Definition: otbDataNode.h:47
@ DOCUMENT
Definition: otbDataNode.h:41
@ ROOT
Definition: otbDataNode.h:40
@ FEATURE_POINT
Definition: otbDataNode.h:43
@ FEATURE_COLLECTION
Definition: otbDataNode.h:49
@ FEATURE_LINE
Definition: otbDataNode.h:44