Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
crop_box.hpp
Go to the documentation of this file.
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  *
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 Willow Garage, Inc. 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  * $Id: crop_box.hpp 5026 2012-03-12 02:51:44Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTERS_IMPL_CROP_BOX_H_
41 #define PCL_FILTERS_IMPL_CROP_BOX_H_
42 
43 #include <pcl/filters/crop_box.h>
44 
45 
47 template<typename PointT>
48 void
50 {
51  output.resize (input_->points.size ());
52  int indice_count = 0;
53 
54  // We filter out invalid points
55  output.is_dense = true;
56 
57  Eigen::Affine3f transform = Eigen::Affine3f::Identity();
58  Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity();
59 
60  if (rotation_ != Eigen::Vector3f::Zero ())
61  {
62  pcl::getTransformation (0, 0, 0,
63  rotation_ (0), rotation_ (1), rotation_ (2),
64  transform);
65  inverse_transform = transform.inverse ();
66  }
67 
68  for (size_t index = 0; index < indices_->size (); ++index)
69  {
70  if (!input_->is_dense)
71  // Check if the point is invalid
72  if (!isFinite (input_->points[index]))
73  continue;
74 
75  // Get local point
76  PointT local_pt = input_->points[(*indices_)[index]];
77 
78  // Transform point to world space
79  if (!(transform_.matrix ().isIdentity ()))
80  local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
81 
82  if (translation_ != Eigen::Vector3f::Zero ())
83  {
84  local_pt.x -= translation_ (0);
85  local_pt.y -= translation_ (1);
86  local_pt.z -= translation_ (2);
87  }
88 
89  // Transform point to local space of crop box
90  if (!(inverse_transform.matrix ().isIdentity ()))
91  local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);
92 
93  if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2])
94  continue;
95  if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2])
96  continue;
97 
98  output.points[indice_count++] = input_->points[(*indices_)[index]];
99  }
100  output.width = indice_count;
101  output.height = 1;
102  output.resize (output.width * output.height);
103 }
104 
106 template<typename PointT> void
107 pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
108 {
109  indices.resize (input_->points.size ());
110  int indice_count = 0;
111 
112  Eigen::Affine3f transform = Eigen::Affine3f::Identity ();
113  Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity ();
114 
115  if (rotation_ != Eigen::Vector3f::Zero ())
116  {
117  pcl::getTransformation (0, 0, 0,
118  rotation_ (0), rotation_ (1), rotation_ (2),
119  transform);
120  inverse_transform = transform.inverse ();
121  }
122 
123  for (size_t index = 0; index < indices_->size (); ++index)
124  {
125  if (!input_->is_dense)
126  // Check if the point is invalid
127  if (!isFinite (input_->points[index]))
128  continue;
129 
130  // Get local point
131  PointT local_pt = input_->points[(*indices_)[index]];
132 
133  // Transform point to world space
134  if (!(transform_.matrix ().isIdentity ()))
135  local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
136 
137  if (translation_ != Eigen::Vector3f::Zero ())
138  {
139  local_pt.x -= translation_ (0);
140  local_pt.y -= translation_ (1);
141  local_pt.z -= translation_ (2);
142  }
143 
144  // Transform point to local space of crop box
145  if (!(inverse_transform.matrix ().isIdentity ()))
146  local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);
147 
148  if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2])
149  continue;
150  if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2])
151  continue;
152 
153  indices[indice_count++] = (*indices_)[index];
154  }
155  indices.resize (indice_count);
156 }
157 
158 #define PCL_INSTANTIATE_CropBox(T) template class PCL_EXPORTS pcl::CropBox<T>;
159 
160 #endif // PCL_FILTERS_IMPL_CROP_BOX_H_