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"
{
trace.beginBlock (
"Example for 2d gridcurves" );
string S = examplesPath + "samples/contourS.fc";
const Point lowerBound( -200, -200 );
const Point upperBound( 200, 200 );
fstream inputStream( S.c_str(), ios::in );
inputStream.close();
Curve c;
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. ) ) );
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 )
<< pixel;
aBoard << c;
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 )
{
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 = (unsigned int)( j + T2.size() - 1 ) % T2.size();
if ( j != last_j )
{
aBoard.
drawLine( RT[i][0], RT[i][1], RT[j][0], RT[j][1] );
}
last_j = j;
}
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Aim: A helper class to build polytopes from digital sets and to check digital k-convexity and full co...
ConstIterator end() const
ConstIterator begin() const
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)
Board & setPenColor(const DGtal::Color &color)
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Board & setLineWidth(double width)
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...