OTB  9.0.0
Orfeo Toolbox
otbPolyLineParametricPathWithValue.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 #ifndef otbPolyLineParametricPathWithValue_hxx
22 #define otbPolyLineParametricPathWithValue_hxx
23 
25 
26 #include "itkNumericTraits.h"
27 
28 namespace otb
29 {
33 template <class TValue, unsigned int VDimension>
35  : m_Key("Value"), m_Length(-1.0), m_LengthIsValid(false), m_BoundingRegion(), m_BoundingRegionIsValid(false)
36 {
37  itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
38  ValueType v;
39  itk::EncapsulateMetaData<ValueType>(dict, m_Key, itk::NumericTraits<ValueType>::ZeroValue(v));
40 }
42 
43 template <class TValue, unsigned int VDimension>
45 {
46  Superclass::AddVertex(vertex);
47  this->Modified();
48 }
49 
50 template <class TValue, unsigned int VDimension>
52 {
53  if (!m_LengthIsValid)
54  {
55  ComputeLength();
56  }
57  return m_Length;
58 }
59 
60 template <class TValue, unsigned int VDimension>
62 {
63  double length = 0.0;
64  VertexListConstIteratorType it = this->GetVertexList()->Begin();
65 
66  if (this->GetVertexList()->Size() > 1)
67  {
68 
69  VertexType pt1 = it.Value(); // just init, won't be used like that
70  VertexType pt2 = it.Value();
71 
72  ++it;
73  while (it != this->GetVertexList()->End())
74  {
75  pt1 = pt2;
76  pt2 = it.Value();
77  double accum = 0.0;
78  for (unsigned int i = 0; i < VDimension; ++i)
79  {
80  accum += (pt1[i] - pt2[i]) * (pt1[i] - pt2[i]);
81  }
82  length += std::sqrt(accum);
83  ++it;
84  }
85  }
86  else // if there is strictly less than 2 points, length is 0
87  {
88  length = 0.0;
89  }
90 
91  m_Length = length;
92  m_LengthIsValid = true;
93 }
94 
98 template <class TValue, unsigned int VDimension>
99 void PolyLineParametricPathWithValue<TValue, VDimension>::PrintSelf(std::ostream& os, itk::Indent indent) const
100 {
101  Superclass::PrintSelf(os, indent);
102  VertexListConstIteratorType it = this->GetVertexList()->Begin();
103  while (it != this->GetVertexList()->End())
104  {
105  os << it.Value() << " - ";
106  ++it;
107  }
108  os << std::endl;
109 }
111 
112 template <class TValue, unsigned int VDimension>
114 {
115  if (!m_BoundingRegionIsValid)
116  {
117  ComputeBoundingRegion();
118  }
119  return m_BoundingRegion;
120 }
121 
125 template <class TValue, unsigned int VDimension>
127 {
128  SizeType size;
129  IndexType index;
130 
131  size.Fill(0);
132  index.Fill(0);
133 
134  IndexType maxId;
135  maxId.Fill(0);
136 
137  VertexListConstIteratorType it = this->GetVertexList()->Begin();
138 
139  double x = 0.0;
140  double y = 0.0;
141 
142  if (this->GetVertexList()->Size() > 0)
143  {
144  x = static_cast<double>(it.Value()[0]);
145  y = static_cast<double>(it.Value()[1]);
146  index[0] = x;
147  index[1] = y;
148  maxId[0] = x;
149  maxId[1] = y;
150 
151  ++it;
152  while (it != this->GetVertexList()->End())
153  {
154  x = static_cast<double>(it.Value()[0]);
155  y = static_cast<double>(it.Value()[1]);
156 
157  // Index search
158  if (x < index[0])
159  {
160  index[0] = x;
161  }
162  if (y < index[1])
163  {
164  index[1] = y;
165  }
166  // Max Id search for size computation
167  if (x > maxId[0])
168  {
169  maxId[0] = x;
170  }
171  if (y > maxId[1])
172  {
173  maxId[1] = y;
174  }
175 
176  ++it;
177  }
178 
179  size[0] = maxId[0] - index[0];
180  size[1] = maxId[1] - index[1];
181  }
182  m_BoundingRegion.SetSize(size);
183  m_BoundingRegion.SetOrigin(index);
184  m_BoundingRegionIsValid = true;
185 }
186 
187 template <class TValue, unsigned int VDimension>
189 {
190  m_LengthIsValid = false;
191  m_BoundingRegionIsValid = false;
192 }
193 
194 } // end namespace otb
195 #endif
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PolyLineParametricPathWithValue< double, 2 >::SizeType
RegionType::SizeType SizeType
Definition: otbPolyLineParametricPathWithValue.h:76
otb::PolyLineParametricPathWithValue< double, 2 >::ContinuousIndexType
Superclass::ContinuousIndexType ContinuousIndexType
Definition: otbPolyLineParametricPathWithValue.h:71
otb::PolyLineParametricPathWithValue< double, 2 >::ValueType
double ValueType
Definition: otbPolyLineParametricPathWithValue.h:63
otb::PolyLineParametricPathWithValue< double, 2 >::VertexListConstIteratorType
VertexListType::ConstIterator VertexListConstIteratorType
Definition: otbPolyLineParametricPathWithValue.h:72
otb::PolyLineParametricPathWithValue< double, 2 >::IndexType
RegionType::IndexType IndexType
Definition: otbPolyLineParametricPathWithValue.h:77
otb::RemoteSensingRegion< double >
otbPolyLineParametricPathWithValue.h
otb::PolyLineParametricPathWithValue
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
Definition: otbPolyLineParametricPathWithValue.h:50
otb::PolyLineParametricPathWithValue< double, 2 >::VertexType
Superclass::VertexType VertexType
Definition: otbPolyLineParametricPathWithValue.h:69
otb::PolyLineParametricPathWithValue::PolyLineParametricPathWithValue
PolyLineParametricPathWithValue()
Definition: otbPolyLineParametricPathWithValue.hxx:34