DGtal  1.3.beta
geometry/curves/exampleArithmeticalDSS.cpp

This example shows the basic usage of a 8-connected and a 4-connected arithmetical DSS.

See also
Digital straight lines and segments
#include <iostream>
#include <exception>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/ArithmeticalDSS.h"
using namespace std;
using namespace DGtal;
using namespace Z2i;
{
trace.beginBlock ( "Naive DSS" );
using namespace Z2i;
// Construct a naive DSS
NaiveDSS8<Integer> segment( 5, 8, //slope
Point(0,0), Point(8,5), //ending points
Point(0,0), Point(8,5), //upper points
Point(3,1), Point(3,1) //lower points
);
// Trace to the standard output
trace.info() << segment << std::endl;
// Trace the position and remainder of each point
it = segment.begin(),
ite = segment.end();
it != ite; ++it )
{
trace.info() << "("
<< segment.position( *it ) << ","
<< segment.remainder( *it )
<< ") ";
}
trace.info() << std::endl;
Board2D board;
// Draw the grid
Domain domain( Point(0,0), Point(8,5) );
board << SetMode(domain.className(), "Grid")
<< domain;
//Draw the points of the DSS
board << SetMode("PointVector", "Both");
board << SetMode(segment.className(), "Points")
<< segment;
// Draw the bounding box
board << SetMode(segment.className(), "BoundingBox")
<< segment;
// Save
board.saveSVG("NaiveDSS8.svg");
#ifdef WITH_CAIRO
board.saveCairo("NaiveDSS8.png", Board2D::CairoPNG);
#endif
}
{
trace.beginBlock ( "Standard DSS" );
using namespace Z2i;
// Construct a standard DSS
StandardDSS4<Integer> segment( 5, 8, //slope
Point(0,0), Point(8,5), //ending points
Point(0,0), Point(8,5), //upper points
Point(4,1), Point(4,1) //lower points
);
// Trace to the standard output
trace.info() << segment << std::endl;
// Display the DSS with a domain on a board
Domain domain( Point(0,0), Point(8,5) );
Board2D board;
// Draw the grid
board << SetMode(domain.className(), "Grid")
<< domain;
// Draw the points of the DSS
board << SetMode("PointVector", "Grid")
<< SetMode(segment.className(), "Points")
<< segment;
// Draw the bounding box
board << SetMode(segment.className(), "BoundingBox")
<< segment;
// Save
board.saveSVG("StandardDSS4.svg");
#ifdef WITH_CAIRO
board.saveCairo("StandardDSS4.png", Board2D::CairoPNG);
#endif
board.clear();
// Draw the pixels
board << SetMode(domain.className(), "Paving")
<< domain;
//Draw the points of the DSS
board << SetMode("PointVector", "Both");
board << SetMode(segment.className(), "Points")
<< segment;
// Draw the bounding box
board << SetMode(segment.className(), "BoundingBox")
<< segment;
board.saveSVG("StandardDSS4bis.svg");
#ifdef WITH_CAIRO
board.saveCairo("StandardDSS4bis.png", Board2D::CairoPNG);
#endif
}
{
trace.beginBlock ( "DSSs constructions" );
using namespace Z2i;
{
// Construct a naive DSS from two upper leaning points
NaiveDSS8<Integer> segment( Point(0,0), Point(8,5), true );
//or simply NaiveDSS8<Integer> segment( Point(0,0), Point(8,5) );
trace.info() << segment << std::endl;
}
{
// Construct a naive DSS from two lower leaning points
NaiveDSS8<Integer> segment( Point(0,0), Point(8,5), false );
trace.info() << segment << std::endl;
}
{
// Construct a naive DSS as a DSL subsegment
NaiveDSS8<Integer> segment( NaiveDSL<Integer>(5,8,0), Point(0,0), Point(8,5) );
trace.info() << segment << std::endl;
}
{
NaiveDSS8<Integer> bigDSS( NaiveDSL<Integer>(5,8,0), Point(-8,-5), Point(16,10) );
// Construct a naive DSS as a subsegment of a greater DSS
NaiveDSS8<Integer> segment( bigDSS, Point(0,0), Point(8,5) );
trace.info() << segment << std::endl;
}
std::vector<Point> r; //container for DSS points
{
// Custom a naive DSS
NaiveDSS8<Integer> segment( 5, 8, //slope
Point(0,0), Point(8,5), //ending points
Point(0,0), Point(8,5), //upper points
Point(3,1), Point(3,1) //lower points
);
//You should be sure that your object is valid before using it
if (!segment.isValid()) throw std::exception();
trace.info() << segment << std::endl;
//copy the DSS points into the container r
std::copy( segment.begin(), segment.end(), std::back_inserter(r) );
}
{
// Construct a DSS from a range of points
NaiveDSS8<Integer> segment( r.begin(), r.end() );
trace.info() << segment << std::endl;
}
}
{
trace.beginBlock ( "DSS update" );
using namespace Z2i;
//Construction --------------------------------------------------
Point M(11, 7);
NaiveDSS8<Integer> S( 5, 8, //slope
Point(0,0), Point(10,6), //ending points
Point(0,0), Point(8,5), //upper points
Point(3,1), Point(3,1) //lower points
);
//this segment should be valid:
if (!S.isValid()) throw std::exception();
// Store a copy before any operation
NaiveDSS8<Integer> copyOfS = S;
trace.info() << S << std::endl;
//Display ------------------------------------------------------
{
Board2D board;
// Draw the grid
Domain domain( Point(0,0), M );
board << SetMode(domain.className(), "Grid")
<< domain;
// Draw the points of the DSS and its bounding box
board << SetMode("PointVector", "Both");
board << SetMode(S.className(), "Points")
<< S
<< SetMode(S.className(), "BoundingBox")
<< S;
// Draw the orthonormal base
board.drawArrow(0.0, 0.0, 1.0, 0.0);
board.drawArrow(0.0, 0.0, 0.0, 1.0);
// Draw M
board << SetMode(M.className(), "Both")
<< CustomStyle( M.className(), new CustomColors( Color(255,0,0), Color(192, 0, 0)) )
<< M;
// Save
board.saveSVG("NaiveDSS8ExtInit.svg");
#ifdef WITH_CAIRO
board.saveCairo("NaiveDSS8ExtInit.png", Board2D::CairoPNG);
#endif
}
// Extension -----------------------------------------------------
bool resExtention = S.extendFront( M );
//this segment should be extended:
if (!resExtention) throw std::exception();
trace.info() << S << std::endl;
//Display ------------------------------------------------------
{
Board2D board;
// Draw the grid
Domain domain( Point(0,0), M );
board << SetMode(domain.className(), "Grid")
<< domain;
// Draw the points of the DSS and its bounding box
board << SetMode("PointVector", "Both");
board << SetMode(S.className(), "Points")
<< S
<< SetMode(S.className(), "BoundingBox")
<< S;
// Draw the orthonormal base
board.drawArrow(0.0, 0.0, 1.0, 0.0);
board.drawArrow(0.0, 0.0, 0.0, 1.0);
// Save
board.saveSVG("NaiveDSS8ExtDone.svg");
#ifdef WITH_CAIRO
board.saveCairo("NaiveDSS8ExtDone.png", Board2D::CairoPNG);
#endif
}
// Retraction ----------------------------------------------------
bool resRetraction = S.retractFront();
//this segment should be retracted:
if (!resRetraction) throw std::exception();
trace.info() << S << std::endl;
// Comparaison ----------------------------------------------------
//this segment and the previous copy should be equal:
if ( !S.equalsTo(copyOfS) ) throw std::exception();
}
int main( int argc, char** argv )
{
trace.beginBlock ( "Example exampleArithmeticalDSS" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
return 0;
}
// //
exampleUpdate
void exampleUpdate()
Function showing how a DSS can be extended and retracted.
Definition: exampleArithmeticalDSS.cpp:270
DGtal::HyperRectDomain< Space >
DGtal::ArithmeticalDSS< TCoordinate, TCoordinate, 8 >::remainder
Integer remainder(const Point &aPoint) const
DGtal::Trace::endBlock
double endBlock()
DGtal::ArithmeticalDSS< TCoordinate, TCoordinate, 8 >::className
std::string className() const
DGtal::ArithmeticalDSS< TCoordinate, TCoordinate, 8 >::position
Position position(const Point &aPoint) const
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::HyperRectDomain::className
std::string className() const
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::NaiveDSS8
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 8-co...
Definition: ArithmeticalDSS.h:968
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
DGtal::NaiveDSL
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
Definition: ArithmeticalDSL.h:776
LibBoard::Board::drawArrow
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depthValue=-1)
Definition: Board.cpp:400
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal::Trace::info
std::ostream & info()
exampleNaiveDSS
void exampleNaiveDSS()
Function that illustrates the basic usage of a naive DSS.
Definition: exampleArithmeticalDSS.cpp:60
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ArithmeticalDSS< TCoordinate, TCoordinate, 8 >::end
ConstIterator end() const
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal::StandardDSS4
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 4-co...
Definition: ArithmeticalDSS.h:829
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
exampleConstructors
void exampleConstructors()
Function showing the different ways of constructing DSSs.
Definition: exampleArithmeticalDSS.cpp:197
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::ArithmeticalDSS< TCoordinate, TCoordinate, 8 >::begin
ConstIterator begin() const
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Point
MyPointD Point
Definition: testClone2.cpp:383
exampleStandardDSS
void exampleStandardDSS()
Function that illustrates the basic usage of a standard DSS.
Definition: exampleArithmeticalDSS.cpp:126