DGtal  1.5.beta
convex-and-concave-parts.cpp File Reference
#include <cmath>
#include <iostream>
#include <sstream>
#include <fstream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/SaturatedSegmentation.h"
#include "ConfigExamples.h"
Include dependency graph for convex-and-concave-parts.cpp:

Go to the source code of this file.

Functions

template<typename Iterator , typename Board >
void drawCCP (const Iterator &itb, const Iterator &ite, Board &aBoard)
 Function that draws the maximal segments with a color that depends on the local convexity: More...
 
template<typename Iterator , typename Board >
void segmentationIntoMaximalDSSs (const Iterator &itb, const Iterator &ite, Board &aBoard)
 Perform a saturated segmentation into maximal digital straight segments of a given range of integer points and draw the result. More...
 
int main (int argc, char **argv)
 Program that draws the maximal segments of digital curve whose chain code may be given as an argument. The chain code must be a sequence of characters belonging to the set {0,1,2,3}. More...
 

Detailed Description

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/01/24

An example file named convex-and-concave-parts.

This file is part of the DGtal library.

Definition in file convex-and-concave-parts.cpp.

Function Documentation

◆ drawCCP()

template<typename Iterator , typename Board >
void drawCCP ( const Iterator &  itb,
const Iterator &  ite,
Board &  aBoard 
)

Function that draws the maximal segments with a color that depends on the local convexity:

  • blue in a convex part,
  • green in a concave part,
  • yellow in an inflection part (both convex and concave),
  • black in an end part (of a connected part).
Parameters
itbbegin iterator on an ArithmeticalDSSComputer
iteend iterator on an ArithmeticalDSSComputer
aBoardboard to draw
Template Parameters
Iteratora model of forward iterator and CSegmentComputerIterator
Boarda Board2D type

Definition at line 95 of file convex-and-concave-parts.cpp.

96 {
97 
98  //choose the drawing mode
99  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" );
100  //prepare the drawing style and the pen color
101  string aStyleName = "ArithmeticalDSS/BoundingBox";
102  CustomPenColor* aPenColor;
103 
104  //for each maximal segment
105  for (Iterator i(itb); i != ite; ++i) {
106 
107  //get the current maximal segment
108  typedef typename Iterator::SegmentComputer::Primitive DSS;
109  DSS maximalDSS = i->primitive();
110 
111  //if located at the end of a connected part
112  if ( !(i.intersectNext() && i.intersectPrevious()) ) {
113 
114  aPenColor = new CustomPenColor( Color::Black );
115 
116  //otherwise
117  } else {
118 
119  //get the points located before and after the maximal segment
120  typedef typename DSS::Point Point;
121  Point beforeFirst = *(--(i->begin()));
122  Point afterLast = *(i->end());
123 
124  //remainders and bounds
125  typedef typename DSS::Integer Integer;
126  Integer r1 = maximalDSS.remainder(beforeFirst);
127  Integer r2 = maximalDSS.remainder(afterLast);
128  Integer mu = maximalDSS.mu();
129  Integer omega = maximalDSS.omega();
130 
131  //configurations
132  if ( (r1<=mu-1)&&(r2<=mu-1) ) { //concave
133  aPenColor = new CustomPenColor( Color::Green);
134  } else if ( (r1>=mu+omega)&&(r2>=mu+omega) ) { //convex
135  aPenColor = new CustomPenColor( Color::Blue );
136  } else if ( (r1>=mu+omega)&&(r2<=mu-1) ) { //convex to concave
137  aPenColor = new CustomPenColor( Color::Yellow );
138  } else if ( (r1<=mu-1)&&(r2>=mu+omega) ) { //concave to convex
139  aPenColor = new CustomPenColor( Color::Yellow );
140  } else { //pb
141  aPenColor = new CustomPenColor( Color::Red );
142  }
143 
144  }
145 
146  // draw the maximal segment on the board
147  aBoard << CustomStyle( aStyleName, aPenColor )
148  << maximalDSS;
149 
150  }
151 
152 }
DGtal::int32_t Integer
Definition: StdDefs.h:74
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:313
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
MyPointD Point
Definition: testClone2.cpp:383

Referenced by segmentationIntoMaximalDSSs().

◆ main()

int main ( int  argc,
char **  argv 
)

Program that draws the maximal segments of digital curve whose chain code may be given as an argument. The chain code must be a sequence of characters belonging to the set {0,1,2,3}.

Parameters
argcnumber of arguments
argvarray of arguments
Returns
0

Definition at line 194 of file convex-and-concave-parts.cpp.

195 {
196 
197  trace.beginBlock ( "Example convex-and-concave-parts" );
198 
199  Board2D aBoard; //create a board
200 
201  //create a chain code
202  string codes;
203  if (argc >= 2) codes = argv[1];
204  else codes = "030030330303303030300001010101101011010000030330303303030300001010110101011010000033";
205 
206  stringstream ss(stringstream::in | stringstream::out);
207  ss << "0 0 " << codes << endl;
208  FreemanChain<int> theContour( ss );
209 
210  trace.info() << "Processing of " << ss.str() << endl;
211 
212  //draw the digital contour
213  aBoard
214  << SetMode( "PointVector", "Grid" )
215  << theContour;
216 
217  //draw the maximal segments
218  segmentationIntoMaximalDSSs(theContour.begin(), theContour.end(), aBoard);
219 
220  //save the drawing
221  aBoard.saveSVG("convex-and-concave-parts.svg");
222  #ifdef WITH_CAIRO
223  aBoard.saveCairo("convex-and-concave-parts.png");
224  #endif
225 
226  trace.endBlock();
227 
228  return 0;
229 }
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1138
void segmentationIntoMaximalDSSs(const Iterator &itb, const Iterator &ite, Board &aBoard)
Perform a saturated segmentation into maximal digital straight segments of a given range of integer p...
Trace trace
Definition: Common.h:153

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), segmentationIntoMaximalDSSs(), and DGtal::trace.

◆ segmentationIntoMaximalDSSs()

template<typename Iterator , typename Board >
void segmentationIntoMaximalDSSs ( const Iterator &  itb,
const Iterator &  ite,
Board &  aBoard 
)

Perform a saturated segmentation into maximal digital straight segments of a given range of integer points and draw the result.

Parameters
itbbegin iterator
iteend iterator
aBoardboard to draw
Template Parameters
Iteratora model of forward iterator on digital points
Boarda Board2D type

Definition at line 167 of file convex-and-concave-parts.cpp.

169 {
170  typedef typename IteratorCirculatorTraits<Iterator>::Value::Coordinate Coordinate;
171 
172  //choose the primitive computer and the segmentation
173  typedef ArithmeticalDSSComputer<Iterator,Coordinate,4> RecognitionAlgorithm;
175 
176  //create the segmentation
177  RecognitionAlgorithm algo;
178  Segmentation s(itb,ite,algo);
179 
180  //draw the result
181  drawCCP(s.begin(), s.end(), aBoard);
182 }
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
void drawCCP(const Iterator &itb, const Iterator &ite, Board &aBoard)
Function that draws the maximal segments with a color that depends on the local convexity:
Aim: Provides nested types for both iterators and circulators: Type, Category, Value,...
SaturatedSegmentation< SegmentComputer > Segmentation

References drawCCP().

Referenced by main().