Creates precomputed tables for determining whether some point is simple within an 2D object.
#include "DGtal/topology/tables/NeighborhoodTablesGenerators.h"
#include <vector>
#include "DGtal/shapes/Shapes.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
using namespace std;
template <typename Object, typename Map>
void
const typename Object::DigitalTopology & ,
{
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 ( DomainConstIterator it =
domain.begin();
{
if ( *it == c )
board << CustomStyle( q.className(),
new CustomColors( Color( 0, 0, 0 ),
Color( 30, 30, 30 ) ) );
else
{
if ( cfg & mask )
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;
}
}
}
template <typename Map>
void
const string & tableName )
{
typedef typename Map::const_iterator MapConstIterator;
out << "const bool " << tableName << "[ " << map.size() << " ] = { ";
for ( MapConstIterator it = map.begin(), it_end = map.end();
it != it_end; )
{
out << *it;
++it;
if ( it != it_end ) out << ", ";
}
out << " };" << std::endl;
}
{
using namespace Z2i;
functions::generateSimplicityTable< Object4_8 >( dt4_8, table4_8 );
functions::generateSimplicityTable< Object8_4 >( dt8_4, table8_4 );
Board2D board;
displaySimplicityTable< Object4_8 >( board, dt4_8, table4_8 );
board.saveEPS( "table4_8.eps" );
board.clear();
displaySimplicityTable< Object8_4 >( board, dt8_4, table8_4 );
board.saveEPS( "table8_4.eps" );
using ConfigMapBit = std::bitset<256> ;
ConfigMapBit bit_table8_4;
ConfigMapBit bit_table4_8;
functions::generateSimplicityTable< Object8_4 >( dt8_4, bit_table8_4 );
functions::generateSimplicityTable< Object4_8 >( dt4_8, bit_table4_8 );
{
string filename = "simplicity_table8_4.zlib";
ofstream file( filename );
ConfigMapBit* table = &bit_table8_4;
std::stringstream table_stream;
table_stream << *table;
namespace io = boost::iostreams;
io::filtering_streambuf<io::input> filter;
filter.push(io::zlib_compressor());
filter.push(table_stream);
io::copy(filter,file);
file.close();
}
{
string filename = "simplicity_table4_8.zlib";
ofstream file( filename );
ConfigMapBit* table = &bit_table4_8;
std::stringstream table_stream;
table_stream << *table;
namespace io = boost::iostreams;
io::filtering_streambuf<io::input> filter;
filter.push(io::zlib_compressor());
filter.push(table_stream);
io::copy(filter,file);
file.close();
}
return 0;
}
void beginBlock(const std::string &keyword="")
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)
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
std::unordered_map< Cell, CubicalCellData > Map
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet