From 7c6cbcb8d133181c68e54e7338ae3cf204d08966 Mon Sep 17 00:00:00 2001 From: caguero Date: Wed, 9 Dec 2015 16:36:32 -0800 Subject: [PATCH] Allow STL files bigger than expected (printing a warning message). --- src/rviz/ogre_helpers/stl_loader.cpp | 15 +++++++++++---- src/test/meshes/invalid.stl | Bin 194 -> 175 bytes src/test/meshes/valid_extra.stl | Bin 0 -> 210 bytes src/test/stl_loader_test.cpp | 6 ++++++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/test/meshes/valid_extra.stl diff --git a/src/rviz/ogre_helpers/stl_loader.cpp b/src/rviz/ogre_helpers/stl_loader.cpp index 9af955700a..c85dca72cd 100644 --- a/src/rviz/ogre_helpers/stl_loader.cpp +++ b/src/rviz/ogre_helpers/stl_loader.cpp @@ -123,7 +123,7 @@ bool STLLoader::load(uint8_t* buffer, const size_t num_bytes, const std::string& static const size_t binary_stl_header_len = 84; if (num_bytes <= binary_stl_header_len) { - ROS_ERROR_STREAM("The STL file '" << origin <<"' is malformed. It " + ROS_ERROR_STREAM("The STL file '" << origin << "' is malformed. It " "appears to be a binary STL file but does not contain " "enough data for the 80 byte header and 32-bit integer " "triangle count."); @@ -134,15 +134,22 @@ bool STLLoader::load(uint8_t* buffer, const size_t num_bytes, const std::string& unsigned int num_triangles = *(reinterpret_cast(buffer + 80)); static const size_t number_of_bytes_per_triangle = 50; size_t expected_size = binary_stl_header_len + num_triangles * number_of_bytes_per_triangle; - if (num_bytes != expected_size) + if (num_bytes < expected_size) { ROS_ERROR_STREAM("The STL file '" << origin << "' is malformed. According " "to the binary STL header it should have '" << - num_triangles << "' triangles, but it has too " << - (num_bytes > expected_size ? "much" : "little") << + num_triangles << "' triangles, but it has too little" << " data for that to be the case."); return false; } + else if (num_bytes > expected_size) + { + ROS_WARN_STREAM("The STL file '" << origin << "' is malformed. According " + "to the binary STL header it should have '" << + num_triangles << "' triangles, but it has too much" << + " data for that to be the case. The extra data will be" << + " ignored."); + } // load the binary STL data return this->load_binary(buffer); diff --git a/src/test/meshes/invalid.stl b/src/test/meshes/invalid.stl index 7c5cb1ffe2b82018e4ab54da70d7ba9b342a232a..a3638efc771f8c6c91db23aadcff4b587cbefb6a 100644 GIT binary patch delta 8 PcmX@axSnysIz}!44wM4D delta 27 XcmZ3_c!+VrIuSO9vuAi57*GHJXzB#< diff --git a/src/test/meshes/valid_extra.stl b/src/test/meshes/valid_extra.stl new file mode 100644 index 0000000000000000000000000000000000000000..1f3ce405d0324c3157ab3d9a9e453a6c4c3ac53e GIT binary patch literal 210 zcmZ?D%u6h)R0t07QAo?oNoAlEFaZrXd*+Po*)u+Nvu4h;1G4RaLiV#}O4=J68`}fL z?bFiI>=_sufb1Ti_)IvRmbMJ2W;0Ok08s1qC!eyNuokYzCu!}LS}kieo<