Point Cloud Library (PCL)  1.12.0-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 <pcl/memory.h>
41 #include <pcl/pcl_macros.h>
42 #include "clipper3D.h"
43 
44 namespace pcl
45 {
46  /**
47  * \author Suat Gedikli <gedikli@willowgarage.com>
48  * \brief Implementation of a box clipper in 3D. Actually it allows affine transformations, thus any parallelepiped in general pose.
49  * 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
50  * \ingroup filters
51  */
52  template<typename PointT>
53  class BoxClipper3D : public Clipper3D<PointT>
54  {
55  public:
56 
57  using Ptr = shared_ptr<BoxClipper3D<PointT> >;
58  using ConstPtr = shared_ptr<const BoxClipper3D<PointT> >;
59 
60 
61  /**
62  * \author Suat Gedikli <gedikli@willowgarage.com>
63  * \brief Constructor taking an affine transformation matrix, which allows also shearing of the clipping area
64  * \param[in] transformation the 3x3 affine transformation matrix that is used to describe the unit cube
65  */
66  BoxClipper3D (const Eigen::Affine3f& transformation);
67 
68  /**
69  * \brief creates a BoxClipper object with a scaled box in general pose
70  * \param[in] rodrigues the rotation axis and angle given by the vector direction and length respectively
71  * \param[in] translation the position of the box center
72  * \param[in] box_size the size of the box for each dimension
73  */
74  BoxClipper3D (const Eigen::Vector3f& rodrigues, const Eigen::Vector3f& translation, const Eigen::Vector3f& box_size);
75 
76  /**
77  * \brief Set the affine transformation
78  * \param[in] transformation
79  */
80  void setTransformation (const Eigen::Affine3f& transformation);
81 
82  /**
83  * \brief sets the box in general pose given by the orientation position and size
84  * \param[in] rodrigues the rotation axis and angle given by the vector direction and length respectively
85  * \param[in] translation the position of the box center
86  * \param[in] box_size the size of the box for each dimension
87  */
88  void setTransformation (const Eigen::Vector3f& rodrigues, const Eigen::Vector3f& translation, const Eigen::Vector3f& box_size);
89 
90  /**
91  * \brief virtual destructor
92  */
93  ~BoxClipper3D () noexcept;
94 
95  bool
96  clipPoint3D (const PointT& point) const override;
97 
98  bool
99  clipLineSegment3D (PointT& from, PointT& to) const override;
100 
101  void
102  clipPlanarPolygon3D (std::vector<PointT, Eigen::aligned_allocator<PointT> >& polygon) const override;
103 
104  void
105  clipPlanarPolygon3D (const std::vector<PointT, Eigen::aligned_allocator<PointT> >& polygon, std::vector<PointT, Eigen::aligned_allocator<PointT> >& clipped_polygon) const override;
106 
107  void
108  clipPointCloud3D (const pcl::PointCloud<PointT> &cloud_in, Indices& clipped, const Indices& indices = Indices ()) const override;
109 
110  Clipper3D<PointT>*
111  clone () const override;
112 
113  protected:
114  float getDistance (const PointT& point) const;
115  void transformPoint (const PointT& pointIn, PointT& pointOut) const;
116  private:
117  /**
118  * \brief the affine transformation that is applied before clipping is done on the unit cube.
119  */
120  Eigen::Affine3f transformation_;
121 
122  public:
124  };
125 }
126 
127 #include <pcl/filters/impl/box_clipper3D.hpp>
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition: convolution.h:46
Eigen
Definition: bfgs.h:10
pcl::Clipper3D
Base class for 3D clipper objects.
Definition: clipper3D.h:54
pcl::BoxClipper3D::BoxClipper3D
BoxClipper3D(const Eigen::Affine3f &transformation)
Constructor taking an affine transformation matrix, which allows also shearing of the clipping area.
Definition: box_clipper3D.hpp:41
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:674
pcl::BoxClipper3D::clone
Clipper3D< PointT > * clone() const override
polymorphic method to clone the underlying clipper with its parameters.
Definition: box_clipper3D.hpp:78
pcl::BoxClipper3D::Ptr
shared_ptr< BoxClipper3D< PointT > > Ptr
Definition: box_clipper3D.h:57
pcl::BoxClipper3D::clipPointCloud3D
void clipPointCloud3D(const pcl::PointCloud< PointT > &cloud_in, Indices &clipped, const Indices &indices=Indices()) const override
interface to clip a point cloud
Definition: box_clipper3D.hpp:199
pcl::BoxClipper3D
Implementation of a box clipper in 3D. Actually it allows affine transformations, thus any parallelep...
Definition: box_clipper3D.h:53
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
pcl::BoxClipper3D::getDistance
float getDistance(const PointT &point) const
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
pcl::BoxClipper3D::transformPoint
void transformPoint(const PointT &pointIn, PointT &pointOut) const
Definition: box_clipper3D.hpp:85
pcl::BoxClipper3D::~BoxClipper3D
~BoxClipper3D() noexcept
virtual destructor
Definition: box_clipper3D.hpp:56
pcl::BoxClipper3D::setTransformation
void setTransformation(const Eigen::Affine3f &transformation)
Set the affine transformation.
Definition: box_clipper3D.hpp:62
pcl::BoxClipper3D::clipLineSegment3D
bool clipLineSegment3D(PointT &from, PointT &to) const override
Definition: box_clipper3D.hpp:123
pcl::BoxClipper3D::ConstPtr
shared_ptr< const BoxClipper3D< PointT > > ConstPtr
Definition: box_clipper3D.h:58
pcl::BoxClipper3D::clipPoint3D
bool clipPoint3D(const PointT &point) const override
interface to clip a single point
Definition: box_clipper3D.hpp:111
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl::BoxClipper3D::clipPlanarPolygon3D
void clipPlanarPolygon3D(std::vector< PointT, Eigen::aligned_allocator< PointT > > &polygon) const override
Definition: box_clipper3D.hpp:189