DGtal  1.3.beta
topology/digitalSetToCubicalComplexes2D.cpp

Converting a digital set to cubical complex.

See also
Cubical Complex
Resulting cubical complex obtained on a flower shape.
#include <iostream>
#include <cmath>
#include <map>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
// Cellular grid
#include "DGtal/topology/CubicalComplex.h"
// Shape construction
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/EuclideanShapesDecorator.h"
#include "DGtal/shapes/parametric/Flower2D.h"
// Drawing
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
using namespace std;
using namespace DGtal;
using namespace functors;
using namespace Z2i;
int main( int , char** )
{
trace.beginBlock ( "Example digitalSetToCubicalComplexes2D" );
trace.beginBlock ( "Generate a 2D shape." );
typedef Flower2D< Space > MyEuclideanShape;
MyEuclideanShape shape( RealPoint( 0.0, 0.0 ), 16, 5, 5, M_PI_2/2. );
MyGaussDigitizer digShape;
digShape.attach( shape );
digShape.init ( shape.getLowerBound(), shape.getUpperBound(), 1.0 );
Domain domainShape = digShape.getDomain();
DigitalSet aSet( domainShape );
Shapes<Domain>::digitalShaper( aSet, digShape );
Board2D board;
board << SetMode( domainShape.className(), "Paving" ) << domainShape;
Color dorange ( 255, 136, 0, 220 );
board << CustomStyle( aSet.className(), new CustomFillColor ( dorange ) );
board << aSet;
trace.beginBlock ( "Generate a 2D cubical representation." );
typedef map<Cell, CubicalCellData> Map;
K.init ( domainShape.lowerBound(), domainShape.upperBound(), true );
CC complex ( K );
complex.construct< DigitalSet >( aSet );
board << SetMode( domainShape.className(), "Paving" ) << domainShape;
for ( Dimension d = 0; d <= 2; ++d )
for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
it != itE; ++it )
{
if ( d == 0 )
board << CustomStyle( it->first.className(),
new CustomColors( Color( 0, 0, 0 ),
Color( 0, 0, 0 ) ) );
else if ( d == 1 )
board << CustomStyle( it->first.className(),
new CustomColors( Color( 200, 0, 0 ),
Color( 100, 255, 100 ) ) );
else
board << CustomStyle( it->first.className(),
new CustomColors( Color( 0, 0, 200 ),
Color( 100, 255, 100 ) ) );
board << it->first;
}
board.saveEPS ( "cubicalComplexes.eps" );
return 0;
}
// //
DGtal::GaussDigitizer< Space, MyEuclideanShape >
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
CellMapConstIterator
CC::CellMapConstIterator CellMapConstIterator
Definition: testCubicalComplex.cpp:59
DGtal::CubicalComplex::begin
ConstIterator begin() const
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::HyperRectDomain::className
std::string className() const
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:137
DGtal::CubicalComplex::CellMapConstIterator
CellMap::const_iterator CellMapConstIterator
Const iterator for visiting type CellMap.
Definition: CubicalComplex.h:252
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
Map
std::unordered_map< Cell, CubicalCellData > Map
Definition: testCubicalComplex.cpp:57
DGtal::CubicalComplex::construct
void construct(const TDigitalSet &set)
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal::CustomFillColor
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:342
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
CC
CubicalComplex< KSpace, Map > CC
Definition: testCubicalComplex.cpp:58
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
DGtal::Shapes
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Definition: DGtal/shapes/Shapes.h:71
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
DGtal::CubicalComplex::end
ConstIterator end() const
DGtal::CubicalComplex
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
Definition: CubicalComplex.h:84
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64