Commit 96386b1b authored by David Frank's avatar David Frank Committed by Tobias Lasser

#41 Add benchmark for intersection

parent 2eef2f45
Pipeline #243728 passed with stages
in 57 minutes and 29 seconds
......@@ -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)
/**
* \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;
};
}
......@@ -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
}
......@@ -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()}
{
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment