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 COBAGenericNaivePlaneComputer.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 COBAGenericNaivePlaneComputer.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 TInternalInteger>
44DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
45~COBAGenericNaivePlaneComputer()
48//-----------------------------------------------------------------------------
49template <typename TSpace, typename TInternalInteger>
51DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
52COBAGenericNaivePlaneComputer()
54 _axesToErase.reserve( 3 );
56//-----------------------------------------------------------------------------
57template <typename TSpace, typename TInternalInteger>
59DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
60COBAGenericNaivePlaneComputer( const COBAGenericNaivePlaneComputer & 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 TInternalInteger>
71DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger> &
72DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
73operator=( const COBAGenericNaivePlaneComputer & 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 TInternalInteger>
88DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
91 ASSERT( myAxes.size() > 0 );
94//-----------------------------------------------------------------------------
95template <typename TSpace, typename TInternalInteger>
97typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::MyIntegerComputer &
98DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
101 return myComputers[ active() ].ic();
103//-----------------------------------------------------------------------------
104template <typename TSpace, typename TInternalInteger>
107DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
111 for ( unsigned int i = 0; i < 3; ++i )
113 myAxes.push_back( i );
114 myComputers[ i ].clear();
117//-----------------------------------------------------------------------------
118template <typename TSpace, typename TInternalInteger>
121DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
122init( InternalInteger diameter,
123 InternalInteger widthNumerator,
124 InternalInteger widthDenominator )
127 for ( unsigned int i = 0; i < 3; ++i )
128 myComputers[ i ].init( i, diameter, widthNumerator, widthDenominator );
130//-----------------------------------------------------------------------------
131template <typename TSpace, typename TInternalInteger>
133typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::ConstIterator
134DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
137 return myComputers[ active() ].begin();
139//-----------------------------------------------------------------------------
140template <typename TSpace, typename TInternalInteger>
142typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::ConstIterator
143DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
146 return myComputers[ active() ].end();
148//-----------------------------------------------------------------------------
149template <typename TSpace, typename TInternalInteger>
151typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
152DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
155 return myComputers[ active() ].size();
157//-----------------------------------------------------------------------------
158template <typename TSpace, typename TInternalInteger>
161DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
164 return myComputers[ active() ].empty();
166//-----------------------------------------------------------------------------
167template <typename TSpace, typename TInternalInteger>
169typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
170DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
173 return myComputers[ active() ].max_size();
175//-----------------------------------------------------------------------------
176template <typename TSpace, typename TInternalInteger>
178typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
179DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
184//-----------------------------------------------------------------------------
185template <typename TSpace, typename TInternalInteger>
187typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
188DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
191 return myComputers[ active() ].complexity();
193//-----------------------------------------------------------------------------
194template <typename TSpace, typename TInternalInteger>
197DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
198operator()( const Point & p ) const
200 return myComputers[ active() ].operator()( p );
203//-----------------------------------------------------------------------------
204template <typename TSpace, typename TInternalInteger>
207DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
208extendAsIs( const Point & p )
211 unsigned int nbok = 0;
212 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
215 nbok += myComputers[ *it ].operator()( p ) ? 1 : 0;
217 if ( nbok != 0 ) // at least one is ok.
219 for ( AxisIterator it = myAxes.begin(); it != myAxes.end(); )
220 // cannot put end() in variable, since end() moves when
221 // modifiying a vector.
223 bool ok = myComputers[ *it ].extendAsIs( p );
225 it = myAxes.erase( it );
229 ASSERT( ! myAxes.empty() );
235//-----------------------------------------------------------------------------
236template <typename TSpace, typename TInternalInteger>
238DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
239extend( const Point & p )
242 unsigned int nbok = 0;
243 _axesToErase.clear();
244 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
245 axIt != axItE; ++axIt )
247 bool ok = myComputers[ *axIt ].extend( p );
248 if ( ! ok ) _axesToErase.push_back( *axIt );
251 if ( nbok != 0 ) // at least one is ok.
252 { // if one is ok, we must remove ko ones from the list of active
254 AxisIterator axIt = myAxes.begin();
255 for ( unsigned int i = 0; i < _axesToErase.size(); ++i )
257 while ( *axIt != _axesToErase[ i ] ) ++axIt;
258 axIt = myAxes.erase( axIt );
264//-----------------------------------------------------------------------------
265template <typename TSpace, typename TInternalInteger>
267DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
268isExtendable( const Point & p ) const
271 unsigned int nbok = 0;
272 for ( AxisConstIterator it = myAxes.begin(), itE = myAxes.end();
275 nbok += myComputers[ *it ].isExtendable( p ) ? 1 : 0;
279//-----------------------------------------------------------------------------
280template <typename TSpace, typename TInternalInteger>
281template <typename TInputIterator>
283DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
284extend( TInputIterator it, TInputIterator itE )
286 BOOST_CONCEPT_ASSERT(( boost::InputIterator<TInputIterator> ));
289 unsigned int nbok = 0;
290 _axesToErase.clear();
291 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
292 axIt != axItE; ++axIt )
294 bool ok = myComputers[ *axIt ].extend( it, itE );
295 if ( ! ok ) _axesToErase.push_back( *axIt );
298 if ( nbok != 0 ) // at least one is ok.
299 { // if one is ok, we must remove ko ones from the list of active
301 AxisIterator axIt = myAxes.begin();
302 for ( unsigned int i = 0; i < _axesToErase.size(); ++i )
304 while ( *axIt != _axesToErase[ i ] ) ++axIt;
305 axIt = myAxes.erase( axIt );
311//-----------------------------------------------------------------------------
312template <typename TSpace, typename TInternalInteger>
313template <typename TInputIterator>
315DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
316isExtendable( TInputIterator it, TInputIterator itE ) const
318 BOOST_CONCEPT_ASSERT(( boost::InputIterator<TInputIterator> ));
321 unsigned int nbok = 0;
322 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
323 axIt != axItE; ++axIt )
325 nbok += myComputers[ *axIt ].isExtendable( it, itE ) ? 1 : 0;
329//-----------------------------------------------------------------------------
330template <typename TSpace, typename TInternalInteger>
332typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Primitive
333DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
336 return myComputers[ active() ].primitive();
338//-----------------------------------------------------------------------------
339template <typename TSpace, typename TInternalInteger>
340template <typename Vector3D>
343DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
344getNormal( Vector3D & normal ) const
346 myComputers[ active() ].getNormal( normal );
348//-----------------------------------------------------------------------------
349//-----------------------------------------------------------------------------
350template <typename TSpace, typename TInternalInteger>
351template <typename Vector3D>
354DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
355getUnitNormal( Vector3D & normal ) const
357 myComputers[ active() ].getUnitNormal( normal );
359//-----------------------------------------------------------------------------
360template <typename TSpace, typename TInternalInteger>
363DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
364getBounds( double & min, double & max ) const
366 myComputers[ active() ].getBounds( min, max );
368//-----------------------------------------------------------------------------
369template <typename TSpace, typename TInternalInteger>
371const typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Point &
372DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
375 return myComputers[ active() ].minimalPoint();
377//-----------------------------------------------------------------------------
378template <typename TSpace, typename TInternalInteger>
380const typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Point &
381DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
384 return myComputers[ active() ].maximalPoint();
389///////////////////////////////////////////////////////////////////////////////
390// Interface - public :
393 * Writes/Displays the object on an output stream.
394 * @param out the output stream where the object is written.
396template <typename TSpace, typename TInternalInteger>
399DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::selfDisplay ( std::ostream & out ) const
401 out << "[COBAGenericNaivePlane";
402 for ( AxisConstIterator axIt = myAxes.begin(), axItE = myAxes.end();
403 axIt != axItE; ++axIt )
404 out << " " << myComputers[ *axIt ];
409 * Checks the validity/consistency of the object.
410 * @return 'true' if the object is valid, 'false' otherwise.
412template <typename TSpace, typename TInternalInteger>
415DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::isValid() const
417 return myComputers[ active() ].isValid();
421///////////////////////////////////////////////////////////////////////////////
423///////////////////////////////////////////////////////////////////////////////
425///////////////////////////////////////////////////////////////////////////////
426// Implementation of inline functions //
428template <typename TSpace, typename TInternalInteger>
431DGtal::operator<< ( std::ostream & out,
432 const COBAGenericNaivePlaneComputer<TSpace, TInternalInteger> & object )
434 object.selfDisplay( out );
439///////////////////////////////////////////////////////////////////////////////