Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
IP
elsa
Commits
96386b1b
Commit
96386b1b
authored
Apr 30, 2020
by
David Frank
Committed by
Tobias Lasser
Apr 30, 2020
Browse files
#41
Add benchmark for intersection
parent
2eef2f45
Pipeline
#243728
passed with stages
in 57 minutes and 29 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
benchmarks/CMakeLists.txt
View file @
96386b1b
...
...
@@ -22,6 +22,7 @@ endmacro(ELSA_BENCHMARK)
ELSA_BENCHMARK
(
RayGenerationBench
)
ELSA_BENCHMARK
(
Projectors
)
ELSA_BENCHMARK
(
Intersection
)
# Add a single executable for all benchmarks, as CTest removes a lot of the output
add_executable
(
bench_all EXCLUDE_FROM_ALL bench_main.cpp
${
BENCHMARK_SOURCES
}
)
...
...
@@ -38,4 +39,4 @@ add_custom_target(benchmarks
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
USES_TERMINAL
COMMENT
"Run benchmarks"
)
add_dependencies
(
benchmarks bench_all
)
\ No newline at end of file
add_dependencies
(
benchmarks bench_all
)
benchmarks/bench_Intersection.cpp
0 → 100644
View file @
96386b1b
/**
* \file test_RayGenerationBench.cpp
*
* \brief Benchmarks for projectors
*
* \author David Frank
*/
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch.hpp>
#include "Logger.h"
#include "Intersection.h"
#include <iostream>
using
namespace
elsa
;
using
Ray
=
Eigen
::
ParametrizedLine
<
real_t
,
Eigen
::
Dynamic
>
;
static
constexpr
index_t
NUM_RAYS
=
100
;
TEST_CASE
(
"Benchmarking 2D Ray-AABB intersections"
)
{
// Turn logger off
Logger
::
setLevel
(
Logger
::
LogLevel
::
OFF
);
index_t
dim
=
2
;
IndexVector_t
voxel
(
dim
);
voxel
<<
10
,
10
;
BoundingBox
aabb
(
voxel
);
std
::
vector
<
Ray
>
rays
;
rays
.
reserve
(
NUM_RAYS
);
// intersection from below
RealVector_t
ro
(
dim
);
ro
<<
5
,
-
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from below"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
// intersection from above
ro
<<
5
,
15
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from above"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
// intersection from the left
ro
<<
-
5
,
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from the left"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
// intersection from the right
ro
<<
15
,
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from the right"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
}
TEST_CASE
(
"Benchmarking 3D intersections"
)
{
// Turn logger off
Logger
::
setLevel
(
Logger
::
LogLevel
::
OFF
);
index_t
dim
=
3
;
IndexVector_t
voxel
(
dim
);
voxel
<<
10
,
10
,
10
;
BoundingBox
aabb
(
voxel
);
std
::
vector
<
Ray
>
rays
;
rays
.
reserve
(
NUM_RAYS
);
RealVector_t
ro
(
dim
);
ro
<<
5
,
5
,
-
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from front"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
ro
<<
5
,
5
,
15
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from behind"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
ro
<<
5
,
-
5
,
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from below"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
ro
<<
5
,
15
,
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from above"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
ro
<<
-
5
,
5
,
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from the left"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
rays
.
clear
();
ro
<<
15
,
5
,
5
;
for
(
int
i
=
0
;
i
<
NUM_RAYS
;
++
i
)
{
auto
rd
=
RealVector_t
::
Random
(
dim
).
normalized
();
rays
.
emplace_back
(
ro
,
rd
);
}
BENCHMARK
(
"Intersection from the right"
)
{
IntersectionResult
result
;
for
(
auto
&
r
:
rays
)
{
auto
opt
=
Intersection
::
withRay
(
aabb
,
r
);
if
(
opt
)
result
=
*
opt
;
}
return
result
;
};
}
benchmarks/bench_Projectors.cpp
View file @
96386b1b
...
...
@@ -138,4 +138,4 @@ TEST_CASE("Testing Joseph's projector in 3D")
GIVEN
(
"A 16x16x16 Problem:"
)
{
runProjector3D
<
Joseph
>
(
16
);
}
GIVEN
(
"A 32x32x32 Problem:"
)
{
runProjector3D
<
Joseph
>
(
32
);
}
}
\ No newline at end of file
}
elsa/projectors/Intersection.h
View file @
96386b1b
...
...
@@ -19,8 +19,8 @@ namespace elsa
/// default constructor
IntersectionResult
()
:
_tmin
{
std
::
numeric_limits
<
real_t
>
().
infinity
()},
_tmax
{
std
::
numeric_limits
<
real_t
>
().
infinity
()}
:
_tmin
{
std
::
numeric_limits
<
real_t
>
::
infinity
()},
_tmax
{
std
::
numeric_limits
<
real_t
>
::
infinity
()}
{
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment