32 #include "DGtal/base/Common.h"
33 #include "DGtal/geometry/curves/ArithmeticalDSL.h"
34 #include "DGtal/geometry/curves/ArithmeticalDSSConvexHull.h"
35 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
37 #include "DGtal/kernel/SpaceND.h"
38 #include "DGtal/kernel/NumberTraits.h"
39 #include "DGtal/arithmetic/LatticePolytope2D.h"
44 using namespace DGtal;
45 using namespace functions;
60 template <
typename DSL>
66 typedef typename DSL::Position Position;
68 unsigned int nbok = 0;
76 Position l = (2*aDSL.patternLength());
77 std::vector<Point> lch, uch;
79 std::back_inserter(uch), std::back_inserter(lch) );
81 if (v ==
Vector(aDSL.b(),aDSL.a()))
84 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
85 if ( aDSL.remainder(lch.back()) == aDSL.mu()-1 )
88 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
89 if ( aDSL.remainder(uch.back()) == aDSL.mu() )
92 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
96 unsigned int threshold = (
unsigned int) std::ceil( std::log(bound) / std::log(1.618) );
97 if ( (lch.size()+uch.size()-1) <= threshold )
100 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
116 template <
typename DSL>
118 typename DSL::Coordinate b)
120 unsigned int nbok = 0;
124 for (
typename DSL::Integer mu = 0; ( (-mu < aDSL.omega())&&(nbok == nb) ); --mu)
143 && basicTest<NaiveDSL<DGtal::int32_t> >(5,8)
145 && basicTest<NaiveDSL<DGtal::int32_t> >(12,29)
147 && basicTest<NaiveDSL<DGtal::int32_t> >(70,29)
149 && basicTest<NaiveDSL<DGtal::int32_t> >(-70,29)
151 && basicTest<NaiveDSL<DGtal::int32_t> >(70,-29)
153 && basicTest<NaiveDSL<DGtal::int32_t> >(-70,-29)
156 && basicTest<StandardDSL<DGtal::int32_t> >(8,13)
158 && basicTest<StandardDSL<DGtal::int32_t> >(29,70)
160 && basicTest<StandardDSL<DGtal::int32_t> >(-29,70)
162 && basicTest<StandardDSL<DGtal::int32_t> >(29,-70)
164 && basicTest<StandardDSL<DGtal::int32_t> >(-29,-70)
168 && basicTest<NaiveDSL<DGtal::int32_t> >(33, 109)
170 && basicTest<NaiveDSL<DGtal::int32_t> >(8, 73)
172 #ifdef WITH_BIGINTEGER
173 && basicTest<NaiveDSL<DGtal::int32_t,DGtal::BigInteger> >(57, 520)
195 template <
typename DSL>
204 typedef typename DSL::Coordinate Coordinate;
206 unsigned int nbok = 0;
212 trace.
info() << a <<
" " << b << std::endl;
213 trace.
info() <<
"testing every mu between 0 and -" << inputDSL.omega() << std::endl;
215 for (
typename DSL::Integer mu = 0; ( (mu-1 >= -inputDSL.omega())&&(nbok == nb) ); --mu)
217 trace.
info() <<
"mu=" << mu <<
", testing every length between 1 and 2*" << inputDSL.omega() << std::endl;
218 inputDSL = DSL(a,b,mu);
220 for (
typename DSL::Position l = 1; ( (l <= 2*inputDSL.patternLength())&&(nbok == nb) ); ++l)
225 std::vector<Point> lch, uch;
227 std::back_inserter(uch), std::back_inserter(lch) );
234 Vector shift = -inputDSL.shift();
239 typename CIP::HalfSpace line(
typename CIP::Vector(a,-b), mu );
240 typename CIP::HalfSpace line2(
typename CIP::Vector(a,-b), mu-1 );
245 typename CIP::HalfSpace constraint(
typename CIP::Vector(shift[1],-shift[0]), l );
246 std::vector<typename CIP::Point> inch, outch, inch2, outch2;
247 inch.push_back(
typename CIP::Point(shift[0],shift[1]) );
248 inch2.push_back(
typename CIP::Point(shift[0],shift[1]) );
249 ASSERT( line(inch[0]) );
250 ASSERT( constraint(inch[0]) );
253 ASSERT( (!line2(outch[0])) );
254 ASSERT( constraint(outch[0]) );
256 cip.getAllPointsOfHull(inch, outch, vBezout, line, constraint);
257 cip.getAllPointsOfHull(inch2, outch2, vBezout, line2, constraint);
265 std::unique(inch2.begin(), inch2.end());
266 if (std::equal(lch.begin(), lch.end(), inch2.begin()))
270 std::unique(outch.begin(), outch.end());
271 if (std::equal(uch.begin(), uch.end(), outch.begin()))
292 && comparisonLeftHull<NaiveDSL<DGtal::int32_t> >(5,8)
294 && comparisonLeftHull<NaiveDSL<DGtal::int32_t> >(12,29)
297 && comparisonLeftHull<StandardDSL<DGtal::int32_t> >(5,8)
299 && comparisonLeftHull<StandardDSL<DGtal::int32_t> >(12,29)
317 template <
typename DSL>
319 typename DSL::Position x,
typename DSL::Position y)
327 Point startingPoint = aDSL.getPoint(x);
330 std::vector<Point> lch, uch;
332 std::back_inserter(uch), std::back_inserter(lch) );
335 Point upperLeaningPoint = uch.back();
337 -
static_cast<Integer>(upperLeaningPoint[1])*
static_cast<Integer>(v[0]));
340 return DSL( v[1],v[0],intercept );
355 template <
typename DSL>
357 typename DSL::Position x,
typename DSL::Position y)
362 typedef typename DSL::Coordinate Coordinate;
367 Point startingPoint = aDSL.getPoint(x);
368 ASSERT( aDSL(startingPoint) );
369 Point endingPoint = aDSL.getPoint(y);
370 ASSERT( aDSL(endingPoint) );
377 for (++it; (it != ite); ++it)
379 dss.extendFront(*it);
383 return DSL(dss.a(), dss.b(), dss.mu());
396 template <
typename DSL>
398 typename DSL::Position x,
typename DSL::Position y)
403 return (dsl1 == dsl2);
415 template <
typename DSL>
418 unsigned int nbok = 0;
424 for (
typename DSL::Integer mu = 0; ( (mu-1 >= -aDSL.omega())&&(nbok == nb) ); --mu)
428 typename DSL::Position f = -aDSL.patternLength();
429 for (
typename DSL::Position l = 1; ( (l <= 2*aDSL.patternLength())&&(nbok == nb) ); ++l)
454 && comparisonSubsegment<NaiveDSL<DGtal::int32_t> >(5,8)
456 && comparisonSubsegment<NaiveDSL<DGtal::int32_t> >(12,29)
458 && comparisonSubsegment<NaiveDSL<DGtal::int32_t> >(8,5)
460 && comparisonSubsegment<NaiveDSL<DGtal::int32_t> >(-8,5)
462 && comparisonSubsegment<NaiveDSL<DGtal::int32_t> >(8,-5)
464 && comparisonSubsegment<NaiveDSL<DGtal::int32_t> >(-8,-5)
467 && comparisonSubsegment<StandardDSL<DGtal::int32_t> >(8,13)
469 && comparisonSubsegment<StandardDSL<DGtal::int32_t> >(29,70)
471 && comparisonSubsegment<StandardDSL<DGtal::int32_t> >(-5,8)
473 && comparisonSubsegment<StandardDSL<DGtal::int32_t> >(5,-8)
475 && comparisonSubsegment<StandardDSL<DGtal::int32_t> >(-5,-8)
478 #ifdef WITH_BIGINTEGER
479 && comparisonSubsegment<NaiveDSL<DGtal::int32_t,DGtal::BigInteger> >(5,8)
498 template <
typename DSL>
503 typedef typename DSL::Coordinate Coordinate;
505 typedef typename DSL::Position Position;
507 unsigned int nbok = 0;
515 Position l = (2*aDSL.patternLength());
516 Point B = aDSL.getPoint( aDSL.position(A) + l + 1 );
517 DSS dss(aDSL.begin(A), aDSL.begin(B) );
522 std::vector<Point> lch, uch;
524 std::back_inserter(uch), std::back_inserter(lch) );
526 trace.
info() << v << lch.back() << uch.back() << std::endl;
528 if ( (uch.back() == A) && (lch.back() == A - aDSL.shift()) )
531 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
533 Vector LU = lch.back() - uch.back();
537 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
553 template <
typename DSL>
555 typename DSL::Coordinate b)
557 unsigned int nbok = 0;
561 for (
typename DSL::Integer mu = 0; ( (-mu < aDSL.omega())&&(nbok == nb) ); --mu)
580 && basicTest2<NaiveDSL<DGtal::int32_t> >(5,8)
582 && basicTest2<NaiveDSL<DGtal::int32_t> >(12,29)
584 && basicTest2<NaiveDSL<DGtal::int32_t> >(70,29)
586 && basicTest2<NaiveDSL<DGtal::int32_t> >(-70,29)
588 && basicTest2<NaiveDSL<DGtal::int32_t> >(70,-29)
590 && basicTest2<NaiveDSL<DGtal::int32_t> >(-70,-29)
593 && basicTest2<StandardDSL<DGtal::int32_t> >(8,13)
595 && basicTest2<StandardDSL<DGtal::int32_t> >(29,70)
597 && basicTest2<StandardDSL<DGtal::int32_t> >(-29,70)
599 && basicTest2<StandardDSL<DGtal::int32_t> >(29,-70)
601 && basicTest2<StandardDSL<DGtal::int32_t> >(-29,-70)
605 && basicTest2<NaiveDSL<DGtal::int32_t> >(33, 109)
607 && basicTest2<NaiveDSL<DGtal::int32_t> >(8, 73)
609 #ifdef WITH_BIGINTEGER
610 && basicTest2<NaiveDSL<DGtal::int32_t,DGtal::BigInteger> >(57, 520)
628 template <
typename DSS>
630 typename DSS::Position aBound)
632 ASSERT( (aBound - aDSS.position(aDSS.back())) > 0 );
637 typedef typename DSS::DSL DSL;
639 Point startingPoint = aDSS.dsl().getPoint(aBound);
642 std::vector<Point> lch, uch;
644 std::back_inserter(uch), std::back_inserter(lch) );
647 Point upperLeaningPoint = uch.back();
649 -
static_cast<Integer>(upperLeaningPoint[1])*
static_cast<Integer>(v[0]));
652 return DSL( v[1],v[0],intercept );
663 template <
typename DSS>
666 typedef typename DSS::DSL DSL;
670 return (dsl1 == dsl2);
684 template <
typename DSL>
687 unsigned int nbok = 0;
693 for (
typename DSL::Integer mu = 0; ( (mu-1 >= -aDSL.omega())&&(nbok == nb) ); --mu)
695 trace.
info() <<
"mu=" << mu << std::endl;
699 typedef typename DSL::Coordinate Coordinate;
703 Point startingPoint = aDSL.getPoint(0);
704 ASSERT( aDSL(startingPoint) );
705 Point endingPoint = aDSL.getPoint(2*aDSL.patternLength()+1);
706 ASSERT( aDSL(endingPoint) );
708 DSS dss = DSS(aDSL.begin(startingPoint), aDSL.begin(endingPoint));
711 for (
typename DSL::Position l = 1; ( (l <= 2*aDSL.patternLength())&&(nbok == nb) ); ++l)
736 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t> >(5,8)
738 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t> >(12,29)
740 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t> >(8,5)
742 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t> >(-8,5)
744 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t> >(8,-5)
746 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t> >(-8,-5)
749 && comparisonSubsegment2<StandardDSL<DGtal::int32_t> >(8,13)
751 && comparisonSubsegment2<StandardDSL<DGtal::int32_t> >(29,70)
753 && comparisonSubsegment2<StandardDSL<DGtal::int32_t> >(-5,8)
755 && comparisonSubsegment2<StandardDSL<DGtal::int32_t> >(5,-8)
757 && comparisonSubsegment2<StandardDSL<DGtal::int32_t> >(-5,-8)
760 #ifdef WITH_BIGINTEGER
761 && comparisonSubsegment2<NaiveDSL<DGtal::int32_t,DGtal::BigInteger> >(5,8)
773 int main(
int argc,
char** argv )
777 for (
int i = 0; i < argc; ++i )
783 std::istringstream issb(argv[1]);
786 std::istringstream issa(argv[2]);
789 if ( (a <= 0)||(b <= 0) )
791 std::cerr <<
" a and b should be strictly positive " << std::endl;
794 std::istringstream issmu(argv[3]);
797 if ( (mu > 0)||(mu <= -(
std::max(std::abs(a),std::abs(b)))) )
799 std::cerr <<
" mu should be within the range ]-max(|a|,|b|); 0] " << std::endl;
805 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
819 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class represents a naive (resp. standard) digital straight segment (DSS),...
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane....
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...
void beginBlock(const std::string &keyword="")
DigitalPlane::Point Vector
Point::Coordinate Integer
MyDigitalSurface::ConstIterator ConstIterator
PointVector smartCH(const PointVector &aFirstPoint, const Coordinate &aRemainderBound, const Position &aPositionBound, const PointVector &aStep, const Coordinate &aRStep, const PointVector &aShift, const Coordinate &aRShift, const PositionFunctor &aPositionFunctor, OutputIterator uIto, OutputIterator lIto)
Procedure that computes the lower and upper left hull of a DSS of first point aFirstPoint,...
PointVector reversedSmartCH(PointVector U, PointVector L, PointVector V, const Position &aFirstPosition, const Position &aLastPosition, const PositionFunctor &aPositionFunctor, OutputIterator uIto, OutputIterator lIto)
Procedure that computes the lower and upper left hull of the left subsegment of a greater DSS charact...
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: The traits class for all models of Cinteger.
DSL smartCHSubsegment(const DSL &aDSL, typename DSL::Position x, typename DSL::Position y)
bool comparisonLeftHull(typename DSL::Coordinate a, typename DSL::Coordinate b)
bool testWithoutLengthConstraint2()
int main(int argc, char **argv)
bool basicTest2(const DSL &aDSL)
bool testWithoutLengthConstraint()
bool comparisonSubsegment2(const DSS &aDSS, typename DSS::Position aBound)
bool basicTest(const DSL &aDSL)
DSL trivialSubsegment(const DSL &aDSL, typename DSL::Position x, typename DSL::Position y)
bool testWithLengthConstraint()
DSS::DSL reversedSmartCHSubsegment(const DSS &aDSS, typename DSS::Position aBound)
bool comparisonSubsegment(const DSL &aDSL, typename DSL::Position x, typename DSL::Position y)