46 #include "DGtal/base/Common.h"
47 #include "DGtal/helpers/StdDefs.h"
48 #include "ConfigExamples.h"
50 #include "DGtal/topology/KhalimskySpaceND.h"
51 #include "DGtal/geometry/curves/FreemanChain.h"
52 #include "DGtal/geometry/curves/GridCurve.h"
53 #include "DGtal/geometry/volumes/DigitalConvexity.h"
55 #include "DGtal/io/boards/Board2D.h"
60 using namespace DGtal;
65 int main(
int argc,
char** argv )
68 string S = examplesPath +
"samples/contourS.fc";
71 const Point lowerBound( -200, -200 );
72 const Point upperBound( 200, 200 );
75 fstream inputStream( S.c_str(), ios::in );
79 c.initFromPointsRange( fc.begin(), fc.end() );
80 auto points = c.getPointsRange();
81 std::vector<Point> T( points.begin(), points.end() );
82 auto midpoints = c.getMidPointsRange();
83 std::vector<RealPoint> RT( midpoints.begin(), midpoints.end() );
84 std::vector<Point> T2;
85 for (
auto && rp : midpoints )
87 T2.push_back(
Point( (
int) round( 2. * rp[ 0 ] + 1. ),
88 (
int) round( 2. * rp[ 1 ] + 1. ) ) );
90 aBoard.
setUnit(Board2D::UCentimeter);
92 const KSpace&
K = dconv.space();
93 Color grey( 200, 200, 200 );
94 std::set<Cell> pixels;
97 pixels.insert(
K.
uCell(
Point( 2*p[ 0 ] - 1, 2*p[ 1 ] - 1 ) ) );
98 pixels.insert(
K.
uCell(
Point( 2*p[ 0 ] + 1, 2*p[ 1 ] - 1 ) ) );
99 pixels.insert(
K.
uCell(
Point( 2*p[ 0 ] - 1, 2*p[ 1 ] + 1 ) ) );
100 pixels.insert(
K.
uCell(
Point( 2*p[ 0 ] + 1, 2*p[ 1 ] + 1 ) ) );
102 for (
auto && pixel : pixels )
109 auto c_cover = dconv.makeCellCover( T.begin(), T.end(), 1, 1 );
111 Point denominator( 2, 2 );
112 unsigned int last_j = 0;
114 for (
unsigned int i = 0; i < T2.size(); ++i )
117 unsigned int start_j = ( i + 1 ) % T2.size();
118 for ( j = ( start_j + 1 ) % T2.size(); j != start_j; j = ( j + 1 ) % T2.size() )
120 auto segment = dconv.makeRationalSimplex( { denominator, T2[i], T2[j] } );
121 if ( ! dconv.isFullySubconvex( segment, c_cover ) )
break;
123 j = ( j + T2.size() - 1 ) % T2.size();
127 aBoard.
drawLine( RT[i][0], RT[i][1], RT[j][0], RT[j][1] );
132 aBoard.
saveEPS(
"myGridCurve.eps", Board2D::BoundingBox );