DGtal  0.9.2
GaussDigitizer.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 GaussDigitizer.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 GaussDigitizer.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, typename TEuclideanShape>
45 inline
46 DGtal::GaussDigitizer<TSpace,TEuclideanShape>::~GaussDigitizer()
47 {
48 }
49 //-----------------------------------------------------------------------------
50 template <typename TSpace, typename TEuclideanShape>
51 inline
52 DGtal::GaussDigitizer<TSpace,TEuclideanShape>::GaussDigitizer()
53  : myEShape( 0 )
54 {}
55 //-----------------------------------------------------------------------------
56 template <typename TSpace, typename TEuclideanShape>
57 inline
58 DGtal::GaussDigitizer<TSpace,TEuclideanShape> &
59 DGtal::GaussDigitizer<TSpace,TEuclideanShape>::
60 operator=( const GaussDigitizer & other )
61 {
62  if ( this != &other )
63  {
64  myEShape = other.myEShape;
65  myPointEmbedder = other.myPointEmbedder;
66  myLowerPoint = other.myLowerPoint;
67  myUpperPoint = other.myUpperPoint;
68  }
69  return *this;
70 }
71 //-----------------------------------------------------------------------------
72 template <typename TSpace, typename TEuclideanShape>
73 inline
74 void
75 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
76 ::attach( const EuclideanShape & shape )
77 {
78  myEShape = &shape;
79 }
80 //-----------------------------------------------------------------------------
81 template <typename TSpace, typename TEuclideanShape>
82 inline
83 void
84 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
85 ::init( const RealPoint & xLow, const RealPoint & xUp,
86  typename RealVector::Component gridStep )
87 {
88  myPointEmbedder.init( gridStep );
89  myLowerPoint = myPointEmbedder.floor( xLow );
90  myUpperPoint = myPointEmbedder.ceil( xUp );
91 }
92 //-----------------------------------------------------------------------------
93 template <typename TSpace, typename TEuclideanShape>
94 inline
95 void
96 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
97 ::init( const RealPoint & xLow, const RealPoint & xUp,
98  const RealVector & aGridSteps )
99 {
100  myPointEmbedder.init( aGridSteps );
101  myLowerPoint = myPointEmbedder.floor( xLow );
102  myUpperPoint = myPointEmbedder.ceil( xUp );
103 }
104 
105 //-----------------------------------------------------------------------------
106 template <typename TSpace, typename TEuclideanShape>
107 inline
108 const typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::PointEmbedder &
109 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
110 ::pointEmbedder() const
111 {
112  return myPointEmbedder;
113 }
114 //-----------------------------------------------------------------------------
115 template <typename TSpace, typename TEuclideanShape>
116 inline
117 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Domain
118 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
119 ::getDomain() const
120 {
121  return Domain( getLowerBound(), getUpperBound() );
122 }
123 
124 //-----------------------------------------------------------------------------
125 template <typename TSpace, typename TEuclideanShape>
126 inline
127 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point
128 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
129 ::floor( const RealPoint & p ) const
130 {
131  return myPointEmbedder.floor( p );
132 }
133 //-----------------------------------------------------------------------------
134 template <typename TSpace, typename TEuclideanShape>
135 inline
136 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point
137 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
138 ::ceil( const RealPoint & p ) const
139 {
140  return myPointEmbedder.ceil( p );
141 }
142 //-----------------------------------------------------------------------------
143 template <typename TSpace, typename TEuclideanShape>
144 inline
145 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point
146 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
147 ::round( const RealPoint & p ) const
148 {
149  return myPointEmbedder.round( p );
150 }
151 //-----------------------------------------------------------------------------
152 template <typename TSpace, typename TEuclideanShape>
153 inline
154 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::RealPoint
155 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
156 ::embed( const Point & p ) const
157 {
158  return myPointEmbedder.embed( p );
159 }
160 //-----------------------------------------------------------------------------
161 template <typename TSpace, typename TEuclideanShape>
162 inline
163 bool
164 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
165 ::operator()( const Point & p ) const
166 {
167  ASSERT( myEShape != 0 );
168  return ((myEShape->orientation( embed( p ) ) == INSIDE)
169  || (myEShape->orientation( embed( p ) ) == ON));
170 }
171 //-----------------------------------------------------------------------------
172 template <typename TSpace, typename TEuclideanShape>
173 inline
174 const typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point &
175 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
176 ::getLowerBound() const
177 {
178  return myLowerPoint;
179 }
180 //-----------------------------------------------------------------------------
181 template <typename TSpace, typename TEuclideanShape>
182 inline
183 const typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point &
184 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
185 ::getUpperBound() const
186 {
187  return myUpperPoint;
188 }
189 //-----------------------------------------------------------------------------
190 template <typename TSpace, typename TEuclideanShape>
191 inline
192 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Vector
193 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
194 ::resolution() const
195 {
196  return getUpperBound() - getLowerBound();
197 }
198 //-----------------------------------------------------------------------------
199 template <typename TSpace, typename TEuclideanShape>
200 inline
201 typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::RealVector
202 DGtal::GaussDigitizer<TSpace,TEuclideanShape>
203 ::gridSteps() const
204 {
205  return myPointEmbedder.gridSteps();
206 }
207 
208 
209 ///////////////////////////////////////////////////////////////////////////////
210 // Interface - public :
211 
212 /**
213  * Writes/Displays the object on an output stream.
214  * @param out the output stream where the object is written.
215  */
216 template <typename TSpace, typename TEuclideanShape>
217 inline
218 void
219 DGtal::GaussDigitizer<TSpace,TEuclideanShape>::selfDisplay ( std::ostream & out ) const
220 {
221  out << "[GaussDigitizer]";
222 }
223 
224 /**
225  * Checks the validity/consistency of the object.
226  * @return 'true' if the object is valid, 'false' otherwise.
227  */
228 template <typename TSpace, typename TEuclideanShape>
229 inline
230 bool
231 DGtal::GaussDigitizer<TSpace,TEuclideanShape>::isValid() const
232 {
233  return true;
234 }
235 
236 
237 
238 ///////////////////////////////////////////////////////////////////////////////
239 // Implementation of inline functions //
240 
241 template <typename TSpace, typename TEuclideanShape>
242 inline
243 std::ostream&
244 DGtal::operator<< ( std::ostream & out,
245  const GaussDigitizer<TSpace,TEuclideanShape> & object )
246 {
247  object.selfDisplay( out );
248  return out;
249 }
250 
251 // //
252 ///////////////////////////////////////////////////////////////////////////////
253 
254