flexible comparison for conditional_removal filter

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

flexible comparison for conditional_removal filter

Julian Löchner
Hi,

for my current project I needed a very flexible filter based on geometric conditions for the x, y, z components of a point cloud. My solution was a new comparison class (TfQuadraticXYZComparison) for the conditional_removal filter. The idea is that you define a quadratic equation "p'Ap + 2v'p + c [OP] 0" as condition (for example, one of these http://en.wikipedia.org/wiki/Quadric). I added a method for comfortable transformation of the defined equation. Since comparisons for the conditional_removal filter are passed as pointers, one can update the transformation of the equation at any point of time without the need to create a new comparison object or conditional_removal filter.

One can also use TfQuadraticXYZComparison for simpler geometric shapes by defining the quadratic parts (i.e. the matrix A) to be zero (but there are probably faster solutions to solve this kind of problems). By combining different instances of TfQuadraticXYZComparison one can get a lot of shapes. For example, to have a simple cylinder (along the x-axis) of specific length one needs three comparisons combined as AND condition:
1) the cylinder: A = [0 0 0, 0 1 0, 0 0 1]; v = [0, 0, 0]; c = radius²; OP = LT (meaning "<")
2) x-min limit: A = 0; v = [1, 0, 0]; c = x_min; OP = GT
3) x-max ....

I actually do not use TfQuadraticXYZComparison directly in my project but instead derived classes for the shapes I needed to have nicer interfaces.

If there is any interest to add this to the current conditional_removal filter, have a look at the attached files for details. I'm quite new to all this stuff, let me know if you would change something of the interface or if you think it is not implemented properly. In the provided files I also added support for the setIndices() method for the conditional_removal filter.


Cheers,  Julian

filters_new.diff
conditional_removal.h
conditional_removal.hpp
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Radu B. Rusu
Administrator
Julian,

Great contribution! Would you mind writing some unit tests and perhaps an usage example/tutorial? It would be great to
integrate this in the upcoming 1.5 release.

Thanks!

Cheers,
Radu.
--
http://pointclouds.org

On 01/19/2012 07:55 AM, Julian Löchner wrote:

> Hi,
>
> for my current project I needed a very flexible filter based on geometric
> conditions for the x, y, z components of a point cloud. My solution was a
> new comparison class (TfQuadraticXYZComparison) for the conditional_removal
> filter. The idea is that you define a quadratic equation "p'Ap + 2v'p + c
> [OP] 0" as condition (for example, one of these
> http://en.wikipedia.org/wiki/Quadric). I added a method for comfortable
> transformation of the defined equation. Since comparisons for the
> conditional_removal filter are passed as pointers, one can update the
> transformation of the equation at any point of time without the need to
> create a new comparison object or conditional_removal filter.
>
> One can also use TfQuadraticXYZComparison for simpler geometric shapes by
> defining the quadratic parts (i.e. the matrix A) to be zero (but there are
> probably faster solutions to solve this kind of problems). By combining
> different instances of TfQuadraticXYZComparison one can get a lot of shapes.
> For example, to have a simple cylinder (along the x-axis) of specific length
> one needs three comparisons combined as AND condition:
> 1) the cylinder: A = [0 0 0, 0 1 0, 0 0 1]; v = [0, 0, 0]; c = radius²; OP =
> LT (meaning "<")
> 2) x-min limit: A = 0; v = [1, 0, 0]; c = x_min; OP = GT
> 3) x-max ....
>
> I actually do not use TfQuadraticXYZComparison directly in my project but
> instead derived classes for the shapes I needed to have nicer interfaces.
>
> If there is any interest to add this to the current conditional_removal
> filter, have a look at the attached files for details. I'm quite new to all
> this stuff, let me know if you would change something of the interface or if
> you think it is not implemented properly. In the provided files I also added
> support for the setIndices() method for the conditional_removal filter.
>
>
> Cheers,  Julian
>
> http://www.pcl-developers.org/file/n5158054/filters_new.diff
> filters_new.diff
> http://www.pcl-developers.org/file/n5158054/conditional_removal.h
> conditional_removal.h
> http://www.pcl-developers.org/file/n5158054/conditional_removal.hpp
> conditional_removal.hpp
>
> --
> View this message in context: http://www.pcl-developers.org/flexible-comparison-for-conditional-removal-filter-tp5158054p5158054.html
> Sent from the Point Cloud Library (PCL) Developers mailing list archive at Nabble.com.
> _______________________________________________
> PCL-developers mailing list
> [hidden email]
> http://pointclouds.org/mailman/listinfo/pcl-developers
> http://pointclouds.org
_______________________________________________
PCL-developers mailing list
[hidden email]
http://pointclouds.org/mailman/listinfo/pcl-developers
http://pointclouds.org
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Francis
Dear all,

I want to use a cylinder aligned Z-axis to filter the point cloud.
 
I have tried to use this filter several times but still got failed.

Although the compiling process is OK, I can't figure out the possible problem which makes the filtering unsuccessful.

Hope some one could give me a hand.

Best regards,

Francis

P.S. The code is as follows:
===================================================
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/filters/impl/conditional_removal.hpp>
#include "pcl/io/pcd_io.h"

int
 main (int argc, char** argv)
{

  // Read in the cloud data
          pcl::PCDReader reader;
          pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
          reader.read ("AOI.pcd", *cloud);
          pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
       

  // build the condition
         Eigen::Matrix3f A;A(0, 0) = 1;A(0, 1) = 0;A(0, 2) = 0;A(1, 0) = 0;A(1, 1) = 1;A(1, 2) = 0;A(2, 0) = 0;A(2, 1) = 0;A(2, 2) = 0;
     Eigen::Vector3f v;v(0)=0;v(1)=0;v(2)=0;
     float c = -9;//radius^2

        pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond (new pcl::ConditionAnd< pcl::PointXYZ > ());
        range_cond->addComparison(pcl:: TfQuadraticXYZComparison < pcl::PointXYZ >::Ptr (new pcl::TfQuadraticXYZComparison < pcl::PointXYZ >(pcl::ComparisonOps::GT , A, v, c)));

 // build the filter
        pcl::ConditionalRemoval<pcl::PointXYZ>condrem (range_cond);
        pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
    condrem.setInputCloud (cloud);
    condrem.setKeepOrganized(true);
       
       
 // apply filter
    condrem.filter (*cloud_filtered);


        std::cerr << "Cloud before filtering: " << cloud->size() <<std::endl;
        std::cerr << "Cloud after filtering: " << cloud_filtered->size()<< std::endl;
       
        pcl::PCDWriter writer;
        writer.write("AOI_AfterFiltered.pcd",*cloud_filtered,false);

  system("pause");
  return (0);
}
==========================================
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Radu B. Rusu
Administrator
Francis,

Please use the [hidden email] mailing list for questions about API usage. Thank you in advance.

Cheers,
Radu.
--
http://pointclouds.org

On 03/12/2012 12:23 AM, Francis wrote:

> Dear all,
>
> I want to use a cylinder aligned Z-axis to filter the point cloud.
>  
> I have tried to use this filter several times but still got failed.
>
> Although the compiling process is OK, I can't figure out the possible
> problem which makes the filtering unsuccessful.
>
> Hope some one could give me a hand.
>
> Best regards,
>
> Francis
>
> P.S. The code is as follows:
> ===================================================
> #include <iostream>
> #include <pcl/point_types.h>
> #include <pcl/filters/conditional_removal.h>
> #include <pcl/filters/impl/conditional_removal.hpp>
> #include "pcl/io/pcd_io.h"
>
> int
>  main (int argc, char** argv)
> {
>
>   // Read in the cloud data
>  pcl::PCDReader reader;
>  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new
> pcl::PointCloud<pcl::PointXYZ>);
>  reader.read ("AOI.pcd", *cloud);
>  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new
> pcl::PointCloud<pcl::PointXYZ>);
>
>
>   // build the condition
> Eigen::Matrix3f A;A(0, 0) = 1;A(0, 1) = 0;A(0, 2) = 0;A(1, 0) = 0;A(1, 1)
> = 1;A(1, 2) = 0;A(2, 0) = 0;A(2, 1) = 0;A(2, 2) = 0;
>      Eigen::Vector3f v;v(0)=0;v(1)=0;v(2)=0;
>      float c = -9;//radius^2
>
> pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond (new pcl::ConditionAnd<
> pcl::PointXYZ > ());
> range_cond->addComparison(pcl:: TfQuadraticXYZComparison < pcl::PointXYZ
>> ::Ptr (new pcl::TfQuadraticXYZComparison < pcl::PointXYZ
>> (pcl::ComparisonOps::GT , A, v, c)));
>
>  // build the filter
> pcl::ConditionalRemoval<pcl::PointXYZ>condrem (range_cond);
> pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
>     condrem.setInputCloud (cloud);
>     condrem.setKeepOrganized(true);
>
>
>  // apply filter
>     condrem.filter (*cloud_filtered);
>
>
> std::cerr << "Cloud before filtering: " << cloud->size() <<std::endl;
> std::cerr &lt;&lt; &quot;Cloud after filtering: &quot; &lt;&lt;
> cloud_filtered->size()<< std::endl;
>
> pcl::PCDWriter writer;
> writer.write("AOI_AfterFiltered.pcd",*cloud_filtered,false);
>
>   system("pause");
>   return (0);
> }
> ==========================================
>
> --
> View this message in context: http://www.pcl-developers.org/flexible-comparison-for-conditional-removal-filter-tp5158054p5556817.html
> Sent from the Point Cloud Library (PCL) Developers mailing list archive at Nabble.com.
> _______________________________________________
> PCL-developers mailing list
> [hidden email]
> http://pointclouds.org/mailman/listinfo/pcl-developers
> http://pointclouds.org
_______________________________________________
PCL-developers mailing list
[hidden email]
http://pointclouds.org/mailman/listinfo/pcl-developers
http://pointclouds.org
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Julian Löchner
In reply to this post by Radu B. Rusu
finally found time to go on with this. Here are updated versions of the files, including the unit tests. The tests run fine for bunny.pcd. I'm not sure what the other pcd files are. It seems to me like some unit tests of the filters are only written for bunny.pcd.
Could someone please check the files and give feedback? Especially conditional_removal.hpp starting from line 759.

Thanks in advance!


Cheers

Julian

test_filters.cpp
conditional_removal.h
conditional_removal.hpp
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Radu B. Rusu-3
Administrator
Julian,

Can you please send us a unified diff against trunk instead? Thanks.

Cheers,
Radu.

On 03/30/2012 06:30 AM, Julian Löchner wrote:

> finally found time to go on with this. Here are updated versions of the
> files, including the unit tests. The tests run fine for bunny.pcd. I'm not
> sure what the other pcd files are. It seems to me like some unit tests of
> the filters are only written for bunny.pcd.
> Could someone please check the files and give feedback? Especially
> conditional_removal.hpp starting from line 759.
>
> Thanks in advance!
>
>
> Cheers
>
> Julian
>
> http://www.pcl-developers.org/file/n5606674/test_filters.cpp
> test_filters.cpp
> http://www.pcl-developers.org/file/n5606674/conditional_removal.h
> conditional_removal.h
> http://www.pcl-developers.org/file/n5606674/conditional_removal.hpp
> conditional_removal.hpp
>
> --
> View this message in context: http://www.pcl-developers.org/flexible-comparison-for-conditional-removal-filter-tp5158054p5606674.html
> Sent from the Point Cloud Library (PCL) Developers mailing list archive at Nabble.com.
> _______________________________________________
> PCL-developers mailing list
> [hidden email]
> http://pointclouds.org/mailman/listinfo/pcl-developers
> http://pointclouds.org
_______________________________________________
PCL-developers mailing list
[hidden email]
http://pointclouds.org/mailman/listinfo/pcl-developers
http://pointclouds.org
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Julian Löchner
here is the diff file with some minor additional changes (computed using "svn diff").
Adding support for setIndices() was straight forward for the case of keep_organized_==false. I never had the case of keep_organized_==true in my project and it seems to be more complicated in this case.

filters.diff
Reply | Threaded
Open this post in threaded view
|

Re: flexible comparison for conditional_removal filter

Radu B. Rusu-3
Administrator
Julian,

Would you mind creating an issue on http://dev so that this doesn't get lost? Thank you.

Cheers,
Radu.

On 04/11/2012 09:04 AM, Julian Löchner wrote:

> here is the diff file with some minor additional changes (computed using "svn
> diff").
> Adding support for setIndices() was straight forward for the case of
> keep_organized_==false. I never had the case of keep_organized_==true in my
> project and it seems to be more complicated in this case.
>
> http://www.pcl-developers.org/file/n5633311/filters.diff filters.diff
>
> --
> View this message in context: http://www.pcl-developers.org/flexible-comparison-for-conditional-removal-filter-tp5158054p5633311.html
> Sent from the Point Cloud Library (PCL) Developers mailing list archive at Nabble.com.
> _______________________________________________
> PCL-developers mailing list
> [hidden email]
> http://pointclouds.org/mailman/listinfo/pcl-developers
> http://pointclouds.org
_______________________________________________
PCL-developers mailing list
[hidden email]
http://pointclouds.org/mailman/listinfo/pcl-developers
http://pointclouds.org