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.
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.
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/>.
18 * @file IntegralInvariantNormalVectorEstimator.ih
19 * @author Jeremy Levallois (\c jeremy.levallois@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), INSA-Lyon, France
21 * LAboratoire de MAthématiques - LAMA (CNRS, UMR 5127), Université de Savoie, France
22 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
23 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
27 * Implementation of inline methods defined in IntegralInvariantNormalVectorEstimator.h
29 * This file is part of the DGtal library.
33//////////////////////////////////////////////////////////////////////////////
35#include "DGtal/math/BasicMathFunctions.h"
36//////////////////////////////////////////////////////////////////////////////
38///////////////////////////////////////////////////////////////////////////////
39// IMPLEMENTATION of inline methods.
40///////////////////////////////////////////////////////////////////////////////
42///////////////////////////////////////////////////////////////////////////////
43// ----------------------- Standard services ------------------------------
45//-----------------------------------------------------------------------------
46template <typename TKSpace, typename TPointPredicate>
48DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
49~IntegralInvariantNormalVectorEstimator()
54//-----------------------------------------------------------------------------
55template <typename TKSpace, typename TPointPredicate>
58DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
61 for( unsigned int i = 0; i < myKernelsSet.size(); ++i )
62 if ( myKernelsSet[ i ] != 0 ) delete myKernelsSet[ i ];
66//-----------------------------------------------------------------------------
67template <typename TKSpace, typename TPointPredicate>
69DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
70IntegralInvariantNormalVectorEstimator()
71 : myKernelFunctor(NumberTraits<Value>::ONE),
72 myKernels(), myKernelsSet(),
73 myKernel( 0 ), myDigKernel( 0 ),
74 myPointPredicate( 0 ), myShapeDomain( 0 ),
75 myShapePointFunctor( 0 ), myShapeSpelFunctor( 0 ),
77 myH( 1.0 ), myRadius( 0.0 )
81//-----------------------------------------------------------------------------
82template <typename TKSpace, typename TPointPredicate>
84DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
85IntegralInvariantNormalVectorEstimator
86( ConstAlias< KSpace > K, ConstAlias< PointPredicate > aPointPredicate )
87 : myKernelFunctor(NumberTraits<Value>::ONE),
88 myKernels(), myKernelsSet(),
89 myKernel( 0 ), myDigKernel( 0 ),
90 myPointPredicate( aPointPredicate ), myShapeDomain( 0 ),
91 myShapePointFunctor( 0 ), myShapeSpelFunctor( 0 ),
93 myH( 1.0 ), myRadius( 0.0 )
95 CountedConstPtrOrConstPtr<KSpace> ptrK( K );
96 myShapeDomain = CountedPtr<Domain>( new Domain( ptrK->lowerBound(), ptrK->upperBound() ) );
97 myShapePointFunctor = CountedPtr<ShapePointFunctor>( new ShapePointFunctor( *myPointPredicate, *myShapeDomain, 1, 0 ) );
98 myShapeSpelFunctor = CountedPtr<ShapeSpelFunctor>( new ShapeSpelFunctor( *myShapePointFunctor, K ) );
99 myConvolver = CountedPtr<Convolver>( new Convolver( *myShapeSpelFunctor, myKernelFunctor, K ) );
102//-----------------------------------------------------------------------------
103template <typename TKSpace, typename TPointPredicate>
105DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
106IntegralInvariantNormalVectorEstimator
108 : myKernelFunctor( other.myKernelFunctor ),
109 myKernels( other.myKernels ), myKernelsSet( other.myKernelsSet ),
110 myKernel( other.myKernel ), myDigKernel( other.myDigKernel ),
111 myPointPredicate( other.myPointPredicate ), myShapeDomain( other.myShapeDomain ),
112 myShapePointFunctor( other.myShapePointFunctor ), myShapeSpelFunctor( other.myShapeSpelFunctor ),
113 myConvolver( other.myConvolver ),
114 myH( other.myH ), myRadius( other.myRadius )
116//-----------------------------------------------------------------------------
117template <typename TKSpace, typename TPointPredicate>
119typename DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::Self&
120DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
121operator= ( const Self& other )
123 if ( this != &other )
125 // myKernelFunctor = other.myKernelFunctor;
126 myKernels = other.myKernels;
127 myKernelsSet = other.myKernelsSet;
128 myKernel = other.myKernel;
129 myDigKernel = other.myDigKernel;
130 myPointPredicate = other.myPointPredicate;
131 myShapeDomain = other.myShapeDomain;
132 myShapePointFunctor = other.myShapePointFunctor;
133 myShapeSpelFunctor = other.myShapeSpelFunctor;
134 myConvolver = other.myConvolver;
136 myRadius = other.myRadius;
140//-----------------------------------------------------------------------------
141template <typename TKSpace, typename TPointPredicate>
143typename DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::Scalar
144DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
149//-----------------------------------------------------------------------------
150template <typename TKSpace, typename TPointPredicate>
153DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
155( ConstAlias< KSpace > K,
156 ConstAlias<PointPredicate> aPointPredicate )
158 myPointPredicate = aPointPredicate;
159 CountedConstPtrOrConstPtr<KSpace> ptrK( K );
160 myShapeDomain = CountedPtr<Domain>( new Domain( ptrK->lowerBound(), ptrK->upperBound() ) );
161 myShapePointFunctor = CountedPtr<ShapePointFunctor>( new ShapePointFunctor( *myPointPredicate, *myShapeDomain, 1, 0 ) );
162 myShapeSpelFunctor = CountedPtr<ShapeSpelFunctor>( new ShapeSpelFunctor( *myShapePointFunctor, K ) );
163 myConvolver = CountedPtr<Convolver>( new Convolver( *myShapeSpelFunctor, myKernelFunctor, K ) );
165//-----------------------------------------------------------------------------
166template <typename TKSpace, typename TPointPredicate>
169DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
171( const double dRadius )
173 ASSERT( ( dRadius > 0.0 )
174 && "[DGtal::deprecated::IntegralInvariantNormalVectorEstimator:setParams] Radius parameter dRadius must be positive." );
178//-----------------------------------------------------------------------------
179template <typename TKSpace, typename TPointPredicate>
180template <typename SurfelConstIterator>
183DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
185( const double _h, SurfelConstIterator /* itb */, SurfelConstIterator /* ite */ )
188 && "[DGtal::deprecated::IntegralInvariantNormalVectorEstimator:init] Gridstep parameter h must be positive." );
189 ASSERT( ( myRadius > 0.0 )
190 && "[DGtal::deprecated::IntegralInvariantNormalVectorEstimator:init] Radius parameter dRadius must have been initialized with a call to 'setParams'." );
191 ASSERT( ( myConvolver != 0 )
192 && "[DGtal::deprecated::IntegralInvariantNormalVectorEstimator:init] Shape of interest must have been initialized with a call to 'attach'." );
194 typedef typename RealPoint::Component Scalar;
196 for( unsigned int i = 0; i < myKernelsSet.size(); ++i )
197 if ( myKernelsSet[ i ] != 0 ) delete myKernelsSet[ i ];
200 double eRadius = myRadius * myH; // Euclidean radius of the ball kernel.
202 // meanFunctor.init( h, radius );
204 RealPoint rOrigin = RealPoint::zero;
205 Point pOrigin = Point::zero;
206 myKernel = CountedPtr<KernelSupport>( new KernelSupport( rOrigin, eRadius ) ); // acquired
207 myDigKernel = CountedPtr<DigitalShapeKernel>( new DigitalShapeKernel() );
208 myDigKernel->attach( *myKernel );
209 myDigKernel->init( myKernel->getLowerBound() + Point::diagonal(-1), myKernel->getUpperBound() + Point::diagonal(1), myH );
210 Domain neighborhood( Point::diagonal(-1), Point::diagonal(1) );
211 unsigned int n = BasicMathFunctions::power( (unsigned int) 3, Space::dimension );
212 myKernels = std::vector< PairIterators > ( n );
213 myKernelsSet = std::vector< DigitalSet* >( n );
214 unsigned int offset = 0;
215 unsigned int middle = n / 2;
216 RealPoint shiftPoint;
217 for ( typename Domain::ConstIterator it_neigh = neighborhood.begin(),
218 it_neigh_end = neighborhood.end();
219 it_neigh != it_neigh_end;
220 ++it_neigh, ++offset )
222 /// Computation of shifting masks
223 if( offset == middle ) continue; // no shift
224 for ( Dimension k = 0; k < Space::dimension; ++k )
225 shiftPoint[ k ] = (Scalar) (*it_neigh)[ k ];
226 shiftPoint *= (Scalar) myH;
227 KernelSupport* kernelShifted = new KernelSupport( shiftPoint, eRadius );
228 EuclideanMinus* current = new EuclideanMinus( *myKernel, *kernelShifted );
229 DigitalShape digCurrent;
230 digCurrent.attach( *current );
231 digCurrent.init( myKernel->getLowerBound() + Point::diagonal(-1), myKernel->getUpperBound() + Point::diagonal(1), myH );
233 myKernelsSet[ offset ] = new DigitalSet( digCurrent.getDomain() );
234 Shapes< Domain>::digitalShaper ( *(myKernelsSet[ offset ]), digCurrent );
236 myKernels[ offset ].first = myKernelsSet[ offset ]->begin();
237 myKernels[ offset ].second = myKernelsSet[ offset ]->end();
240 delete kernelShifted;
242 /// End of computation of masks
243 myConvolver->init( pOrigin, *myDigKernel, myKernels );
246//-----------------------------------------------------------------------------
247template <typename TKSpace, typename TPointPredicate>
248template <typename SurfelConstIterator>
250typename DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::Quantity
251DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::
253( SurfelConstIterator it ) const
255 CovarianceMatrix2NormalDirectionFunctor normalFunctor;
256 return normalFunctor( myConvolver->evalCovarianceMatrix( it ) );
259//-----------------------------------------------------------------------------
260template <typename TKSpace, typename TPointPredicate>
261template <typename OutputIterator, typename SurfelConstIterator>
264DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::eval
265( SurfelConstIterator itb,
266 SurfelConstIterator ite,
267 OutputIterator result ) const
269 CovarianceMatrix2NormalDirectionFunctor normalFunctor;
270 myConvolver->evalCovarianceMatrix( itb, ite, result, normalFunctor );
274//-----------------------------------------------------------------------------
275template <typename TKSpace, typename TPointPredicate>
278DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::selfDisplay
279( std::ostream & out ) const
281 out << "[IntegralInvariantNormalVectorEstimator h=" << myH
282 << " digR=" << myRadius << " eucR=" << (myH*myRadius) << " ]";
285//-----------------------------------------------------------------------------
286template <typename TKSpace, typename TPointPredicate>
289DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate>::isValid() const
291 return ( myH > 0 ) && ( myRadius > 0 ) && ( myConvolver != 0 );
294//-----------------------------------------------------------------------------
295template <typename TKSpace, typename TPointPredicate>
300 const DGtal::deprecated::IntegralInvariantNormalVectorEstimator<TKSpace, TPointPredicate> & object )
302 object.selfDisplay( out );