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 ChordGenericNaivePlaneComputer.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
24 * Implementation of inline methods defined in ChordGenericNaivePlaneComputer.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 //-----------------------------------------------------------------------------
42 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
44 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
45 ~ChordGenericNaivePlaneComputer()
48 //-----------------------------------------------------------------------------
49 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
51 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
52 ChordGenericNaivePlaneComputer()
53 { // Object is invalid
54 _axesToErase.reserve( 3 );
56 //-----------------------------------------------------------------------------
57 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
59 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
60 ChordGenericNaivePlaneComputer( const ChordGenericNaivePlaneComputer & other )
61 : myAxes( other.myAxes )
63 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
65 myComputers[ *it ] = other.myComputers[ *it ];
66 _axesToErase.reserve( 3 );
68 //-----------------------------------------------------------------------------
69 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
71 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar> &
72 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
73 operator=( const ChordGenericNaivePlaneComputer & other )
77 myAxes = other.myAxes;
78 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
80 myComputers[ *it ] = other.myComputers[ *it ];
84 //-----------------------------------------------------------------------------
85 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
88 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
91 ASSERT( myAxes.size() > 0 );
94 //-----------------------------------------------------------------------------
95 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
98 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
102 for ( unsigned int i = 0; i < 3; ++i )
104 myAxes.push_back( i );
105 myComputers[ i ].clear();
108 //-----------------------------------------------------------------------------
109 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
112 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
113 init( InternalScalar widthNumerator,
114 InternalScalar widthDenominator )
117 for ( unsigned int i = 0; i < 3; ++i )
118 myComputers[ i ].init( i, widthNumerator, widthDenominator );
120 //-----------------------------------------------------------------------------
121 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
123 typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Size
124 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
127 return myComputers[ active() ].size();
129 //-----------------------------------------------------------------------------
130 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
133 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
136 return myComputers[ active() ].empty();
138 //-----------------------------------------------------------------------------
139 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
141 typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::ConstIterator
142 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
145 return myComputers[ active() ].begin();
147 //-----------------------------------------------------------------------------
148 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
150 typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::ConstIterator
151 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
154 return myComputers[ active() ].end();
157 //-----------------------------------------------------------------------------
158 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
160 typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Size
161 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
164 return myComputers[ active() ].max_size();
166 //-----------------------------------------------------------------------------
167 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
169 typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Size
170 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
175 //-----------------------------------------------------------------------------
176 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
179 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
180 operator()( const Point & p ) const
182 return myComputers[ active() ].operator()( p );
185 //-----------------------------------------------------------------------------
186 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
189 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
190 extendAsIs( const InputPoint & p )
193 unsigned int nbok = 0;
194 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
197 nbok += myComputers[ *it ].operator()( p ) ? 1 : 0;
199 if ( nbok != 0 ) // at least one is ok.
201 for ( AxisIterator it = myAxes.begin(); it != myAxes.end(); )
202 // cannot put end() in variable, since end() moves when
203 // modifiying a vector.
205 bool ok = myComputers[ *it ].extendAsIs( p );
207 it = myAxes.erase( it );
211 ASSERT( ! myAxes.empty() );
217 //-----------------------------------------------------------------------------
218 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
220 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
221 extend( const InputPoint & p )
224 unsigned int nbok = 0;
225 _axesToErase.clear();
226 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
227 axIt != axItE; ++axIt )
229 bool ok = myComputers[ *axIt ].extend( p );
230 if ( ! ok ) _axesToErase.push_back( *axIt );
233 if ( nbok != 0 ) // at least one is ok.
234 { // if one is ok, we must remove ko ones from the list of active
236 AxisIterator axIt = myAxes.begin();
237 for ( unsigned int i = 0; i < _axesToErase.size(); ++i )
239 while ( *axIt != _axesToErase[ i ] ) ++axIt;
240 axIt = myAxes.erase( axIt );
246 //-----------------------------------------------------------------------------
247 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
249 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
250 isExtendable( const InputPoint & p ) const
253 unsigned int nbok = 0;
254 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
257 nbok += myComputers[ *it ].isExtendable( p ) ? 1 : 0;
261 //-----------------------------------------------------------------------------
262 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
263 template <typename TInputIterator>
265 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
266 extend( TInputIterator it, TInputIterator itE )
268 BOOST_CONCEPT_ASSERT(( boost::InputIterator<TInputIterator> ));
271 unsigned int nbok = 0;
272 _axesToErase.clear();
273 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
274 axIt != axItE; ++axIt )
276 bool ok = myComputers[ *axIt ].extend( it, itE );
277 if ( ! ok ) _axesToErase.push_back( *axIt );
280 if ( nbok != 0 ) // at least one is ok.
281 { // if one is ok, we must remove ko ones from the list of active
283 AxisIterator axIt = myAxes.begin();
284 for ( unsigned int i = 0; i < _axesToErase.size(); ++i )
286 while ( *axIt != _axesToErase[ i ] ) ++axIt;
287 axIt = myAxes.erase( axIt );
293 //-----------------------------------------------------------------------------
294 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
295 template <typename TInputIterator>
297 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
298 isExtendable( TInputIterator it, TInputIterator itE ) const
300 BOOST_CONCEPT_ASSERT(( boost::InputIterator<TInputIterator> ));
303 unsigned int nbok = 0;
304 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
305 axIt != axItE; ++axIt )
307 nbok += myComputers[ *axIt ].isExtendable( it, itE ) ? 1 : 0;
312 //-----------------------------------------------------------------------------
313 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
315 typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Primitive
316 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
319 return myComputers[ active() ].primitive();
322 //-----------------------------------------------------------------------------
323 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
324 template <typename Vector3D>
327 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
328 getNormal( Vector3D & normal ) const
330 myComputers[ active() ].getNormal( normal );
332 //-----------------------------------------------------------------------------
333 //-----------------------------------------------------------------------------
334 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
335 template <typename Vector3D>
338 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
339 getUnitNormal( Vector3D & normal ) const
341 myComputers[ active() ].getUnitNormal( normal );
343 //-----------------------------------------------------------------------------
344 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
347 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
348 getBounds( double & min, double & max ) const
350 myComputers[ active() ].getBounds( min, max );
352 //-----------------------------------------------------------------------------
353 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
355 const typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::InputPoint &
356 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
359 return myComputers[ active() ].minimalPoint();
361 //-----------------------------------------------------------------------------
362 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
364 const typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::InputPoint &
365 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
368 return myComputers[ active() ].maximalPoint();
373 ///////////////////////////////////////////////////////////////////////////////
374 // Interface - public :
377 * Writes/Displays the object on an output stream.
378 * @param out the output stream where the object is written.
380 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
383 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::selfDisplay ( std::ostream & out ) const
385 out << "[ChordGenericNaivePlaneComputer";
386 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
387 axIt != axItE; ++axIt )
388 out << " " << myComputers[ *axIt ];
393 * Checks the validity/consistency of the object.
394 * @return 'true' if the object is valid, 'false' otherwise.
396 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
399 DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::isValid() const
401 return myComputers[ active() ].isValid();
405 ///////////////////////////////////////////////////////////////////////////////
407 ///////////////////////////////////////////////////////////////////////////////
409 ///////////////////////////////////////////////////////////////////////////////
410 // Implementation of inline functions //
412 template <typename TSpace, typename TInputPoint, typename TInternalScalar>
415 DGtal::operator<< ( std::ostream & out,
416 const ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar> & object )
418 object.selfDisplay( out );
423 ///////////////////////////////////////////////////////////////////////////////