DGtal  1.3.beta
geometry/volumes/fullConvexityLUT2D.cpp

This example creates precomputed tables for determining whether some 3x3 neighborhood of a point is fully convex, collapsible, etc. More precisely it produces the following tables, if the neighbor points are the possible 8 points around the point of interest.

See also
Applications of full digital convexity
#include <vector>
#include <fstream>
#include "DGtal/shapes/Shapes.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/geometry/volumes/DigitalConvexity.h"
#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
#include "DGtal/helpers/Shortcuts.h"
#include "ConfigExamples.h"
// Using standard 2D digital space.
using namespace std;
using namespace DGtal;
using namespace Z2i;
typedef std::vector<bool> ConfigMap;
void
outputTableAsArray( ostream & out,
const string & tableName,
const ConfigMap & map )
{
out << "const bool " << tableName << "[ " << map.size() << " ] = { ";
for ( auto it = map.cbegin(), it_end = map.cend();
it != it_end; )
{
out << (int) *it;
++it;
if ( it != it_end ) out << ", ";
}
out << " };" << std::endl;
}
void
const ConfigMap & map,
bool complement,
bool with )
{
Point p1 = Point::diagonal( -1 );
Point p2 = Point::diagonal( 1 );
Point c = Point::diagonal( 0 );
Domain domain( p1, p2 );
Point q1 = Point::diagonal( -1 );
Point q2 = Point::diagonal( 4*16-1 );
Domain fullDomain( q1, q2 );
board << SetMode( fullDomain.className(), "Paving" );
unsigned int cfg = 0;
for ( unsigned int y = 0; y < 16; ++y )
for ( unsigned int x = 0; x < 16; ++x, ++cfg )
{
bool simple = map[ cfg ];
Point base( x*4, y*4 );
unsigned int mask = 1;
for ( auto it = domain.begin();
it != domain.end(); ++it )
{
Point q = base + (*it);
if ( *it == c ) {
if ( with )
board << CustomStyle( q.className(),
simple
? new CustomColors( Color( 0, 0, 0 ),
Color( 30, 128, 30 ) )
: new CustomColors( Color( 0, 0, 0 ),
Color( 128, 30, 30 ) ) );
else
board << CustomStyle( q.className(),
simple
? new CustomColors( Color( 0, 0, 0 ),
Color( 200, 255, 200 ) )
: new CustomColors( Color( 0, 0, 0 ),
Color( 255, 200, 200 ) ) );
} else {
bool in_cfg = cfg & mask;
bool display = complement ? ( ! in_cfg ) : in_cfg;
if ( display )
board <<
CustomStyle( q.className(),
simple
? new CustomColors( Color( 0, 0, 0 ),
Color( 10, 255, 10 ) )
: new CustomColors( Color( 0, 0, 0 ),
Color( 255, 10, 10 ) ) );
else
board <<
CustomStyle( q.className(),
simple
? new CustomColors( Color( 0, 0, 0 ),
Color( 245, 255, 245 ) )
: new CustomColors( Color( 0, 0, 0 ),
Color( 255, 245, 245 ) ) );
mask <<= 1;
}
board << q;
}
}
}
int main( int argc, char** argv )
{
DConv dconv( Point::diagonal( -5 ), Point::diagonal( 5 ) );
trace.beginBlock ( "Generate 2d tables" );
ConfigMap table_with ( 256, false );
ConfigMap table_without ( 256, false );
ConfigMap table_cwith ( 256, false );
ConfigMap table_cwithout( 256, false );
Point p1 = Point::diagonal( -1 );
Point p2 = Point::diagonal( 1 );
Point c = Point::diagonal( 0 );
Domain domain( p1, p2 );
unsigned int cfg = 0;
K.init( p1, p2, true );
for ( unsigned int y = 0; y < 16; ++y )
for ( unsigned int x = 0; x < 16; ++x )
{
// Building a configuration.
std::vector< Point > Xwith;
std::vector< Point > Xwithout;
Point base( x, y );
unsigned int mask = 1;
for ( auto it = domain.begin(); it != domain.end(); ++it )
{
const Point p = *it;
if ( p != c )
{
image.setValue( p, cfg & mask );
mask <<= 1;
}
}
// Checking full convexity.
LCA.setCenter( c, image );
bool full_with = LCA.isFullyConvex( true );
bool full_without = LCA.isFullyConvex( false );
bool full_cwith = LCA.isComplementaryFullyConvex( true );
bool full_cwithout = LCA.isComplementaryFullyConvex( false );
table_with [ cfg ] = full_with;
table_without [ cfg ] = full_without;
table_cwith [ cfg ] = full_cwith;
table_cwithout[ cfg ] = full_cwithout;
cfg += 1;
}
trace.beginBlock ( "Computing topology-related tables" );
ConfigMap table_regular ( 256, false );
for ( cfg = 0; cfg < 256; cfg++ )
table_regular[ cfg ] = table_with[ cfg ] && table_without[ 255 - cfg ];
ConfigMap table_collapsible( 256, false );
for ( cfg = 0; cfg < 256; cfg++ )
table_collapsible[ cfg ] = table_with[ cfg ] && table_without[ cfg ]
&& ( cfg != 0 );
trace.beginBlock ( "Display 2d tables" );
{
Board2D board;
displaySimplicityTable( board, table_with, false, true );
board.saveEPS( "table-fcvx-with-center.eps" );
}
{
Board2D board;
displaySimplicityTable( board, table_without, false, false );
board.saveEPS( "table-fcvx-without-center.eps" );
}
{
Board2D board;
displaySimplicityTable( board, table_cwith, true, true );
board.saveEPS( "table-complementary-fcvx-with-center.eps" );
}
{
Board2D board;
displaySimplicityTable( board, table_cwithout, true, false );
board.saveEPS( "table-complementary-fcvx-without-center.eps" );
}
{
Board2D board;
displaySimplicityTable( board, table_regular, false, true );
board.saveEPS( "table-fcvx-regular.eps" );
}
{
Board2D board;
displaySimplicityTable( board, table_collapsible, false, true );
board.saveEPS( "table-fcvx-collapsible.eps" );
}
trace.beginBlock ( "Output 2d tables as C arrays" );
ofstream out( "table-fcvx.cpp" );
outputTableAsArray( out, "table-fcvx-with-center",
table_with );
outputTableAsArray( out, "table-fcvx-without-center",
table_without );
outputTableAsArray( out, "table-complementary-fcvx-with-center",
table_cwith );
outputTableAsArray( out, "table-complementary-fcvx-without-center",
table_cwithout );
outputTableAsArray( out, "table-fcvx-regular",
table_regular );
outputTableAsArray( out, "table-fcvx-collapsible",
table_collapsible );
out.close();
return 0;
}
image
Image image(domain)
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
displaySimplicityTable
void displaySimplicityTable(Board2D &board, const ConfigMap &map, bool complement, bool with)
Definition: fullConvexityLUT2D.cpp:102
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
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.
DGtal::trace
Trace trace
Definition: Common.h:154
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
outputTableAsArray
void outputTableAsArray(ostream &out, const string &tableName, const ConfigMap &map)
Definition: fullConvexityLUT2D.cpp:86
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:104
ConfigMap
std::vector< bool > ConfigMap
Definition: fullConvexityLUT2D.cpp:76
DGtal::CustomStyle
Definition: Board2D.h:217
DConv
DigitalConvexity< KSpace > DConv
Definition: fullConvexityCollapsiblePoints2D.cpp:56
SH2
Shortcuts< KSpace > SH2
Definition: fullConvexityCollapsiblePoints2D.cpp:57
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
display
void display(ostream &out, const AContainer &C)
Definition: testLabelledMap.cpp:94
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::NeighborhoodConvexityAnalyzer
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
Definition: NeighborhoodConvexityAnalyzer.h:94
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
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
DGtal::DigitalConvexity< KSpace >
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383
NCA1
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA1
Definition: fullConvexityCollapsiblePoints2D.cpp:58
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64