OTB  10.0.0
Orfeo Toolbox
otbVectorData.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 #ifndef otbVectorData_hxx
22 #define otbVectorData_hxx
23 
24 #include "otbVectorData.h"
25 #include "otbMetaDataKey.h"
26 
27 namespace otb
28 {
29 
30 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
32 {
33  m_root = DataNodeType::New();
34  m_root->SetNodeType(otb::ROOT);
35  m_root->SetNodeId("Root");
36  boost::add_vertex(m_root, m_DataTree);
37  m_Origin.Fill(0);
38  m_Spacing.Fill(1);
39 }
40 
41 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
43 {
44  itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
45 
46  itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, projectionRef);
47  this->Modified();
48 }
49 
50 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
52 {
53  const itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
54 
55  std::string projectionRef;
56  itk::ExposeMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, projectionRef);
57 
58  return projectionRef;
59 }
60 
61 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
63 {
64  itkDebugMacro("setting Spacing to " << spacing);
65  if (this->m_Spacing != spacing)
66  {
67  this->m_Spacing = spacing;
68  this->Modified();
69  }
70 }
71 
72 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
74 {
75  SpacingType s(spacing);
76  this->SetSpacing(s);
77 }
78 
79 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
81 {
82  itk::Vector<float, 2> sf(spacing);
83  SpacingType s;
84  s.CastFrom(sf);
85  this->SetSpacing(s);
86 }
87 
88 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
90 {
91  OriginType p(origin);
92  this->SetOrigin(p);
93 }
94 
95 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
97 {
98  itk::Point<float, 2> of(origin);
99  OriginType p;
100  p.CastFrom(of);
101  this->SetOrigin(p);
102 }
103 
104 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
106 {
107  m_DataTree.clear();
108  //Always add a root node by default
109  boost::add_vertex(m_root,m_DataTree);
110 }
111 
112 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
114 {
115  return boost::num_vertices(m_DataTree);
116 }
117 
118 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
119 void VectorData<TPrecision, VDimension, TValuePrecision>::PrintSelf(std::ostream& os, itk::Indent indent) const
120 {
121  Superclass::PrintSelf(os, indent);
122  os << "\n";
123 
124  typename boost::graph_traits<DataTreeType>::vertex_iterator it,it_end;
125  boost::tie(it, it_end) = vertices(m_DataTree);
126  uint8_t indentcounts = 0;
127  for (;it!=it_end;it++)
128  {
129  for(auto i = 0; i<indentcounts;i++)
130  {
131  os << indent;
132  }
133  os << "+" << m_DataTree[*it]->GetNodeTypeAsString() << "\n";
134  typename boost::graph_traits<DataTreeType>::adjacency_iterator ai, a_end;
135  boost::tie(ai, a_end) = boost::adjacent_vertices(*it, m_DataTree);
136  for (; ai != a_end; ai++) {
137  indentcounts++;
138  break;
139  }
140  }
141 }
142 
143 template <class TPrecision, unsigned int VDimension, class TValuePrecision>
145 {
146  // call the superclass' implementation
147  Superclass::Graft(data);
148 
149  if (data)
150  {
151  // Attempt to cast data to an Image
152  const Self* vdData = dynamic_cast<const Self*>(data);
153 
154  if (vdData)
155  {
156  // Copy all the needed data : DataTree, spacing, origin and
157  // Projection Ref
158  this->m_DataTree.clear(); //Before copy make sure the datatree is EMPTY
159  this->CopyDataTree(vdData);
160  this->SetSpacing(vdData->GetSpacing());
161  this->SetOrigin(vdData->GetOrigin());
162  this->SetProjectionRef(vdData->GetProjectionRef());
163  this->m_root = vdData->GetRoot();
164  }
165  else
166  {
167  // pointer could not be cast back down
168  itkExceptionMacro(<< "otb::VectorData::Graft() cannot cast " << typeid(data).name() << " to " << typeid(const Self*).name());
169  }
170  }
171 }
172 } // end namespace otb
173 
174 #endif
This class represents a hierarchy of vector data.
Definition: otbVectorData.h:62
void SetProjectionRef(const std::string &projectionRef)
virtual const SpacingType & GetSpacing() const
itk::Vector< double, 2 > SpacingType
Definition: otbVectorData.h:85
std::string GetProjectionRef() const
void Graft(const itk::DataObject *data) override
virtual const OriginType & GetOrigin() const
void SetSpacing(const SpacingType &spacing)
virtual void SetOrigin(OriginType _arg)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
int Size() const
void SetOrigin(const float origin[2])
itk::Point< double, 2 > OriginType
Definition: otbVectorData.h:86
DataNodePointerType GetRoot() const
OTBMetadata_EXPORT char const * ProjectionRefKey
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
@ ROOT
Definition: otbDataNode.h:40