DGtal  1.4.beta
Functions
exampleDigitalConvexity.cpp File Reference

An example file for DigitalConvexity in 2D. More...

#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"
Include dependency graph for exampleDigitalConvexity.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

An example file for DigitalConvexity in 2D.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2020/02/02

This file is part of the DGtal library.

Definition in file exampleDigitalConvexity.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 64 of file exampleDigitalConvexity.cpp.

65 {
66  trace.beginBlock ( "Example for 2d gridcurves" );
67  string S = examplesPath + "samples/contourS.fc";
68 
69  // domain
70  const Point lowerBound( -200, -200 );
71  const Point upperBound( 200, 200 );
72 
73  fstream inputStream( S.c_str(), ios::in );
74  FreemanChain<int> fc(inputStream);
75  inputStream.close();
76  Curve c;
77  c.initFromPointsRange( fc.begin(), fc.end() );
78  auto points = c.getPointsRange();
79  std::vector<Point> T( points.begin(), points.end() );
80  Board2D aBoard;
81  aBoard.setUnit(Board2D::UCentimeter);
82  DigitalConvexity<KSpace> dconv( lowerBound, upperBound );
83  auto c_cover = dconv.makeCellCover( T.begin(), T.end(), 1, 1 );
84  const float sx = -0.5;
85  const float sy = -0.5;
86  trace.beginBlock( "Compute fully subconvex sets" );
87  for ( size_t i = 0; i < T.size(); ++i )
88  for ( size_t j = i+2; j < T.size(); ++j )
89  {
90  aBoard.setPenColorRGBi( rand() % 255, rand() % 255, rand() % 255 );
91  size_t k = (i+j)/2;
92  if ( ! dconv.isSimplexFullDimensional( { T[i], T[j], T[k] } ) ) continue;
93  auto triangle = dconv.makeSimplex( { T[i], T[j], T[k] } );
94  if ( dconv.isFullySubconvex( triangle, c_cover ) )
95  {
96  aBoard.drawLine( sx+(float)T[i][0], sy+(float)T[i][1],
97  sx+(float)T[j][0], sy+(float)T[j][1] );
98  aBoard.drawLine( sx+(float)T[i][0], sy+(float)T[i][1],
99  sx+(float)T[k][0], sy+(float)T[k][1] );
100  aBoard.drawLine( sx+(float)T[k][0], sy+(float)T[k][1],
101  sx+(float)T[j][0], sy+(float)T[j][1] );
102  }
103  else
104  j = T.size();
105  }
106  trace.endBlock();
107  aBoard.setPenColor( Color::Black );
108  aBoard << c;
109  aBoard.saveEPS( "myGridCurve.eps", Board2D::BoundingBox );//, 5000 );
110  trace.endBlock();
111  return 0;
112 }

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), LibBoard::Board::drawLine(), DGtal::FreemanChain< TInteger >::end(), DGtal::Trace::endBlock(), DGtal::DigitalConvexity< TKSpace >::isFullySubconvex(), DGtal::DigitalConvexity< TKSpace >::isSimplexFullDimensional(), DGtal::DigitalConvexity< TKSpace >::makeCellCover(), DGtal::DigitalConvexity< TKSpace >::makeSimplex(), LibBoard::Board::saveEPS(), LibBoard::Board::setPenColor(), LibBoard::Board::setPenColorRGBi(), LibBoard::Board::setUnit(), and DGtal::trace.

LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
DGtal::DigitalConvexity::makeSimplex
static LatticePolytope makeSimplex(PointIterator itB, PointIterator itE)
DGtal::DigitalConvexity::isFullySubconvex
bool isFullySubconvex(const PointRange &Y, const LatticeSet &StarX) const
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< int >
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Z2i::Curve
GridCurve< K2 > Curve
Definition: StdDefs.h:116
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< KSpace >
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