32 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/topology/SurfelAdjacency.h"
35 #include "DGtal/topology/DigitalSurface.h"
36 #include "DGtal/topology/helpers/BoundaryPredicate.h"
37 #include "DGtal/topology/SetOfSurfels.h"
38 #include "DGtal/topology/SCellsFunctors.h"
40 #include "DGtal/shapes/Shapes.h"
41 #include "DGtal/shapes/ShapeFactory.h"
42 #include "DGtal/shapes/GaussDigitizer.h"
44 #include "DGtal/io/boards/Board2D.h"
46 #include "DGtalCatch.h"
50 using namespace DGtal;
58 double angle = atan2(point[1], point[0]);
59 if(angle < 0.) angle += 2. * M_PI;
66 return angle(h * emb(cell));
75 AngleLessCell(
const KSpace& kspace,
const double h) : _kspace(kspace), _h(h)
79 inline bool operator()(
const SCell& a,
const SCell& b)
const
81 return angle(_kspace, a, _h) <
angle(_kspace, b, _h);
90 template <
typename Shape>
91 void digitize(
Shape& shape, std::vector<SCell>& sCells0, std::vector<SCell>& sCells1,
KSpace& kspace,
const double h)
103 digitizer.attach(shape);
105 domain = digitizer.getDomain();
107 kspace.
init(digitizer.getLowerBound(), digitizer.getUpperBound(),
true);
109 const SurfelAdj surfel_adjacency(
true);
110 const KSpace::SCell cell_bel = Surf::findABel(kspace, digitizer);
111 Surf::track2DBoundary(sCells1, kspace, surfel_adjacency, digitizer, cell_bel);
113 typedef std::vector<Point> Points;
115 Surf::track2DBoundaryPoints(points, kspace, surfel_adjacency, digitizer, cell_bel);
117 for(Points::const_iterator pi = points.begin(), pe = points.end(); pi != pe; ++pi) sCells0.push_back(kspace.
sCell(*pi, point_ref));
120 std::sort(sCells0.begin(), sCells0.end(), AngleLessCell(kspace, h));
121 std::sort(sCells1.begin(), sCells1.end(), AngleLessCell(kspace, h));
123 ASSERT(sCells0.size() == sCells1.size());
126 template <
typename Shape>
129 std::vector<SCell> sCells0, sCells1;
133 digitize(shape, sCells0, sCells1, kspace, h);
137 for(
unsigned int i = 0; i < sCells0.size(); i++)
142 const int prev = ( i + sCells0.size() - 3 ) % sCells0.size(), next = (i + 3) % sCells0.size();
144 RealPoint inner_prev = sCellToInnerPoint( sCells0[prev] );
145 RealPoint outer_prev = sCellToOuterPoint( sCells0[prev] );
147 RealPoint inner_next = sCellToInnerPoint( sCells0[next] );
148 RealPoint outer_next = sCellToOuterPoint( sCells0[next] );
160 const double norm2 = (p - h * canonicSCellEmbedder( sCells0[i]) ).norm();
162 if ( norm2 > sqrt(2.) * h)