DGtal 1.3.0
Loading...
Searching...
No Matches
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//-----------------------------------------------------------------------------
44template <typename TSpace, typename TEuclideanShape>
45inline
46DGtal::GaussDigitizer<TSpace,TEuclideanShape>::~GaussDigitizer()
47{
48}
49//-----------------------------------------------------------------------------
50template <typename TSpace, typename TEuclideanShape>
51inline
52DGtal::GaussDigitizer<TSpace,TEuclideanShape>::GaussDigitizer()
53 : myEShape( 0 )
54{}
55//-----------------------------------------------------------------------------
56template <typename TSpace, typename TEuclideanShape>
57inline
58DGtal::GaussDigitizer<TSpace,TEuclideanShape> &
59DGtal::GaussDigitizer<TSpace,TEuclideanShape>::
60operator=( 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//-----------------------------------------------------------------------------
72template <typename TSpace, typename TEuclideanShape>
73inline
74void
75DGtal::GaussDigitizer<TSpace,TEuclideanShape>
76::attach( ConstAlias<EuclideanShape> shape )
77{
78 myEShape = shape;
79}
80//-----------------------------------------------------------------------------
81template <typename TSpace, typename TEuclideanShape>
82inline
83void
84DGtal::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//-----------------------------------------------------------------------------
93template <typename TSpace, typename TEuclideanShape>
94inline
95void
96DGtal::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//-----------------------------------------------------------------------------
106template <typename TSpace, typename TEuclideanShape>
107inline
108const typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::PointEmbedder &
109DGtal::GaussDigitizer<TSpace,TEuclideanShape>
110::pointEmbedder() const
111{
112 return myPointEmbedder;
113}
114//-----------------------------------------------------------------------------
115template <typename TSpace, typename TEuclideanShape>
116inline
117typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Domain
118DGtal::GaussDigitizer<TSpace,TEuclideanShape>
119::getDomain() const
120{
121 return Domain( getLowerBound(), getUpperBound() );
122}
123
124//-----------------------------------------------------------------------------
125template <typename TSpace, typename TEuclideanShape>
126inline
127typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point
128DGtal::GaussDigitizer<TSpace,TEuclideanShape>
129::floor( const RealPoint & p ) const
130{
131 return myPointEmbedder.floor( p );
132}
133//-----------------------------------------------------------------------------
134template <typename TSpace, typename TEuclideanShape>
135inline
136typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point
137DGtal::GaussDigitizer<TSpace,TEuclideanShape>
138::ceil( const RealPoint & p ) const
139{
140 return myPointEmbedder.ceil( p );
141}
142//-----------------------------------------------------------------------------
143template <typename TSpace, typename TEuclideanShape>
144inline
145typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point
146DGtal::GaussDigitizer<TSpace,TEuclideanShape>
147::round( const RealPoint & p ) const
148{
149 return myPointEmbedder.round( p );
150}
151//-----------------------------------------------------------------------------
152template <typename TSpace, typename TEuclideanShape>
153inline
154typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::RealPoint
155DGtal::GaussDigitizer<TSpace,TEuclideanShape>
156::embed( const Point & p ) const
157{
158 return myPointEmbedder.embed( p );
159}
160//-----------------------------------------------------------------------------
161template <typename TSpace, typename TEuclideanShape>
162inline
163bool
164DGtal::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//-----------------------------------------------------------------------------
172template <typename TSpace, typename TEuclideanShape>
173inline
174const typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point &
175DGtal::GaussDigitizer<TSpace,TEuclideanShape>
176::getLowerBound() const
177{
178 return myLowerPoint;
179}
180//-----------------------------------------------------------------------------
181template <typename TSpace, typename TEuclideanShape>
182inline
183const typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Point &
184DGtal::GaussDigitizer<TSpace,TEuclideanShape>
185::getUpperBound() const
186{
187 return myUpperPoint;
188}
189//-----------------------------------------------------------------------------
190template <typename TSpace, typename TEuclideanShape>
191inline
192typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::Vector
193DGtal::GaussDigitizer<TSpace,TEuclideanShape>
194::resolution() const
195{
196 return getUpperBound() - getLowerBound();
197}
198//-----------------------------------------------------------------------------
199template <typename TSpace, typename TEuclideanShape>
200inline
201typename DGtal::GaussDigitizer<TSpace,TEuclideanShape>::RealVector
202DGtal::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 */
216template <typename TSpace, typename TEuclideanShape>
217inline
218void
219DGtal::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 */
228template <typename TSpace, typename TEuclideanShape>
229inline
230bool
231DGtal::GaussDigitizer<TSpace,TEuclideanShape>::isValid() const
232{
233 return true;
234}
235
236
237
238///////////////////////////////////////////////////////////////////////////////
239// Implementation of inline functions //
240
241template <typename TSpace, typename TEuclideanShape>
242inline
243std::ostream&
244DGtal::operator<< ( std::ostream & out,
245 const GaussDigitizer<TSpace,TEuclideanShape> & object )
246{
247 object.selfDisplay( out );
248 return out;
249}
250
251// //
252///////////////////////////////////////////////////////////////////////////////
253
254