OTB  6.7.0
Orfeo Toolbox
otbPolyLineParametricPathWithValue.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 #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>
36  m_Key("Value"), m_Length(-1.0), m_LengthIsValid(false),
37  m_BoundingRegion(), m_BoundingRegionIsValid(false)
38 {
39  itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
40  ValueType v;
41  itk::EncapsulateMetaData<ValueType>(dict, m_Key, itk::NumericTraits<ValueType>::ZeroValue(v));
42 }
44 
45 template <class TValue, unsigned int VDimension>
48 {
49  Superclass::AddVertex(vertex);
50  this->Modified();
51 }
52 
53 template <class TValue, unsigned int VDimension>
55 ::GetLength() const
56 {
57  if (!m_LengthIsValid)
58  {
59  ComputeLength();
60  }
61  return m_Length;
62 }
63 
64 template <class TValue, unsigned int VDimension>
65 void
68 {
69  double length = 0.0;
70  VertexListConstIteratorType it = this->GetVertexList()->Begin();
71 
72  if (this->GetVertexList()->Size() > 1)
73  {
74 
75  VertexType pt1 = it.Value(); //just init, won't be used like that
76  VertexType pt2 = it.Value();
77 
78  ++it;
79  while (it != this->GetVertexList()->End())
80  {
81  pt1 = pt2;
82  pt2 = it.Value();
83  double accum = 0.0;
84  for (unsigned int i = 0; i < VDimension; ++i)
85  {
86  accum += (pt1[i] - pt2[i]) * (pt1[i] - pt2[i]);
87  }
88  length += std::sqrt(accum);
89  ++it;
90  }
91 
92  }
93  else //if there is strictly less than 2 points, length is 0
94  {
95  length = 0.0;
96  }
97 
98  m_Length = length;
99  m_LengthIsValid = true;
100 }
101 
105 template <class TValue, unsigned int VDimension>
106 void
108 ::PrintSelf(std::ostream& os, itk::Indent indent) const
109 {
110  Superclass::PrintSelf(os, indent);
111  VertexListConstIteratorType it = this->GetVertexList()->Begin();
112  while (it != this->GetVertexList()->End())
113  {
114  os << it.Value() << " - ";
115  ++it;
116  }
117  os << std::endl;
118 }
120 
121 template <class TValue, unsigned int VDimension>
123 ::RegionType
126 {
127  if (!m_BoundingRegionIsValid)
128  {
129  ComputeBoundingRegion();
130  }
131  return m_BoundingRegion;
132 }
133 
137 template <class TValue, unsigned int VDimension>
138 void
141 {
142  SizeType size;
143  IndexType index;
144 
145  size.Fill(0);
146  index.Fill(0);
147 
148  IndexType maxId;
149  maxId.Fill(0);
150 
151  VertexListConstIteratorType it = this->GetVertexList()->Begin();
152 
153  double x = 0.0;
154  double y = 0.0;
155 
156  if (this->GetVertexList()->Size() > 0)
157  {
158  x = static_cast<double>(it.Value()[0]);
159  y = static_cast<double>(it.Value()[1]);
160  index[0] = x;
161  index[1] = y;
162  maxId[0] = x;
163  maxId[1] = y;
164 
165  ++it;
166  while (it != this->GetVertexList()->End())
167  {
168  x = static_cast<double>(it.Value()[0]);
169  y = static_cast<double>(it.Value()[1]);
170 
171  // Index search
172  if (x < index[0])
173  {
174  index[0] = x;
175  }
176  if (y < index[1])
177  {
178  index[1] = y;
179  }
180  // Max Id search for size computation
181  if (x > maxId[0])
182  {
183  maxId[0] = x;
184  }
185  if (y > maxId[1])
186  {
187  maxId[1] = y;
188  }
189 
190  ++it;
191  }
192 
193  size[0] = maxId[0] - index[0];
194  size[1] = maxId[1] - index[1];
195  }
196  m_BoundingRegion.SetSize(size);
197  m_BoundingRegion.SetOrigin(index);
198  m_BoundingRegionIsValid = true;
199 }
200 
201 template <class TValue, unsigned int VDimension>
202 void
204 ::Modified() const
205 {
206  m_LengthIsValid = false;
207  m_BoundingRegionIsValid = false;
208 }
209 
210 } // end namespace otb
211 #endif
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
static T ZeroValue()
const Element & Value(void) const
void Fill(const ValueType &)
void Fill(IndexValueType value)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual void AddVertex(const ContinuousIndexType &vertex)