DGtal 1.4.0
Loading...
Searching...
No Matches
TrueDigitalSurfaceLocalEstimator.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 TrueDigitalSurfaceLocalEstimator.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/14
23 *
24 * Implementation of inline methods defined in TrueDigitalSurfaceLocalEstimator.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//-----------------------------------------------------------------------------
42template <typename TKSpace, typename TShape, typename TGeometricFunctor>
43inline
44DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
45~TrueDigitalSurfaceLocalEstimator()
46{
47}
48//-----------------------------------------------------------------------------
49template <typename TKSpace, typename TShape, typename TGeometricFunctor>
50inline
51DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
52TrueDigitalSurfaceLocalEstimator()
53 : myKSpace( 0 ), myFct( 0 ), myEmbedder(),
54 myShape( 0 ), myH( 1.0 ),
55 myMaxIter( 20 ), myAccuracy( 0.0001 ), myGamma( 0.5 )
56{
57}
58//-----------------------------------------------------------------------------
59template <typename TKSpace, typename TShape, typename TGeometricFunctor>
60inline
61DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
62TrueDigitalSurfaceLocalEstimator( const Self& other )
63 : myKSpace( other.myKSpace ), myFct( other.myFct ), myEmbedder( other.myEmbedder ),
64 myShape( other.myShape ), myH( other.myH ),
65 myMaxIter( other.myMaxIter ), myAccuracy( other.myAccuracy ), myGamma( other.myGamma )
66{
67}
68//-----------------------------------------------------------------------------
69template <typename TKSpace, typename TShape, typename TGeometricFunctor>
70inline
71DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>&
72DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
73operator=( const Self& other )
74{
75 if ( this != &other )
76 {
77 myKSpace = other.myKSpace;
78 myFct = other.myFct;
79 myEmbedder = other.myEmbedder;
80 myShape = other.myShape;
81 myH = other.myH;
82 myMaxIter = other.myMaxIter;
83 myAccuracy = other.myAccuracy;
84 myGamma = other.myGamma;
85 }
86 return *this;
87}
88
89//-----------------------------------------------------------------------------
90template <typename TKSpace, typename TShape, typename TGeometricFunctor>
91inline
92typename DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::Scalar
93DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
94h() const
95{
96 return myH;
97}
98//-----------------------------------------------------------------------------
99template <typename TKSpace, typename TShape, typename TGeometricFunctor>
100inline
101void
102DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
103attach( ConstAlias<Shape> aShape )
104{
105 myShape = aShape;
106 if ( ( myShape != 0 ) && ( myFct != 0 ) ) myFct->attach( myShape );
107}
108//-----------------------------------------------------------------------------
109template <typename TKSpace, typename TShape, typename TGeometricFunctor>
110inline
111void
112DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
113setParams( ConstAlias<KSpace> ks,
114 Clone<GeometricFunctor> fct,
115 const int maxIter,
116 const Scalar accuracy,
117 const Scalar gamma )
118{
119 myKSpace = ks;
120 myFct = fct;
121 if ( ( myShape != 0 ) && ( myFct != 0 ) ) myFct->attach( myShape );
122 myEmbedder = SCellEmbedder( *myKSpace );
123 myMaxIter = maxIter;
124 myAccuracy = accuracy;
125 myGamma = gamma;
126}
127//-----------------------------------------------------------------------------
128template <typename TKSpace, typename TShape, typename TGeometricFunctor>
129template <typename SurfelConstIterator>
130inline
131void
132DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
133init( const Scalar _h,
134 SurfelConstIterator /* itb */,
135 SurfelConstIterator /* ite */ )
136{
137 myH = _h;
138}
139
140//-----------------------------------------------------------------------------
141template <typename TKSpace, typename TShape, typename TGeometricFunctor>
142template <typename SurfelConstIterator>
143inline
144typename DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::Quantity
145DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
146eval( SurfelConstIterator it ) const
147{
148 ASSERT( isValid() );
149 BOOST_CONCEPT_ASSERT(( boost::InputIterator<SurfelConstIterator> ));
150 return myFct->operator()( embed( *it ) );
151}
152//-----------------------------------------------------------------------------
153template <typename TKSpace, typename TShape, typename TGeometricFunctor>
154template <typename OutputIterator, typename SurfelConstIterator>
155inline
156OutputIterator
157DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
158eval( SurfelConstIterator itb,
159 SurfelConstIterator ite,
160 OutputIterator result ) const
161{
162 BOOST_CONCEPT_ASSERT(( boost::InputIterator<SurfelConstIterator> ));
163 BOOST_CONCEPT_ASSERT(( boost::OutputIterator<OutputIterator,Quantity> ));
164 for ( ; itb != ite; ++itb )
165 *result++ = this->eval( itb );
166 return result;
167}
168//-----------------------------------------------------------------------------
169template <typename TKSpace, typename TShape, typename TGeometricFunctor>
170inline
171typename DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::RealPoint
172DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
173embed( Surfel surfel ) const
174{
175 ASSERT( isValid() );
176 RealPoint p = myEmbedder( surfel );
177 p *= myH;
178 return ( myMaxIter > 0 )
179 ? myShape->nearestPoint( p, myAccuracy, myMaxIter, myGamma )
180 : p;
181}
182
183///////////////////////////////////////////////////////////////////////////////
184// Interface - public :
185
186/**
187 * Writes/Displays the object on an output stream.
188 * @param out the output stream where the object is written.
189 */
190template <typename TKSpace, typename TShape, typename TGeometricFunctor>
191inline
192void
193DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
194selfDisplay ( std::ostream & out ) const
195{
196 out << "[TrueDigitalSurfaceLocalEstimator]";
197}
198
199/**
200 * Checks the validity/consistency of the object.
201 * @return 'true' if the object is valid, 'false' otherwise.
202 */
203template <typename TKSpace, typename TShape, typename TGeometricFunctor>
204inline
205bool
206DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
207isValid() const
208{
209 return ( myKSpace != 0 )
210 && ( myFct != 0 )
211 && ( myShape != 0 )
212 && ( myEmbedder.isValid() );
213}
214
215
216
217///////////////////////////////////////////////////////////////////////////////
218// Implementation of inline functions //
219
220template <typename TKSpace, typename TShape, typename TGeometricFunctor>
221inline
222std::ostream&
223DGtal::operator<< ( std::ostream & out,
224 const TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor> & object )
225{
226 object.selfDisplay( out );
227 return out;
228}
229
230// //
231///////////////////////////////////////////////////////////////////////////////
232
233