32 #include "DGtal/base/Common.h"
35 #include "DGtal/kernel/SpaceND.h"
36 #include "DGtal/kernel/domains/HyperRectDomain.h"
37 #include "DGtal/topology/KhalimskySpaceND.h"
40 #include "DGtal/shapes/ShapeFactory.h"
41 #include "DGtal/shapes/Shapes.h"
42 #include "DGtal/topology/helpers/Surfaces.h"
43 #include "DGtal/shapes/GaussDigitizer.h"
44 #include "DGtal/geometry/curves/GridCurve.h"
47 #include "DGtal/geometry/curves/CBidirectionalSegmentComputer.h"
49 #include "DGtal/geometry/curves/StabbingCircleComputer.h"
51 #include "DGtal/geometry/curves/SegmentComputerUtils.h"
52 #include "DGtal/geometry/curves/GreedySegmentation.h"
53 #include "DGtal/geometry/curves/SaturatedSegmentation.h"
56 #include "DGtal/io/boards/Board2D.h"
57 #include "DGtal/io/boards/CDrawableWithBoard2D.h"
59 #include "ConfigTest.h"
64 using namespace DGtal;
69 template<
typename TP,
typename TI>
70 struct MyBallPredicate
74 MyBallPredicate(
const Integer& aR) : myRad(aR) {};
75 bool operator()(
const Point &aP)
const {
return aP.dot(aP) <= myRad*myRad; };
79 template<
typename TKSpace,
typename Integer>
89 MyBallPredicate<Point,Integer> predicate(aR);
96 std::vector<Point> points, points2;
101 points2.assign( points.rbegin(), points.rend() );
112 <<
" error in finding a bel." << std::endl;
132 template <
typename TCurve>
136 typedef typename TCurve::IncidentPointsRange
Range;
137 Range r = curve.getIncidentPointsRange();
146 std::stringstream ss;
147 ss <<
"StabbingCircleComputerDrawingTest" << suffix <<
".eps";
148 board.
saveEPS(ss.str().c_str());
158 std::stringstream ss;
159 ss <<
"StabbingCircleComputerDrawingTest" << suffix <<
"2.eps";
160 board.
saveEPS(ss.str().c_str());
169 template <
typename TCurve>
173 typedef typename TCurve::IncidentPointsRange
Range;
177 unsigned int nbok = 0;
182 Range r = curve.getIncidentPointsRange();
199 &&(s2 == s4)&&(s2 != s5)&&(s2 != s1)
200 &&(s3 != s5)&&(s1 == s3);
202 nbok += myFlag ? 1 : 0;
210 Range r = curve.getIncidentPointsRange();
214 trace.
info() <<
"forward extension " << endl;
220 while ( (s.end() != itEnd) && (s.isExtendableFront()) && (s.extendFront()) ) {}
226 while ( (t.begin() != itBegin) && (t.extendBack()) ) {}
229 trace.
info() <<
"backward extension " << endl;
232 ConstReverseIterator ritBegin ( s.end() );
233 ConstReverseIterator ritEnd ( itBegin );
239 ConstReverseIterator ritLast (rs.
end()); --ritLast;
246 trace.
info() <<
"comparison... " << endl;
247 bool myFlag = (s == t)
250 nbok += myFlag ? 1 : 0;
255 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
269 unsigned int nbok = 0;
275 for (
unsigned int i = 1; i < 200 && flag; ++i)
278 KSpace kspace( Point::diagonal(-2*radius), Point::diagonal(2*radius),
true );
280 ballGenerator<KSpace>( kspace, c, radius, ((i%2)==0) );
281 trace.
info() <<
" #ball c(0,0) r=" << radius
282 <<
" cw=" << ((i%2)==0) << endl;
286 Range r = c.getIncidentPointsRange();
293 if (s.end() != r.end())
295 trace.
info()<<
"Complete circle not recognized"<<std::endl;
303 for (
ConstIterator it = s.begin(); ((it != s.end()) && flag) ; ++it)
305 FirstInCirclePred p1( s.getSeparatingCircle() );
306 SecondInCirclePred p2( s.getSeparatingCircle() );
307 flag = ( p1(it->first)&&p2(it->second) );
310 trace.
info() << s.getSeparatingCircle() <<
" "
312 << it->second << std::endl;
317 nbok += flag ? 1 : 0;
323 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
330 template <
typename TCurve>
334 typedef typename TCurve::IncidentPointsRange
Range;
335 Range r = curve.getIncidentPointsRange();
340 unsigned int nbok = 0;
354 unsigned int suml = 0;
355 for ( ; it != itEnd; ++it, ++n) {
362 board.
saveSVG(
"StabbingCircleComputerGreedySegmentationTest.svg", Board2D::BoundingBox, 5000 );
364 trace.
info() << r.size() <<
";" << n <<
";" << suml << endl;
366 bool flag = ((r.size()==85)&&(n==6)&&(suml==90)&&((r.size()+n-1)==suml));
367 nbok += flag ? 1 : 0;
376 theSegmentation.
setMode(
"Last");
384 unsigned int suml = 0;
385 for ( ; it != itEnd; ++it, ++n) {
392 board.
saveSVG(
"StabbingCircleComputerSaturatedSegmentationTest.svg", Board2D::BoundingBox, 5000 );
394 trace.
info() << r.size() <<
";" << n <<
";" << suml << endl;
396 nbok += ((r.size()==85)&&(n==20)&&(suml==326)) ? 1 : 0;
401 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
407 int main(
int argc,
char** argv )
411 for (
int i = 0; i < argc; ++i )
424 KSpace kspace(Point::diagonal(-10),Point::diagonal(10),
true);
439 std::string filename = testPath +
"samples/sinus2D4.dat";
441 instream.open (filename.c_str(), ifstream::in);
450 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: Represents a circle uniquely defined by three 2D points and that is able to return for any given...
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
bool initFromVectorStream(std::istream &in)
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: Specific iterator to visit all the maximal segments of a saturated segmentation.
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
SaturatedSegmentation::SegmentComputerIterator end() const
void setMode(const std::string &aMode)
SaturatedSegmentation::SegmentComputerIterator begin() const
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
TConstIterator ConstIterator
std::reverse_iterator< ConstIterator > ConstReverseIterator
Aim: On-line recognition of a digital circular arcs (DCA) defined as a sequence of connected grid edg...
ConstIterator begin() const
void init(const ConstIterator &anIt)
Reverse getReverse() const
ConstIterator end() const
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
void beginBlock(const std::string &keyword="")
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Point::Coordinate Integer
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
void longestSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &end, IteratorType)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: Defines the concept describing a bidirectional segment computer, ie. a model of concepts::CSeg...
Aim: The concept CDrawableWithBoard2D specifies what are the classes that admit an export with Board2...
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
SaturatedSegmentation< SegmentComputer > Segmentation
bool drawingTestStabbingCircleComputer(const TCurve &curve, const string &suffix)
void testStabbingCircleComputerConceptChecking()
int main(int argc, char **argv)
bool testSegmentation(const TCurve &curve)
void ballGenerator(const TKSpace &aKSpace, GridCurve< TKSpace > &aGC, const Integer &aR, const bool &aFlagIsCW)
bool testStabbingCircleComputer(const TCurve &curve)