removeconcavehullframe.h 3.02 KB
Newer Older
Sven Schneider's avatar
Sven Schneider committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef REMOVECONCAVEHULLFRAME_H
#define REMOVECONCAVEHULLFRAME_H

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/pca.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/passthrough.h>



template <typename PointInT>
class RemoveConcaveHullFrame: public pcl::PCLBase<PointInT>
{

protected:
    typedef typename pcl::PointCloud<PointInT>::Ptr PointCloudPtr;
    typedef typename pcl::PointCloud<PointInT>::ConstPtr PointCloudConstPtr;


public:

    typedef boost::shared_ptr< RemoveConcaveHullFrame<PointInT> > Ptr;
    typedef boost::shared_ptr< const RemoveConcaveHullFrame<PointInT> > ConstPtr;


    RemoveConcaveHullFrame () :
          tollerance_ (0.0),
          hullFrame_ (new pcl::PointCloud<PointInT>),
          cloudWithoutFrame_ (new pcl::PointCloud<PointInT>)
          { };



    inline void setTollerance(float toll) {tollerance_ = toll;}

    void apply(typename pcl::PointCloud<PointInT>::Ptr cloudOut);


    virtual ~RemoveConcaveHullFrame ()
    {

    }

protected:


    float tollerance_;
    /** \brief An input point cloud describing the surface that is to be used for nearest neighbors estimation. */
    using pcl::PCLBase<PointInT>::input_;
    /** \brief The subtracted (inverted) point cloud. */
    typename pcl::PointCloud<PointInT>::Ptr hullFrame_;
    typename pcl::PointCloud<PointInT>::Ptr cloudWithoutFrame_;


};

template <typename PointInT>
void RemoveConcaveHullFrame<PointInT>::apply(typename pcl::PointCloud<PointInT>::Ptr cloudOut){

    typename pcl::PointCloud<PointInT>::Ptr cloudFiltered (new pcl::PointCloud<PointInT>);
    typename pcl::PointCloud<PointInT>::Ptr cloudFiltered2 (new pcl::PointCloud<PointInT>);

    //get extension of point cloud
    PointInT minPt;
    PointInT maxPt;
    pcl::getMinMax3D(*input_, minPt, maxPt);

    // add and subtract a small tolerance to the determined bounds to generate a wider range
    // to be sure to filter all the outside borders

    if (tollerance_ != 0){
        minPt.x = minPt.x + tollerance_;
        minPt.y = minPt.y + tollerance_;
        minPt.z = minPt.z + tollerance_;

        maxPt.x = maxPt.x - tollerance_;
        maxPt.y = maxPt.y - tollerance_;
        maxPt.z = maxPt.z - tollerance_;
    }

    // Create the filtering object
      pcl::PassThrough<PointInT> pass;
      pass.setInputCloud (input_);
      pass.setFilterFieldName ("x");        // filter in x
      pass.setFilterLimits (minPt.x, maxPt.x);
      //pass.setFilterLimitsNegative (true);
      pass.filter (*cloudFiltered);

      // filter in y
      pass.setInputCloud (cloudFiltered);
      pass.setFilterFieldName ("y");
      pass.setFilterLimits (minPt.y, maxPt.y);
      //pass.setFilterLimitsNegative (true);
      pass.filter (*cloudFiltered2);


      // filter in z
      pass.setInputCloud (cloudFiltered2);
      pass.setFilterFieldName ("z");
      pass.setFilterLimits (minPt.z, maxPt.z);
      //pass.setFilterLimitsNegative (true);
      pass.filter (*cloudOut);
      //viewer<PointInT> (cloudOut);


}

#endif // REMOVECONCAVEHULLFRAME_H