DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
NeighborhoodTablesGenerators.h
1
16
30
31
#if defined(NeighborhoodConfigurationsGenerators_RECURSES)
32
#error Recursive header files inclusion detected in NeighborhoodConfigurationsGenerators.h
33
#else
// defined(NeighborhoodConfigurationsGenerators_RECURSES)
35
#define NeighborhoodConfigurationsGenerators_RECURSES
36
37
#if !defined NeighborhoodConfigurationsGenerators_h
39
#define NeighborhoodConfigurationsGenerators_h
41
// Inclusions
42
#include <iostream>
43
#include <bitset>
44
#include <memory>
45
#include "DGtal/topology/Object.h"
46
#include "DGtal/helpers/StdDefs.h"
47
#include <unordered_map>
48
#include "boost/dynamic_bitset.hpp"
49
#include <DGtal/topology/helpers/NeighborhoodConfigurationsHelper.h>
50
#include "DGtal/topology/VoxelComplexFunctions.h"
51
52
namespace
DGtal
{
53
namespace
functions
{
54
69
template
<
typename
TObject,
typename
TMap>
70
void
71
generateSimplicityTable
(
72
const
typename
TObject::DigitalTopology &
dt
,
73
TMap & map )
74
{
75
typedef
typename
TObject::DigitalSet
DigitalSet
;
76
typedef
typename
TObject::Point
Point
;
77
typedef
typename
DigitalSet::Domain
Domain
;
78
typedef
typename
Domain::ConstIterator
DomainConstIterator;
79
80
Point
p1 = Point::diagonal( -1 );
81
Point
p2 = Point::diagonal( 1 );
82
Point
c = Point::diagonal( 0 );
83
Domain
domain
( p1, p2 );
84
DigitalSet
shapeSet(
domain
);
85
TObject shape(
dt
, shapeSet );
86
unsigned
int
k = 0;
87
for
( DomainConstIterator it =
domain
.begin(); it !=
domain
.end(); ++it )
88
if
( *it != c ) ++k;
89
ASSERT( ( k < 32 )
90
&&
"[generateSimplicityTable] number of configurations is too high."
);
91
unsigned
int
nbCfg = 1 << k;
92
for
(
NeighborhoodConfiguration
cfg = 0; cfg < nbCfg; ++cfg )
93
{
94
if
( ( cfg % 1000 ) == 0 )
95
{
96
trace
.
progressBar
( (
double
) cfg, (
double
) nbCfg );
97
}
98
shape.pointSet().clear();
99
shape.pointSet().insert( c );
100
NeighborhoodConfiguration
mask = 1;
101
for
( DomainConstIterator it =
domain
.begin(); it !=
domain
.end(); ++it )
102
{
103
if
( *it != c )
104
{
105
if
( cfg & mask ) shape.pointSet().insert( *it );
106
mask <<= 1;
107
}
108
}
109
bool
simple = shape.isSimple( c );
110
map[ cfg ] = simple;
111
}
112
}
113
130
template
<
typename
TVoxelComplex,
typename
TMap>
131
void
132
generateVoxelComplexTable
(
133
TMap & map,
134
std::function<
bool
(
135
const
TVoxelComplex & ,
136
const
typename
TVoxelComplex::Cell & )
137
> skelFunction
138
)
139
{
140
using
Domain
=
DGtal::Z3i::Domain
;
141
using
Point
=
typename
Domain::Point
;
142
using
DigitalSet
=
DigitalSetByAssociativeContainer
<
143
Domain
, std::unordered_set< Point > >;
144
using
DomainConstIterator =
typename
Domain::ConstIterator
;
145
using
KSpace
=
typename
TVoxelComplex::KSpace;
146
147
Point
p1 = Point::diagonal( -1 );
148
Point
p2 = Point::diagonal( 1 );
149
Point
c = Point::diagonal( 0 );
150
Domain
domain
( p1, p2 );
151
DigitalSet
shapeSet(
domain
);
152
unsigned
int
k = 0;
153
for
( DomainConstIterator it =
domain
.begin(); it !=
domain
.end(); ++it )
154
if
( *it != c ) ++k;
155
ASSERT( ( k < 32 )
156
&&
"[generateVoxelComplexTable] number of configurations is too high."
);
157
unsigned
int
nbCfg = 1 << k;
158
159
KSpace
ks;
160
// Pad KSpace domain.
161
ks.
init
(
domain
.lowerBound() + Point::diagonal( -1 ) ,
162
domain
.upperBound() + Point::diagonal( 1 ),
163
true
);
164
TVoxelComplex vc(ks);
165
vc.construct(shapeSet);
166
for
(
unsigned
int
cfg = 0; cfg < nbCfg; ++cfg ){
167
if
( ( cfg % 1000 ) == 0 )
168
trace
.
progressBar
( (
double
) cfg, (
double
) nbCfg );
169
vc.clear();
170
vc.insertVoxelPoint(c);
171
unsigned
int
mask = 1;
172
for
( DomainConstIterator it =
domain
.begin(); it !=
domain
.end(); ++it ){
173
if
( *it != c ) {
174
if
( cfg & mask ) vc.insertVoxelPoint( *it );
175
mask <<= 1;
176
}
177
}
178
const
auto
&kcell = vc.space().uSpel(c);
179
bool
predicate_output = skelFunction(vc, kcell);
180
map[ cfg ] = predicate_output;
181
}
182
}
183
}
// namespace functions
184
}
// namespace DGtal
186
187
#endif
// !defined NeighborhoodConfigurationsGenerators_h
188
189
#undef NeighborhoodConfigurationsGenerators_RECURSES
190
#endif
// else defined(NeighborhoodConfigurationsGenerators_RECURSES)
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition
DigitalSetByAssociativeContainer.h:90
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::HyperRectDomain< Space >::Point
Space::Point Point
Definition
HyperRectDomain.h:113
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::Point
DGtal::Trace::progressBar
void progressBar(const double currentValue, const double maximalValue)
DGtal::Domain
dt
float dt
Definition
dgtalCalculus-geodesic.cpp:63
DGtal::Z3i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:172
DGtal::functions
functions namespace gathers all DGtal functionsxs.
Definition
ConstExpressions.h:50
DGtal::functions::generateVoxelComplexTable
void generateVoxelComplexTable(TMap &map, std::function< bool(const TVoxelComplex &, const typename TVoxelComplex::Cell &) > skelFunction)
Definition
NeighborhoodTablesGenerators.h:132
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
DGtal::NeighborhoodConfiguration
uint32_t NeighborhoodConfiguration
Definition
NeighborhoodConfigurationsHelper.h:43
KSpace
Z3i::KSpace KSpace
Definition
testArithmeticalDSSComputerOnSurfels.cpp:48
domain
Domain domain
Definition
testProjection.cpp:88
DigitalSet
Z2i::DigitalSet DigitalSet
Definition
testVoronoiMapComplete.cpp:40
src
DGtal
topology
tables
NeighborhoodTablesGenerators.h
Generated on
for DGtal by
1.18.0