DGtal  1.5.beta
DigitalSurfaceEmbedderWithNormalVectorEstimator.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 DigitalSurfaceEmbedderWithNormalVectorEstimator.ih
19  * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20  * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21  *
22  * @date 2012/02/14
23  *
24  * Implementation of inline methods defined in DigitalSurfaceEmbedderWithNormalVectorEstimator.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
40 
41 //-----------------------------------------------------------------------------
42 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
43 inline
44 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
45 ~DigitalSurfaceEmbedderWithNormalVectorEstimator()
46 {}
47 
48 //-----------------------------------------------------------------------------
49 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
50 inline
51 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
52 DigitalSurfaceEmbedderWithNormalVectorEstimator()
53  : myDSEmbedder( 0 ), myEstimator( 0 )
54 {}
55 
56 //-----------------------------------------------------------------------------
57 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
58 inline
59 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
60 DigitalSurfaceEmbedderWithNormalVectorEstimator
61 ( ConstAlias<DigitalSurfaceEmbedder> aDSEmbedder,
62  ConstAlias<NormalVectorEstimator> anEstimator )
63  : myDSEmbedder( &aDSEmbedder ),
64  myEstimator( &anEstimator )
65 {}
66 
67 //-----------------------------------------------------------------------------
68 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
69 inline
70 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
71 DigitalSurfaceEmbedderWithNormalVectorEstimator
72 ( const Self & other )
73  : myDSEmbedder( other.myDSEmbedder ),
74  myEstimator( other.myEstimator )
75 {}
76 
77 //-----------------------------------------------------------------------------
78 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
79 inline
80 typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::Self &
81 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
82 operator=
83 ( const Self & other )
84 {
85  myDSEmbedder = other.myDSEmbedder;
86  myEstimator = other.myEstimator;
87  return *this;
88 }
89 
90 //-----------------------------------------------------------------------------
91 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
92 inline
93 const typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::Surface &
94 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
95 surface() const
96 {
97  ASSERT( this->isValid() );
98  return myDSEmbedder->surface();
99 }
100 
101 //-----------------------------------------------------------------------------
102 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
103 inline
104 typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::RealPoint
105 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
106 operator()( const SCell & scell ) const
107 {
108  ASSERT( this->isValid() );
109  return myDSEmbedder->operator()( scell );
110 }
111 
112 //-----------------------------------------------------------------------------
113 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
114 inline
115 typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::RealVector
116 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
117 gradient( const SCell & scell ) const
118 {
119  ASSERT( this->isValid() );
120  return myEstimator->eval( scell );
121 }
122 
123 //-----------------------------------------------------------------------------
124 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
125 inline
126 typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::GradientMap
127 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
128 gradientMap() const
129 {
130  ASSERT( this->isValid() );
131  return GradientMap( *this );
132 }
133 
134 ///////////////////////////////////////////////////////////////////////////////
135 // Interface - public :
136 
137 /**
138  * Writes/Displays the object on an output stream.
139  * @param out the output stream where the object is written.
140  */
141 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
142 inline
143 void
144 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
145 selfDisplay ( std::ostream & out ) const
146 {
147  out << "[DigitalSurfaceEmbedderWithNormalVectorEstimator]";
148 }
149 
150 /**
151  * Checks the validity/consistency of the object.
152  * @return 'true' if the object is valid, 'false' otherwise.
153  */
154 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
155 inline
156 bool
157 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
158 isValid() const
159 {
160  return ( myEstimator != 0 ) && ( myDSEmbedder != 0 )
161  && ( myEstimator->isValid() ) && ( myDSEmbedder->isValid() );
162 }
163 
164 ///////////////////////////////////////////////////////////////////////////////
165 // class DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap
166 
167 //-----------------------------------------------------------------------------
168 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
169 inline
170 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
171 ~DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap()
172 {}
173 
174 //-----------------------------------------------------------------------------
175 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
176 inline
177 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
178 DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap()
179  : myEmbedder( 0 )
180 {}
181 
182 //-----------------------------------------------------------------------------
183 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
184 inline
185 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
186 DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap
187 ( ConstAlias<Embedder> embedder )
188  : myEmbedder( &embedder )
189 {}
190 
191 //-----------------------------------------------------------------------------
192 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
193 inline
194 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
195 DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap
196 ( const Self & other )
197  : myEmbedder( other.myEmbedder )
198 {}
199 
200 //-----------------------------------------------------------------------------
201 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
202 inline
203 typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::Self &
204 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
205 operator=
206 ( const Self & other )
207 {
208  myEmbedder = other.myEmbedder;
209  return *this;
210 }
211 
212 //-----------------------------------------------------------------------------
213 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
214 inline
215 typename DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::Value
216 DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimatorGradientMap<TDigitalSurfaceEmbedder, TNormalVectorEstimator>::
217 operator()( const Argument & arg ) const
218 {
219  ASSERT( myEmbedder != 0 );
220  return myEmbedder->gradient( arg );
221 }
222 
223 
224 ///////////////////////////////////////////////////////////////////////////////
225 // Implementation of inline functions //
226 
227 template < typename TDigitalSurfaceEmbedder, typename TNormalVectorEstimator >
228 inline
229 std::ostream&
230 DGtal::operator<< ( std::ostream & out,
231  const DigitalSurfaceEmbedderWithNormalVectorEstimator<TDigitalSurfaceEmbedder, TNormalVectorEstimator> & object )
232 {
233  object.selfDisplay( out );
234  return out;
235 }
236 
237 // //
238 ///////////////////////////////////////////////////////////////////////////////
239 
240