This snippet shows how to identify and display digital fully subconvex sets of a grid curve form its tangent bundle.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/volumes/DigitalConvexity.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace Z2i;
int main(
int argc,
char** argv )
{
string S = examplesPath + "samples/contourS.fc";
const Point lowerBound( -200, -200 );
const Point upperBound( 200, 200 );
DigitalConvexity<KSpace> dconv( lowerBound, upperBound );
fstream inputStream( S.c_str(), ios::in );
FreemanChain<int> fc(inputStream);
inputStream.close();
c.initFromPointsRange( fc.begin(), fc.end() );
auto points = c.getPointsRange();
std::vector<Point> T( points.begin(), points.end() );
auto midpoints = c.getMidPointsRange();
std::vector<RealPoint> RT( midpoints.begin(), midpoints.end() );
std::vector<Point> T2;
for ( auto && rp : midpoints )
T2.push_back(
Point( (
int) round( 2. * rp[ 0 ] + 1. ),
(int) round( 2. * rp[ 1 ] + 1. ) ) );
Board2D aBoard;
aBoard.setUnit(Board2D::UCentimeter);
Color grey( 200, 200, 200 );
std::set<Cell> pixels;
for ( auto p : T )
{
pixels.insert(
K.uCell(
Point( 2*p[ 0 ] - 1, 2*p[ 1 ] - 1 ) ) );
pixels.insert(
K.uCell(
Point( 2*p[ 0 ] + 1, 2*p[ 1 ] - 1 ) ) );
pixels.insert(
K.uCell(
Point( 2*p[ 0 ] - 1, 2*p[ 1 ] + 1 ) ) );
pixels.insert(
K.uCell(
Point( 2*p[ 0 ] + 1, 2*p[ 1 ] + 1 ) ) );
}
for ( auto && pixel : pixels )
aBoard << CustomStyle( pixel.className(), new CustomColors( grey, grey ) )
<< pixel;
aBoard.setPenColor( Color::Black );
aBoard << c;
Point denominator( 2, 2 );
unsigned int last_j = 0;
unsigned int j = 0;
for ( unsigned int i = 0; i < T2.size(); ++i )
{
aBoard.setPenColorRGBi( rand() % 255, rand() % 255, rand() % 255 );
unsigned int start_j = ( i + 1 ) % T2.size();
for ( j = ( start_j + 1 ) % T2.size(); j != start_j; j = ( j + 1 ) % T2.size() )
{
}
j = (unsigned int)( j + T2.size() - 1 ) % T2.size();
if ( j != last_j )
{
aBoard.setLineWidth( 2.5 );
aBoard.drawLine( RT[i][0], RT[i][1], RT[j][0], RT[j][1] );
}
last_j = j;
}
aBoard.saveEPS( "myGridCurve.eps", Board2D::BoundingBox );
return 0;
}
static RationalPolytope makeRationalSimplex(Integer d, PointIterator itB, PointIterator itE)
bool isFullySubconvex(const PointRange &Y, const LatticeSet &StarX) const
const KSpace & space() const
CellGeometry makeCellCover(PointIterator itB, PointIterator itE, Dimension i=0, Dimension k=KSpace::dimension) const
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)