Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shot_lrf_omp.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, 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  * $Id$
35  */
36 
37 #ifndef PCL_FEATURES_IMPL_SHOT_LRF_OMP_H_
38 #define PCL_FEATURES_IMPL_SHOT_LRF_OMP_H_
39 
40 #include <utility>
42 #include <pcl/features/shot_lrf.h>
43 
44 template<typename PointInT, typename PointOutT>
45 void
47 {
48  if (threads_ < 0)
49  threads_ = 1;
50 
51  //check whether used with search radius or search k-neighbors
52  if (this->getKSearch () != 0)
53  {
54  PCL_ERROR(
55  "[pcl::%s::computeFeature] Error! Search method set to k-neighborhood. Call setKSearch(0) and setRadiusSearch( radius ) to use this class.\n",
56  getClassName().c_str ());
57  return;
58  }
59  tree_->setSortedResults (true);
60 
61  int data_size = static_cast<int> (indices_->size ());
62 #pragma omp parallel for num_threads(threads_)
63  for (int i = 0; i < data_size; ++i)
64  {
65  // point result
66  Eigen::Matrix3f rf;
67  PointOutT& output_rf = output[i];
68 
69  //output_rf.confidence = getLocalRF ((*indices_)[i], rf);
70  //if (output_rf.confidence == std::numeric_limits<float>::max ())
71 
72  std::vector<int> n_indices;
73  std::vector<float> n_sqr_distances;
74  this->searchForNeighbors ((*indices_)[i], search_parameter_, n_indices, n_sqr_distances);
75  if (getLocalRF ((*indices_)[i], rf) == std::numeric_limits<float>::max ())
76  {
77  output.is_dense = false;
78  }
79 
80  output_rf.x_axis.getNormalVector3fMap () = rf.row (0);
81  output_rf.y_axis.getNormalVector3fMap () = rf.row (1);
82  output_rf.z_axis.getNormalVector3fMap () = rf.row (2);
83  }
84 
85 }
86 
87 template<typename PointInT, typename PointOutT>
88 void
90 {
91  if (threads_ < 0)
92  threads_ = 1;
93 
94  //check whether used with search radius or search k-neighbors
95  if (this->getKSearch () != 0)
96  {
97  PCL_ERROR(
98  "[pcl::%s::computeFeatureEigen] Error! Search method set to k-neighborhood. Call setKSearch(0) and setRadiusSearch( radius ) to use this class.\n",
99  getClassName().c_str ());
100  return;
101  }
102  tree_->setSortedResults (true);
103 
104  int data_size = static_cast<int> (indices_->size ());
105 
106  // Set up the output channels
107  output.channels["shot_lrf"].name = "shot_lrf";
108  output.channels["shot_lrf"].offset = 0;
109  output.channels["shot_lrf"].size = 4;
110  output.channels["shot_lrf"].count = 9;
111  output.channels["shot_lrf"].datatype = sensor_msgs::PointField::FLOAT32;
112 
113  //output.points.resize (indices_->size (), 10);
114  output.points.resize (data_size, 9);
115 
116 #pragma omp parallel for num_threads(threads_)
117  for (int i = 0; i < data_size; ++i)
118  {
119  // point result
120  Eigen::Matrix3f rf;
121 
122  //output.points (i, 9) = getLocalRF ((*indices_)[i], rf);
123  //if (output.points (i, 9) == std::numeric_limits<float>::max ())
124  if (getLocalRF ((*indices_)[i], rf) == std::numeric_limits<float>::max ())
125  {
126  output.is_dense = false;
127  }
128 
129  output.points.block<1, 3> (i, 0) = rf.row (0);
130  output.points.block<1, 3> (i, 3) = rf.row (1);
131  output.points.block<1, 3> (i, 6) = rf.row (2);
132  }
133 
134 }
135 
136 #define PCL_INSTANTIATE_SHOTLocalReferenceFrameEstimationOMP(T,OutT) template class PCL_EXPORTS pcl::SHOTLocalReferenceFrameEstimationOMP<T,OutT>;
137 
138 #endif // PCL_FEATURES_IMPL_SHOT_LRF_H_