Point Cloud Library (PCL)  1.7.1
shadowpoints.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  *
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 #ifndef PCL_FILTERS_IMPL_SHADOW_POINTS_FILTER_H_
39 #define PCL_FILTERS_IMPL_SHADOW_POINTS_FILTER_H_
40 
41 #include <pcl/filters/shadowpoints.h>
42 
43 #include <vector>
44 
45 ///////////////////////////////////////////////////////////////////////////////
46 template<typename PointT, typename NormalT> void
48 {
49  assert (input_normals_ != NULL);
50  output.points.resize (input_->points.size ());
51  if (extract_removed_indices_)
52  removed_indices_->resize (input_->points.size ());
53 
54  unsigned int cp = 0;
55  unsigned int ri = 0;
56  for (unsigned int i = 0; i < input_->points.size (); i++)
57  {
58  const NormalT &normal = input_normals_->points[i];
59  const PointT &pt = input_->points[i];
60  float val = fabsf (normal.normal_x * pt.x + normal.normal_y * pt.y + normal.normal_z * pt.z);
61 
62  if ( (val >= threshold_) ^ negative_)
63  output.points[cp++] = pt;
64  else
65  {
66  if (extract_removed_indices_)
67  (*removed_indices_)[ri++] = i;
68  if (keep_organized_)
69  {
70  PointT &pt_new = output.points[cp++] = pt;
71  pt_new.x = pt_new.y = pt_new.z = user_filter_value_;
72  }
73 
74  }
75  }
76  output.points.resize (cp);
77  removed_indices_->resize (ri);
78  output.width = 1;
79  output.height = static_cast<uint32_t> (output.points.size ());
80 }
81 
82 ///////////////////////////////////////////////////////////////////////////////
83 template<typename PointT, typename NormalT> void
85 {
86  assert (input_normals_ != NULL);
87  indices.resize (input_->points.size ());
88  if (extract_removed_indices_)
89  removed_indices_->resize (indices_->size ());
90 
91  unsigned int k = 0;
92  unsigned int z = 0;
93  for (std::vector<int>::const_iterator idx = indices_->begin (); idx != indices_->end (); ++idx)
94  {
95  const NormalT &normal = input_normals_->points[*idx];
96  const PointT &pt = input_->points[*idx];
97 
98  float val = fabsf (normal.normal_x * pt.x + normal.normal_y * pt.y + normal.normal_z * pt.z);
99 
100  if ( (val >= threshold_) ^ negative_)
101  indices[k++] = *idx;
102  else if (extract_removed_indices_)
103  (*removed_indices_)[z++] = *idx;
104  }
105  indices.resize (k);
106  removed_indices_->resize (z);
107 }
108 
109 #define PCL_INSTANTIATE_ShadowPoints(T,NT) template class PCL_EXPORTS pcl::ShadowPoints<T,NT>;
110 
111 #endif // PCL_FILTERS_IMPL_NORMAL_SPACE_SAMPLE_H_