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 ------------------------------
41 template <typename TConstIterator>
43 DGtal::StabbingLineComputer<TConstIterator>::StabbingLineComputer()
44 :myBegin(), myEnd(), myPreimagePtr(), myFlagIsInit(false), myFlagIsCW(true)
48 template <typename TConstIterator>
50 DGtal::StabbingLineComputer<TConstIterator>::StabbingLineComputer( const Self& other )
51 :myBegin(other.myBegin), myEnd(other.myEnd), myPreimagePtr(other.myPreimagePtr),
52 myFlagIsInit(other.myFlagIsInit), myFlagIsCW(other.myFlagIsCW)
56 template <typename TConstIterator>
58 typename DGtal::StabbingLineComputer<TConstIterator>::Self&
59 DGtal::StabbingLineComputer<TConstIterator>::operator= ( const Self& other )
63 myBegin = other.myBegin;
65 myPreimagePtr = other.myPreimagePtr;
66 myFlagIsInit = other.myFlagIsInit;
67 myFlagIsCW = other.myFlagIsCW;
72 template <typename TConstIterator>
74 DGtal::StabbingLineComputer<TConstIterator>::~StabbingLineComputer()
78 template <typename TConstIterator>
81 DGtal::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()) );
112 template <typename TConstIterator>
115 DGtal::StabbingLineComputer<TConstIterator>::operator!=( const Self& other ) const
117 return !(*this == other);
120 template <typename TConstIterator>
122 typename DGtal::StabbingLineComputer<TConstIterator>::Reverse
123 DGtal::StabbingLineComputer<TConstIterator>::getReverse() const
129 template <typename TConstIterator>
131 typename DGtal::StabbingLineComputer<TConstIterator>::Self
132 DGtal::StabbingLineComputer<TConstIterator>::getSelf() const
139 ///////////////////////////////////////////////////////////////////////////////
140 // Interface - public :
142 template <typename TConstIterator>
145 DGtal::StabbingLineComputer<TConstIterator>::isValid() const
147 if ( myPreimagePtr.get() != 0 )
149 return myPreimagePtr->isValid();
157 template <typename TConstIterator>
159 typename DGtal::StabbingLineComputer<TConstIterator>::ConstIterator
160 DGtal::StabbingLineComputer<TConstIterator>::begin() const
165 template <typename TConstIterator>
167 typename DGtal::StabbingLineComputer<TConstIterator>::ConstIterator
168 DGtal::StabbingLineComputer<TConstIterator>::end() const
173 template <typename TConstIterator>
175 typename DGtal::StabbingLineComputer<TConstIterator>::Point
176 DGtal::StabbingLineComputer<TConstIterator>::Uf() const
178 ASSERT( myPreimagePtr.get() != 0 );
179 return myPreimagePtr->Uf();
182 template <typename TConstIterator>
184 typename DGtal::StabbingLineComputer<TConstIterator>::Point
185 DGtal::StabbingLineComputer<TConstIterator>::Ul() const
187 ASSERT( myPreimagePtr.get() != 0 );
188 return myPreimagePtr->Ul();
191 template <typename TConstIterator>
193 typename DGtal::StabbingLineComputer<TConstIterator>::Point
194 DGtal::StabbingLineComputer<TConstIterator>::Lf() const
196 ASSERT( myPreimagePtr.get() != 0 );
197 return myPreimagePtr->Lf();
200 template <typename TConstIterator>
202 typename DGtal::StabbingLineComputer<TConstIterator>::Point
203 DGtal::StabbingLineComputer<TConstIterator>::Ll() const
205 ASSERT( myPreimagePtr.get() != 0 );
206 return myPreimagePtr->Ll();
210 template <typename TConstIterator>
212 typename DGtal::StabbingLineComputer<TConstIterator>::PreimagePtr
213 DGtal::StabbingLineComputer<TConstIterator>::getPreimage() const
215 ASSERT( myPreimagePtr.get() != 0 );
216 return myPreimagePtr;
220 template <typename TConstIterator>
223 DGtal::StabbingLineComputer<TConstIterator>::isClockwiseOriented() const
229 template <typename TConstIterator>
232 DGtal::StabbingLineComputer<TConstIterator>::getParameters(double& alpha, double& beta, double& gamma) const
234 ASSERT( myPreimagePtr.get() != 0 );
235 myPreimagePtr->getSeparatingStraightLine(alpha, beta, gamma);
238 template <typename TConstIterator>
241 DGtal::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 //
254 template <typename TConstIterator>
257 DGtal::StabbingLineComputer<TConstIterator>::init(const ConstIterator& anIt)
263 myPreimagePtr = PreimagePtr( new Preimage( aPair.first, aPair.second, StraightLine() ) );
266 template <typename TConstIterator>
269 DGtal::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 );
288 template <typename TConstIterator>
291 DGtal::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 );
310 template <typename TConstIterator>
313 DGtal::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 );
334 template <typename TConstIterator>
337 DGtal::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 );
359 template <typename TConstIterator>
362 DGtal::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 ) )
387 template <typename TConstIterator>
390 DGtal::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 ) )
426 template <typename TConstIterator>
429 DGtal::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 ) )
456 template <typename TConstIterator>
459 DGtal::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 ///////////////////////////////////////////////////////////////////////////////
500 template <typename TConstIterator>
503 DGtal::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;
525 template <typename TConstIterator>
528 DGtal::StabbingLineComputer<TConstIterator>::className() const
530 return "StabbingLineComputer";
533 ///////////////////////////////////////////////////////////////////////////////
534 // Implementation of inline functions //
536 template <typename TConstIterator>
539 DGtal::operator<< ( std::ostream & out,
540 const StabbingLineComputer<TConstIterator> & object )
542 object.selfDisplay( out );
547 ///////////////////////////////////////////////////////////////////////////////