Skip to content

Commit

Permalink
Use assimp to load stl (#1063)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
  • Loading branch information
ahcorde authored Oct 16, 2023
1 parent 59c1485 commit d02d94f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 303 deletions.
1 change: 0 additions & 1 deletion rviz_rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ add_library(rviz_rendering SHARED
src/rviz_rendering/render_system.cpp
src/rviz_rendering/render_window.cpp
src/rviz_rendering/resource_config.cpp
src/rviz_rendering/mesh_loader_helpers/stl_loader.cpp
src/rviz_rendering/mesh_loader_helpers/assimp_loader.cpp
src/rviz_rendering/string_helper.cpp
src/rviz_rendering/objects/arrow.cpp
Expand Down
15 changes: 0 additions & 15 deletions rviz_rendering/src/rviz_rendering/mesh_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "resource_retriever/retriever.hpp"

#include "mesh_loader_helpers/assimp_loader.hpp"
#include "mesh_loader_helpers/stl_loader.hpp"
#include "rviz_rendering/logging.hpp"

namespace rviz_rendering
Expand Down Expand Up @@ -107,20 +106,6 @@ Ogre::MeshPtr loadMeshFromResource(const std::string & resource_path)
stream->close();

return mesh;
} else if (ext == "stl" || ext == "STL" || ext == "stlb" || ext == "STLB") {
auto res = getResource(resource_path);

if (res.size == 0) {
return Ogre::MeshPtr();
}

STLLoader stl_loader;
if (!stl_loader.load(res.data.get(), res.size, resource_path)) {
RVIZ_RENDERING_LOG_ERROR_STREAM("Failed to load file [" << resource_path.c_str() << "]");
return Ogre::MeshPtr();
}

return stl_loader.toMesh(resource_path);
} else {
AssimpLoader assimp_loader;

Expand Down
211 changes: 0 additions & 211 deletions rviz_rendering/src/rviz_rendering/mesh_loader_helpers/stl_loader.cpp

This file was deleted.

This file was deleted.

Empty file.
19 changes: 12 additions & 7 deletions rviz_rendering_tests/test/mesh_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ TEST_F(MeshLoaderTestFixture, can_load_stl_files) {
float expected_bound_radius = 34.920441f;
size_t expected_vertex_count = 35532;
size_t actual_vertex_count = 0;
// Meshes are divided and stored in submeshes with at most 2004 vertices each.
for (int i = 0; i < 18; ++i) {
for (size_t i = 0; i < mesh->getNumSubMeshes(); ++i) {
actual_vertex_count += mesh->getSubMesh(i)->vertexData->vertexCount;
}
ASSERT_TRUE(mesh->isManuallyLoaded());
Expand Down Expand Up @@ -126,6 +125,13 @@ TEST_F(MeshLoaderTestFixture, loading_invalid_stl_files_fail) {
ASSERT_FALSE(rviz_rendering::loadMeshFromResource(mesh_path));
}

TEST_F(MeshLoaderTestFixture, loading_invalid_ascii_stl_file) {
/// Load an invalid STL binary file (size does not match the expected size).
std::string mesh_path = "package://rviz_rendering_tests/test_meshes/invalid_ascii.stl";

ASSERT_FALSE(rviz_rendering::loadMeshFromResource(mesh_path));
}

TEST_F(MeshLoaderTestFixture, loading_invalid_stl_files_should_fail) {
/// Load an invalid STL binary file (size does not match the expected size,
/// but does if incorrectly read as an 16-bit uint)
Expand All @@ -135,13 +141,12 @@ TEST_F(MeshLoaderTestFixture, loading_invalid_stl_files_should_fail) {
ASSERT_FALSE(rviz_rendering::loadMeshFromResource(mesh_path));
}

TEST_F(MeshLoaderTestFixture, loading_almost_valid_stl_files_should_succed) {
TEST_F(MeshLoaderTestFixture, loading_almost_invalid_stl_files_should_fail) {
/// Load a "potentially" valid STL binary file with bigger size than the
/// expected. The extra "unexpected" data at the end of the file should be
/// ignored.
std::string mesh_path = "package://rviz_rendering_tests/test_meshes/valid_extra.stl";
/// expected. The file will not load.
std::string mesh_path = "package://rviz_rendering_tests/test_meshes/invalid_extra.stl";

ASSERT_TRUE(rviz_rendering::loadMeshFromResource(mesh_path));
EXPECT_FALSE(rviz_rendering::loadMeshFromResource(mesh_path));
}

TEST_F(MeshLoaderTestFixture, loading_stl_mesh_twice_should_not_fail) {
Expand Down

0 comments on commit d02d94f

Please sign in to comment.