mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add BVH module in unsupported (patch from Ilya Baran)
(I thought I committed it a week ago but it seems the command failed)
This commit is contained in:
2
unsupported/doc/CMakeLists.txt
Normal file
2
unsupported/doc/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
add_subdirectory(examples)
|
||||
@@ -626,7 +626,11 @@ EXCLUDE_SYMBOLS = MatrixBase<* MapBase<* RotationBase<* Matrix<*
|
||||
EXAMPLE_PATH = "${Eigen_SOURCE_DIR}/doc/snippets" \
|
||||
"${Eigen_BINARY_DIR}/doc/snippets" \
|
||||
"${Eigen_SOURCE_DIR}/doc/examples" \
|
||||
"${Eigen_BINARY_DIR}/doc/examples"
|
||||
"${Eigen_BINARY_DIR}/doc/examples" \
|
||||
"${Eigen_SOURCE_DIR}/unsupported/doc/snippets" \
|
||||
"${Eigen_BINARY_DIR}/unsupported/doc/snippets" \
|
||||
"${Eigen_SOURCE_DIR}/unsupported/doc/examples" \
|
||||
"${Eigen_BINARY_DIR}/unsupported/doc/examples"
|
||||
|
||||
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
|
||||
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
|
||||
|
||||
45
unsupported/doc/examples/BVH_Example.cpp
Normal file
45
unsupported/doc/examples/BVH_Example.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <unsupported/Eigen/BVH>
|
||||
|
||||
using namespace Eigen;
|
||||
typedef AlignedBox<double, 2> Box2d;
|
||||
|
||||
Box2d ei_bounding_box(const Vector2d &v) { return Box2d(v, v); } //compute the bounding box of a single point
|
||||
|
||||
struct PointPointMinimizer //how to compute squared distances between points and rectangles
|
||||
{
|
||||
PointPointMinimizer() : calls(0) {}
|
||||
typedef double Scalar;
|
||||
|
||||
double minimumOnVolumeVolume(const Box2d &r1, const Box2d &r2) { ++calls; return r1.squaredExteriorDistance(r2); }
|
||||
double minimumOnVolumeObject(const Box2d &r, const Vector2d &v) { ++calls; return r.squaredExteriorDistance(v); }
|
||||
double minimumOnObjectVolume(const Vector2d &v, const Box2d &r) { ++calls; return r.squaredExteriorDistance(v); }
|
||||
double minimumOnObjectObject(const Vector2d &v1, const Vector2d &v2) { ++calls; return (v1 - v2).squaredNorm(); }
|
||||
|
||||
int calls;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<Vector2d> redPoints, bluePoints;
|
||||
for(int i = 0; i < 100; ++i) { //initialize random set of red points and blue points
|
||||
redPoints.push_back(Vector2d::Random());
|
||||
bluePoints.push_back(Vector2d::Random());
|
||||
}
|
||||
|
||||
PointPointMinimizer minimizer;
|
||||
double minDistSq = std::numeric_limits<double>::max();
|
||||
|
||||
//brute force to find closest red-blue pair
|
||||
for(int i = 0; i < (int)redPoints.size(); ++i)
|
||||
for(int j = 0; j < (int)bluePoints.size(); ++j)
|
||||
minDistSq = std::min(minDistSq, minimizer.minimumOnObjectObject(redPoints[i], bluePoints[j]));
|
||||
std::cout << "Brute force distance = " << sqrt(minDistSq) << ", calls = " << minimizer.calls << std::endl;
|
||||
|
||||
//using BVH to find closest red-blue pair
|
||||
minimizer.calls = 0;
|
||||
KdBVH<double, 2, Vector2d> redTree(redPoints.begin(), redPoints.end()), blueTree(bluePoints.begin(), bluePoints.end()); //construct the trees
|
||||
minDistSq = BVMinimize(redTree, blueTree, minimizer); //actual BVH minimization call
|
||||
std::cout << "BVH distance = " << sqrt(minDistSq) << ", calls = " << minimizer.calls << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
unsupported/doc/examples/CMakeLists.txt
Normal file
17
unsupported/doc/examples/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
FILE(GLOB examples_SRCS "*.cpp")
|
||||
|
||||
ADD_CUSTOM_TARGET(unsupported_examples)
|
||||
|
||||
FOREACH(example_src ${examples_SRCS})
|
||||
GET_FILENAME_COMPONENT(example ${example_src} NAME_WE)
|
||||
ADD_EXECUTABLE(${example} ${example_src})
|
||||
GET_TARGET_PROPERTY(example_executable
|
||||
${example} LOCATION)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET ${example}
|
||||
POST_BUILD
|
||||
COMMAND ${example_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(unsupported_examples ${example})
|
||||
ENDFOREACH(example_src)
|
||||
25
unsupported/doc/snippets/CMakeLists.txt
Normal file
25
unsupported/doc/snippets/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
FILE(GLOB snippets_SRCS "*.cpp")
|
||||
|
||||
ADD_CUSTOM_TARGET(unsupported_snippets)
|
||||
|
||||
FOREACH(snippet_src ${snippets_SRCS})
|
||||
GET_FILENAME_COMPONENT(snippet ${snippet_src} NAME_WE)
|
||||
SET(compile_snippet_target compile_${snippet})
|
||||
SET(compile_snippet_src ${compile_snippet_target}.cpp)
|
||||
FILE(READ ${snippet_src} snippet_source_code)
|
||||
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/doc/compile_snippet.cpp.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
|
||||
ADD_EXECUTABLE(${compile_snippet_target}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
|
||||
GET_TARGET_PROPERTY(compile_snippet_executable
|
||||
${compile_snippet_target} LOCATION)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET ${compile_snippet_target}
|
||||
POST_BUILD
|
||||
COMMAND ${compile_snippet_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${snippet}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(unsupported_snippets ${compile_snippet_target})
|
||||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}
|
||||
PROPERTIES OBJECT_DEPENDS ${snippet_src})
|
||||
ENDFOREACH(snippet_src)
|
||||
Reference in New Issue
Block a user