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;
68 template<
typename TKSpace>
74 typedef TKSpace KSpace;
75 typedef typename KSpace::SCell SCell;
84 Shape aShape(
Point(aCx,aCy), aR);
87 RealPoint xLow ( -aR-1, -aR-1 );
88 RealPoint xUp( aR+1, aR+1 );
91 dig.
init( xLow, xUp, 1 );
99 <<
" error in creating KSpace." << std::endl;
109 std::vector<Point> points, points2;
115 points2.assign( points.rbegin(), points.rend() );
127 <<
" error in finding a bel." << std::endl;
148 template <
typename TCurve>
152 typedef typename TCurve::IncidentPointsRange
Range;
153 Range r = curve.getIncidentPointsRange();
162 std::stringstream ss;
163 ss <<
"StabbingCircleComputerDrawingTest" << suffix <<
".eps";
164 board.saveEPS(ss.str().c_str());
174 std::stringstream ss;
175 ss <<
"StabbingCircleComputerDrawingTest" << suffix <<
"2.eps";
176 board.saveEPS(ss.str().c_str());
185 template <
typename TCurve>
189 typedef typename TCurve::IncidentPointsRange
Range;
193 unsigned int nbok = 0;
198 Range r = curve.getIncidentPointsRange();
210 trace.
info() << s4.isValid() << s4 << endl;
215 &&(s2 == s4)&&(s2 != s5)&&(s2 != s1)
216 &&(s3 != s5)&&(s1 == s3);
218 nbok += myFlag ? 1 : 0;
226 Range r = curve.getIncidentPointsRange();
230 trace.
info() <<
"forward extension " << endl;
232 ConstIterator itBegin (r.
begin());
233 ConstIterator itEnd (r.
end());
239 ConstIterator itLast (s.
end()); --itLast;
245 trace.
info() <<
"backward extension " << endl;
248 ConstReverseIterator ritBegin ( s.
end() );
249 ConstReverseIterator ritEnd ( itBegin );
255 ConstReverseIterator ritLast (rs.
end()); --ritLast;
262 trace.
info() <<
"comparison... " << endl;
263 bool myFlag = (s == t)
266 nbok += myFlag ? 1 : 0;
271 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
284 unsigned int nbok = 0;
289 for (
unsigned int i = 0; i < 50; ++i)
292 double cx = (rand()%100 ) / 100.0;
293 double cy = (rand()%100 ) / 100.0;
294 double radius = (rand()%100 )+100;
295 c = ballGenerator<KSpace>( cx, cy, radius, ((i%2)==1) );
296 trace.
info() <<
" #ball #" << i <<
" c(" << cx <<
"," << cy <<
") r=" << radius << endl;
314 for (ConstIterator it = s.
begin(); ((it != s.
end()) && flag) ; ++it)
318 flag = ( p1(it->first)&&p2(it->second) );
322 nbok += flag ? 1 : 0;
328 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
335 template <
typename TCurve>
339 typedef typename TCurve::IncidentPointsRange
Range;
340 Range r = curve.getIncidentPointsRange();
345 unsigned int nbok = 0;
351 Segmentation theSegmentation( r.
begin(), r.
end(), SegmentComputer() );
356 typename Segmentation::SegmentComputerIterator it = theSegmentation.
begin();
357 typename Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
359 unsigned int suml = 0;
360 for ( ; it != itEnd; ++it, ++n) {
361 board <<
SetMode(SegmentComputer().className(),
"Sector")
363 for (ConstIterator i = it->begin(); i != it->end(); ++i)
367 board.saveSVG(
"StabbingCircleComputerGreedySegmentationTest.svg", Board2D::BoundingBox, 5000 );
369 trace.
info() << r.size() <<
";" << n <<
";" << suml << endl;
371 bool flag = ((r.size()==85)&&(n==6)&&(suml==90)&&((r.size()+n-1)==suml));
372 nbok += flag ? 1 : 0;
380 Segmentation theSegmentation( r.
begin(), r.
end(), SegmentComputer() );
381 theSegmentation.
setMode(
"Last");
386 typename Segmentation::SegmentComputerIterator it = theSegmentation.begin();
387 typename Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
389 unsigned int suml = 0;
390 for ( ; it != itEnd; ++it, ++n) {
391 board <<
SetMode(SegmentComputer().className(),
"Annulus")
393 for (ConstIterator i = it->begin(); i != it->end(); ++i)
397 board.
saveSVG(
"StabbingCircleComputerSaturatedSegmentationTest.svg", Board2D::BoundingBox, 5000 );
399 trace.
info() << r.size() <<
";" << n <<
";" << suml << endl;
401 nbok += ((r.size()==85)&&(n==20)&&(suml==326)) ? 1 : 0;
406 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
412 int main(
int argc,
char** argv )
416 for (
int i = 0; i < argc; ++i )
430 c = ballGenerator<KSpace>(0,0,6,
false);
431 std::vector<PointVector<2,int> > rv;
432 rc = ballGenerator<KSpace>(0,0,6,
true);
444 std::string filename = testPath +
"samples/sinus2D4.dat";
446 instream.open (filename.c_str(), ifstream::in);
455 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
void beginBlock(const std::string &keyword="")
void testStabbingCircleComputerConceptChecking()
HyperRectDomain< Space > Domain
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
const Point & getLowerBound() const
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
const Point & getUpperBound() const
Circle getSeparatingCircle() const
int main(int argc, char **argv)
void attach(const EuclideanShape &shape)
Aim: Represents a circle uniquely defined by three 2D points and that is able to return for any given...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Reverse getReverse() const
void setMode(const std::string &aMode)
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators. The last element of a given segment is the first one one of the next segment.
Aim: On-line recognition of a digital circular arcs (DCA) defined as a sequence of connected grid edg...
void longestSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &end, IteratorType)
Aim: Predicate returning 'true' iff a given point is in the 'interior' of a given shape...
ConstIterator end() const
Aim: The concept CDrawableWithBoard2D specifies what are the classes that admit an export with Board2...
Aim: Model of the concept StarShaped represents any circle in the plane.
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
bool drawingTestStabbingCircleComputer(const TCurve &curve, const string &suffix)
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
bool testStabbingCircleComputer(const TCurve &curve)
std::reverse_iterator< ConstIterator > ConstReverseIterator
ConstIterator begin() const
void init(const ConstIterator &anIt)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
bool testSegmentation(const TCurve &curve)
bool initFromVectorStream(std::istream &in)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
GridCurve< TKSpace > ballGenerator(double aCx, double aCy, double aR, bool aFlagIsCW)
TConstIterator ConstIterator
Aim: Defines the concept describing a bidirectional segment computer, ie. a model of concepts::CSegme...
IncidentPointsRange getIncidentPointsRange() const
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...