Point Cloud Library (PCL)  1.9.1-dev
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 #pragma once
39 
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  ~BoxClipper3D () throw ();
92 
93  bool
94  clipPoint3D (const PointT& point) const override;
95 
96  bool
97  clipLineSegment3D (PointT& from, PointT& to) const override;
98 
99  void
100  clipPlanarPolygon3D (std::vector<PointT, Eigen::aligned_allocator<PointT> >& polygon) const override;
101 
102  void
103  clipPlanarPolygon3D (const std::vector<PointT, Eigen::aligned_allocator<PointT> >& polygon, std::vector<PointT, Eigen::aligned_allocator<PointT> >& clipped_polygon) const override;
104 
105  void
106  clipPointCloud3D (const pcl::PointCloud<PointT> &cloud_in, std::vector<int>& clipped, const std::vector<int>& indices = std::vector<int> ()) const override;
107 
108  Clipper3D<PointT>*
109  clone () const override;
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 #include <pcl/filters/impl/box_clipper3D.hpp>
float getDistance(const PointT &point) const
void transformPoint(const PointT &pointIn, PointT &pointOut) const
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
BoxClipper3D(const Eigen::Affine3f &transformation)
Constructor taking an affine transformation matrix, which allows also shearing of the clipping area...
void clipPlanarPolygon3D(std::vector< PointT, Eigen::aligned_allocator< PointT > > &polygon) const override
Definition: bfgs.h:9
Clipper3D< PointT > * clone() const override
polymorphic method to clone the underlying clipper with its parameters.
void clipPointCloud3D(const pcl::PointCloud< PointT > &cloud_in, std::vector< int > &clipped, const std::vector< int > &indices=std::vector< int >()) const override
interface to clip a point cloud
Implementation of a box clipper in 3D. Actually it allows affine transformations, thus any parallelep...
Definition: box_clipper3D.h:51
boost::shared_ptr< const BoxClipper3D< PointT > > ConstPtr
Definition: box_clipper3D.h:56
PointCloud represents the base class in PCL for storing collections of 3D points. ...
bool clipPoint3D(const PointT &point) const override
interface to clip a single point
boost::shared_ptr< BoxClipper3D< PointT > > Ptr
Definition: box_clipper3D.h:55
void setTransformation(const Eigen::Affine3f &transformation)
Set the affine transformation.
A point structure representing Euclidean xyz coordinates, and the RGB color.
bool clipLineSegment3D(PointT &from, PointT &to) const override
~BoxClipper3D()
virtual destructor
Base class for 3D clipper objects.
Definition: clipper3D.h:52