Skip to content

Commit

Permalink
fixup style and wording in #878
Browse files Browse the repository at this point in the history
  • Loading branch information
wjwwood committed Apr 16, 2015
1 parent c620874 commit b1db0d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion rviz.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"-I${folder:${project_path:rviz.sublime-project}}/src",
"-I/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
"-I/usr/local/include",
"-I/Library/Developer/CommandLineTools/usr/bin/../lib/clang/6.0/include",
"-I/Library/Developer/CommandLineTools/usr/bin/../lib/clang/6.1.0/include",
"-I/Library/Developer/CommandLineTools/usr/include",
"-I/usr/include",
"-Wno-deprecated-register"
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/mesh_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ Ogre::MeshPtr loadMeshFromResource(const std::string& resource_path)
}

ogre_tools::STLLoader loader;
if (!loader.load(res.data.get(),res.size,resource_path))
if (!loader.load(res.data.get(), res.size, resource_path))
{
ROS_ERROR("Failed to load file [%s]", resource_path.c_str());
return Ogre::MeshPtr();
Expand Down
51 changes: 28 additions & 23 deletions src/rviz/ogre_helpers/stl_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool STLLoader::load(const std::string& path)
if ( num_bytes_read != fileSize )
{
ROS_ERROR("STLLoader::load( \"%s\" ) only read %ld bytes out of total %ld.",
path.c_str(), num_bytes_read, fileSize );
path.c_str(), num_bytes_read, fileSize);
fclose( input );
return false;
}
Expand All @@ -92,50 +92,55 @@ bool STLLoader::load(const std::string& path)
bool STLLoader::load(uint8_t* buffer, const size_t num_bytes, const std::string& origin)
{
// check for ascii since we can only load binary types with this class
std::string buffer_str =
std::string(reinterpret_cast<char *>(buffer), num_bytes);
std::string buffer_str = std::string(reinterpret_cast<char *>(buffer), num_bytes);

if (buffer_str.substr(0,5) == std::string("solid"))
if (buffer_str.substr(0, 5) == std::string("solid"))
{
// file says that it is ascii, but why should we trust it?

// check for "endsolid" as well
if (buffer_str.find("endsolid", 5) != std::string::npos)
{
ROS_ERROR_STREAM("Your STL file \"" << origin << "\" is malformed. It "
"starts with the word \"solid\" and also contains the "
"word \"endsolid\", indicating that it's an ASCII STL "
"file, but RVIZ can only load binary STL files so it "
"will not be loaded. Please convert the file to a binary"
" format.");
ROS_ERROR_STREAM("The STL file '" << origin << "' is malformed. It "
"starts with the word 'solid' and also contains the "
"word 'endsolid', indicating that it's an ASCII STL "
"file, but rviz can only load binary STL files so it "
"will not be loaded. Please convert it to a "
"binary STL file.");
return false;
}

// chastise the user for malformed files
ROS_WARN_STREAM("Your STL file \"" << origin << "\" is malformed. It starts"
" with the word \"solid\", indicating that it's an ASCII "
"STL file, but it does not contain the word \"endsolid\" so"
ROS_WARN_STREAM("The STL file '" << origin << "' is malformed. It starts"
" with the word 'solid', indicating that it's an ASCII "
"STL file, but it does not contain the word 'endsolid' so"
"it is either a malformed ASCII STL file or it is actually "
"a binary STL file. Proceeding assuming binary format.");
"a binary STL file. Trying to interpret it as a binary "
"STL file instead.");
}

// make sure there's enough data for a binary STL header and triangle count
if (num_bytes <= 84)
static const size_t binary_stl_header_len = 84;
if (num_bytes <= binary_stl_header_len)
{
ROS_ERROR_STREAM("Your STL file \"" << origin <<"\" is malformed. It "
"appears to be a binary file but does not contain enough "
"data for the 80 byte header and 16-bit integer triangle "
"count.");
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 16-bit integer "
"triangle count.");
return false;
}

// one last check to make sure that the size matches the number of triangles
unsigned int num_triangles = *(reinterpret_cast<uint16_t *>(buffer + 80));
if (num_bytes != 84 + num_triangles * 50)
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)
{
ROS_ERROR_STREAM("Your STL file \"" << origin << "\" is malformed. It "
"appears to be a binary file but does not appear to "
"contain the number of triangles described in the header.");
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") <<
" data for that to be the case.");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ add_dependencies(tests two_render_widgets)
# This is a GTest which tests the STL loader
catkin_add_gtest(stl_loader_test stl_loader_test.cpp
../rviz/ogre_helpers/stl_loader.cpp)
target_link_libraries(stl_loader_test ${catkin_LIBRARIES} OgreMain)
target_link_libraries(stl_loader_test ${catkin_LIBRARIES} ${OGRE_OV_LIBRARIES_ABS})

0 comments on commit b1db0d0

Please sign in to comment.