kzampog / cilantro

A lean C++ library for working with point cloud data
MIT License
1.01k stars 206 forks source link

Questions about using this library #63

Closed fmigneault closed 2 years ago

fmigneault commented 2 years ago

Hi, I would like to attempt using this library for estimating cylinder models with RANDAC. I looked at the sample https://github.com/kzampog/cilantro/blob/master/examples/ransac_plane_estimator.cpp. I was wondering if this was applicable for "cylinders" as well instead of "planes", similar to how Open3D and PCL offer these shapes for fitting the estimated models?

I'm also having problems viewing PLY points. Using the https://github.com/kzampog/cilantro/blob/master/examples/visualizer.cpp, I can only see blank windows as shown below, while the same file loads accordingly in CloudCompare, PCL, etc. Is there something I'm doing incorrectly? I did not have any compilation issue, but I fail to see what could be the problem. Thanks for any guidance.

image

kzampog commented 2 years ago

Hi!

Unfortunately, there is no out of the box cylinder estimator implemented in the library at the moment. If you would like to write one, I would be more than happy to accept a PR :D

About the visualization, it's hard to troubleshoot without having the PLY file at hand. I assume there are no issues with the bundled test cloud examples/test_clouds/test.ply? The visualizer by default has its "camera" located at (0, 0, 0) and looking towards positive z (this can be easily configured). Assuming the PLY file is correctly formed (and in the expected format), could it be the case that the points are not in the camera's field of view (e.g., "behind" the camera/beyond the clipping plane/etc.)? [BTW, please note that this executable is only meant to demo some of the Visualizer class functionality, but can be easily adapted to an actual simple point cloud visualizer app.]

fmigneault commented 2 years ago

Hi. Thanks for the feedback.

I can run the test. It produces the following result: image I'm guessing the code works as intended then?

I have tried spinning the XYZ coordinates in every direction, but can't seem to locate the object. Could it be due to missing RGB colors in my sample contrary to the test cloud? Here is the PLY for testing: C1_S1_G1_S1.zip

That's too bad cylinders are not supported. I see the library offer "representation of generic (general dimension) space regions as unions of convex polytopes". Would this be applicable for my sample to obtain a generic "minimal region" that forms it, even if not a cylinder model? If so, which sample would be the best one to start (convex_hull)? I'm not sure of the results since the window still looks empty with my sample.

kzampog commented 2 years ago

Thanks for sharing the sample data! The issue is that the model is centered very far from the coordinate frame origin (which is the default camera position) and outside of the finite (default) view frustum. [It's located at: (644.434, 826.769, 0.86843).]

You could place the visualizer camera close to that location (e.g. using the setCameraPose() API), or center your model (close) to the origin. If the latter is a viable option, you could do something like:

cloud.points.colwise() -= cloud.points.rowwise().mean();

which would center the model at (0, 0, 0).

About the second part, yes, you can always compute the convex hull of the point set if that works for your purposes. Please also see the convex_hull.cpp example for a (hopefully) helpful usage reference.

fmigneault commented 2 years ago

Nice! Re-centering with the proposed code worked like a charm. It looks like I can work with the convex hull too. Thank a lot.

image

I noticed while including the headers from convex_hull.cpp that I got multiple errors related to TrueFalseToggle (from pangolin). Strangely, it happens when including this way:

#include <cilantro/spatial/convex_polytope.hpp>
#include <cilantro/utilities/point_cloud.hpp>
#include <cilantro/model_estimation/ransac_hyperplane_estimator.hpp>
#include <cilantro/visualization.hpp>

But errors go away when included this way instead:

#include <cilantro/model_estimation/ransac_hyperplane_estimator.hpp>
#include <cilantro/visualization.hpp>
#include <cilantro/spatial/convex_polytope.hpp>
#include <cilantro/utilities/point_cloud.hpp>

Is this normal?

kzampog commented 2 years ago

Unfortunately, yes, you have to reorder the includes so that the convex hull headers (which rely on qhull) go after the visualization headers (that rely on Pangolin). The issue is coming from qhull's preprocessor definitions, see also https://github.com/qhull/qhull/issues/95.

fmigneault commented 2 years ago

Perfect. Thanks for your support.