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//-----------------------------------------------------------------------------
42template <typename TSpace, typename TInputPoint, typename TInternalScalar>
44DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
45~ChordGenericNaivePlaneComputer()
48//-----------------------------------------------------------------------------
49template <typename TSpace, typename TInputPoint, typename TInternalScalar>
51DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
52ChordGenericNaivePlaneComputer()
54 _axesToErase.reserve( 3 );
56//-----------------------------------------------------------------------------
57template <typename TSpace, typename TInputPoint, typename TInternalScalar>
59DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
60ChordGenericNaivePlaneComputer( 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//-----------------------------------------------------------------------------
69template <typename TSpace, typename TInputPoint, typename TInternalScalar>
71DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar> &
72DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
73operator=( const ChordGenericNaivePlaneComputer & other )
77 myAxes = other.myAxes;
78 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
80 myComputers[ *it ] = other.myComputers[ *it ];
84//-----------------------------------------------------------------------------
85template <typename TSpace, typename TInputPoint, typename TInternalScalar>
88DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
91 ASSERT( myAxes.size() > 0 );
94//-----------------------------------------------------------------------------
95template <typename TSpace, typename TInputPoint, typename TInternalScalar>
98DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
102 for ( unsigned int i = 0; i < 3; ++i )
104 myAxes.push_back( i );
105 myComputers[ i ].clear();
108//-----------------------------------------------------------------------------
109template <typename TSpace, typename TInputPoint, typename TInternalScalar>
112DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
113init( InternalScalar widthNumerator,
114 InternalScalar widthDenominator )
117 for ( unsigned int i = 0; i < 3; ++i )
118 myComputers[ i ].init( i, widthNumerator, widthDenominator );
120//-----------------------------------------------------------------------------
121template <typename TSpace, typename TInputPoint, typename TInternalScalar>
123typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Size
124DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
127 return myComputers[ active() ].size();
129//-----------------------------------------------------------------------------
130template <typename TSpace, typename TInputPoint, typename TInternalScalar>
133DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
136 return myComputers[ active() ].empty();
138//-----------------------------------------------------------------------------
139template <typename TSpace, typename TInputPoint, typename TInternalScalar>
141typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::ConstIterator
142DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
145 return myComputers[ active() ].begin();
147//-----------------------------------------------------------------------------
148template <typename TSpace, typename TInputPoint, typename TInternalScalar>
150typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::ConstIterator
151DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
154 return myComputers[ active() ].end();
157//-----------------------------------------------------------------------------
158template <typename TSpace, typename TInputPoint, typename TInternalScalar>
160typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Size
161DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
164 return myComputers[ active() ].max_size();
166//-----------------------------------------------------------------------------
167template <typename TSpace, typename TInputPoint, typename TInternalScalar>
169typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Size
170DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
175//-----------------------------------------------------------------------------
176template <typename TSpace, typename TInputPoint, typename TInternalScalar>
179DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
180operator()( const Point & p ) const
182 return myComputers[ active() ].operator()( p );
185//-----------------------------------------------------------------------------
186template <typename TSpace, typename TInputPoint, typename TInternalScalar>
189DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
190extendAsIs( 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//-----------------------------------------------------------------------------
218template <typename TSpace, typename TInputPoint, typename TInternalScalar>
220DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
221extend( 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//-----------------------------------------------------------------------------
247template <typename TSpace, typename TInputPoint, typename TInternalScalar>
249DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
250isExtendable( 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//-----------------------------------------------------------------------------
262template <typename TSpace, typename TInputPoint, typename TInternalScalar>
263template <typename TInputIterator>
265DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
266extend( 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//-----------------------------------------------------------------------------
294template <typename TSpace, typename TInputPoint, typename TInternalScalar>
295template <typename TInputIterator>
297DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
298isExtendable( 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//-----------------------------------------------------------------------------
313template <typename TSpace, typename TInputPoint, typename TInternalScalar>
315typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::Primitive
316DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
319 return myComputers[ active() ].primitive();
322//-----------------------------------------------------------------------------
323template <typename TSpace, typename TInputPoint, typename TInternalScalar>
324template <typename Vector3D>
327DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
328getNormal( Vector3D & normal ) const
330 myComputers[ active() ].getNormal( normal );
332//-----------------------------------------------------------------------------
333//-----------------------------------------------------------------------------
334template <typename TSpace, typename TInputPoint, typename TInternalScalar>
335template <typename Vector3D>
338DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
339getUnitNormal( Vector3D & normal ) const
341 myComputers[ active() ].getUnitNormal( normal );
343//-----------------------------------------------------------------------------
344template <typename TSpace, typename TInputPoint, typename TInternalScalar>
347DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
348getBounds( double & min, double & max ) const
350 myComputers[ active() ].getBounds( min, max );
352//-----------------------------------------------------------------------------
353template <typename TSpace, typename TInputPoint, typename TInternalScalar>
355const typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::InputPoint &
356DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::
359 return myComputers[ active() ].minimalPoint();
361//-----------------------------------------------------------------------------
362template <typename TSpace, typename TInputPoint, typename TInternalScalar>
364const typename DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::InputPoint &
365DGtal::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.
380template <typename TSpace, typename TInputPoint, typename TInternalScalar>
383DGtal::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.
396template <typename TSpace, typename TInputPoint, typename TInternalScalar>
399DGtal::ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar>::isValid() const
401 return myComputers[ active() ].isValid();
405///////////////////////////////////////////////////////////////////////////////
407///////////////////////////////////////////////////////////////////////////////
409///////////////////////////////////////////////////////////////////////////////
410// Implementation of inline functions //
412template <typename TSpace, typename TInputPoint, typename TInternalScalar>
415DGtal::operator<< ( std::ostream & out,
416 const ChordGenericNaivePlaneComputer<TSpace, TInputPoint, TInternalScalar> & object )
418 object.selfDisplay( out );
423///////////////////////////////////////////////////////////////////////////////