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 //-----------------------------------------------------------------------------
42 template <typename TSpace, typename TInternalInteger>
44 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
45 ~COBAGenericNaivePlaneComputer()
48 //-----------------------------------------------------------------------------
49 template <typename TSpace, typename TInternalInteger>
51 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
52 COBAGenericNaivePlaneComputer()
53 { // Object is invalid
54 _axesToErase.reserve( 3 );
56 //-----------------------------------------------------------------------------
57 template <typename TSpace, typename TInternalInteger>
59 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
60 COBAGenericNaivePlaneComputer( 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 //-----------------------------------------------------------------------------
69 template <typename TSpace, typename TInternalInteger>
71 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger> &
72 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
73 operator=( const COBAGenericNaivePlaneComputer & 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 TInternalInteger>
88 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
91 ASSERT( myAxes.size() > 0 );
94 //-----------------------------------------------------------------------------
95 template <typename TSpace, typename TInternalInteger>
97 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::MyIntegerComputer &
98 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
101 return myComputers[ active() ].ic();
103 //-----------------------------------------------------------------------------
104 template <typename TSpace, typename TInternalInteger>
107 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
111 for ( unsigned int i = 0; i < 3; ++i )
113 myAxes.push_back( i );
114 myComputers[ i ].clear();
117 //-----------------------------------------------------------------------------
118 template <typename TSpace, typename TInternalInteger>
121 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
122 init( 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 //-----------------------------------------------------------------------------
131 template <typename TSpace, typename TInternalInteger>
133 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::ConstIterator
134 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
137 return myComputers[ active() ].begin();
139 //-----------------------------------------------------------------------------
140 template <typename TSpace, typename TInternalInteger>
142 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::ConstIterator
143 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
146 return myComputers[ active() ].end();
148 //-----------------------------------------------------------------------------
149 template <typename TSpace, typename TInternalInteger>
151 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
152 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
155 return myComputers[ active() ].size();
157 //-----------------------------------------------------------------------------
158 template <typename TSpace, typename TInternalInteger>
161 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
164 return myComputers[ active() ].empty();
166 //-----------------------------------------------------------------------------
167 template <typename TSpace, typename TInternalInteger>
169 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
170 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
173 return myComputers[ active() ].max_size();
175 //-----------------------------------------------------------------------------
176 template <typename TSpace, typename TInternalInteger>
178 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
179 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
184 //-----------------------------------------------------------------------------
185 template <typename TSpace, typename TInternalInteger>
187 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Size
188 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
191 return myComputers[ active() ].complexity();
193 //-----------------------------------------------------------------------------
194 template <typename TSpace, typename TInternalInteger>
197 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
198 operator()( const Point & p ) const
200 return myComputers[ active() ].operator()( p );
203 //-----------------------------------------------------------------------------
204 template <typename TSpace, typename TInternalInteger>
207 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
208 extendAsIs( 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 //-----------------------------------------------------------------------------
236 template <typename TSpace, typename TInternalInteger>
238 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
239 extend( 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 //-----------------------------------------------------------------------------
265 template <typename TSpace, typename TInternalInteger>
267 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
268 isExtendable( 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 //-----------------------------------------------------------------------------
280 template <typename TSpace, typename TInternalInteger>
281 template <typename TInputIterator>
283 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
284 extend( 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 //-----------------------------------------------------------------------------
312 template <typename TSpace, typename TInternalInteger>
313 template <typename TInputIterator>
315 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
316 isExtendable( 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 //-----------------------------------------------------------------------------
330 template <typename TSpace, typename TInternalInteger>
332 typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Primitive
333 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
336 return myComputers[ active() ].primitive();
338 //-----------------------------------------------------------------------------
339 template <typename TSpace, typename TInternalInteger>
340 template <typename Vector3D>
343 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
344 getNormal( Vector3D & normal ) const
346 myComputers[ active() ].getNormal( normal );
348 //-----------------------------------------------------------------------------
349 //-----------------------------------------------------------------------------
350 template <typename TSpace, typename TInternalInteger>
351 template <typename Vector3D>
354 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
355 getUnitNormal( Vector3D & normal ) const
357 myComputers[ active() ].getUnitNormal( normal );
359 //-----------------------------------------------------------------------------
360 template <typename TSpace, typename TInternalInteger>
363 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
364 getBounds( double & min, double & max ) const
366 myComputers[ active() ].getBounds( min, max );
368 //-----------------------------------------------------------------------------
369 template <typename TSpace, typename TInternalInteger>
371 const typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Point &
372 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::
375 return myComputers[ active() ].minimalPoint();
377 //-----------------------------------------------------------------------------
378 template <typename TSpace, typename TInternalInteger>
380 const typename DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::Point &
381 DGtal::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.
396 template <typename TSpace, typename TInternalInteger>
399 DGtal::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.
412 template <typename TSpace, typename TInternalInteger>
415 DGtal::COBAGenericNaivePlaneComputer<TSpace, TInternalInteger>::isValid() const
417 return myComputers[ active() ].isValid();
421 ///////////////////////////////////////////////////////////////////////////////
423 ///////////////////////////////////////////////////////////////////////////////
425 ///////////////////////////////////////////////////////////////////////////////
426 // Implementation of inline functions //
428 template <typename TSpace, typename TInternalInteger>
431 DGtal::operator<< ( std::ostream & out,
432 const COBAGenericNaivePlaneComputer<TSpace, TInternalInteger> & object )
434 object.selfDisplay( out );
439 ///////////////////////////////////////////////////////////////////////////////