DGtal 1.4.2
Loading...
Searching...
No Matches
CanonicEmbedder.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 CanonicEmbedder.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
21 *
22 * @date 2012/02/28
23 *
24 * Implementation of inline methods defined in CanonicEmbedder.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
32
33//////////////////////////////////////////////////////////////////////////////
34#include <cstdlib>
35#include <cmath>
36#include "DGtal/kernel/NumberTraits.h"
37//////////////////////////////////////////////////////////////////////////////
38
39
40
41///////////////////////////////////////////////////////////////////////////////
42// Implementation of inline methods //
43//-----------------------------------------------------------------------------
44template <typename TSpace>
45inline
46typename DGtal::CanonicEmbedder<TSpace>::Point
47DGtal::CanonicEmbedder<TSpace>::floor( const RealPoint & p ) const
48{
49 Point dp;
50 for ( Dimension i = 0; i < dp.size(); ++i )
51 dp[ i ] = (Integer) floor( p[ i ] );
52 return dp;
53}
54//-----------------------------------------------------------------------------
55template <typename TSpace>
56inline
57typename DGtal::CanonicEmbedder<TSpace>::Point
58DGtal::CanonicEmbedder<TSpace>::ceil( const RealPoint & p ) const
59{
60 Point dp;
61 for ( Dimension i = 0; i < dp.size(); ++i )
62 dp[ i ] = (Integer) ceil( p[ i ] );
63 return dp;
64}
65//-----------------------------------------------------------------------------
66template <typename TSpace>
67inline
68typename DGtal::CanonicEmbedder<TSpace>::Point
69DGtal::CanonicEmbedder<TSpace>::round( const RealPoint & p ) const
70{
71 Point dp;
72 for ( Dimension i = 0; i < dp.size(); ++i )
73 dp[ i ] = (Integer) round( p[ i ] );
74 return dp;
75}
76//-----------------------------------------------------------------------------
77template <typename TSpace>
78inline
79typename DGtal::CanonicEmbedder<TSpace>::RealPoint
80DGtal::CanonicEmbedder<TSpace>::embed( const Point & dp ) const
81{
82 return this->operator()( dp );
83}
84//-----------------------------------------------------------------------------
85template <typename TSpace>
86inline
87typename DGtal::CanonicEmbedder<TSpace>::RealPoint
88DGtal::CanonicEmbedder<TSpace>::operator()( const Point & dp ) const
89{
90 RealPoint p;
91 for ( Dimension i = 0; i < dp.size(); ++i )
92 p[ i ] = NumberTraits<Integer>::castToDouble( dp[ i ] );
93 return p;
94}
95//-----------------------------------------------------------------------------
96template <typename TSpace>
97inline
98bool
99DGtal::CanonicEmbedder<TSpace>::isValid( ) const
100{
101 return true;
102}
103///////////////////////////////////////////////////////////////////////////////
104// Implementation of inline functions and external operators //
105
106/**
107 * Overloads 'operator<<' for displaying objects of class 'CanonicEmbedder'.
108 * @param out the output stream where the object is written.
109 * @param object the object of class 'CanonicEmbedder' to write.
110 * @return the output stream after the writing.
111 */
112template <typename TSpace>
113inline
114std::ostream&
115DGtal::operator<< ( std::ostream & out,
116 const CanonicEmbedder<TSpace> & object )
117{
118 object.selfDisplay ( out );
119 return out;
120}
121
122// //
123///////////////////////////////////////////////////////////////////////////////
124
125