DGtal 1.3.0
Loading...
Searching...
No Matches
LocalConvolutionNormalVectorEstimator.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
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 2011/06/27
23 *
24 * Implementation of inline methods defined in SummationBasedNormalVectorEstimator.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 * Constructor.
43 */
44template <typename DigitalSurf, typename KernelFunctor>
45inline
46DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>
47::LocalConvolutionNormalVectorEstimator (
48 ConstAlias<DigitalSurf> digitalSurface,
49 ConstAlias<KernelFunctor> aKernelFunctor )
50 : mySurface ( digitalSurface ), myKernelFunctor ( aKernelFunctor )
51{
52}
53
54/**
55 * Init.
56 */
57template <typename DigitalSurf, typename KernelFunctor>
58inline
59void
60DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::init ( const double h,
61 const unsigned int radius )
62{
63 myFlagIsInit = true;
64 myH = h;
65 myRadius = radius;
66}
67
68/**
69 * @return the estimated quantity at *it
70 * from itb till ite
71 */
72template <typename DigitalSurf, typename KernelFunctor>
73template <typename OutputIterator>
74inline
75OutputIterator
76DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
77eval ( const ConstIterator& itb,
78 const ConstIterator& ite,
79 OutputIterator result ) const
80{
81 for ( ConstIterator it = itb; it != ite; ++it )
82 {
83 Quantity q = eval( *it );
84 *result++ = q;
85 }
86
87 return result;
88}
89
90//-----------------------------------------------------------------------------
91template <typename DigitalSurf, typename KernelFunctor>
92inline
93const typename DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::Surface &
94DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
95surface() const
96{
97 return mySurface;
98}
99
100//-----------------------------------------------------------------------------
101template <typename DigitalSurf, typename KernelFunctor>
102template <typename OutputIterator>
103inline
104OutputIterator
105DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
106evalAll ( OutputIterator result ) const
107{
108 for ( ConstIterator it = surface().begin(), it_end = surface().end();
109 it != it_end; ++it )
110 {
111 *result++ = eval ( *it );
112 }
113
114 return result;
115}
116
117/**
118 * @return the estimated quantity at *it
119 */
120
121template <typename DigitalSurf, typename KernelFunctor>
122inline
123typename DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::Quantity
124DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::eval ( const ConstIterator& it ) const
125{
126 return eval ( *it );
127}
128//-----------------------------------------------------------------------------
129template <typename DigitalSurf, typename KernelFunctor>
130inline
131typename DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::Quantity
132DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
133eval ( const SCell & scell ) const
134{
135 typedef BreadthFirstVisitor<DigitalSurf> MyBreadthFirstVisitor;
136 typedef typename MyBreadthFirstVisitor::Node MyNode;
137 MyBreadthFirstVisitor visitor ( mySurface, scell );
138
139 MyNode node;
140 Quantity n, elementary;
141 Dimension i;
142 typename DigitalSurf::Surfel s;
143 const typename DigitalSurf::KSpace & K = mySurface.container().space();
144
145 ASSERT ( myFlagIsInit );
146
147 while ( ! visitor.finished() )
148 {
149 node = visitor.current();
150 if ( node.second < myRadius )
151 {
152 s = node.first;
153 i = K.sOrthDir ( s );
154 elementary[ i ] = K.sDirect ( s, i ) ? 1 : -1;
155
156 elementary *= myKernelFunctor ( node.second );
157 n+= elementary;
158
159 elementary [ i ] = 0;
160
161 visitor.expand();
162 }
163 else
164 visitor.ignore();
165 }
166 return n.getNormalized();
167}
168
169
170/**
171 * Checks the validity/consistency of the object.
172 * @return 'true' if the object is valid, 'false' otherwise.
173 */
174template <typename DigitalSurf, typename KernelFunctor>
175inline
176bool
177DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::isValid() const
178{
179 return true;
180}