template<typename PointT, typename NormalT> bool pcl::NormalSpaceSampling<PointT, NormalT>::initCompute () { if (!FilterIndices<PointT>::initCompute ()) return false; // If sample size is 0 or if the sample size is greater then input cloud size then return entire copy of cloud if (sample_ >= input_->size ()) { PCL_ERROR ("[NormalSpaceSampling::initCompute] Requested more samples than the input cloud size: %d vs %lu\n", sample_, input_->size ()); return false; } boost::mt19937 rng (static_cast<unsigned int> (seed_)); boost::uniform_int<unsigned int> uniform_distrib (0, unsigned (input_->size ())); delete rng_uniform_distribution_; rng_uniform_distribution_ = new boost::variate_generator<boost::mt19937, boost::uniform_int<unsigned int> > (rng, uniform_distrib); return (true); }
template <typename PointInT, typename PointOutT> void pcl::MovingLeastSquares<PointInT, PointOutT>::process (PointCloudOut &output) { // Reset or initialize the collection of indices corresponding_input_indices_.reset (new PointIndices); // Check if normals have to be computed/saved if (compute_normals_) { normals_.reset (new NormalCloud); // Copy the header normals_->header = input_->header; // Clear the fields in case the method exits before computation normals_->width = normals_->height = 0; normals_->points.clear (); } // Copy the header output.header = input_->header; output.width = output.height = 0; output.points.clear (); if (search_radius_ <= 0 || sqr_gauss_param_ <= 0) { PCL_ERROR ("[pcl::%s::process] Invalid search radius (%f) or Gaussian parameter (%f)!\n", getClassName ().c_str (), search_radius_, sqr_gauss_param_); return; } // Check if distinct_cloud_ was set if (upsample_method_ == DISTINCT_CLOUD && !distinct_cloud_) { PCL_ERROR ("[pcl::%s::process] Upsample method was set to DISTINCT_CLOUD, but no distinct cloud was specified.\n", getClassName ().c_str ()); return; } if (!initCompute ()) return; // Initialize the spatial locator if (!tree_) { KdTreePtr tree; if (input_->isOrganized ()) tree.reset (new pcl::search::OrganizedNeighbor<PointInT> ()); else tree.reset (new pcl::search::KdTree<PointInT> (false)); setSearchMethod (tree); } // Send the surface dataset to the spatial locator tree_->setInputCloud (input_); switch (upsample_method_) { // Initialize random number generator if necessary case (RANDOM_UNIFORM_DENSITY): { rng_alg_.seed (static_cast<unsigned> (std::time (0))); float tmp = static_cast<float> (search_radius_ / 2.0f); boost::uniform_real<float> uniform_distrib (-tmp, tmp); rng_uniform_distribution_.reset (new boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > (rng_alg_, uniform_distrib)); break; } case (VOXEL_GRID_DILATION): case (DISTINCT_CLOUD): { break; } default: break; } mls_results_.resize (input_->size ()); // Perform the actual surface reconstruction performProcessing (output); if (compute_normals_) { normals_->height = 1; normals_->width = static_cast<uint32_t> (normals_->size ()); for (unsigned int i = 0; i < output.size (); ++i) { typedef typename pcl::traits::fieldList<PointOutT>::type FieldList; pcl::for_each_type<FieldList> (SetIfFieldExists<PointOutT, float> (output.points[i], "normal_x", normals_->points[i].normal_x)); pcl::for_each_type<FieldList> (SetIfFieldExists<PointOutT, float> (output.points[i], "normal_y", normals_->points[i].normal_y)); pcl::for_each_type<FieldList> (SetIfFieldExists<PointOutT, float> (output.points[i], "normal_z", normals_->points[i].normal_z)); pcl::for_each_type<FieldList> (SetIfFieldExists<PointOutT, float> (output.points[i], "curvature", normals_->points[i].curvature)); } } // Set proper widths and heights for the clouds output.height = 1; output.width = static_cast<uint32_t> (output.size ()); deinitCompute (); }