DGtal 1.3.0
Loading...
Searching...
No Matches
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//-----------------------------------------------------------------------------
44template <typename TSpace>
45inline
46DGtal::RegularPointEmbedder<TSpace>::~RegularPointEmbedder()
47{
48}
49//-----------------------------------------------------------------------------
50template <typename TSpace>
51inline
52DGtal::RegularPointEmbedder<TSpace>::RegularPointEmbedder()
53{}
54//-----------------------------------------------------------------------------
55template <typename TSpace>
56inline
57DGtal::RegularPointEmbedder<TSpace> &
58DGtal::RegularPointEmbedder<TSpace>::
59operator=( const RegularPointEmbedder & other )
60{
61 if ( this != &other )
62 {
63 myGridSteps = other.myGridSteps;
64 }
65 return *this;
66}
67//-----------------------------------------------------------------------------
68template <typename TSpace>
69inline
70void
71DGtal::RegularPointEmbedder<TSpace>
72::init( typename RealVector::Component gridStep )
73{
74 myGridSteps = RealVector::diagonal( gridStep );
75}
76//-----------------------------------------------------------------------------
77template <typename TSpace>
78inline
79void
80DGtal::RegularPointEmbedder<TSpace>
81::init( const RealVector & aGridSteps )
82{
83 myGridSteps = aGridSteps;
84}
85//-----------------------------------------------------------------------------
86template <typename TSpace>
87inline
88typename DGtal::RegularPointEmbedder<TSpace>::Point
89DGtal::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//-----------------------------------------------------------------------------
98template <typename TSpace>
99inline
100typename DGtal::RegularPointEmbedder<TSpace>::Point
101DGtal::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//-----------------------------------------------------------------------------
110template <typename TSpace>
111inline
112typename DGtal::RegularPointEmbedder<TSpace>::Point
113DGtal::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//-----------------------------------------------------------------------------
122template <typename TSpace>
123inline
124typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
125DGtal::RegularPointEmbedder<TSpace>
126::embed( const Point & p ) const
127{
128 return this->operator()( p );
129}
130//-----------------------------------------------------------------------------
131template <typename TSpace>
132inline
133typename DGtal::RegularPointEmbedder<TSpace>::RealPoint
134DGtal::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//-----------------------------------------------------------------------------
144template <typename TSpace>
145inline
146typename DGtal::RegularPointEmbedder<TSpace>::RealVector
147DGtal::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 */
161template <typename TSpace>
162inline
163void
164DGtal::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 */
173template <typename TSpace>
174inline
175bool
176DGtal::RegularPointEmbedder<TSpace>::isValid() const
177{
178 return true;
179}
180
181
182
183///////////////////////////////////////////////////////////////////////////////
184// Implementation of inline functions //
185
186template <typename TSpace>
187inline
188std::ostream&
189DGtal::operator<< ( std::ostream & out,
190 const RegularPointEmbedder<TSpace> & object )
191{
192 object.selfDisplay( out );
193 return out;
194}
195
196// //
197///////////////////////////////////////////////////////////////////////////////
198
199