DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
generateSimplicityTables2D.cpp
Go to the documentation of this file.
1
16
31
33
#include "DGtal/topology/tables/NeighborhoodTablesGenerators.h"
34
#include <vector>
35
#include "DGtal/shapes/Shapes.h"
36
#include "DGtal/io/boards/Board2D.h"
37
#include "DGtal/io/Color.h"
38
39
// For saving compressed tables.
40
#include <boost/iostreams/filtering_streambuf.hpp>
41
#include <boost/iostreams/copy.hpp>
42
#include <boost/iostreams/filter/zlib.hpp>
44
45
using namespace
std
;
46
using namespace
DGtal
;
47
49
63
template
<
typename
Object,
typename
Map>
64
void
65
displaySimplicityTable
(
Board2D
& board,
66
const
typename
Object::DigitalTopology
&
/*dt*/
,
67
const
Map
& map )
68
{
69
typedef
typename
Object::DigitalSet
DigitalSet
;
70
typedef
typename
Object::Point
Point
;
71
typedef
typename
DigitalSet::Domain
Domain
;
72
typedef
typename
Domain::ConstIterator
DomainConstIterator;
73
74
Point
p1 = Point::diagonal( -1 );
75
Point
p2 = Point::diagonal( 1 );
76
Point
c = Point::diagonal( 0 );
77
Domain
domain
( p1, p2 );
78
79
Point
q1 = Point::diagonal( -1 );
80
Point
q2 = Point::diagonal( 4*16-1 );
81
Domain
fullDomain( q1, q2 );
82
board <<
SetMode
( fullDomain.className(),
"Paving"
);
83
unsigned
int
cfg = 0;
84
for
(
unsigned
int
y = 0; y < 16; ++y )
85
for
(
unsigned
int
x = 0; x < 16; ++x, ++cfg )
86
{
87
bool
simple = map[ cfg ];
88
Point
base( x*4, y*4 );
89
unsigned
int
mask = 1;
90
for
( DomainConstIterator it =
domain
.begin();
91
it !=
domain
.end(); ++it )
92
{
93
Point
q = base + (*it);
94
if
( *it == c )
95
board <<
CustomStyle
( q.className(),
96
new
CustomColors
(
Color
( 0, 0, 0 ),
97
Color
( 30, 30, 30 ) ) );
98
else
99
{
100
if
( cfg & mask )
101
board <<
102
CustomStyle
( q.className(),
103
simple
104
?
new
CustomColors
(
Color
( 0, 0, 0 ),
105
Color
( 10, 255, 10 ) )
106
:
new
CustomColors
(
Color
( 0, 0, 0 ),
107
Color
( 255, 10, 10 ) ) );
108
else
109
board <<
110
CustomStyle
( q.className(),
111
simple
112
?
new
CustomColors
(
Color
( 0, 0, 0 ),
113
Color
( 245, 255, 245 ) )
114
:
new
CustomColors
(
Color
( 0, 0, 0 ),
115
Color
( 255, 245, 245 ) ) );
116
mask <<= 1;
117
}
118
board << q;
119
}
120
}
121
}
122
126
template
<
typename
Map>
127
void
128
outputTableAsArray
( ostream & out,
129
const
Map
& map,
130
const
string
& tableName )
131
{
132
typedef
typename
Map::const_iterator MapConstIterator;
133
out <<
"const bool "
<< tableName <<
"[ "
<< map.size() <<
" ] = { "
;
134
for
( MapConstIterator it = map.begin(), it_end = map.end();
135
it != it_end; )
136
{
137
out << *it;
138
++it;
139
if
( it != it_end ) out <<
", "
;
140
}
141
out <<
" };"
<< std::endl;
142
}
143
144
145
int
main
(
int
/*argc*/
,
char
**
/*argv*/
)
146
{
147
typedef
std::vector<bool>
ConfigMap
;
148
149
using namespace
Z2i
;
150
trace
.
beginBlock
(
"Generate 2d table for 4-8 topology"
);
151
ConfigMap
table4_8( 256 );
152
functions::generateSimplicityTable< Object4_8 >
( dt4_8, table4_8 );
153
trace
.
endBlock
();
154
155
trace
.
beginBlock
(
"Generate 2d table for 8-4 topology"
);
156
ConfigMap
table8_4( 256 );
157
functions::generateSimplicityTable< Object8_4 >
( dt8_4, table8_4 );
158
trace
.
endBlock
();
159
160
Board2D
board;
161
trace
.
beginBlock
(
"Display 2d table for 4-8 topology"
);
162
displaySimplicityTable< Object4_8 >
( board, dt4_8, table4_8 );
163
board.
saveEPS
(
"table4_8.eps"
);
164
trace
.
endBlock
();
165
166
board.
clear
();
167
trace
.
beginBlock
(
"Display 2d table for 8-4 topology"
);
168
displaySimplicityTable< Object8_4 >
( board, dt8_4, table8_4 );
169
board.
saveEPS
(
"table8_4.eps"
);
170
trace
.
endBlock
();
171
172
outputTableAsArray
( std::cout, table4_8,
"simplicityTable4_8"
);
173
outputTableAsArray
( std::cout, table8_4,
"simplicityTable8_4"
);
174
175
/* Output bitset tables to files,
176
* for using with NeighborhoodConfigurations.h interface.
177
* These tables can be accessed from NeighborhoodTables.h header.
178
*/
179
using
ConfigMapBit = std::bitset<256> ;
// 2^8
180
ConfigMapBit bit_table8_4;
181
ConfigMapBit bit_table4_8;
182
functions::generateSimplicityTable< Object8_4 >
( dt8_4, bit_table8_4 );
183
functions::generateSimplicityTable< Object4_8 >
( dt4_8, bit_table4_8 );
184
// string filename = "simplicity_table8_4.txt";
185
// ofstream file1( filename );
186
// file1 << bit_table8_4;
187
// file1.close();
188
{
189
string
filename =
"simplicity_table8_4.zlib"
;
190
ofstream file( filename );
191
ConfigMapBit* table = &bit_table8_4;
192
std::stringstream table_stream;
193
table_stream << *table;
194
namespace
io = boost::iostreams;
195
io::filtering_streambuf<io::input> filter;
196
filter.push(io::zlib_compressor());
197
filter.push(table_stream);
198
io::copy(filter,file);
199
file.close();
200
}
201
202
// string filename = "simplicity_table4_8.txt";
203
// ofstream file2( filename );
204
// file2 << bit_table4_8;
205
// file2.close();
206
{
207
string
filename =
"simplicity_table4_8.zlib"
;
208
ofstream file( filename );
209
ConfigMapBit* table = &bit_table4_8;
210
std::stringstream table_stream;
211
table_stream << *table;
212
namespace
io = boost::iostreams;
213
io::filtering_streambuf<io::input> filter;
214
filter.push(io::zlib_compressor());
215
filter.push(table_stream);
216
io::copy(filter,file);
217
file.close();
218
}
219
220
return
0;
221
}
222
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Color::Color
Color()
Definition
Color.h:139
DGtal::DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > >::Domain
Domain Domain
Definition
DigitalSetByAssociativeContainer.h:94
DGtal::HyperRectDomain< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::Object::DigitalSet
TDigitalSet DigitalSet
Definition
Object.h:123
DGtal::Object::Point
DigitalSet::Point Point
Definition
Object.h:141
DGtal::Object::DigitalTopology
TDigitalTopology DigitalTopology
Definition
Object.h:138
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::endBlock
double endBlock()
DGtal::Domain
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition
Board.cpp:151
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
ConfigMap
std::vector< bool > ConfigMap
Definition
fullConvexityLUT2D.cpp:76
displaySimplicityTable
void displaySimplicityTable(Board2D &board, const ConfigMap &map, bool complement, bool with)
Definition
fullConvexityLUT2D.cpp:102
outputTableAsArray
void outputTableAsArray(ostream &out, const string &tableName, const ConfigMap &map)
Definition
fullConvexityLUT2D.cpp:86
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal::functions::generateSimplicityTable
void generateSimplicityTable(const typename TObject::DigitalTopology &dt, TMap &map)
Definition
NeighborhoodTablesGenerators.h:71
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition
Board2D.h:279
DGtal::CustomColors::CustomColors
CustomColors(const Color &penColor, const Color &fillColor)
Definition
Board2D.h:289
DGtal::CustomStyle::CustomStyle
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition
Board2D.h:224
DGtal::SetMode::SetMode
SetMode(std::string classname, std::string mode)
Definition
Board2D.h:254
Map
std::unordered_map< Cell, CubicalCellData > Map
Definition
testCubicalComplex.cpp:57
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
DigitalSet
Z2i::DigitalSet DigitalSet
Definition
testVoronoiMapComplete.cpp:40
examples
topology
generateSimplicityTables2D.cpp
Generated on
for DGtal by
1.18.0