DGtal  0.9.2
VCMDigitalSurfaceLocalEstimator.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 VCMDigitalSurfaceLocalEstimator.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 2014/02/13
23  *
24  * Implementation of inline methods defined in VCMDigitalSurfaceLocalEstimator.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 TDigitalSurfaceContainer, typename TSeparableMetric,
43  typename TKernelFunction, typename TVCMGeometricFunctor>
44 inline
45 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
46 ~VCMDigitalSurfaceLocalEstimator()
47 {
48 }
49 
50 //-----------------------------------------------------------------------------
51 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
52  typename TKernelFunction, typename TVCMGeometricFunctor>
53 inline
54 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
55 VCMDigitalSurfaceLocalEstimator()
56  : mySurface( 0 ),
57  mySurfelEmbedding( InnerSpel ),
58  myVCMOnSurface( 0 ),
59  myGeomFct(),
60  myH( 1.0 )
61 {
62 }
63 
64 //-----------------------------------------------------------------------------
65 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
66  typename TKernelFunction, typename TVCMGeometricFunctor>
67 inline
68 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
69 VCMDigitalSurfaceLocalEstimator( const Self& other )
70  : mySurface( other.mySurface ),
71  mySurfelEmbedding( other.mySurfelEmbedding ),
72  myVCMOnSurface( other.myVCMOnSurface ),
73  myGeomFct( other.myGeomFct ),
74  myH( other.myH )
75 {
76 }
77 
78 //-----------------------------------------------------------------------------
79 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
80  typename TKernelFunction, typename TVCMGeometricFunctor>
81 inline
82 typename DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::Self&
83 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
84 operator=( const Self& other )
85 {
86  if ( this != &other )
87  {
88  mySurface = other.mySurface;
89  mySurfelEmbedding = other.mySurfelEmbedding;
90  myVCMOnSurface = other.myVCMOnSurface;
91  myGeomFct = other.myGeomFct;
92  myH = other.myH;
93  }
94  return *this;
95 }
96 
97 //-----------------------------------------------------------------------------
98 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
99  typename TKernelFunction, typename TVCMGeometricFunctor>
100 inline
101 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
102 VCMDigitalSurfaceLocalEstimator( ConstAlias< VCMOnSurface > vcmSurface )
103  : mySurface( vcmSurface->surface() ),
104  mySurfelEmbedding( vcmSurface->surfelEmbedding() ),
105  myVCMOnSurface( vcmSurface ),
106  myGeomFct( vcmSurface ),
107  myH( 1.0 )
108 {
109 }
110 //-----------------------------------------------------------------------------
111 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
112  typename TKernelFunction, typename TVCMGeometricFunctor>
113 inline
114 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
115 VCMDigitalSurfaceLocalEstimator( ConstAlias< Surface > surface )
116  : mySurface( surface ),
117  mySurfelEmbedding( InnerSpel ),
118  myVCMOnSurface( 0 ),
119  myGeomFct(),
120  myH( 1.0 )
121 {
122 }
123 
124 //-----------------------------------------------------------------------------
125 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
126  typename TKernelFunction, typename TVCMGeometricFunctor>
127 inline
128 void
129 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
130 attach( ConstAlias<Surface> surface )
131 {
132  mySurface = surface;
133  myVCMOnSurface = CountedConstPtrOrConstPtr<VCMOnSurface>( 0,false );
134 }
135 
136 //-----------------------------------------------------------------------------
137 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
138  typename TKernelFunction, typename TVCMGeometricFunctor>
139 inline
140 void
141 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
142 setParams( Surfel2PointEmbedding surfelEmbedding,
143  const Scalar R, const Scalar r, KernelFunction chi_r,
144  const Scalar t, Metric aMetric, bool verbose )
145 {
146  mySurfelEmbedding = surfelEmbedding;
147  myVCMOnSurface = CountedConstPtrOrConstPtr<VCMOnSurface>
148  ( new VCMOnSurface( mySurface, mySurfelEmbedding,
149  R, r, chi_r, t, aMetric, verbose ), true );
150  myGeomFct.attach( myVCMOnSurface );
151 }
152 //-----------------------------------------------------------------------------
153 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
154  typename TKernelFunction, typename TVCMGeometricFunctor>
155 template <typename SurfelConstIterator>
156 inline
157 void
158 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
159 init( const Scalar _h,
160  SurfelConstIterator /* itb */,
161  SurfelConstIterator /* ite */ )
162 {
163  ASSERT( mySurface != 0 );
164  ASSERT( myVCMOnSurface != 0 );
165  // Unused. The VCM is necessarily initialized on the whole surface.
166  myH = _h;
167 }
168 //-----------------------------------------------------------------------------
169 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
170  typename TKernelFunction, typename TVCMGeometricFunctor>
171 template <typename SurfelConstIterator>
172 inline
173 typename DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::Quantity
174 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
175 eval( SurfelConstIterator it ) const
176 {
177  BOOST_CONCEPT_ASSERT(( boost::InputIterator<SurfelConstIterator> ));
178  ASSERT( mySurface != 0 );
179  ASSERT( myVCMOnSurface != 0 );
180  return myGeomFct( *it );
181 }
182 //-----------------------------------------------------------------------------
183 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
184  typename TKernelFunction, typename TVCMGeometricFunctor>
185 template <typename SurfelConstIterator, typename OutputIterator>
186 inline
187 OutputIterator
188 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
189 eval( SurfelConstIterator itb,
190  SurfelConstIterator ite,
191  OutputIterator result ) const
192 {
193  BOOST_CONCEPT_ASSERT(( boost::InputIterator<SurfelConstIterator> ));
194  BOOST_CONCEPT_ASSERT(( boost::OutputIterator<OutputIterator,Quantity> ));
195  ASSERT( myVCMOnSurface != 0 );
196  for ( ; itb != ite; ++itb )
197  {
198  *result++ = myGeomFct( *itb );
199  }
200  return result;
201 }
202 
203 //-----------------------------------------------------------------------------
204 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
205  typename TKernelFunction, typename TVCMGeometricFunctor>
206 inline
207 typename DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::Scalar
208 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
209 h() const
210 {
211  return myH;
212 }
213 
214 ///////////////////////////////////////////////////////////////////////////////
215 // Interface - public :
216 
217 /**
218  * Writes/Displays the object on an output stream.
219  * @param out the output stream where the object is written.
220  */
221 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
222  typename TKernelFunction, typename TVCMGeometricFunctor>
223 inline
224 void
225 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
226 selfDisplay ( std::ostream & out ) const
227 {
228  out << "[VCMDigitalSurfaceLocalEstimator]";
229 }
230 
231 /**
232  * Checks the validity/consistency of the object.
233  * @return 'true' if the object is valid, 'false' otherwise.
234  */
235 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
236  typename TKernelFunction, typename TVCMGeometricFunctor>
237 inline
238 bool
239 DGtal::VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor>::
240 isValid() const
241 {
242  return true;
243 }
244 
245 
246 
247 ///////////////////////////////////////////////////////////////////////////////
248 // Implementation of inline functions //
249 
250 template <typename TDigitalSurfaceContainer, typename TSeparableMetric,
251  typename TKernelFunction, typename TVCMGeometricFunctor>
252 inline
253 std::ostream&
254 DGtal::operator<<( std::ostream & out,
255  const VCMDigitalSurfaceLocalEstimator<TDigitalSurfaceContainer, TSeparableMetric, TKernelFunction, TVCMGeometricFunctor> & object )
256 {
257  object.selfDisplay( out );
258  return out;
259 }
260 
261 // //
262 ///////////////////////////////////////////////////////////////////////////////
263 
264