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

Model outlier removal contribution #702

Merged
merged 6 commits into from Jun 15, 2014
Merged

Model outlier removal contribution #702

merged 6 commits into from Jun 15, 2014

Conversation

VictorLamoine
Copy link
Contributor

Is it the good way to update @TimoHackel's contribution #254 ?

  • Rebase on current master
  • Licence update
  • Formatting
    • Update with Eclipse formatter
    • Correct weird line breaks
    • Correct member field names format (add _ suffix)
  • single_threshold method:
    • Rename to checkSingleThreshold
    • Improve (reduce) source code
  • Others
    • Use SacModel enum instead of int
    • Fix getThreshhold typo
    • Mark getter functions with const modifier
    • Remove model_from_normals_ class member
    • Remove PCLPointCloud2 specialization
    • Use pcl::isFinite instead of pcl_isfinite
    • Change cloud_normals_ into a ConstPtr
    • Remove getFilterLimitsNegative and setFilterLimitsNegative


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::ModelOutlierRemoval<PointT>::initSACModel (int model_type)
Copy link
Member

Choose a reason for hiding this comment

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

I would rather be specific and use the SacModel enum instead of int here.

@taketwo
Copy link
Member

taketwo commented May 26, 2014

@jspricke Should we remove PCLPointCloud2 specialization?


This tutorial demonstrates how to extract parametric models for example for planes or spheres
out of a PointCloud by using SAC_Models with known coefficients.
If you don't know the models coefficients take a look at the Sample Consensus tutorials.
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to have a link here and in the previous line.

@taketwo
Copy link
Member

taketwo commented May 26, 2014

Hi Victor, thanks for taking care of this abandoned pull request. I think it might be appropriate to deviate a bit from our usual rule of squashing commits and leave the original contribution of Timo as is, adding modifications in separate commit(s) on top of it.

/** \brief returns the models coefficients
*/
pcl::ModelCoefficients
getModelCoefficients ()
Copy link
Member

Choose a reason for hiding this comment

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

We usually mark getter functions with const modifier.

@jspricke
Copy link
Member

@taketwo Regarding PCLPointCloud2, I'm still in favor of deprecating it at some point (or rather have a new, more capable, point type in the future). My point was that this patch contains two identical (didn't check) copies of initSACModel(). I know that we have quite a lot of similar things in the codebase already, so people could be used to having both versions. Still I think it would be better for PCL to not add more of them. But I'm not a user of that part at the moment, so I let it to you to decide.

Regarding cleaning up Timos contribution, I would propose to adopt Something like the kernel guidelines [1] or [2].

[1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches?id=4e8a2372f9255a1464ef488ed925455f53fbdaa1#n286
[2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=375536

@taketwo
Copy link
Member

taketwo commented May 27, 2014

Regarding cleaning up Timos contribution, I would propose to adopt Something like the kernel guidelines [1] or [2].

Do you mean that you would rather see a single commit with an attribution to Victor in the commit message? I think in this case quite a number of changes are being made on top of the original one, and it's easier to digest them as several commits.

But I'm not a user of that part at the moment, so I let it to you to decide.

I'm a PCL user since 2012, but I never had a necessity to use a specialization of any class for PCLPointCloud2. I also dislike code duplication, so +1 for removing it.

@jspricke
Copy link
Member

  • Sergey Alexandrov notifications@github.com [2014-05-27 02:45]:

    Do you mean that you would rather see a single commit with an attribution to Victor in the commit message? I think in this case quite a number of changes are being made on top of the original one, and it's easier to digest them as several commits.

No:
"Note that under no circumstances can you change the author's identity
(the From header), as it is the one which appears in the changelog."

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches?id=4e8a2372f9255a1464ef488ed925455f53fbdaa1#n353

So as I understand it, you add a comment to the commit message stating
what you changed and a Signed-off-by, or Also-By, depending on what you
did.

@VictorLamoine
Copy link
Contributor Author

@TimoHackel do not seem very active on GitHub and never wrote a Signed-off-by, do I sign for him? 😝
The goal is:

  • Not stealing his work
  • Not making him endorse bugs he did not created

I'll will delete PCLPointCloud2 specialization.

@jspricke
Copy link
Member

@VictorLamoine I guess it should be enough to add your Signed-off-by, but I'm not an expert there.

@taketwo
Copy link
Member

taketwo commented May 27, 2014

Still I don't get what are the cons for just leaving the original commit as is (like if it was merged), and then putting the updates on top?

@jspricke
Copy link
Member

@taketwo It's the same as with all other style changes, you are changing the author of the code and it's making the commit history harder to read.

@taketwo
Copy link
Member

taketwo commented May 28, 2014

That is true. On the other hand, in this case Victor stood up to take care of an abandoned code. Even though he is not the original author, he took the responsibility of cleaning up and integrating the contribution in PCL. Therefore, if the fabulous git blame returns his name, it makes perfect sense to me. Furthermore I suspect Timo would be surprised if he is held responsible for the code that he did not care enough to integrate and that was also modified by someone else.

@jspricke
Copy link
Member

True, we are not the kernel community, so I'm ok with doing separate commits.

@VictorLamoine
Copy link
Contributor Author

Ok fine.
I need some help if you want me to change the pointer, see comment #702 (comment)

Otherwise I think the code is now pretty clean and matches the PCL style guide !

@taketwo
Copy link
Member

taketwo commented May 28, 2014

Sorry I overlooked your comment. The syntax is correct, however it would be nicer to use a typedef that is already present within the class: SampleConsensusModelFromNormals<PointT, pcl::Normal>::Ptr.

The errors you get are anticipated. Boost shared pointer is "similar" to a plain pointer, but does not have exactly the same semantics. I would strongly recommend you to get acquainted with this, since smart pointers are an essential tool in modern C++. This short article may get you started.

@TimoHackel
Copy link
Contributor

Hi,
this pointer is a hack to work with multiple inheritence, the object behind this pointer gets deleted by an other shared pointer ... if you want to get rid of plain pointers, you can write an empty delete function for that pointer.

Anyways, it would be nicer to remove that pointer completely and try a type casts instead.

@taketwo
Copy link
Member

taketwo commented May 29, 2014

Why do we need custom delete functions? Won't something like this work?

case SACMODEL_NORMAL_PLANE:
{
  PCL_DEBUG ("[pcl::%s::segment] Using a model of type: modelNORMAL_PLANE\n", getClassName ().c_str ());
  model_from_normals_.reset (new SampleConsensusModelNormalPlane<PointT, pcl::Normal> (input_));
  model_ = model_from_normals_;
  break;
}

@TimoHackel
Copy link
Contributor

I don't think so. There's no inheritance between type of model_ and type of model_from_normals_ (compare: https://github.com/PointCloudLibrary/pcl/blob/master/sample_consensus/include/pcl/sample_consensus/sac_model.h#L557 ). Hence, model_ = model_from_normals_ will fail.

@VictorLamoine
Copy link
Contributor Author

Anyways, it would be nicer to remove that pointer completely and try a type casts instead.

I don't understand how I could remove the model_from_normals_ pointer.

What do we do here ? I'm far from being a C++ expert and you quite lost me here :)

@TimoHackel
Copy link
Contributor

I would remove the member model_from_normals_ by doing the following:
a) initSACModel:

template <typename PointT> bool
pcl::ModelOutlierRemoval<PointT>::initSACModel (pcl::SacModel model_type)
{
 ...
 case SACMODEL_NORMAL_PLANE:
 {
   PCL_DEBUG ("[pcl::%s::segment] Using a model of type: modelNORMAL_PLANE\n", getClassName ().c_str ());
   model_.reset (new SampleConsensusModelNormalPlane<PointT, pcl::Normal> (input_));
   break;
 }
 ...
}

b) applyFilterIndices:

template <typename PointT> void
pcl::ModelOutlierRemoval<PointT>::applyFilterIndices (std::vector<int> &indices)
{
 ...
  valid_setup &= initSACModel (model_type_);
  SampleConsensusModelFromNormals<PointT, pcl::Normal> *model_from_normals = dynamic_cast< SampleConsensusModelFromNormals<PointT, pcl::Normal> * >( &(*model_) ); //returns NULL if cast isn't possible
  if (model_from_normals)
  {
    ...
  }
 ...
}

(not tested and a typedef for SampleConsensusModelFromNormals<PointT, pcl::Normal> would be nice)

@VictorLamoine
Copy link
Contributor Author

Thank you for your help!

It compiles fine by my side with gcc and the test unit is ok.
When this pull request will be merged don't forget to close #254

initSACModel (pcl::SacModel model_type);
};
}

Copy link
Member

Choose a reason for hiding this comment

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

We need a conditional include of the implementation file here for the "no precompilation" option:

#ifdef PCL_NO_PRECOMPILE
#include <pcl/filters/impl/model_outlier_removal.hpp>
#endif

#include <pcl/sample_consensus/sac_model_parallel_line.h>
#include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/sample_consensus/sac_model_sphere.h>
Copy link
Member

Choose a reason for hiding this comment

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

I would move as many of these model includes as possible to the implementation file. The user of this class might want only a single model, no need to pull in all the existing model headers.

@taketwo
Copy link
Member

taketwo commented Jun 7, 2014

The reason why the compilation succeeds on your machine is because you did not enable PCL_ONLY_CORE_POINT_TYPES option in CMake, which is set to ON on Travis. Turn it on and you will get the same linker errors.

When this option is on, consensus models are instantiated only for a subset of XYZ point types. Our new class is instantiated for all XYZ point types unconditionally. Therefore to circumvent the problem we need to instantiate ModelOutlierRemoval only for the same reduced set of point types. This means in 'model_outlier_removal.cpp' we need something like:

#ifdef PCL_ONLY_CORE_POINT_TYPES
  PCL_INSTANTIATE (ModelOutlierRemoval, (pcl::PointXYZ)(pcl::PointXYZI)(pcl::PointXYZRGBA)(pcl::PointXYZRGB))
#else
  PCL_INSTANTIATE (ModelOutlierRemoval, PCL_XYZ_POINT_TYPES)
#endif

@TimoHackel
Copy link
Contributor

Thanks for your work and help. The pull request #254 is now closed.

@VictorLamoine
Copy link
Contributor Author

@taketwo: I think it is good to merge, is it ?

{
PCL_DEBUG ("[pcl::%s::segment] Using a model of type: modelCYLINDER\n", getClassName ().c_str ());
SampleConsensusModelCylinder<PointT, pcl::Normal> *ptr = new SampleConsensusModelCylinder<PointT, pcl::Normal> (input_);
model_.reset (ptr);
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 can merge pointer creation and reset() in a single instruction? And in the subsequent cases as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was there before because of model_from_normals_ but now the ptr pointer is useless.

@taketwo
Copy link
Member

taketwo commented Jun 11, 2014

@VictorLamoine I don't think so :)


/** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max)
* Default: false.
* \warning This method will be removed in the future. Use setNegative() instead.
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why we are introducing a brand new class with to-be-removed functions. We are committing to this interface, let's not pollute it.

@taketwo
Copy link
Member

taketwo commented Jun 15, 2014

Thanks for working on this Victor!

taketwo added a commit that referenced this pull request Jun 15, 2014
Model outlier removal contribution
@taketwo taketwo merged commit 2e20bc8 into PointCloudLibrary:master Jun 15, 2014
@VictorLamoine
Copy link
Contributor Author

Finally 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants