DGtal  1.5.beta
CanonicDigitalSurfaceEmbedder.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 CanonicDigitalSurfaceEmbedder.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 CanonicDigitalSurfaceEmbedder.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 //-----------------------------------------------------------------------------
44 template <typename TDigitalSurface>
45 inline
46 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::
47 ~CanonicDigitalSurfaceEmbedder()
48 {}
49 //-----------------------------------------------------------------------------
50 template <typename TDigitalSurface>
51 inline
52 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::
53 CanonicDigitalSurfaceEmbedder()
54  : mySurface( 0 )
55 {}
56 //-----------------------------------------------------------------------------
57 template <typename TDigitalSurface>
58 inline
59 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::
60 CanonicDigitalSurfaceEmbedder( ConstAlias<Surface> aSurface )
61  : mySurface( &aSurface )
62 {}
63 //-----------------------------------------------------------------------------
64 template <typename TDigitalSurface>
65 inline
66 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::
67 CanonicDigitalSurfaceEmbedder( const Self & other )
68  : mySurface( other.mySurface )
69 {}
70 //-----------------------------------------------------------------------------
71 template <typename TDigitalSurface>
72 inline
73 typename DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::Self &
74 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::
75 operator=( const Self & other )
76 {
77  mySurface = other.mySurface;
78  return *this;
79 }
80 //-----------------------------------------------------------------------------
81 template <typename TDigitalSurface>
82 inline
83 const typename DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::Surface &
84 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::surface() const
85 {
86  ASSERT( this->isValid() );
87  return *mySurface;
88 }
89 //-----------------------------------------------------------------------------
90 template <typename TDigitalSurface>
91 inline
92 typename DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::RealPoint
93 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::embed( const SCell & scell ) const
94 {
95  return this->operator()( scell );
96 }
97 //-----------------------------------------------------------------------------
98 template <typename TDigitalSurface>
99 inline
100 typename DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::RealPoint
101 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::operator()( const SCell & scell ) const
102 {
103  ASSERT( this->isValid() );
104  Point dp = mySurface->container().space().sKCoords( scell );
105  RealPoint p;
106  for ( Dimension i = 0; i < dp.size(); ++i )
107  p[ i ] = NumberTraits<Integer>::castToDouble( dp[ i ] ) / 2;
108  return p;
109 }
110 //-----------------------------------------------------------------------------
111 template <typename TDigitalSurface>
112 inline
113 bool
114 DGtal::CanonicDigitalSurfaceEmbedder<TDigitalSurface>::isValid( ) const
115 {
116  return mySurface != 0;
117 }
118 ///////////////////////////////////////////////////////////////////////////////
119 // Implementation of inline functions and external operators //
120 
121 /**
122  * Overloads 'operator<<' for displaying objects of class 'CanonicDigitalSurfaceEmbedder'.
123  * @param out the output stream where the object is written.
124  * @param object the object of class 'CanonicDigitalSurfaceEmbedder' to write.
125  * @return the output stream after the writing.
126  */
127 template <typename TDigitalSurface>
128 inline
129 std::ostream&
130 DGtal::operator<< ( std::ostream & out,
131  const CanonicDigitalSurfaceEmbedder<TDigitalSurface> & object )
132 {
133  object.selfDisplay ( out );
134  return out;
135 }
136 
137 // //
138 ///////////////////////////////////////////////////////////////////////////////
139 
140