From d63ae1c6085f02fa64b250b01071a3ec94406504 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 29 Oct 2019 16:27:53 +0100 Subject: [PATCH] Simple openvdb conversion test. --- CMakeLists.txt | 5 +++ sandboxes/openvdb/CMakeLists.txt | 11 +++---- tests/CMakeLists.txt | 3 +- tests/hollowing/CMakeLists.txt | 8 +++++ tests/hollowing/hollowing_tests.cpp | 49 +++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 tests/hollowing/CMakeLists.txt create mode 100644 tests/hollowing/hollowing_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ecae7e3c9..c6ddbb0f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,6 +402,11 @@ if(SLIC3R_STATIC) set(USE_BLOSC TRUE) endif() +find_package(OpenVDB 5.0 COMPONENTS openvdb) +if(OpenVDB_FOUND) + slic3r_remap_configs(IlmBase::Half RelWithDebInfo Release) +endif() + # libslic3r, PrusaSlicer GUI and the PrusaSlicer executable. add_subdirectory(src) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT PrusaSlicer_app_console) diff --git a/sandboxes/openvdb/CMakeLists.txt b/sandboxes/openvdb/CMakeLists.txt index 250c6cc68..c32d6c8d6 100644 --- a/sandboxes/openvdb/CMakeLists.txt +++ b/sandboxes/openvdb/CMakeLists.txt @@ -1,8 +1,7 @@ -add_executable(openvdb_example openvdb_example.cpp) +if(TARGET OpenVDB::openvdb) + add_executable(openvdb_example openvdb_example.cpp) -find_package(OpenVDB 5.0 REQUIRED COMPONENTS openvdb) -slic3r_remap_configs(IlmBase::Half RelWithDebInfo Release) - -target_link_libraries(openvdb_example libslic3r) -target_link_libraries(openvdb_example OpenVDB::openvdb) + target_link_libraries(openvdb_example libslic3r) + target_link_libraries(openvdb_example OpenVDB::openvdb) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3afc1c3e2..2dfe05dad 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,4 +27,5 @@ add_subdirectory(libslic3r) add_subdirectory(timeutils) add_subdirectory(fff_print) add_subdirectory(sla_print) -add_subdirectory(example) +add_subdirectory(hollowing) +#add_subdirectory(example) diff --git a/tests/hollowing/CMakeLists.txt b/tests/hollowing/CMakeLists.txt new file mode 100644 index 000000000..e6f01b0e8 --- /dev/null +++ b/tests/hollowing/CMakeLists.txt @@ -0,0 +1,8 @@ +if(TARGET OpenVDB::openvdb) + add_executable(hollowing_tests hollowing_tests.cpp) + + find_package(GTest REQUIRED) + + target_link_libraries(hollowing_tests libslic3r OpenVDB::openvdb GTest::GTest GTest::Main) + target_compile_definitions(hollowing_tests PRIVATE TEST_DATA_DIR=R"\(${TEST_DATA_DIR}\)") +endif() diff --git a/tests/hollowing/hollowing_tests.cpp b/tests/hollowing/hollowing_tests.cpp new file mode 100644 index 000000000..2ba61a63d --- /dev/null +++ b/tests/hollowing/hollowing_tests.cpp @@ -0,0 +1,49 @@ +#include +#include + +#include +#include +#include +#include "libslic3r/Format/OBJ.hpp" + +#if defined(WIN32) || defined(_WIN32) +#define PATH_SEPARATOR R"(\)" +#else +#define PATH_SEPARATOR R"(/)" +#endif + +class TriangleMeshDataAdapter { +public: + Slic3r::TriangleMesh mesh; + + size_t polygonCount() const { return mesh.its.indices.size(); } + size_t pointCount() const { return mesh.its.vertices.size(); } + size_t vertexCount(size_t) const { return 3; } + + // Return position pos in local grid index space for polygon n and vertex v + void getIndexSpacePoint(size_t n, size_t v, openvdb::Vec3d& pos) const { + auto vidx = size_t(mesh.its.indices[n](Eigen::Index(v))); + Slic3r::Vec3d p = mesh.its.vertices[vidx].cast(); + pos = {double(p.x()), double(p.y()), p.z()}; + } +}; + +static Slic3r::TriangleMesh load_model(const std::string &obj_filename) +{ + Slic3r::TriangleMesh mesh; + auto fpath = TEST_DATA_DIR PATH_SEPARATOR + obj_filename; + Slic3r::load_obj(fpath.c_str(), &mesh); + return mesh; +} + +TEST(Hollowing, LoadObject) { + TriangleMeshDataAdapter mesh{load_model("20mm_cube.obj")}; + auto ptr = openvdb::tools::meshToVolume(mesh, {}); + + ASSERT_TRUE(ptr); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}