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 StandardDSS6Computer.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 StandardDSS6Computer.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
33//////////////////////////////////////////////////////////////////////////////
35#include <boost/version.hpp>
36#if BOOST_VERSION < 105800
37#include <boost/math/common_factor_rt.hpp>
39#include <boost/integer/common_factor_rt.hpp>
41#include "DGtal/io/Color.h"
42//////////////////////////////////////////////////////////////////////////////
48///////////////////////////////////////////////////////////////////////////////
49// Implementation of inline methods //
52 * Default constructor.
55template <typename TIterator, typename TInteger, int connectivity>
57DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::StandardDSS6Computer()
61 std::vector<DGtal::Dimension> v1,v2,v3;
69 myProjXY.init(v1.begin(),v1.end());
70 myProjXZ.init(v2.begin(),v2.end());
71 myProjYZ.init(v3.begin(),v3.end());
76 * Constructor with initialisation
78template <typename TIterator, typename TInteger, int connectivity>
80DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::StandardDSS6Computer(const ConstIterator& it)
83 std::vector<DGtal::Dimension> v1,v2,v3;
91 myProjXY.init(v1.begin(),v1.end());
92 myProjXZ.init(v2.begin(),v2.end());
93 myProjYZ.init(v3.begin(),v3.end());
100 * @param it an iterator on a sequence of points
102template <typename TIterator, typename TInteger, int connectivity>
104void DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::init(const ConstIterator& it)
107 //begin and end iterators
113 //adapters and projections
114 IteratorAdapter XYit(it,myProjXY);
117 IteratorAdapter XZit(it,myProjXZ);
120 IteratorAdapter YZit(it,myProjYZ);
127 * @param other the object to clone.
128 * Forbidden by default.
130template <typename TIterator, typename TInteger, int connectivity>
132DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::StandardDSS6Computer (
133 const StandardDSS6Computer<TIterator,TInteger,connectivity> & other ) :
134 myProjXY(other.myProjXY), myProjXZ(other.myProjXZ), myProjYZ(other.myProjYZ),
135 myXYalgo(other.myXYalgo), myXZalgo(other.myXZalgo), myYZalgo(other.myYZalgo),
136 myBegin(other.myBegin), myEnd(other.myEnd) {}
141 * @param other the object to copy.
142 * @return a reference on 'this'.
143 * Forbidden by default.
145template <typename TIterator, typename TInteger, int connectivity>
147DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity> &
148DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::operator= (
149 const StandardDSS6Computer<TIterator,TInteger,connectivity> & other )
152 myProjXY = other.myProjXY;
153 myProjXZ = other.myProjXZ;
154 myProjYZ = other.myProjYZ;
155 myXYalgo = other.myXYalgo;
156 myXZalgo = other.myXZalgo;
157 myYZalgo = other.myYZalgo;
158 myBegin = other.myBegin;
164template <typename TIterator, typename TInteger, int connectivity>
166typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::Self
167DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::getSelf() const {
172template <typename TIterator, typename TInteger, int connectivity>
174typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::Reverse
175DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::getReverse() const {
179template <typename TIterator, typename TInteger, int connectivity>
182DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::isInDSS ( const Point3d & point) const
185 if ( myXYalgo.isInDSS ( myProjXY ( point ) ) ) test++;
186 if ( myXZalgo.isInDSS ( myProjXZ ( point ) ) ) test++;
187 if ( myYZalgo.isInDSS ( myProjYZ ( point ) ) ) test++;
192template <typename TIterator, typename TInteger, int connectivity>
195DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::isInDSS ( const ConstIterator & it) const
198 if ( myXYalgo.isInDSS ( myProjXY ( *it ) ) ) test++;
199 if ( myXZalgo.isInDSS ( myProjXZ ( *it ) ) ) test++;
200 if ( myYZalgo.isInDSS ( myProjYZ ( *it ) ) ) test++;
207 * @param other the object to compare with.
208 * @return 'true' either if the points perfectly match
209 * or if the first points match to the last ones
210 * (same DSS scanned in the conversed way)
211 * and 'false' otherwise
213template <typename TIterator, typename TInteger, int connectivity>
216DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::operator==(
217 const StandardDSS6Computer<TIterator,TInteger,connectivity>& other ) const
219 return ( ( myXYalgo == other.myXYalgo ) &&
220 ( myXZalgo == other.myXZalgo ) &&
221 ( myYZalgo == other.myYZalgo ) &&
222 (*myBegin == *other.myBegin) &&
223 (*myEnd == *other.myEnd) );
227 * Difference operator.
228 * @param other the object to compare with.
229 * @return 'false' if equal
232template <typename TIterator, typename TInteger, int connectivity>
235DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::operator!=(
236 const StandardDSS6Computer<TIterator,TInteger,connectivity> & other ) const
238 return (!(*this == other));
245 * Tests whether the union between a point
246 * (adding to the front of the DSS
247 * with respect to the scan orientaion)
248 * and a DSS is a DSS.
249 * Computes the parameters of the new DSS
250 * with the adding point if true.
251 * @return 'true' if the union is a DSS, 'false' otherwise.
253template <typename TIterator, typename TInteger, int connectivity>
256DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::extendFront()
258 if( isExtendableFront() ) {
260 bool XYflag = myXYalgo.extendFront();
261 bool XZflag = myXZalgo.extendFront();
262 bool YZflag = myYZalgo.extendFront();
263 ASSERT( (XYflag)&&(XZflag)&&(YZflag) );
264 boost::ignore_unused_variable_warning(XYflag);
265 boost::ignore_unused_variable_warning(XZflag);
266 boost::ignore_unused_variable_warning(YZflag);
275/** Tests whether the 3d DSS can be extended at the front.
277 * @return 'true' if yes, 'false' otherwise
279template <typename TIterator, typename TInteger, int connectivity>
282DGtal::StandardDSS6Computer<TIterator, TInteger,connectivity>::isExtendableFront()
284 //projection on xy-plane
285 bool XYflag = myXYalgo.isExtendableFront();
287 //projection on xz-plane
288 bool XZflag = myXZalgo.isExtendableFront();
290 //projection on yz-plane
291 bool YZflag = myYZalgo.isExtendableFront();
293 return (XYflag && XZflag && YZflag);
299template <typename TIterator, typename TInteger, int connectivity>
302DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::begin() const {
306template <typename TIterator, typename TInteger, int connectivity>
309DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::end() const {
316//-----------------------------------------------------------------
318 * Checks the validity/consistency of the object.
319 * @return 'true' if the object is valid, 'false' otherwise.
322template <typename TIterator, typename TInteger, int connectivity>
325DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::isValid() const
327 return ( (myXYalgo.isValid())&&
328 (myXZalgo.isValid())&&
329 (myYZalgo.isValid()) );
334 * Computes the parameters
335 * (direction, intercept, thickness)
338template <typename TIterator, typename TInteger, int connectivity>
341DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>
342::getParameters ( Point3d& direction, PointR3d& intercept, PointR3d& thickness ) const
345 //let us take the pair of projection planes for which
346 //the common coordinate of the main vector cannot be 0
348 if (myXYalgo.b() != 0) { //XY-plane, XZ-plane
350 Integer a1 = myXYalgo.b();
351 Integer b1 = myXYalgo.a();
352 Integer a2 = myXZalgo.b();
353 Integer c1 = myXZalgo.a();
355 direction = Point3d(a1*a2,a2*b1,a1*c1);
357 Integer mu1 = myXYalgo.mu();
358 Integer mu2 = myXZalgo.mu();
359 intercept[0] = std::make_pair ( 0, 1 ); intercept[1] = std::make_pair ( -mu1, a1 ); intercept[2] = std::make_pair ( -mu2, a2 );
361 Integer omega1 = myXYalgo.omega()-1;
362 Integer omega2 = myXZalgo.omega()-1;
363 thickness[0] = std::make_pair ( 0, 1 ); thickness[1] = std::make_pair ( -omega1, a1 ); thickness[2] = std::make_pair ( -omega2, a2 );
367 if (myXYalgo.a() != 0) {//XY-plane, YZ-plane
369 Integer a1 = myXYalgo.b();
370 Integer b1 = myXYalgo.a();
371 Integer b2 = myYZalgo.b();
372 Integer c2 = myYZalgo.a();
374 direction = Point3d(b2*a1,b1*b2,b1*c2);
376 Integer mu1 = myXYalgo.mu();
377 Integer mu2 = myYZalgo.mu();
378 intercept[0] = std::make_pair ( mu1, b1 ); intercept[1] = std::make_pair ( 0, 1 ); intercept[2] = std::make_pair ( -mu2, b2 );
380 Integer omega1 = myXYalgo.omega()-1;
381 Integer omega2 = myYZalgo.omega()-1;
382 thickness[0] = std::make_pair ( omega1, b1 ); thickness[1] = std::make_pair ( 0, 1 ); thickness[2] = std::make_pair ( -omega2, b2 );
386 if (myYZalgo.a() != 0) {//YZ-plane, XZ-plane
388 std::cerr << "YZ-XZ" << std::endl;
390 Integer b2 = myYZalgo.b();
391 Integer c2 = myYZalgo.a();
392 Integer a2 = myXZalgo.b();
393 Integer c1 = myXZalgo.a();
395 direction = Point3d(c2*a2,c1*b2,c1*c2);
397 Integer mu1 = myYZalgo.mu();
398 Integer mu2 = myXZalgo.mu();
399 intercept[0] = std::make_pair ( mu2, c1 ); intercept[1] = std::make_pair ( mu1, c2 ); intercept[2] = std::make_pair ( 0, 1 );
401 Integer omega1 = myYZalgo.omega()-1;
402 Integer omega2 = myXZalgo.omega()-1;
403 thickness[0] = std::make_pair ( omega2, c1 ); thickness[1] = std::make_pair ( omega1, c2 ); thickness[2] = std::make_pair ( 0, 1);
405 } else {//degenerated case
406 direction = Point3d(0,0,0);
407 intercept[0] = std::make_pair ( 0, 1 ); intercept[1] = std::make_pair ( 0, 1 ); intercept[2] = std::make_pair ( 0, 1 );
408 thickness[0] = std::make_pair ( 0, 1 ); thickness[1] = std::make_pair ( 0, 1 ); thickness[2] = std::make_pair ( 0, 1);
415//-----------------------------------------------------------------------------
416template <typename TIterator, typename TInteger, int connectivity>
418const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
419DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXY() const
423//-----------------------------------------------------------------------------
424template <typename TIterator, typename TInteger, int connectivity>
426const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
427DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXZ() const
431//-----------------------------------------------------------------------------
432template <typename TIterator, typename TInteger, int connectivity>
434const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
435DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2dYZ() const
439//-----------------------------------------------------------------------------
440template <typename TIterator, typename TInteger, int connectivity>
442const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
443DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2d( Dimension i ) const
445 ASSERT( ( 0 <= i ) && ( i < 3 ) );
447 case 0: return myYZalgo; break;
448 case 1: return myXZalgo; break;
449 default: return myXYalgo; break;
455 * @return the style name used for drawing this object.
457template <typename TIterator, typename TInteger, int connectivity>
460DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::className() const
462 return "StandardDSS6Computer";
465//------------------------------------------------------------------------------
469 * Writes/Displays the object on an output stream.
470 * @param out the output stream where the object is written.
472template <typename TIterator, typename TInteger, int connectivity>
475DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::selfDisplay ( std::ostream & out) const
478 out << "[StandardDSS6Computer]" << std::endl;
479 out << "[XYprojection]" << std::endl;
480 out << myXYalgo << std::endl;
481 out << "[XZprojection]" << std::endl;
482 out << myXZalgo << std::endl;
483 out << "[YZprojection]" << std::endl;
484 out << myYZalgo << std::endl;
485 out << "[End StandardDSS6Computer]" << std::endl;
490//------------------------------------------------------------------------------