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 StabbingLineComputer.ih
19 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in StabbingLineComputer.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
32//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
41template <typename TConstIterator>
43DGtal::StabbingLineComputer<TConstIterator>::StabbingLineComputer()
44:myBegin(), myEnd(), myPreimagePtr(), myFlagIsInit(false), myFlagIsCW(true)
48template <typename TConstIterator>
50DGtal::StabbingLineComputer<TConstIterator>::StabbingLineComputer( const Self& other )
51:myBegin(other.myBegin), myEnd(other.myEnd), myPreimagePtr(other.myPreimagePtr),
52myFlagIsInit(other.myFlagIsInit), myFlagIsCW(other.myFlagIsCW)
56template <typename TConstIterator>
58typename DGtal::StabbingLineComputer<TConstIterator>::Self&
59DGtal::StabbingLineComputer<TConstIterator>::operator= ( const Self& other )
63 myBegin = other.myBegin;
65 myPreimagePtr = other.myPreimagePtr;
66 myFlagIsInit = other.myFlagIsInit;
67 myFlagIsCW = other.myFlagIsCW;
72template <typename TConstIterator>
74DGtal::StabbingLineComputer<TConstIterator>::~StabbingLineComputer()
78template <typename TConstIterator>
81DGtal::StabbingLineComputer<TConstIterator>::operator==( const Self& other ) const
83 if (isValid()&&other.isValid())
85 Pair firstPair( *myBegin );
86 Pair oFirstPair( *(other.myBegin) );
87 if ( (firstPair.first == oFirstPair.first)
88 &&(firstPair.second == oFirstPair.second) )
90 ConstIterator it (myEnd);
93 ConstIterator oIt (other.myEnd);
95 Pair oLastPair( *oIt );
97 if ( (lastPair.first == oLastPair.first)
98 &&(lastPair.second == oLastPair.second) )
100 return ( *myPreimagePtr == *(other.myPreimagePtr) );
108 return ( (!isValid()) && (!other.isValid()) );
112template <typename TConstIterator>
115DGtal::StabbingLineComputer<TConstIterator>::operator!=( const Self& other ) const
117 return !(*this == other);
120template <typename TConstIterator>
122typename DGtal::StabbingLineComputer<TConstIterator>::Reverse
123DGtal::StabbingLineComputer<TConstIterator>::getReverse() const
129template <typename TConstIterator>
131typename DGtal::StabbingLineComputer<TConstIterator>::Self
132DGtal::StabbingLineComputer<TConstIterator>::getSelf() const
139///////////////////////////////////////////////////////////////////////////////
140// Interface - public :
142template <typename TConstIterator>
145DGtal::StabbingLineComputer<TConstIterator>::isValid() const
147 if ( myPreimagePtr.get() != 0 )
149 return myPreimagePtr->isValid();
157template <typename TConstIterator>
159typename DGtal::StabbingLineComputer<TConstIterator>::ConstIterator
160DGtal::StabbingLineComputer<TConstIterator>::begin() const
165template <typename TConstIterator>
167typename DGtal::StabbingLineComputer<TConstIterator>::ConstIterator
168DGtal::StabbingLineComputer<TConstIterator>::end() const
173template <typename TConstIterator>
175typename DGtal::StabbingLineComputer<TConstIterator>::Point
176DGtal::StabbingLineComputer<TConstIterator>::Uf() const
178 ASSERT( myPreimagePtr.get() != 0 );
179 return myPreimagePtr->Uf();
182template <typename TConstIterator>
184typename DGtal::StabbingLineComputer<TConstIterator>::Point
185DGtal::StabbingLineComputer<TConstIterator>::Ul() const
187 ASSERT( myPreimagePtr.get() != 0 );
188 return myPreimagePtr->Ul();
191template <typename TConstIterator>
193typename DGtal::StabbingLineComputer<TConstIterator>::Point
194DGtal::StabbingLineComputer<TConstIterator>::Lf() const
196 ASSERT( myPreimagePtr.get() != 0 );
197 return myPreimagePtr->Lf();
200template <typename TConstIterator>
202typename DGtal::StabbingLineComputer<TConstIterator>::Point
203DGtal::StabbingLineComputer<TConstIterator>::Ll() const
205 ASSERT( myPreimagePtr.get() != 0 );
206 return myPreimagePtr->Ll();
210template <typename TConstIterator>
212typename DGtal::StabbingLineComputer<TConstIterator>::PreimagePtr
213DGtal::StabbingLineComputer<TConstIterator>::getPreimage() const
215 ASSERT( myPreimagePtr.get() != 0 );
216 return myPreimagePtr;
220template <typename TConstIterator>
223DGtal::StabbingLineComputer<TConstIterator>::isClockwiseOriented() const
229template <typename TConstIterator>
232DGtal::StabbingLineComputer<TConstIterator>::getParameters(double& alpha, double& beta, double& gamma) const
234 ASSERT( myPreimagePtr.get() != 0 );
235 myPreimagePtr->getSeparatingStraightLine(alpha, beta, gamma);
238template <typename TConstIterator>
241DGtal::StabbingLineComputer<TConstIterator>::projects(double& x, double& y,
242 const double& alpha, const double& beta, const double& gamma) const
244 ASSERT( (alpha!=0)||(beta!=0) );
245 double d2 = ( alpha * alpha + beta * beta );
246 double s = beta*x - alpha*y;
247 x = (beta*s - alpha*gamma)/d2;
248 y = -(alpha*s + beta*gamma)/d2;
251///////////////////////////////////////////////////////////////////////////////
252// Growth operations //
254template <typename TConstIterator>
257DGtal::StabbingLineComputer<TConstIterator>::init(const ConstIterator& anIt)
263 myPreimagePtr = PreimagePtr( new Preimage( aPair.first, aPair.second, StraightLine() ) );
266template <typename TConstIterator>
269DGtal::StabbingLineComputer<TConstIterator>::isConcave()
271 ASSERT( myPreimagePtr.get() != 0 );
272 Pair aPair( *myEnd );
273 bool isExterior = false;
279 isExterior = myPreimagePtr->isLeftExteriorAtTheFront( aPair.first, aPair.second );
281 isExterior = myPreimagePtr->isRightExteriorAtTheBack( aPair.first, aPair.second );
288template <typename TConstIterator>
291DGtal::StabbingLineComputer<TConstIterator>::isConvex()
293 ASSERT( myPreimagePtr.get() != 0 );
294 Pair aPair( *myEnd );
295 bool isExterior = false;
301 isExterior = myPreimagePtr->isRightExteriorAtTheFront( aPair.first, aPair.second );
303 isExterior = myPreimagePtr->isLeftExteriorAtTheBack( aPair.first, aPair.second );
310template <typename TConstIterator>
313DGtal::StabbingLineComputer<TConstIterator>::isOppositeEndConcave()
315 ASSERT( myPreimagePtr.get() != 0 );
316 ConstIterator it( myBegin );
319 bool isExterior = false;
325 isExterior = myPreimagePtr->isRightExteriorAtTheBack( aPair.first, aPair.second );
327 isExterior = myPreimagePtr->isLeftExteriorAtTheFront( aPair.first, aPair.second );
334template <typename TConstIterator>
337DGtal::StabbingLineComputer<TConstIterator>::isOppositeEndConvex()
339 ASSERT( myPreimagePtr.get() != 0 );
340 ConstIterator it( myBegin );
343 bool isExterior = false;
349 isExterior = myPreimagePtr->isLeftExteriorAtTheBack( aPair.first, aPair.second );
351 isExterior = myPreimagePtr->isRightExteriorAtTheFront( aPair.first, aPair.second );
359template <typename TConstIterator>
362DGtal::StabbingLineComputer<TConstIterator>::isExtendableFront()
364 ASSERT( myPreimagePtr.get() != 0 );
365 Pair aPair( *myEnd );
372 isOK = myPreimagePtr->canBeAddedAtTheFront( aPair.first, aPair.second );
374 isOK = myPreimagePtr->canBeAddedAtTheBack( aPair.first, aPair.second );
377 { //not initialized yet
378 if ( myPreimagePtr->canBeAddedAtTheFront( aPair.first, aPair.second ) )
380 else if ( myPreimagePtr->canBeAddedAtTheBack( aPair.first, aPair.second ) )
387template <typename TConstIterator>
390DGtal::StabbingLineComputer<TConstIterator>::extendFront()
392 ASSERT( myPreimagePtr.get() != 0 );
393 Pair aPair( *myEnd );
400 isOK = myPreimagePtr->addFront( aPair.first, aPair.second );
402 isOK = myPreimagePtr->addBack( aPair.first, aPair.second );
405 { //not initialized yet
406 if ( myPreimagePtr->addFront( aPair.first, aPair.second ) )
411 else if ( myPreimagePtr->addBack( aPair.first, aPair.second ) )
426template <typename TConstIterator>
429DGtal::StabbingLineComputer<TConstIterator>::isExtendableBack()
431 ASSERT( myPreimagePtr.get() != 0 );
432 ConstIterator it( myBegin );
441 isOK = myPreimagePtr->canBeAddedAtTheBack( aPair.first, aPair.second );
443 isOK = myPreimagePtr->canBeAddedAtTheFront( aPair.first, aPair.second );
446 { //not initialized yet
447 if ( myPreimagePtr->canBeAddedAtTheBack( aPair.first, aPair.second ) )
449 else if ( myPreimagePtr->canBeAddedAtTheFront( aPair.first, aPair.second ) )
456template <typename TConstIterator>
459DGtal::StabbingLineComputer<TConstIterator>::extendBack()
461 ASSERT( myPreimagePtr.get() != 0 );
462 ConstIterator it( myBegin );
471 isOK = myPreimagePtr->addBack( aPair.first, aPair.second );
473 isOK = myPreimagePtr->addFront( aPair.first, aPair.second );
476 { //not initialized yet
477 if ( myPreimagePtr->addBack( aPair.first, aPair.second ) )
482 else if ( myPreimagePtr->addFront( aPair.first, aPair.second ) )
497///////////////////////////////////////////////////////////////////////////////
500template <typename TConstIterator>
503DGtal::StabbingLineComputer<TConstIterator>::selfDisplay ( std::ostream & out ) const
506 out << "[StabbingLineComputer]" << std::endl;
509 Pair firstPair( *myBegin );
510 out << "\t From " << firstPair.first << firstPair.second << std::endl;
511 ConstIterator it (myEnd);
513 Pair lastPair( *it );
514 out << "\t To " << lastPair.first << lastPair.second << std::endl;
515 ASSERT( myPreimagePtr.get() != 0 );
516 out << (*myPreimagePtr);
520 out << "\t not valid" << std::endl;
522 out << "[end of StabbingLineComputer]" << std::endl;
525template <typename TConstIterator>
528DGtal::StabbingLineComputer<TConstIterator>::className() const
530 return "StabbingLineComputer";
533///////////////////////////////////////////////////////////////////////////////
534// Implementation of inline functions //
536template <typename TConstIterator>
539DGtal::operator<< ( std::ostream & out,
540 const StabbingLineComputer<TConstIterator> & object )
542 object.selfDisplay( out );
547///////////////////////////////////////////////////////////////////////////////