-
-
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
Add ability to cache mls results #1952
Conversation
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.
Looks almost fine, except to the return type, see the inline comments.
surface/include/pcl/surface/mls.h
Outdated
@@ -106,6 +128,7 @@ namespace pcl | |||
upsampling_radius_ (0.0), | |||
upsampling_step_ (0.0), | |||
desired_num_points_in_radius_ (0), | |||
cache_mls_results_(false), |
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.
Missing space
surface/include/pcl/surface/mls.h
Outdated
* /param[in] True if the mls results should be stored, otherwise false. | ||
*/ | ||
inline void | ||
setCacheMLSResults(bool cache_mls_results) {cache_mls_results_ = cache_mls_results;} |
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.
Missing space after function name and inside curly braces.
Also, I don't know how useful this will be, but in PCL we always have accessors for the algorithm configuration parameters. This would be getCacheMLSResults()
in this case.
Edit: actually, this parameter can be modified during the algorithm execution, so I think this indeed will be a useful getter.
surface/include/pcl/surface/mls.h
Outdated
* /note The results are only stored if setCacheMLSResults(true) was called | ||
* or when using the upsampling method DISTINCT_CLOUD or VOXEL_GRID_DILATION. | ||
*/ | ||
inline std::vector<MLSResult> getMLSResults() const {return mls_results_;} |
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.
Why not returning by const ref? Otherwise will be quite a costly function.
Also missing spaces as above.
@taketwo I made the requested changes. |
With these changes I did not need a wrapper class around the MovingLeastSquares class so I started relocating the functions and ran into an issue. If I want to create a function that take the MLSResults structure I have to define it with the template arguments |
|
@taketwo, Thank you I pushed a new commit moving it outside the class. |
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.
I need to better understand what is the intent of this functionality. Currently this is what it does:
- Allows the user to specify caching, regardless of the upsampling method.
- Forces caching, regardless of user option if the method is
VOXEL_GRID_DILATION
orDISTINCT_CLOUD
What was the original objective of this PR? Extend caching to all upsampling methods? Because from what I can tell VOXEL_GRID_DILATION
or DISTINCT_CLOUD
were already caching mls_results_
, although it was not publicly accessible.
surface/include/pcl/surface/mls.h
Outdated
@@ -549,6 +568,7 @@ namespace pcl | |||
using MovingLeastSquares<PointInT, PointOutT>::order_; | |||
using MovingLeastSquares<PointInT, PointOutT>::compute_normals_; | |||
using MovingLeastSquares<PointInT, PointOutT>::upsample_method_; | |||
using MovingLeastSquares<PointInT, PointOutT>::cache_mls_results_; |
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.
Can we move all these which are not public to a non-public scope?
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.
Sure.
surface/include/pcl/surface/mls.h
Outdated
*/ | ||
struct MLSResult | ||
{ | ||
MLSResult () : mean (), plane_normal (), u_axis (), v_axis (), c_vec (), num_neighbors (), curvature (), valid (false) {} |
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.
Can we remove the eigen default initializers which do nothing and explicitly set the value initialized the native types to 0/false?
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.
Sure I will make the change. I just kept the same as it was.
surface/include/pcl/surface/mls.h
Outdated
Eigen::VectorXd c_vec; | ||
int num_neighbors; | ||
float curvature; | ||
bool valid; |
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.
It would be cool to have some doxygen comments on these.
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.
Sure, I will add the documentation.
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 a lot
|
||
break; | ||
} | ||
case (VOXEL_GRID_DILATION): | ||
case (DISTINCT_CLOUD): | ||
{ | ||
mls_results_.resize (input_->size ()); | ||
cache_mls_results_ = true; |
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.
So if the method is VOXEL_GRID_DILATION or DISTINCT_CLOUD, the caching is automatically set to true, despite if the user previously set caching to be false. It this happens we should be throwing a warning.
For everything else, it uses whatever option the user has decided before.
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.
I agree, I will wait until a determination is made if this should always cache because then this function would be removed.
@@ -396,9 +407,6 @@ pcl::MovingLeastSquares<PointInT, PointOutT>::computeMLSPointNormal (int index, | |||
case (VOXEL_GRID_DILATION): | |||
case (DISTINCT_CLOUD): | |||
{ | |||
// Take all point pairs and sample space between them in a grid-fashion | |||
// \note consider only point pairs with increasing indices | |||
mls_result = MLSResult (point, plane_normal, u_axis, v_axis, c_vec, static_cast<int> (nn_indices.size ()), curvature); |
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.
Any reason to leave the empty case blocks here?
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.
I think it was to suppress warning messages. I can remove the two and default instead?
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.
Makes sense. I would go with default.
surface/include/pcl/surface/mls.h
Outdated
@@ -52,6 +52,28 @@ | |||
|
|||
namespace pcl | |||
{ | |||
/** \brief Data structure used to store the results of the MLS fitting | |||
* \note Used only in the case of VOXEL_GRID_DILATION or DISTINCT_CLOUD upsampling |
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.
I don't think this comment is true. VOXEL_GRID_DILATION or DISTINCT_CLOUD set the the caching procedure to true. But the other methods, also use caching as long as the user manually sets it.
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.
I agree. I will remove the note.
surface/include/pcl/surface/mls.h
Outdated
bool valid; | ||
}; | ||
/** \brief True if the mls results for the input cloud should be stored */ | ||
bool cache_mls_results_; |
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.
I think we need a warning here in the comments stating that this will be forced to true if the methods used are VOXEL_GRID_DILATION or DISTINCT_CLOUD.
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.
I agree, I will wait until a determination is made if this should always cache because then this function would be removed.
surface/include/pcl/surface/mls.h
Outdated
* \param[in] True if the mls results should be stored, otherwise false. | ||
*/ | ||
inline void | ||
setCacheMLSResults (bool cache_mls_results) { cache_mls_results_ = cache_mls_results; } |
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.
I think we need a warning here in the comments stating that cache_mls_results_
will be forced to true if the methods used are VOXEL_GRID_DILATION or DISTINCT_CLOUD.
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.
I agree, I will wait until a determination is made if this should always cache because then this function would be removed.
surface/include/pcl/surface/mls.h
Outdated
@@ -106,6 +128,7 @@ namespace pcl | |||
upsampling_radius_ (0.0), | |||
upsampling_step_ (0.0), | |||
desired_num_points_in_radius_ (0), | |||
cache_mls_results_ (false), |
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.
Should we not cache by default?
The objective is what you observed.
This was needed for the implementation of the Advancing Front Meshing.
This is required for these two methods only because they are preformed after the MLS surface was generated but the MLS data is required to perform the upsampling.
That is correct, I just kept it the same as it was before. The only reason I assume they did not cache it for each was for the purpose of memory consumption. I can change it to always cache which would simplify the code. |
I would leave the option to cache/not cache if desired, but enable cache by default on the constructor. That way, if the user has special memory constraints, it still can save some memory. What are your feelings on this @Levi-Armstrong and @taketwo ? |
I am OK with leaving the option to cache. Though if we do set it to true by default this is not the same behavior as the original, but not sure if that would be an issue. |
Also I noticed that several of the getter methods are not const. Are you OK if I make them const? |
Yes. Keep it on a separate commit. |
I have made the requested changes and set the default to cache the mls results. |
I don't have a strong opinion about what should be the default. I think that making caching "opt-out" is fine as long as there is a note in the documentation which sheds some light on why the user might want to disable it. Side note: Sergio, should we maybe have a separate section in our next changelog which lists breaking changes and changes of behavior? |
I will add a note explaining when setting it to false may be necessary. |
I can see the importance yes... How about we format it differently using italic (change of behavior) and bold (breaking changes). |
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 for the effort guys.
surface/include/pcl/surface/mls.h
Outdated
/** \brief Data structure used to store the results of the MLS fitting */ | ||
struct MLSResult | ||
{ | ||
MLSResult () : num_neighbors (), curvature (), valid (false) {} |
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.
My previous comment on this was also to explicitly initialize an curvature as well to make more obvious what's happening
MLSResult () : num_neighbors (0), curvature (0.f), valid (false) {}
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.
OK, I make the change.
2ba1b3a
to
1208060
Compare
1208060
to
90b1b7c
Compare
@SergioRAgostinho I added the note about when not caching mls result would be useful and added update the initialized members. |
No description provided.