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.
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.
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/>.
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
24 * Implementation of inline methods defined in RegularPointEmbedder.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
33 #include "DGtal/kernel/NumberTraits.h"
34 //////////////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 // ----------------------- Standard services ------------------------------
43 //-----------------------------------------------------------------------------
44 template <typename TSpace>
46 DGtal::RegularPointEmbedder<TSpace>::~RegularPointEmbedder()
49 //-----------------------------------------------------------------------------
50 template <typename TSpace>
52 DGtal::RegularPointEmbedder<TSpace>::RegularPointEmbedder()
54 //-----------------------------------------------------------------------------
55 template <typename TSpace>
57 DGtal::RegularPointEmbedder<TSpace> &
58 DGtal::RegularPointEmbedder<TSpace>::
59 operator=( const RegularPointEmbedder & other )
63 myGridSteps = other.myGridSteps;
67 //-----------------------------------------------------------------------------
68 template <typename TSpace>
71 DGtal::RegularPointEmbedder<TSpace>
72 ::init( typename RealVector::Component gridStep )
74 myGridSteps = RealVector::diagonal( gridStep );
76 //-----------------------------------------------------------------------------
77 template <typename TSpace>
80 DGtal::RegularPointEmbedder<TSpace>
81 ::init( const RealVector & aGridSteps )
83 myGridSteps = aGridSteps;
85 //-----------------------------------------------------------------------------
86 template <typename TSpace>
88 typename DGtal::RegularPointEmbedder<TSpace>::Point
89 DGtal::RegularPointEmbedder<TSpace>
90 ::floor( const RealPoint & p ) const
93 for ( Dimension i = 0; i < Space::dimension; ++i )
94 aPoint[ i ] = (Integer) ::floor( p[ i ] / myGridSteps[ i ] );
97 //-----------------------------------------------------------------------------
98 template <typename TSpace>
100 typename DGtal::RegularPointEmbedder<TSpace>::Point
101 DGtal::RegularPointEmbedder<TSpace>
102 ::ceil( const RealPoint & p ) const
105 for ( Dimension i = 0; i < Space::dimension; ++i )
106 aPoint[ i ] = (Integer) ::ceil( p[ i ] / myGridSteps[ i ] );
109 //-----------------------------------------------------------------------------
110 template <typename TSpace>
112 typename DGtal::RegularPointEmbedder<TSpace>::Point
113 DGtal::RegularPointEmbedder<TSpace>
114 ::round( const RealPoint & p ) const
117 for ( Dimension i = 0; i < Space::dimension; ++i )
118 aPoint[ i ] = (Integer) ::round( p[ i ] / myGridSteps[ i ] );
121 //-----------------------------------------------------------------------------
122 template <typename TSpace>
124 typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
125 DGtal::RegularPointEmbedder<TSpace>
126 ::embed( const Point & p ) const
128 return this->operator()( p );
130 //-----------------------------------------------------------------------------
131 template <typename TSpace>
133 typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
134 DGtal::RegularPointEmbedder<TSpace>
135 ::operator()( const Point & p ) const
137 RealPoint aRealPoint;
138 for ( Dimension i = 0; i < Space::dimension; ++i )
139 aRealPoint[ i ] = NumberTraits<Integer>::castToDouble( p[ i ] )
143 //-----------------------------------------------------------------------------
144 template <typename TSpace>
146 typename DGtal::RegularPointEmbedder<TSpace>::RealVector
147 DGtal::RegularPointEmbedder<TSpace>
154 ///////////////////////////////////////////////////////////////////////////////
155 // Interface - public :
158 * Writes/Displays the object on an output stream.
159 * @param out the output stream where the object is written.
161 template <typename TSpace>
164 DGtal::RegularPointEmbedder<TSpace>::selfDisplay ( std::ostream & out ) const
166 out << "[RegularPointEmbedder]";
170 * Checks the validity/consistency of the object.
171 * @return 'true' if the object is valid, 'false' otherwise.
173 template <typename TSpace>
176 DGtal::RegularPointEmbedder<TSpace>::isValid() const
183 ///////////////////////////////////////////////////////////////////////////////
184 // Implementation of inline functions //
186 template <typename TSpace>
189 DGtal::operator<< ( std::ostream & out,
190 const RegularPointEmbedder<TSpace> & object )
192 object.selfDisplay( out );
197 ///////////////////////////////////////////////////////////////////////////////