Point Cloud Library (PCL)  1.11.1
crop_box.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2011, Willow Garage, Inc.
6  * Copyright (c) 2015, Google, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id: extract_indices.hpp 1897 2011-07-26 20:35:49Z rusu $
38  *
39  */
40 
41 #ifndef PCL_FILTERS_IMPL_CROP_BOX_H_
42 #define PCL_FILTERS_IMPL_CROP_BOX_H_
43 
44 #include <pcl/filters/crop_box.h>
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 template<typename PointT> void
48 pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
49 {
50  indices.resize (input_->size ());
51  removed_indices_->resize (input_->size ());
52  int indices_count = 0;
53  int removed_indices_count = 0;
54 
55  Eigen::Affine3f transform = Eigen::Affine3f::Identity ();
56  Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity ();
57 
58  if (rotation_ != Eigen::Vector3f::Zero ())
59  {
60  pcl::getTransformation (0, 0, 0,
61  rotation_ (0), rotation_ (1), rotation_ (2),
62  transform);
63  inverse_transform = transform.inverse ();
64  }
65 
66  bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
67  bool translation_is_zero = (translation_ == Eigen::Vector3f::Zero ());
68  bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();
69 
70  for (const auto index : *indices_)
71  {
72  if (!input_->is_dense)
73  // Check if the point is invalid
74  if (!isFinite ((*input_)[index]))
75  continue;
76 
77  // Get local point
78  PointT local_pt = (*input_)[index];
79 
80  // Transform point to world space
81  if (!transform_matrix_is_identity)
82  local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
83 
84  if (!translation_is_zero)
85  {
86  local_pt.x -= translation_ (0);
87  local_pt.y -= translation_ (1);
88  local_pt.z -= translation_ (2);
89  }
90 
91  // Transform point to local space of crop box
92  if (!inverse_transform_matrix_is_identity)
93  local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);
94 
95  // If outside the cropbox
96  if ( (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2]) ||
97  (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2]))
98  {
99  if (negative_)
100  indices[indices_count++] = index;
101  else if (extract_removed_indices_)
102  (*removed_indices_)[removed_indices_count++] = static_cast<int> (index);
103  }
104  // If inside the cropbox
105  else
106  {
107  if (negative_ && extract_removed_indices_)
108  (*removed_indices_)[removed_indices_count++] = static_cast<int> (index);
109  else if (!negative_)
110  indices[indices_count++] = index;
111  }
112  }
113  indices.resize (indices_count);
114  removed_indices_->resize (removed_indices_count);
115 }
116 
117 #define PCL_INSTANTIATE_CropBox(T) template class PCL_EXPORTS pcl::CropBox<T>;
118 
119 #endif // PCL_FILTERS_IMPL_CROP_BOX_H_
void applyFilter(std::vector< int > &indices) override
Sample of point indices.
Definition: crop_box.hpp:48
void getTransformation(Scalar x, Scalar y, Scalar z, Scalar roll, Scalar pitch, Scalar yaw, Eigen::Transform< Scalar, 3, Eigen::Affine > &t)
Create a transformation from the given translation and Euler angles (XYZ-convention)
Definition: eigen.hpp:608
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
Definition: point_tests.h:55
A point structure representing Euclidean xyz coordinates, and the RGB color.