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