DGtal  1.5.beta
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  */
44 template <typename DigitalSurf, typename KernelFunctor>
45 inline
46 DGtal::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  */
57 template <typename DigitalSurf, typename KernelFunctor>
58 inline
59 void
60 DGtal::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  */
72 template <typename DigitalSurf, typename KernelFunctor>
73 template <typename OutputIterator>
74 inline
75 OutputIterator
76 DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
77 eval ( 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 //-----------------------------------------------------------------------------
91 template <typename DigitalSurf, typename KernelFunctor>
92 inline
93 const typename DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::Surface &
94 DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
95 surface() const
96 {
97  return mySurface;
98 }
99 
100 //-----------------------------------------------------------------------------
101 template <typename DigitalSurf, typename KernelFunctor>
102 template <typename OutputIterator>
103 inline
104 OutputIterator
105 DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
106 evalAll ( 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 
121 template <typename DigitalSurf, typename KernelFunctor>
122 inline
123 typename DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::Quantity
124 DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::eval ( const ConstIterator& it ) const
125 {
126  return eval ( *it );
127 }
128 //-----------------------------------------------------------------------------
129 template <typename DigitalSurf, typename KernelFunctor>
130 inline
131 typename DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::Quantity
132 DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::
133 eval ( 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  */
174 template <typename DigitalSurf, typename KernelFunctor>
175 inline
176 bool
177 DGtal::deprecated::LocalConvolutionNormalVectorEstimator<DigitalSurf,KernelFunctor>::isValid() const
178 {
179  return true;
180 }