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