Point Cloud Library (PCL)  1.7.1
box_clipper3D.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef PCL_BOX_CLIPPER3D_H_
39 #define PCL_BOX_CLIPPER3D_H_
40 #include "clipper3D.h"
41 
42 namespace pcl
43 {
44  /**
45  * \author Suat Gedikli <gedikli@willowgarage.com>
46  * \brief Implementation of a box clipper in 3D. Actually it allows affine transformations, thus any parallelepiped in general pose.
47  * The affine transformation is used to transform the point before clipping it using the unit cube centered at origin and with an extend of -1 to +1 in each dimension
48  * \ingroup filters
49  */
50  template<typename PointT>
51  class BoxClipper3D : public Clipper3D<PointT>
52  {
53  public:
54 
55  typedef boost::shared_ptr< BoxClipper3D<PointT> > Ptr;
56  typedef boost::shared_ptr< const BoxClipper3D<PointT> > ConstPtr;
57 
58 
59  /**
60  * \author Suat Gedikli <gedikli@willowgarage.com>
61  * \brief Constructor taking an affine transformation matrix, which allows also shearing of the clipping area
62  * \param[in] transformation the 3x3 affine transformation matrix that is used to describe the unit cube
63  */
64  BoxClipper3D (const Eigen::Affine3f& transformation);
65 
66  /**
67  * \brief creates a BoxClipper object with a scaled box in general pose
68  * \param[in] rodrigues the rotation axis and angle given by the vector direction and length respectively
69  * \param[in] translation the position of the box center
70  * \param[in] box_size the size of the box for each dimension
71  */
72  BoxClipper3D (const Eigen::Vector3f& rodrigues, const Eigen::Vector3f& translation, const Eigen::Vector3f& box_size);
73 
74  /**
75  * \brief Set the affine transformation
76  * \param[in] transformation
77  */
78  void setTransformation (const Eigen::Affine3f& transformation);
79 
80  /**
81  * \brief sets the box in general pose given by the orientation position and size
82  * \param[in] rodrigues the rotation axis and angle given by the vector direction and length respectively
83  * \param[in] translation the position of the box center
84  * \param[in] box_size the size of the box for each dimension
85  */
86  void setTransformation (const Eigen::Vector3f& rodrigues, const Eigen::Vector3f& translation, const Eigen::Vector3f& box_size);
87 
88  /**
89  * \brief virtual destructor
90  */
91  virtual ~BoxClipper3D () throw ();
92 
93  virtual bool
94  clipPoint3D (const PointT& point) const;
95 
96  virtual bool
97  clipLineSegment3D (PointT& from, PointT& to) const;
98 
99  virtual void
100  clipPlanarPolygon3D (std::vector<PointT>& polygon) const;
101 
102  virtual void
103  clipPlanarPolygon3D (const std::vector<PointT>& polygon, std::vector<PointT>& clipped_polygon) const;
104 
105  virtual void
106  clipPointCloud3D (const pcl::PointCloud<PointT> &cloud_in, std::vector<int>& clipped, const std::vector<int>& indices = std::vector<int> ()) const;
107 
108  virtual Clipper3D<PointT>*
109  clone () const;
110 
111  protected:
112  float getDistance (const PointT& point) const;
113  void transformPoint (const PointT& pointIn, PointT& pointOut) const;
114  private:
115  /**
116  * \brief the affine transformation that is applied before clipping is done on the unit cube.
117  */
118  Eigen::Affine3f transformation_;
119 
120  public:
121  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
122  };
123 }
124 
125 #ifdef PCL_NO_PRECOMPILE
126 #include <pcl/filters/impl/box_clipper3D.hpp>
127 #endif
128 
129 #endif // PCL_BOX_CLIPPER3D_H_