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 ArithmeticalDSSComputerOnSurfels.ih
19 * @author Jocelyn Meyron (\c jocelyn.meyron@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
22 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
26 * Implementation of inline methods defined in ArithmeticalDSSComputerOnSurfels.h
28 * This file is part of the DGtal library.
31 ///////////////////////////////////////////////////////////////////////////////
32 // IMPLEMENTATION of inline methods.
33 ///////////////////////////////////////////////////////////////////////////////
35 //////////////////////////////////////////////////////////////////////////////
38 #include <boost/version.hpp>
39 #if BOOST_VERSION < 105800
40 #include <boost/math/common_factor_rt.hpp>
42 #include <boost/integer/common_factor_rt.hpp>
45 //////////////////////////////////////////////////////////////////////////////
48 ///////////////////////////////////////////////////////////////////////////////
49 // Implementation of inline methods //
51 //-----------------------------------------------------------------------------
52 template <typename TKSpace, typename TIterator, typename TInteger>
54 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
55 ArithmeticalDSSComputerOnSurfels()
56 : myKSpace(nullptr), mySliceAxis1(), mySliceAxis2(), myProjectionAxis(),
57 my2DProjector(), myExtractor(nullptr), myDSS( Point(0,0) ), myBegin(), myEnd()
61 //-----------------------------------------------------------------------------
62 template <typename TKSpace, typename TIterator, typename TInteger>
64 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
65 ArithmeticalDSSComputerOnSurfels(const KSpace& aKSpace, Dimension aDim1, Dimension aDim2, bool aFlagToReverse)
66 : myKSpace(&aKSpace), mySliceAxis1(aDim1), mySliceAxis2(aDim2), myProjectionAxis(),
67 my2DProjector(), myExtractor(), myDSS( Point(0,0) ), myBegin(), myEnd()
69 ASSERT(aDim1 != aDim2);
71 myProjectionAxis = dimNotIn(aDim1, aDim2);
73 std::vector<Dimension> v = {aDim1, aDim2};
74 my2DProjector.init(v.begin(),v.end());
77 myExtractor = PairExtractor(new IndirectPairExtractor());
79 myExtractor = PairExtractor(new DirectPairExtractor());
83 //-----------------------------------------------------------------------------
84 template <typename TKSpace, typename TIterator, typename TInteger>
86 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
87 ArithmeticalDSSComputerOnSurfels ( const ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger> & other )
88 : myKSpace(other.myKSpace), mySliceAxis1(other.mySliceAxis1), mySliceAxis2(other.mySliceAxis2), myProjectionAxis(other.myProjectionAxis),
89 my2DProjector(other.my2DProjector), myExtractor(other.myExtractor), myDSS(other.myDSS), myBegin(other.myBegin), myEnd(other.myEnd)
93 //-----------------------------------------------------------------------------
94 template <typename TKSpace, typename TIterator, typename TInteger>
96 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>&
97 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
98 operator=( const ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger> & other )
100 if ( this != &other )
102 myKSpace = other.myKSpace;
103 mySliceAxis1 = other.mySliceAxis1;
104 mySliceAxis2 = other.mySliceAxis2;
105 myProjectionAxis = other.myProjectionAxis;
106 my2DProjector = other.my2DProjector;
107 myExtractor = other.myExtractor;
109 myBegin = other.myBegin;
115 //-----------------------------------------------------------------------------
116 template <typename TKSpace, typename TIterator, typename TInteger>
118 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Reverse
119 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>
122 return Reverse(*myKSpace, mySliceAxis1, mySliceAxis2, true);
125 //-----------------------------------------------------------------------------
126 template <typename TKSpace, typename TIterator, typename TInteger>
128 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Self
129 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>
132 return Self(*myKSpace, mySliceAxis1, mySliceAxis2);
135 //-----------------------------------------------------------------------------
136 template <typename TKSpace, typename TIterator, typename TInteger>
139 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
140 operator==( const ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>& other ) const
142 return ( (myBegin == other.myBegin)
143 && (myEnd == other.myEnd)
144 && (myDSS == other.myDSS) );
147 //-----------------------------------------------------------------------------
148 template <typename TKSpace, typename TIterator, typename TInteger>
151 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
152 operator!=( const ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger> & other ) const
154 return (!(*this == other));
157 ///////////////////////////////////////////////////////////////////////////////
159 ///////////////////////////////////////////////////////////////////////////////
160 //--------------------------------------------------------------------
161 template <typename TKSpace, typename TIterator, typename TInteger>
164 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::isExtendableFront()
166 //the caller must be sure that 'myEnd' can be safely dereferenced
167 return myDSS.isExtendableFront( getNextProjectedPoint(*myEnd) );
170 //--------------------------------------------------------------------
171 template <typename TKSpace, typename TIterator, typename TInteger>
174 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::isExtendableBack()
176 ConstIterator it = myBegin;
178 //the caller must be sure that 'it' can be safely dereferenced
179 return myDSS.isExtendableBack( getPreviousProjectedPoint(*it) );
182 //-----------------------------------------------------------------------------
183 template <typename TKSpace, typename TIterator, typename TInteger>
186 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::extendFront()
188 //the caller must be sure that 'myEnd' can be safely dereferenced
189 if (myDSS.extendFront(getNextProjectedPoint(*myEnd)))
198 //--------------------------------------------------------------------
199 template <typename TKSpace, typename TIterator, typename TInteger>
202 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::extendBack()
204 ConstIterator it = myBegin;
206 //the caller must be sure that 'it' can be safely dereferenced
207 if (myDSS.extendBack(getPreviousProjectedPoint(*it)))
216 //--------------------------------------------------------------------
217 template <typename TKSpace, typename TIterator, typename TInteger>
220 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::retractFront()
222 if (myDSS.retractFront())
231 //--------------------------------------------------------------------
232 template <typename TKSpace, typename TIterator, typename TInteger>
235 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::retractBack()
237 if (myDSS.retractBack())
246 ///////////////////////////////////////////////////////////////////////////////
248 ///////////////////////////////////////////////////////////////////////////////
249 //-------------------------------------------------------------------------
250 template <typename TKSpace, typename TIterator, typename TInteger>
252 const typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Primitive&
253 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::primitive() const
258 //-------------------------------------------------------------------------
259 template <typename TKSpace, typename TIterator, typename TInteger>
262 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::a() const
267 //-------------------------------------------------------------------------
268 template <typename TKSpace, typename TIterator, typename TInteger>
271 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::b() const
276 //-------------------------------------------------------------------------
277 template <typename TKSpace, typename TIterator, typename TInteger>
280 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::mu() const
285 //-------------------------------------------------------------------------
286 template <typename TKSpace, typename TIterator, typename TInteger>
289 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::omega() const
291 return myDSS.omega();
294 //-------------------------------------------------------------------------
295 template <typename TKSpace, typename TIterator, typename TInteger>
297 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
298 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Uf() const
303 //-------------------------------------------------------------------------
304 template <typename TKSpace, typename TIterator, typename TInteger>
306 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
307 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Ul() const
312 //-------------------------------------------------------------------------
313 template <typename TKSpace, typename TIterator, typename TInteger>
315 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
316 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Lf() const
321 //-------------------------------------------------------------------------
322 template <typename TKSpace, typename TIterator, typename TInteger>
324 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
325 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Ll() const
330 //-------------------------------------------------------------------------
331 template <typename TKSpace, typename TIterator, typename TInteger>
333 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
334 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::back() const
339 //-------------------------------------------------------------------------
340 template <typename TKSpace, typename TIterator, typename TInteger>
342 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
343 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::front() const
345 return myDSS.front();
348 //-------------------------------------------------------------------------
349 template <typename TKSpace, typename TIterator, typename TInteger>
352 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::begin() const
357 //-------------------------------------------------------------------------
358 template <typename TKSpace, typename TIterator, typename TInteger>
361 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::end() const
366 //-----------------------------------------------------------------
367 template <typename TKSpace, typename TIterator, typename TInteger>
370 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::isValid() const
372 return ( (myDSS.isValid())&&(isNotEmpty(myBegin,myEnd)) );
375 //-----------------------------------------------------------------
376 template <typename TKSpace, typename TIterator, typename TInteger>
379 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::selfDisplay ( std::ostream & out) const
381 out << "[ArithmeticalDSSComputerOnSurfels] " << myDSS;
384 ///////////////////////////////////////////////////////////////////////////////
386 ///////////////////////////////////////////////////////////////////////////////
388 //-----------------------------------------------------------------------------
389 template <typename TKSpace, typename TIterator, typename TInteger>
391 void DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::
392 init(const ConstIterator& it)
394 ASSERT(myKSpace != nullptr);
401 auto pair = getProjectedPointsFromSurfel(surfel);
402 auto p = myExtractor->first(pair);
404 auto q = myExtractor->second(pair);
405 ASSERT(myDSS.isExtendableFront( q ));
406 myDSS.extendFront( q );
409 ///////////////////////////////////////////////////////////////////////////////
411 ///////////////////////////////////////////////////////////////////////////////
413 //-----------------------------------------------------------------
414 template <typename TKSpace, typename TIterator, typename TInteger>
416 std::pair<typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point,
417 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point>
418 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::getProjectedPointsFromSurfel(SCell const& aSurfel) const
422 //this convention has been chosen so that
423 //linels always stand at the same side
424 if (myKSpace->sSign(aSurfel) == myKSpace->POS) {
425 linel1 = myKSpace->sDirectIncident(aSurfel, myProjectionAxis);
427 linel1 = myKSpace->sIndirectIncident(aSurfel, myProjectionAxis);
430 return getProjectedPointsFromLinel(linel1);
433 //-----------------------------------------------------------------
434 template <typename TKSpace, typename TIterator, typename TInteger>
436 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
437 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::getNextProjectedPoint(SCell const& aSurfel) const
439 return myExtractor->second(getProjectedPointsFromSurfel(aSurfel));
442 //-----------------------------------------------------------------
443 template <typename TKSpace, typename TIterator, typename TInteger>
445 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point
446 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::getPreviousProjectedPoint(SCell const& aSurfel) const
448 return myExtractor->first(getProjectedPointsFromSurfel(aSurfel));
451 ///////////////////////////////////////////////////////////////////////////////
452 // Private methods //
453 ///////////////////////////////////////////////////////////////////////////////
456 //-----------------------------------------------------------------
457 template <typename TKSpace, typename TIterator, typename TInteger>
459 std::pair<typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point,
460 typename DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::Point>
461 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::getProjectedPointsFromLinel(SCell const& aLinel) const
463 auto dim = *myKSpace->sDirs(aLinel);
465 auto pointel1 = myKSpace->sIndirectIncident(aLinel, dim);
466 auto p1 = my2DProjector(myKSpace->sCoords(pointel1));
468 auto pointel2 = myKSpace->sDirectIncident(aLinel, dim);
469 auto p2 = my2DProjector(myKSpace->sCoords(pointel2));
474 //-----------------------------------------------------------------
475 template <typename TKSpace, typename TIterator, typename TInteger>
478 DGtal::ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger>::dimNotIn(Dimension const& aDim1, Dimension const& aDim2) const
480 ASSERT( KSpace::dimension == 3 );
481 ASSERT( aDim1 != aDim2 );
483 bool marks[3] = {false, false, false};
488 while (marks[i] == true) {
492 ASSERT( (marks[i] == false) && (i < 3) );