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

Add ability to cache mls results #1952

Merged
merged 4 commits into from
Aug 9, 2017

Conversation

Levi-Armstrong
Copy link
Contributor

No description provided.

@SergioRAgostinho SergioRAgostinho added this to the pcl-1.9.0 milestone Jul 28, 2017
@SergioRAgostinho SergioRAgostinho added the needs: code review Specify why not closed/merged yet label Jul 28, 2017
Copy link
Member

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

@@ -106,6 +128,7 @@ namespace pcl
upsampling_radius_ (0.0),
upsampling_step_ (0.0),
desired_num_points_in_radius_ (0),
cache_mls_results_(false),
Copy link
Member

Choose a reason for hiding this comment

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

Missing space

* /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;}
Copy link
Member

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.

* /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_;}
Copy link
Member

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 taketwo added needs: author reply Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels Jul 29, 2017
@Levi-Armstrong
Copy link
Contributor Author

@taketwo I made the requested changes.

@taketwo taketwo added status: ready to merge and removed needs: author reply Specify why not closed/merged yet labels Jul 30, 2017
@Levi-Armstrong
Copy link
Contributor Author

Levi-Armstrong commented Aug 1, 2017

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 pcl::MoveingLeastSquares<pcl::PointXYZ, pcl::PointNormal>::MLSResults. Should this MLSResults structure be moved outside the class or some other location?

@taketwo
Copy link
Member

taketwo commented Aug 1, 2017

MLSResults per se is point type agnostic, so I agree it makes sense to shift it out of the class. I'd keep the declaration it in the same header since it's tightly coupled.

@Levi-Armstrong
Copy link
Contributor Author

@taketwo, Thank you I pushed a new commit moving it outside the class.

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.

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 or DISTINCT_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.

@@ -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_;
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

*/
struct MLSResult
{
MLSResult () : mean (), plane_normal (), u_axis (), v_axis (), c_vec (), num_neighbors (), curvature (), valid (false) {}
Copy link
Member

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?

Copy link
Contributor Author

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.

Eigen::VectorXd c_vec;
int num_neighbors;
float curvature;
bool valid;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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;
Copy link
Member

@SergioRAgostinho SergioRAgostinho Aug 2, 2017

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.

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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.

bool valid;
};
/** \brief True if the mls results for the input cloud should be stored */
bool cache_mls_results_;
Copy link
Member

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.

Copy link
Contributor Author

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.

* \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; }
Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -106,6 +128,7 @@ namespace pcl
upsampling_radius_ (0.0),
upsampling_step_ (0.0),
desired_num_points_in_radius_ (0),
cache_mls_results_ (false),
Copy link
Member

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?

@Levi-Armstrong
Copy link
Contributor Author

Levi-Armstrong commented Aug 4, 2017

What was the original objective of this PR?

The objective is what you observed.

  • Allows the user to specify caching, regardless of the upsampling method.

This was needed for the implementation of the Advancing Front Meshing.

  • Forces caching, regardless of user option if the method is VOXEL_GRID_DILATION or DISTINCT_CLOUD

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.

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.

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.

@SergioRAgostinho
Copy link
Member

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 ?

@Levi-Armstrong
Copy link
Contributor Author

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.

@Levi-Armstrong
Copy link
Contributor Author

Also I noticed that several of the getter methods are not const. Are you OK if I make them const?

@SergioRAgostinho
Copy link
Member

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.

@Levi-Armstrong
Copy link
Contributor Author

I have made the requested changes and set the default to cache the mls results.

@taketwo
Copy link
Member

taketwo commented Aug 4, 2017

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?

@Levi-Armstrong
Copy link
Contributor Author

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.

I will add a note explaining when setting it to false may be necessary.

@SergioRAgostinho
Copy link
Member

Side note: Sergio, should we maybe have a separate section in our next changelog which lists breaking changes and changes of behavior?

I can see the importance yes... How about we format it differently using italic (change of behavior) and bold (breaking changes).

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 for the effort guys.

/** \brief Data structure used to store the results of the MLS fitting */
struct MLSResult
{
MLSResult () : num_neighbors (), curvature (), valid (false) {}
Copy link
Member

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) {}

Copy link
Contributor Author

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.

@Levi-Armstrong
Copy link
Contributor Author

@SergioRAgostinho I added the note about when not caching mls result would be useful and added update the initialized members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: API break Meta-information for changelog generation module: surface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants