DGtal 1.3.0
Loading...
Searching...
No Matches
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.endBlock();
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;
typedef CC::CellMapConstIterator CellMapConstIterator;
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" );
trace.endBlock();
trace.endBlock();
return 0;
}
// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
void attach(ConstAlias< EuclideanShape > shape)
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
void beginBlock(const std::string &keyword="")
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:137
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:343
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Z2i::RealPoint RealPoint
int main()
Definition: testBits.cpp:56
KSpace K
std::unordered_map< Cell, CubicalCellData > Map
CubicalComplex< KSpace, Map > CC
CC::CellMapConstIterator CellMapConstIterator
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet