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.
#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 namespace std;
using namespace Z2i;
typedef Shortcuts<KSpace>
SH2;
typedef NeighborhoodConvexityAnalyzer<KSpace,1>
NCA1;
void
const string & tableName,
{
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
bool complement,
bool with )
{
Point p1 = Point::diagonal( -1 );
Point p2 = Point::diagonal( 1 );
Point c = Point::diagonal( 0 );
Point q1 = Point::diagonal( -1 );
Point q2 = Point::diagonal( 4*16-1 );
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 ];
unsigned int mask = 1;
for (
auto it =
domain.begin();
{
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;
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 ) );
Point p1 = Point::diagonal( -1 );
Point p2 = Point::diagonal( 1 );
Point c = Point::diagonal( 0 );
unsigned int cfg = 0;
NeighborhoodConvexityAnalyzer< KSpace, 1 > LCA(
K );
ImageContainerBySTLVector< Domain, bool >
image(
domain );
for ( unsigned int y = 0; y < 16; ++y )
for ( unsigned int x = 0; x < 16; ++x )
{
std::vector< Point > Xwith;
std::vector< Point > Xwithout;
unsigned int mask = 1;
{
if ( p != c )
{
image.setValue( p, cfg & mask );
mask <<= 1;
}
}
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;
}
for ( cfg = 0; cfg < 256; cfg++ )
table_regular[ cfg ] = table_with[ cfg ] && table_without[ 255 - cfg ];
for ( cfg = 0; cfg < 256; cfg++ )
table_collapsible[ cfg ] = table_with[ cfg ] && table_without[ cfg ]
&& ( cfg != 0 );
{
Board2D board;
board.saveEPS( "table-fcvx-with-center.eps" );
}
{
Board2D board;
board.saveEPS( "table-fcvx-without-center.eps" );
}
{
Board2D board;
board.saveEPS( "table-complementary-fcvx-with-center.eps" );
}
{
Board2D board;
board.saveEPS( "table-complementary-fcvx-without-center.eps" );
}
{
Board2D board;
board.saveEPS( "table-fcvx-regular.eps" );
}
{
Board2D board;
board.saveEPS( "table-fcvx-collapsible.eps" );
}
ofstream out( "table-fcvx.cpp" );
table_with );
table_without );
table_cwith );
table_cwithout );
table_regular );
table_collapsible );
out.close();
return 0;
}
void beginBlock(const std::string &keyword="")
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA1
DigitalConvexity< KSpace > DConv
std::vector< bool > ConfigMap
void displaySimplicityTable(Board2D &board, const ConfigMap &map, bool complement, bool with)
void outputTableAsArray(ostream &out, const string &tableName, const ConfigMap &map)
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
void display(ostream &out, const AContainer &C)
HyperRectDomain< Space > Domain