DGtal  1.3.beta
geometry/curves/exampleRationalConvexity.cpp

This snippet shows how to identify and display digital fully subconvex sets of a grid curve form its tangent bundle.

See also
Digital convexity
Extraction of all maximal rational segments between midpoints that are subconvex to the digital curve.
#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 DGtal;
using namespace Z2i;
int main( int argc, char** argv )
{
trace.beginBlock ( "Example for 2d gridcurves" );
string S = examplesPath + "samples/contourS.fc";
// domain
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();
Curve c;
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 )
// there is a shift of (0.5,0.5) between points and cells embedder.
T2.push_back( Point( (int) round( 2. * rp[ 0 ] + 1. ),
(int) round( 2. * rp[ 1 ] + 1. ) ) );
Board2D aBoard;
aBoard.setUnit(Board2D::UCentimeter);
// Display cells
const KSpace& K = dconv.space();
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;
// Display contour
aBoard.setPenColor( Color::Black );
aBoard << c;
// Compute subconvex rational segments.
auto c_cover = dconv.makeCellCover( T.begin(), T.end(), 1, 1 );
trace.beginBlock( "Compute fully subconvex rational sets" );
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() )
{
auto segment = dconv.makeRationalSimplex( { denominator, T2[i], T2[j] } );
if ( ! dconv.isFullySubconvex( segment, c_cover ) ) break;
}
j = ( j + T2.size() - 1 ) % T2.size();
if ( j != last_j )
{ // display fully subconvex segments
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 );//, 5000 );
return 0;
}
// //
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
DGtal::KhalimskySpaceND::uCell
Cell uCell(const PreCell &c) const
From an unsigned cell, returns an unsigned cell lying into this Khalismky space.
LibBoard::Board::setPenColor
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
DGtal::Trace::endBlock
double endBlock()
LibBoard::Board::setPenColorRGBi
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:278
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::FreemanChain::begin
ConstIterator begin() const
DGtal::FreemanChain< int >
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::DigitalConvexity::makeRationalSimplex
static RationalPolytope makeRationalSimplex(Integer d, PointIterator itB, PointIterator itE)
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
DGtal::Z2i::Curve
GridCurve< K2 > Curve
Definition: StdDefs.h:116
DGtal::DigitalConvexity::isFullySubconvex
bool isFullySubconvex(const LatticePolytope &P, const CellGeometry &C) const
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::FreemanChain::end
ConstIterator end() const
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::DigitalConvexity::makeCellCover
CellGeometry makeCellCover(PointIterator itB, PointIterator itE, Dimension i=0, Dimension k=KSpace::dimension) const
DGtal::DigitalConvexity
Aim: A helper class to build polytopes from digital sets and to check digital k-convexity.
Definition: DigitalConvexity.h:73
LibBoard::Board::setLineWidth
Board & setLineWidth(double width)
Definition: Board.cpp:329
DGtal::DigitalConvexity::space
const KSpace & space() const
Point
MyPointD Point
Definition: testClone2.cpp:383
LibBoard::Board::drawLine
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:368
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64