DGtal  0.9.2
RegularPointEmbedder.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file RegularPointEmbedder.ih
19  * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20  * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
21  *
22  * @date 2011/06/29
23  *
24  * Implementation of inline methods defined in RegularPointEmbedder.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 #include <cmath>
33 #include "DGtal/kernel/NumberTraits.h"
34 //////////////////////////////////////////////////////////////////////////////
35 
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 // ----------------------- Standard services ------------------------------
42 
43 //-----------------------------------------------------------------------------
44 template <typename TSpace>
45 inline
46 DGtal::RegularPointEmbedder<TSpace>::~RegularPointEmbedder()
47 {
48 }
49 //-----------------------------------------------------------------------------
50 template <typename TSpace>
51 inline
52 DGtal::RegularPointEmbedder<TSpace>::RegularPointEmbedder()
53 {}
54 //-----------------------------------------------------------------------------
55 template <typename TSpace>
56 inline
57 DGtal::RegularPointEmbedder<TSpace> &
58 DGtal::RegularPointEmbedder<TSpace>::
59 operator=( const RegularPointEmbedder & other )
60 {
61  if ( this != &other )
62  {
63  myGridSteps = other.myGridSteps;
64  }
65  return *this;
66 }
67 //-----------------------------------------------------------------------------
68 template <typename TSpace>
69 inline
70 void
71 DGtal::RegularPointEmbedder<TSpace>
72 ::init( typename RealVector::Component gridStep )
73 {
74  myGridSteps = RealVector::diagonal( gridStep );
75 }
76 //-----------------------------------------------------------------------------
77 template <typename TSpace>
78 inline
79 void
80 DGtal::RegularPointEmbedder<TSpace>
81 ::init( const RealVector & aGridSteps )
82 {
83  myGridSteps = aGridSteps;
84 }
85 //-----------------------------------------------------------------------------
86 template <typename TSpace>
87 inline
88 typename DGtal::RegularPointEmbedder<TSpace>::Point
89 DGtal::RegularPointEmbedder<TSpace>
90 ::floor( const RealPoint & p ) const
91 {
92  Point aPoint;
93  for ( Dimension i = 0; i < Space::dimension; ++i )
94  aPoint[ i ] = (Integer) ::floor( p[ i ] / myGridSteps[ i ] );
95  return aPoint;
96 }
97 //-----------------------------------------------------------------------------
98 template <typename TSpace>
99 inline
100 typename DGtal::RegularPointEmbedder<TSpace>::Point
101 DGtal::RegularPointEmbedder<TSpace>
102 ::ceil( const RealPoint & p ) const
103 {
104  Point aPoint;
105  for ( Dimension i = 0; i < Space::dimension; ++i )
106  aPoint[ i ] = (Integer) ::ceil( p[ i ] / myGridSteps[ i ] );
107  return aPoint;
108 }
109 //-----------------------------------------------------------------------------
110 template <typename TSpace>
111 inline
112 typename DGtal::RegularPointEmbedder<TSpace>::Point
113 DGtal::RegularPointEmbedder<TSpace>
114 ::round( const RealPoint & p ) const
115 {
116  Point aPoint;
117  for ( Dimension i = 0; i < Space::dimension; ++i )
118  aPoint[ i ] = (Integer) ::round( p[ i ] / myGridSteps[ i ] );
119  return aPoint;
120 }
121 //-----------------------------------------------------------------------------
122 template <typename TSpace>
123 inline
124 typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
125 DGtal::RegularPointEmbedder<TSpace>
126 ::embed( const Point & p ) const
127 {
128  return this->operator()( p );
129 }
130 //-----------------------------------------------------------------------------
131 template <typename TSpace>
132 inline
133 typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
134 DGtal::RegularPointEmbedder<TSpace>
135 ::operator()( const Point & p ) const
136 {
137  RealPoint aRealPoint;
138  for ( Dimension i = 0; i < Space::dimension; ++i )
139  aRealPoint[ i ] = NumberTraits<Integer>::castToDouble( p[ i ] )
140  * myGridSteps[ i ];
141  return aRealPoint;
142 }
143 //-----------------------------------------------------------------------------
144 template <typename TSpace>
145 inline
146 typename DGtal::RegularPointEmbedder<TSpace>::RealVector
147 DGtal::RegularPointEmbedder<TSpace>
148 ::gridSteps() const
149 {
150  return myGridSteps;
151 }
152 
153 
154 ///////////////////////////////////////////////////////////////////////////////
155 // Interface - public :
156 
157 /**
158  * Writes/Displays the object on an output stream.
159  * @param out the output stream where the object is written.
160  */
161 template <typename TSpace>
162 inline
163 void
164 DGtal::RegularPointEmbedder<TSpace>::selfDisplay ( std::ostream & out ) const
165 {
166  out << "[RegularPointEmbedder]";
167 }
168 
169 /**
170  * Checks the validity/consistency of the object.
171  * @return 'true' if the object is valid, 'false' otherwise.
172  */
173 template <typename TSpace>
174 inline
175 bool
176 DGtal::RegularPointEmbedder<TSpace>::isValid() const
177 {
178  return true;
179 }
180 
181 
182 
183 ///////////////////////////////////////////////////////////////////////////////
184 // Implementation of inline functions //
185 
186 template <typename TSpace>
187 inline
188 std::ostream&
189 DGtal::operator<< ( std::ostream & out,
190  const RegularPointEmbedder<TSpace> & object )
191 {
192  object.selfDisplay( out );
193  return out;
194 }
195 
196 // //
197 ///////////////////////////////////////////////////////////////////////////////
198 
199