DGtal  1.5.beta
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 //-----------------------------------------------------------------------------
42 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
43 inline
44 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
45 ~TrueDigitalSurfaceLocalEstimator()
46 {
47 }
48 //-----------------------------------------------------------------------------
49 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
50 inline
51 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
52 TrueDigitalSurfaceLocalEstimator()
53  : myKSpace( 0 ), myFct( 0 ), myEmbedder(),
54  myShape( 0 ), myH( 1.0 ),
55  myMaxIter( 20 ), myAccuracy( 0.0001 ), myGamma( 0.5 )
56 {
57 }
58 //-----------------------------------------------------------------------------
59 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
60 inline
61 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
62 TrueDigitalSurfaceLocalEstimator( 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 //-----------------------------------------------------------------------------
69 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
70 inline
71 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>&
72 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
73 operator=( 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 //-----------------------------------------------------------------------------
90 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
91 inline
92 typename DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::Scalar
93 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
94 h() const
95 {
96  return myH;
97 }
98 //-----------------------------------------------------------------------------
99 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
100 inline
101 void
102 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
103 attach( ConstAlias<Shape> aShape )
104 {
105  myShape = aShape;
106  if ( ( myShape != 0 ) && ( myFct != 0 ) ) myFct->attach( myShape );
107 }
108 //-----------------------------------------------------------------------------
109 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
110 inline
111 void
112 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
113 setParams( 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 //-----------------------------------------------------------------------------
128 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
129 template <typename SurfelConstIterator>
130 inline
131 void
132 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
133 init( const Scalar _h,
134  SurfelConstIterator /* itb */,
135  SurfelConstIterator /* ite */ )
136 {
137  myH = _h;
138 }
139 
140 //-----------------------------------------------------------------------------
141 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
142 template <typename SurfelConstIterator>
143 inline
144 typename DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::Quantity
145 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
146 eval( SurfelConstIterator it ) const
147 {
148  ASSERT( isValid() );
149  BOOST_CONCEPT_ASSERT(( boost::InputIterator<SurfelConstIterator> ));
150  return myFct->operator()( embed( *it ) );
151 }
152 //-----------------------------------------------------------------------------
153 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
154 template <typename OutputIterator, typename SurfelConstIterator>
155 inline
156 OutputIterator
157 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
158 eval( 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 //-----------------------------------------------------------------------------
169 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
170 inline
171 typename DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::RealPoint
172 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
173 embed( 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  */
190 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
191 inline
192 void
193 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
194 selfDisplay ( 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  */
203 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
204 inline
205 bool
206 DGtal::TrueDigitalSurfaceLocalEstimator<TKSpace, TShape, TGeometricFunctor>::
207 isValid() 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 
220 template <typename TKSpace, typename TShape, typename TGeometricFunctor>
221 inline
222 std::ostream&
223 DGtal::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