-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved obj file parsing efficiency. Make parsing robust against situations where there are more normals than points. Added unit tests. #2450
Conversation
Reading the header of an obj file (aka counting number of vertices etc.) has been sped up by removing unnecessary string operations. This is especially noticable when reading large obj files.
When importing an obj file with more vertex normals than vertices, the import would crash. This has been fixed by skipping vertex normal indices larger than number of vertices.
io/src/obj_io.cpp
Outdated
@@ -592,6 +592,10 @@ pcl::OBJReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, | |||
// Vertex normal | |||
if (st[0] == "vn") | |||
{ | |||
if (normal_idx >= cloud.width) | |||
{ | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should print a PCL_WARNING
the first time you encounter a normal from a non existing point so that the user knows there are is an unexpected problem, but it's being gracefully handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 3d34bad.
Forgot to add
Can you provide some time metrics on those improvements? |
We don't seem to have any OBJ unit tests at the moment. If you have a bit of extra time, it would be great to add a simple test, maybe something similar to |
With a 13.8 MB obj file on Win10 x64 I measured these speeds:
This was especially annoying when debugging my code, so I just tried to speed it up a bit :)
I'll see what I can do. |
I've added a small test that reads a simple obj and mtl file and checks the size of the data and if the fields are correct. Hope it helps! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Should we not be testing for the situation you also patched? The existence of a larger number of normals vs points.
pcl::PCLPointCloud2 blob; | ||
pcl::OBJReader objreader = pcl::OBJReader(); | ||
int res = objreader.read ("test_obj.obj", blob); | ||
EXPECT_NE (int (res), -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here you want a result which is specifically 0.
Generated files for testing are now removed when the test is done. Also added a line to the obj test that should trigger a warning. Also renamed some tests to avoid name conflicts.
Small improvements in OBJ parsing efficiency and stability.
Reading the header of an obj file (aka counting number of vertices etc.) has been sped up by removing unnecessary string operations.
This is especially noticable when reading large obj files.
Also fixed a crash when reading an obj file with more vertex noramls than vertices.
Vertex noraml indices are now skipped if they are larger than the number of vertices.