Point Cloud Library (PCL)  1.15.0-dev
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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_ != nullptr);
50  output.resize (input_->size ());
51  if (extract_removed_indices_)
52  removed_indices_->resize (input_->size ());
53 
54  std::size_t cp = 0;
55  std::size_t ri = 0;
56  for (std::size_t i = 0; i < input_->size (); i++)
57  {
58  const NormalT &normal = (*input_normals_)[i];
59  const PointT &pt = (*input_)[i];
60  const float val = std::abs (normal.normal_x * pt.x + normal.normal_y * pt.y + normal.normal_z * pt.z);
61 
62  if ( (val >= threshold_) ^ negative_)
63  output[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[cp++] = pt;
71  pt_new.x = pt_new.y = pt_new.z = user_filter_value_;
72  if(!std::isfinite(user_filter_value_))
73  output.is_dense = false;
74  }
75 
76  }
77  }
78  output.resize (cp);
79  removed_indices_->resize (ri);
80  output.height = 1;
81  output.width = output.size ();
82 }
83 
84 ///////////////////////////////////////////////////////////////////////////////
85 template<typename PointT, typename NormalT> void
87 {
88  assert (input_normals_ != nullptr);
89  indices.resize (input_->size ());
90  if (extract_removed_indices_)
91  removed_indices_->resize (indices_->size ());
92 
93  unsigned int k = 0;
94  unsigned int z = 0;
95  for (const auto& idx : (*indices_))
96  {
97  const NormalT &normal = (*input_normals_)[idx];
98  const PointT &pt = (*input_)[idx];
99 
100  float val = std::abs (normal.normal_x * pt.x + normal.normal_y * pt.y + normal.normal_z * pt.z);
101 
102  if ( (val >= threshold_) ^ negative_)
103  indices[k++] = idx;
104  else if (extract_removed_indices_)
105  (*removed_indices_)[z++] = idx;
106  }
107  indices.resize (k);
108  removed_indices_->resize (z);
109 }
110 
111 #define PCL_INSTANTIATE_ShadowPoints(T,NT) template class PCL_EXPORTS pcl::ShadowPoints<T,NT>;
112 
113 #endif // PCL_FILTERS_IMPL_NORMAL_SPACE_SAMPLE_H_
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
Definition: point_cloud.h:403
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:462
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
std::size_t size() const
Definition: point_cloud.h:443
void applyFilter(PointCloud &output) override
Sample of point indices into a separate PointCloud.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing normal coordinates and the surface curvature estimate.
A point structure representing Euclidean xyz coordinates, and the RGB color.