Skip to content
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

Merged
merged 7 commits into from
Sep 21, 2018

Conversation

pherbers
Copy link
Contributor

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.

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.
@SergioRAgostinho SergioRAgostinho added needs: code review Specify why not closed/merged yet module: io labels Sep 19, 2018
@@ -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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3d34bad.

@SergioRAgostinho
Copy link
Member

Forgot to add

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.

Can you provide some time metrics on those improvements?

@taketwo
Copy link
Member

taketwo commented Sep 19, 2018

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 ComplexPCDFileAscii here. Just create a small OBJ file in the test body and check that we can read it.

@pherbers
Copy link
Contributor Author

Can you provide some time metrics on those improvements?

With a 13.8 MB obj file on Win10 x64 I measured these speeds:

Release: from 2.7s to 2.03s (33% speedup)
Debug: from 126.18s to 61.91 (104% speedup)

This was especially annoying when debugging my code, so I just tried to speed it up a bit :)

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 ComplexPCDFileAscii here. Just create a small OBJ file in the test body and check that we can read it.

I'll see what I can do.

@pherbers
Copy link
Contributor Author

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!

io/src/obj_io.cpp Outdated Show resolved Hide resolved
io/src/obj_io.cpp Outdated Show resolved Hide resolved
Copy link
Member

@SergioRAgostinho SergioRAgostinho left a 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.

test/io/test_io.cpp Show resolved Hide resolved
pcl::PCLPointCloud2 blob;
pcl::OBJReader objreader = pcl::OBJReader();
int res = objreader.read ("test_obj.obj", blob);
EXPECT_NE (int (res), -1);
Copy link
Member

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.

@SergioRAgostinho SergioRAgostinho added needs: author reply Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels Sep 20, 2018
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.
@taketwo taketwo merged commit ceec989 into PointCloudLibrary:master Sep 21, 2018
@taketwo taketwo removed the needs: author reply Specify why not closed/merged yet label Sep 21, 2018
@SergioRAgostinho SergioRAgostinho changed the title Improved obj file parsing efficiency and stability Improved obj file parsing efficiency. Make parsing robust against situations where there are more normals than points. Added unit tests. Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants