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//-----------------------------------------------------------------------------
44template <typename TSpace>
46DGtal::RegularPointEmbedder<TSpace>::~RegularPointEmbedder()
49//-----------------------------------------------------------------------------
50template <typename TSpace>
52DGtal::RegularPointEmbedder<TSpace>::RegularPointEmbedder()
54//-----------------------------------------------------------------------------
55template <typename TSpace>
57DGtal::RegularPointEmbedder<TSpace> &
58DGtal::RegularPointEmbedder<TSpace>::
59operator=( const RegularPointEmbedder & other )
63 myGridSteps = other.myGridSteps;
67//-----------------------------------------------------------------------------
68template <typename TSpace>
71DGtal::RegularPointEmbedder<TSpace>
72::init( typename RealVector::Component gridStep )
74 myGridSteps = RealVector::diagonal( gridStep );
76//-----------------------------------------------------------------------------
77template <typename TSpace>
80DGtal::RegularPointEmbedder<TSpace>
81::init( const RealVector & aGridSteps )
83 myGridSteps = aGridSteps;
85//-----------------------------------------------------------------------------
86template <typename TSpace>
88typename DGtal::RegularPointEmbedder<TSpace>::Point
89DGtal::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//-----------------------------------------------------------------------------
98template <typename TSpace>
100typename DGtal::RegularPointEmbedder<TSpace>::Point
101DGtal::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//-----------------------------------------------------------------------------
110template <typename TSpace>
112typename DGtal::RegularPointEmbedder<TSpace>::Point
113DGtal::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//-----------------------------------------------------------------------------
122template <typename TSpace>
124typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
125DGtal::RegularPointEmbedder<TSpace>
126::embed( const Point & p ) const
128 return this->operator()( p );
130//-----------------------------------------------------------------------------
131template <typename TSpace>
133typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
134DGtal::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//-----------------------------------------------------------------------------
144template <typename TSpace>
146typename DGtal::RegularPointEmbedder<TSpace>::RealVector
147DGtal::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.
161template <typename TSpace>
164DGtal::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.
173template <typename TSpace>
176DGtal::RegularPointEmbedder<TSpace>::isValid() const
183///////////////////////////////////////////////////////////////////////////////
184// Implementation of inline functions //
186template <typename TSpace>
189DGtal::operator<< ( std::ostream & out,
190 const RegularPointEmbedder<TSpace> & object )
192 object.selfDisplay( out );
197///////////////////////////////////////////////////////////////////////////////