OTB  6.7.0
Orfeo Toolbox
otbImageReference.h
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 otbImageReference_h
22 #define otbImageReference_h
23 
24 #include "itkPoint.h"
25 
26 namespace otb
27 {
28 namespace ogr
29 {
38 template <typename TPrecision> class ImageReference
39 {
40 public:
41  typedef TPrecision PrecisionType;
42  enum { Dimension = 2 };
43 
46 
47  bool GetDebug() const
48  {
49  return m_Holder.GetDebug();
50  }
52 
58 
59  inline const char * GetNameOfClass()
60  {
61  return "ImageReference";
62  }
63 
68  ImageReference(itk::Object const& holder)
69  : m_Holder(holder)
70  {
71  m_Spacing.Fill(1);
72  m_Origin.Fill(0);
73  }
74 
79  ImageReference(SpacingType const& spacing, OriginType const& origin, itk::Object const& holder)
80  : m_Holder(holder) , m_Spacing(spacing), m_Origin(origin)
81  {
82  }
83 
84  void Modified() const
85  {
87  }
88 
93  itkGetConstReferenceMacro(Origin, OriginType);
94  itkSetMacro(Origin, OriginType);
95  void SetOrigin(const TPrecision origin[Dimension])
96  {
97  const OriginType p(origin);
98  this->SetOrigin(p);
99  }
101 
102 
107  itkGetConstReferenceMacro(Spacing, SpacingType);
108  void SetSpacing(const SpacingType& spacing)
109  {
110  // itkDebugMacro("setting Spacing to " << spacing);
111  if (this->m_Spacing != spacing)
112  {
113  this->m_Spacing = spacing;
114  this->Modified();
115  }
116  }
117  void SetSpacing(const TPrecision spacing[Dimension])
118  {
119  const SpacingType s(spacing);
120  this->SetSpacing(s);
121  }
123 
124 
132  void TransformPointToPhysicalPoint(const PointType& point, PointType& physicalPoint) const
133  {
134  for (size_t i=0; i!=Dimension; ++i)
135  physicalPoint[i] = point[i] * m_Spacing[i] + m_Origin[i];
136  }
138 
147  {
148  // why no loop on VDimension ?
149  PointType physicalPoint;
150  for (size_t i=0; i!=Dimension; ++i)
151  physicalPoint[i] = point[i] * m_Spacing[i] + m_Origin[i];
152  return physicalPoint;
153  }
155 
165  {
166  m_Spacing = rhs.m_Spacing;
167  m_Origin = rhs.m_Origin;
168  return *this;
169  }
171 
172 private:
176 };
177 
178 } // ogr namespace
179 
180 } // end namespace otb
181 
182 #ifndef OTB_MANUAL_INSTANTIATION
183 // #include "otbImageReference.hxx"
184 #endif
185 
186 #endif // otbImageReference_h
void SetSpacing(const SpacingType &spacing)
Spacing getter.
PointType TransformPointToPhysicalPoint(const PointType &point) const
void TransformPointToPhysicalPoint(const PointType &point, PointType &physicalPoint) const
void SetSpacing(const TPrecision spacing[Dimension])
Spacing getter.
ImageReference & operator=(ImageReference const &rhs)
itk::Point< PrecisionType, 2 > OriginType
void Fill(const ValueType &)
itk::Object const & m_Holder
void SetOrigin(const TPrecision origin[Dimension])
Origin setter.
virtual void SetOrigin(OriginType _arg)
Origin getter.
itk::Vector< PrecisionType, 2 > SpacingType
virtual void Modified() const
ImageReference(SpacingType const &spacing, OriginType const &origin, itk::Object const &holder)
ImageReference(itk::Object const &holder)
bool GetDebug() const
itk::Point< PrecisionType, 2 > PointType