Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
LocalEstimatorFromSurfelFunctorAdapter.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 LocalEstimatorFromSurfelFunctorAdapter.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 *
22 * @date 2013/05/28
23 *
24 * Implementation of inline methods defined in LocalEstimatorFromSurfelFunctorAdapter.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29//////////////////////////////////////////////////////////////////////////////
30#include <cstdlib>
31//////////////////////////////////////////////////////////////////////////////
32
33///////////////////////////////////////////////////////////////////////////////
34// IMPLEMENTATION of inline methods.
35///////////////////////////////////////////////////////////////////////////////
36
37template <typename TDigitalSurfaceContainer, typename TMetric,
38 typename TFunctorOnSurfel, typename TConvolutionFunctor>
39inline
40DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
41 TFunctorOnSurfel, TConvolutionFunctor>::
42LocalEstimatorFromSurfelFunctorAdapter()
43{
44 myInit = false;
45}
46
47template <typename TDigitalSurfaceContainer, typename TMetric,
48 typename TFunctorOnSurfel, typename TConvolutionFunctor>
49inline
50DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
51 TFunctorOnSurfel, TConvolutionFunctor>::
52LocalEstimatorFromSurfelFunctorAdapter
53( ConstAlias< Surface > aSurf,
54 ConstAlias< Metric> aMetric,
55 Alias< FunctorOnSurfel > aFunctor,
56 ConstAlias< ConvolutionFunctor > aConvolutionFunctor)
57 : mySurface(aSurf), myFunctor(&aFunctor), myMetric(aMetric),
58 myEmbedder(Embedder( mySurface->container().space())), myConvFunctor(aConvolutionFunctor)
59{
60 myInit = false;
61}
62///////////////////////////////////////////////////////////////////////////////
63template <typename TDigitalSurfaceContainer, typename TMetric,
64 typename TFunctorOnSurfel, typename TConvolutionFunctor>
65inline
66DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
67 TFunctorOnSurfel, TConvolutionFunctor>::
68~LocalEstimatorFromSurfelFunctorAdapter()
69{
70}
71
72///////////////////////////////////////////////////////////////////////////////
73template <typename TDigitalSurfaceContainer, typename TMetric,
74 typename TFunctorOnSurfel, typename TConvolutionFunctor>
75inline
76void
77DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
78 TFunctorOnSurfel, TConvolutionFunctor>::
79selfDisplay ( std::ostream & out ) const
80{
81 out << "[LocalEstimatorFromSurfelFunctorAdapter]";
82}
83///////////////////////////////////////////////////////////////////////////////
84template <typename TDigitalSurfaceContainer, typename TMetric,
85 typename TFunctorOnSurfel, typename TConvolutionFunctor>
86inline
87bool
88DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
89 TFunctorOnSurfel, TConvolutionFunctor>::
90isValid() const
91{
92 return myInit;
93}
94
95
96//-----------------------------------------------------------------------------
97template <typename TDigitalSurfaceContainer, typename TMetric,
98 typename TFunctorOnSurfel, typename TConvolutionFunctor>
99inline
100void
101DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
102 TFunctorOnSurfel, TConvolutionFunctor>::
103attach( ConstAlias<Surface> aSurface )
104{
105 mySurface = aSurface;
106 myEmbedder = Embedder( mySurface->container().space());
107}
108
109//-----------------------------------------------------------------------------
110template <typename TDigitalSurfaceContainer, typename TMetric,
111 typename TFunctorOnSurfel, typename TConvolutionFunctor>
112inline
113void
114DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
115 TFunctorOnSurfel, TConvolutionFunctor>::
116setParams( ConstAlias<TMetric> aMetric,
117 Alias<FunctorOnSurfel> aFunctor,
118 ConstAlias<ConvolutionFunctor> aConvolutionFunctor,
119 const Value radius )
120{
121 ASSERT(radius>0);
122 myFunctor = &aFunctor;
123 myMetric = aMetric;
124 myConvFunctor = aConvolutionFunctor;
125 myRadius = radius;
126}
127
128//-----------------------------------------------------------------------------
129template <typename TDigitalSurfaceContainer, typename TMetric,
130 typename TFunctorOnSurfel, typename TConvolutionFunctor>
131inline
132typename DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric, TFunctorOnSurfel, TConvolutionFunctor>::Scalar
133DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
134 TFunctorOnSurfel, TConvolutionFunctor>::
135h() const
136{
137 return myH;
138}
139
140///////////////////////////////////////////////////////////////////////////////
141template <typename TDigitalSurfaceContainer, typename TMetric,
142 typename TFunctorOnSurfel, typename TConvolutionFunctor>
143
144template<typename SurfelIt>
145inline
146void
147DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
148 TFunctorOnSurfel, TConvolutionFunctor>::
149init(const double _h,
150 SurfelIt /*itb*/,
151 SurfelIt /*ite*/)
152{
153 ASSERT(_h>0);
154 myH = _h;
155 myInit = true;
156}
157///////////////////////////////////////////////////////////////////////////////
158template <typename TDigitalSurfaceContainer, typename TMetric,
159 typename TFunctorOnSurfel, typename TConvolutionFunctor>
160template <typename SurfelConstIterator>
161inline
162typename DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
163 TFunctorOnSurfel, TConvolutionFunctor>::Quantity
164DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
165 TFunctorOnSurfel, TConvolutionFunctor>::
166eval( const SurfelConstIterator& it ) const
167{
168 ASSERT_MSG( isValid(), "Missing init() before evaluation" );
169 const MetricToPoint metricToPoint = std::bind( *myMetric, myEmbedder( *it ), std::placeholders::_1 );
170 const VertexFunctor vfunctor( myEmbedder, metricToPoint);
171 Visitor visitor( *mySurface, vfunctor, *it);
172 ASSERT( ! visitor.finished() );
173 double currentDistance = 0.0;
174 while ( (! visitor.finished() ) && (currentDistance < myRadius) )
175 {
176 typename Visitor::Node node = visitor.current();
177 currentDistance = node.second;
178 if ( currentDistance < myRadius )
179 myFunctor->pushSurfel( node.first , myConvFunctor->operator()((myRadius - currentDistance)/myRadius));
180 else break;
181 visitor.expand();
182 }
183 Quantity val = myFunctor->eval();
184 myFunctor->reset();
185 return val;
186}
187///////////////////////////////////////////////////////////////////////////////
188template <typename TDigitalSurfaceContainer, typename TMetric,
189 typename TFunctorOnSurfel, typename TConvolutionFunctor>
190inline
191typename DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
192 TFunctorOnSurfel, TConvolutionFunctor>::Quantity
193DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
194 TFunctorOnSurfel, TConvolutionFunctor>::
195eval( const Surfel& scell ) const
196{
197 ASSERT_MSG( isValid(), "Missing init() before evaluation" );
198 const MetricToPoint metricToPoint = std::bind( *myMetric, myEmbedder( scell ), std::placeholders::_1 );
199 const VertexFunctor vfunctor( myEmbedder, metricToPoint);
200 Visitor visitor( *mySurface, vfunctor, scell);
201 ASSERT( ! visitor.finished() );
202 double currentDistance = 0.0;
203 while ( (! visitor.finished() ) && (currentDistance < myRadius) )
204 {
205 typename Visitor::Node node = visitor.current();
206 currentDistance = node.second;
207 if ( currentDistance < myRadius )
208 myFunctor->pushSurfel( node.first , myConvFunctor->operator()((myRadius - currentDistance)/myRadius));
209 else break;
210 visitor.expand();
211 }
212 Quantity val = myFunctor->eval();
213 myFunctor->reset();
214 return val;
215}
216///////////////////////////////////////////////////////////////////////////////
217template <typename TDigitalSurfaceContainer, typename TMetric,
218 typename TFunctorOnSurfel, typename TConvolutionFunctor>
219template <typename SurfelConstIterator, typename OutputIterator>
220inline
221OutputIterator
222DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
223 TFunctorOnSurfel, TConvolutionFunctor>::
224eval ( const SurfelConstIterator& itb,
225 const SurfelConstIterator& ite,
226 OutputIterator result ) const
227{
228 for ( SurfelConstIterator it = itb; it != ite; ++it )
229 {
230 Quantity q = eval( it );
231 *result++ = q;
232 }
233 return result;
234}
235///////////////////////////////////////////////////////////////////////////////
236template <typename TDigitalSurfaceContainer, typename TMetric,
237 typename TFunctorOnSurfel, typename TConvolutionFunctor>
238template <typename OutputIterator>
239inline
240OutputIterator
241DGtal::LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
242 TFunctorOnSurfel, TConvolutionFunctor>::
243evalAll ( OutputIterator result ) const
244{
245 for ( auto it = mySurface->begin(), it_end = mySurface->end();
246 it != it_end; ++it )
247 {
248 *result++ = eval ( *it );
249 }
250
251 return result;
252}
253
254
255///////////////////////////////////////////////////////////////////////////////
256template <typename TDigitalSurfaceContainer, typename TMetric,
257 typename TFunctorOnSurfel, typename TConvolutionFunctor>
258inline
259std::ostream&
260DGtal::operator<< ( std::ostream & out,
261 const LocalEstimatorFromSurfelFunctorAdapter<TDigitalSurfaceContainer, TMetric,
262 TFunctorOnSurfel, TConvolutionFunctor> & object )
263{
264 object.selfDisplay( out );
265 return out;
266}
267///////////////////////////////////////////////////////////////////////////////