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 Z2i;
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 )
simple
Color( 128, 30, 30 ) ) );
else
simple
Color( 255, 200, 200 ) ) );
} else {
bool in_cfg = cfg & mask;
bool display = complement ? ( ! in_cfg ) : in_cfg;
board <<
simple
Color( 255, 10, 10 ) ) );
else
board <<
simple
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;
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 );
{
board.
saveEPS(
"table-fcvx-with-center.eps" );
}
{
board.
saveEPS(
"table-fcvx-without-center.eps" );
}
{
board.
saveEPS(
"table-complementary-fcvx-with-center.eps" );
}
{
board.
saveEPS(
"table-complementary-fcvx-without-center.eps" );
}
{
board.
saveEPS(
"table-fcvx-regular.eps" );
}
{
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;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
void beginBlock(const std::string &keyword="")
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
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.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
void display(ostream &out, const AContainer &C)
HyperRectDomain< Space > Domain