Point Cloud Library (PCL)  1.8.0
passthrough.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #ifndef PCL_CUDA_FILTERS_PASSTHROUGH_H_
37 #define PCL_CUDA_FILTERS_PASSTHROUGH_H_
38 
39 #include <pcl_cuda/filters/filter.h>
40 #include <thrust/count.h>
41 #include <thrust/remove.h>
42 #include <vector_types.h>
43 
44 namespace pcl_cuda
45 {
46 
47  /** \brief Check if a specific point is valid or not. Applicable to AOS structures. */
48  struct isFiniteAOS
49  {
50  __inline__ __device__ bool
51  operator () (const PointXYZRGB &pt)
52  //operator () (const float3 &pt)
53  {
54  return (isfinite (pt.x) && isfinite (pt.y) && isfinite (pt.z));
55  }
56  };
57 
58  /** \brief Check if a specific point is valid or not. Applicable to SOA structures. */
59  struct isFiniteSOA
60  {
61  __inline__ __device__ bool
62  operator () (const float &pt)
63  {
64  return (isfinite (pt));
65  }
66  };
67 
68  /** \brief Check if a specific point is valid or not. Applicable to SOA structures. */
70  {
71  __inline__ __device__ bool
72  operator () (const PointCloudSOA<Device>::tuple_type& tuple)
73  {
74  using thrust::get;
75  return (!isfinite (get<0> (tuple)) ||
76  !isfinite (get<1> (tuple)) ||
77  !isfinite (get<2> (tuple)));
78  }
79  };
80 
81  ///////////////////////////////////////////////////////////////////////////////////////////
82  /** \brief @b PassThrough uses the base Filter class methods to pass through
83  * all data that satisfies the user given constraints.
84  */
85  template <typename CloudT>
86  class PassThrough: public Filter<CloudT>
87  {
88  public:
90 
91  typedef typename PCLCUDABase<CloudT>::PointCloud PointCloud;
92  typedef typename PointCloud::Ptr PointCloudPtr;
94 
95  /** \brief Empty constructor. */
97  {
98  filter_name_ = "PassThrough";
99  };
100 
101  protected:
102  /** \brief Filter a Point Cloud.
103  * \param output the resultant point cloud message
104  */
105  void
106  applyFilter (PointCloud &output)
107  {
108  std::cerr << "applyFilter" << std::endl;
109  }
110  };
111 
112  ///////////////////////////////////////////////////////////////////////////////////////////
113  template <>
114  class PassThrough<PointCloudAOS<Device> >: public Filter<PointCloudAOS<Device> >
115  {
116  public:
117  /** \brief Empty constructor. */
119  {
120  filter_name_ = "PassThroughAOS";
121  };
122 
123  protected:
124  /** \brief Filter a Point Cloud.
125  * \param output the resultant point cloud message
126  */
127  void
129  {
130  // Allocate enough space
131  output.points.resize (input_->points.size ());
132  // Copy data
133  Device<PointXYZRGB>::type::iterator nr_points = thrust::copy_if (input_->points.begin (), input_->points.end (), output.points.begin (), isFiniteAOS ());
134  //Device<float3>::type::iterator nr_points = thrust::copy_if (input_->points.begin (), input_->points.end (), output.points.begin (), isFiniteAOS ());
135  output.points.resize (nr_points - output.points.begin ());
136 
137  //std::cerr << "[applyFilterAOS]: ";
138  //std::cerr << input_->points.size () << " " << output.points.size () << std::endl;
139  }
140  };
141 
142  //////////////////////////////////////////////////////////////////////////////////////////
143  template <>
144  class PassThrough<PointCloudSOA<Device> >: public Filter<PointCloudSOA<Device> >
145  {
146  public:
147  /** \brief Empty constructor. */
148  PassThrough () : zip_(false)
149  {
150  filter_name_ = "PassThroughSOA";
151  };
152 
153  inline void
154  setZip (bool zip)
155  {
156  zip_ = zip;
157  }
158 
159 
160  protected:
161  /** \brief Filter a Point Cloud.
162  * \param output the resultant point cloud message
163  */
164  void
166  {
167  if (!zip_)
168  {
169  // Allocate enough space
170  output.resize (input_->size ());
171  // Copy data
172  Device<float>::type::iterator nr_points = thrust::copy_if (input_->points_x.begin (), input_->points_x.end (), output.points_x.begin (), isFiniteSOA ());
173  nr_points = thrust::copy_if (input_->points_y.begin (), input_->points_y.end (), output.points_y.begin (), isFiniteSOA ());
174  nr_points = thrust::copy_if (input_->points_z.begin (), input_->points_z.end (), output.points_z.begin (), isFiniteSOA ());
175  output.resize (nr_points - output.points_z.begin ());
176 
177  //std::cerr << "[applyFilterSOA]: ";
178  //std::cerr << input_->size () << " " << output.size () << std::endl;
179  }
180 
181  else
182  {
183  output = *input_;
184  PointCloud::zip_iterator result = thrust::remove_if (output.zip_begin (), output.zip_end (), isFiniteZIPSOA ());
185  PointCloud::iterator_tuple result_tuple = result.get_iterator_tuple ();
186  PointCloud::float_iterator xiter = thrust::get<0> (result_tuple),
187  yiter = thrust::get<1> (result_tuple),
188  ziter = thrust::get<2> (result_tuple);
189 
190  unsigned badpoints = distance (xiter, output.points_x.end ());
191  unsigned goodpoints = distance (output.points_x.begin (), xiter);
192 
193  output.resize (goodpoints);
194 
195  //std::cerr << "[applyFilterSOA-ZIP]: ";
196  //std::cerr << input_->size () << " " << output.size () << std::endl;
197  }
198  }
199 
200  private:
201  bool zip_;
202  };
203 }
204 
205 #endif //#ifndef PCL_FILTERS_PASSTHROUGH_H_
void applyFilter(PointCloud &output)
Filter a Point Cloud.
Definition: passthrough.h:165
Check if a specific point is valid or not.
Definition: passthrough.h:59
__inline__ __device__ bool operator()(const PointXYZRGB &pt)
Definition: passthrough.h:51
Check if a specific point is valid or not.
Definition: passthrough.h:48
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
PointCloud::Ptr PointCloudPtr
Definition: passthrough.h:92
PassThrough uses the base Filter class methods to pass through all data that satisfies the user given...
Definition: passthrough.h:86
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
PCLCUDABase< PointCloudAOS< Device > >::PointCloud PointCloud
Definition: filter.h:67
Removes points with x, y, or z equal to NaN.
Definition: filter.h:59
PCLCUDABase< CloudT >::PointCloud PointCloud
Definition: passthrough.h:91
Check if a specific point is valid or not.
Definition: passthrough.h:69
PassThrough()
Empty constructor.
Definition: passthrough.h:96
void applyFilter(PointCloud &output)
Filter a Point Cloud.
Definition: passthrough.h:106
void applyFilter(PointCloud &output)
Filter a Point Cloud.
Definition: passthrough.h:128
PointCloud::ConstPtr PointCloudConstPtr
Definition: passthrough.h:93