DGtal  1.3.beta
geometry/curves/exampleDigitalConvexity.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 subconvex triangles to the digital curve.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.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 );
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() );
Board2D aBoard;
aBoard.setUnit(Board2D::UCentimeter);
DigitalConvexity<KSpace> dconv( lowerBound, upperBound );
auto c_cover = dconv.makeCellCover( T.begin(), T.end(), 1, 1 );
const float sx = -0.5;
const float sy = -0.5;
trace.beginBlock( "Compute fully subconvex sets" );
for ( unsigned int i = 0; i < T.size(); ++i )
for ( unsigned int j = i+2; j < T.size(); ++j )
{
aBoard.setPenColorRGBi( rand() % 255, rand() % 255, rand() % 255 );
unsigned int k = (i+j)/2;
if ( ! dconv.isSimplexFullDimensional( { T[i], T[j], T[k] } ) ) continue;
auto triangle = dconv.makeSimplex( { T[i], T[j], T[k] } );
if ( dconv.isFullySubconvex( triangle, c_cover ) )
{
aBoard.drawLine( sx+(float)T[i][0], sy+(float)T[i][1],
sx+(float)T[j][0], sy+(float)T[j][1] );
aBoard.drawLine( sx+(float)T[i][0], sy+(float)T[i][1],
sx+(float)T[k][0], sy+(float)T[k][1] );
aBoard.drawLine( sx+(float)T[k][0], sy+(float)T[k][1],
sx+(float)T[j][0], sy+(float)T[j][1] );
}
else
j = T.size();
}
aBoard.setPenColor( Color::Black );
aBoard << c;
aBoard.saveEPS( "myGridCurve.eps", Board2D::BoundingBox );//, 5000 );
return 0;
}
// //
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
DGtal::DigitalConvexity::makeSimplex
static LatticePolytope makeSimplex(PointIterator itB, PointIterator itE)
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::trace
Trace trace
Definition: Common.h:154
DGtal::FreemanChain::begin
ConstIterator begin() const
DGtal::FreemanChain< int >
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
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
DGtal::DigitalConvexity::isSimplexFullDimensional
static bool isSimplexFullDimensional(PointIterator itB, PointIterator itE)
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
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