DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
benchmarkDigitalSetByOctree.cpp
1
#include "DGtal/helpers/StdDefs.h"
2
#include "DGtal/helpers/Shortcuts.h"
3
#include "DGtal/io/readers/VolReader.h"
4
#include "DGtal/kernel/sets/DigitalSetByOctree.h"
5
6
#include "DGtalCatch.h"
7
8
using namespace
DGtal
;
9
using namespace
std
;
10
11
using
SH3 =
Shortcuts<Z3i::KSpace>
;
12
using
Octree =
DigitalSetByOctree<Z3i::Space>
;
13
using
Image
=
ImageContainerBySTLVector<Z3i::Domain, double>
;
14
15
const
auto
CountingFunction = [](
Z3i::Point
,
const
std::vector<Z3i::Point>& neighborhood) {
16
return
neighborhood.size();
17
};
18
19
// Context for each benchmark
20
struct
BenchInfo
21
{
22
inline
static
std::vector<std::vector<Z3i::Point>>
shapes
;
23
inline
static
std::vector<Z3i::Domain>
domains
;
24
inline
static
std::vector<std::string>
names
;
25
26
BenchInfo
() {
27
if
(
shapes
.size() != 0)
return
;
28
29
const
auto
polys =
SH3::getPolynomialList
();
30
const
double
steps[] = { 1.00, 0.50, 0.25 };
31
const
double
noises[] = { 0.00, 0.10 };
32
33
for
(
const
auto
& poly : polys) {
34
for
(
const
auto
& step : steps) {
35
for
(
const
auto
& noise : noises) {
36
37
auto
params =
SH3::defaultParameters
();
38
params(
"polynomial"
, poly.second )
39
(
"gridstep"
, step)
40
(
"noise"
, noise);
41
42
auto
ishape =
SH3::makeImplicitShape3D
(params);
43
auto
dshape =
SH3::makeDigitizedImplicitShape3D
(ishape, params);
44
auto
nshape =
SH3::makeBinaryImage
(dshape, params);
45
46
const
std::string name = poly.first +
"_"
+ std::to_string(step) +
"_"
+ std::to_string(noise);
47
const
auto
domain
= nshape->
domain
();
48
49
names
.push_back(name);
50
domains
.push_back(nshape->domain());
51
shapes
.push_back({});
52
53
for
(
auto
it =
domain
.begin(); it !=
domain
.end(); ++it) {
54
if
(nshape->operator()(*it) != 0) {
55
shapes
.back().push_back(*it);
56
}
57
}
58
}
59
}
60
}
61
62
std::cout <<
"Shapes: "
<< std::endl;
63
for
(
const
auto
& n :
names
) {
64
std::cout <<
"\t -"
<< n << std::endl;
65
}
66
}
67
};
68
69
TEST_CASE_METHOD(
BenchInfo
,
"Benchmarking DigitalSetByOctree using Catch2"
,
"[catch]"
)
70
{
71
auto
i = GENERATE(range(0, (
int
)names.size()));
72
73
const
auto
& name = names[i];
74
const
auto
&
domain
= domains[i];
75
const
auto
& pts = shapes[i];
76
77
Octree tree(
domain
);
78
for
(
const
auto
& pt : pts) {
79
tree.insert(pt);
80
}
81
82
83
BENCHMARK
(
"Octree insert: "
+ name)
84
{
85
Octree subtree(
domain
);
86
for
(
const
auto
& pt : pts) {
87
subtree.insert(pt);
88
}
89
};
90
91
BENCHMARK_ADVANCED(
"Octree To DAG: "
+ name)(Catch::Benchmark::Chronometer meter)
92
{
93
Octree subtree = tree;
94
// Only measure conversion, not copy
95
meter.measure([&] {
96
subtree.
convertToDAG
();
97
});
98
};
99
100
BENCHMARK
(
"Iterating octree: "
+ name)
101
{
102
size_t
count = 0;
103
for
(
auto
it = tree.begin(); it != tree.end(); ++it) {
104
count++;
105
}
106
return
count;
107
};
108
109
size_t
oldMemory = tree.memoryFootprint();
110
tree.convertToDAG();
111
size_t
count = 0;
for
(
auto
it = tree.begin(); it != tree.end(); ++it) count++;
112
113
std::cout <<
"\n\n Stats:\n"
<< std::endl;
114
std::cout <<
"\t Domain: "
<< tree.domain() << std::endl;
115
std::cout <<
"\t Memory footprint (octree): "
<< oldMemory <<
" bytes."
<< std::endl;
116
std::cout <<
"\t Memory footprint (dag) : "
<< tree.memoryFootprint() <<
" bytes."
<< std::endl;
117
std::cout <<
"\t Voxel count (source): "
<< pts.size() << std::endl;
118
std::cout <<
"\t Voxel count (dag) : "
<< count << std::endl;
119
std::cout << std::endl;
120
121
BENCHMARK
(
"Counting number of voxel: "
+ name)
122
{
123
tree.computeFunction(tree.begin(), tree.end(), 1, CountingFunction);
124
};
125
};
DGtal::DigitalSetByOctree
A DigitalSet that stores voxels as an octree, or a DAG.
Definition
DigitalSetByOctree.h:70
DGtal::DigitalSetByOctree::convertToDAG
void convertToDAG()
Converts the octree to DAG.
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition
Shortcuts.h:102
DGtal::Shortcuts< Z3i::KSpace >::getPolynomialList
static std::map< std::string, std::string > getPolynomialList()
Definition
Shortcuts.h:233
DGtal::Shortcuts< Z3i::KSpace >::makeDigitizedImplicitShape3D
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition
Shortcuts.h:520
DGtal::Shortcuts< Z3i::KSpace >::defaultParameters
static Parameters defaultParameters()
Definition
Shortcuts.h:200
DGtal::Shortcuts< Z3i::KSpace >::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition
Shortcuts.h:558
DGtal::Shortcuts< Z3i::KSpace >::makeImplicitShape3D
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters ¶ms=parametersImplicitShape3D())
Definition
Shortcuts.h:279
DGtal::VoronoiMap::domain
const Domain & domain() const
Definition
VoronoiMap.h:265
DGtal::Z3i::Point
Space::Point Point
Definition
StdDefs.h:168
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
std
STL namespace.
BenchInfo
Definition
benchmarkDigitalSetByOctree.cpp:21
BenchInfo::shapes
static std::vector< std::vector< Z3i::Point > > shapes
Definition
benchmarkDigitalSetByOctree.cpp:22
BenchInfo::BenchInfo
BenchInfo()
Definition
benchmarkDigitalSetByOctree.cpp:26
BenchInfo::domains
static std::vector< Z3i::Domain > domains
Definition
benchmarkDigitalSetByOctree.cpp:23
BenchInfo::names
static std::vector< std::string > names
Definition
benchmarkDigitalSetByOctree.cpp:24
BENCHMARK
BENCHMARK(BM_StringCreation)
domain
Domain domain
Definition
testProjection.cpp:88
tests
benchmarks
kernel
benchmarkDigitalSetByOctree.cpp
Generated on
for DGtal by
1.18.0