marching_cubes_rbf.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  */
00038 
00039 #ifndef PCL_SURFACE_IMPL_MARCHING_CUBES_RBF_H_
00040 #define PCL_SURFACE_IMPL_MARCHING_CUBES_RBF_H_
00041 
00042 #include <pcl/surface/marching_cubes_rbf.h>
00043 #include <pcl/common/common.h>
00044 #include <pcl/common/vector_average.h>
00045 #include <pcl/Vertices.h>
00046 #include <pcl/kdtree/kdtree_flann.h>
00047 
00049 template <typename PointNT>
00050 pcl::MarchingCubesRBF<PointNT>::MarchingCubesRBF ()
00051   : MarchingCubes<PointNT> (),
00052     off_surface_epsilon_ (0.1f)
00053 {
00054 }
00055 
00057 template <typename PointNT>
00058 pcl::MarchingCubesRBF<PointNT>::~MarchingCubesRBF ()
00059 {
00060 }
00061 
00063 template <typename PointNT> void
00064 pcl::MarchingCubesRBF<PointNT>::voxelizeData ()
00065 {
00066   // Initialize data structures
00067   unsigned int N = static_cast<unsigned int> (input_->size ());
00068   Eigen::MatrixXd M (2*N, 2*N),
00069                   d (2*N, 1);
00070 
00071   for (unsigned int row_i = 0; row_i < 2*N; ++row_i)
00072   {
00073     // boolean variable to determine whether we are in the off_surface domain for the rows
00074     bool row_off = (row_i >= N) ? 1 : 0;
00075     for (unsigned int col_i = 0; col_i < 2*N; ++col_i)
00076     {
00077       // boolean variable to determine whether we are in the off_surface domain for the columns
00078       bool col_off = (col_i >= N) ? 1 : 0;
00079       M (row_i, col_i) = kernel (Eigen::Vector3f (input_->points[col_i%N].getVector3fMap ()).cast<double> () + Eigen::Vector3f (input_->points[col_i%N].getNormalVector3fMap ()).cast<double> () * col_off * off_surface_epsilon_,
00080                                  Eigen::Vector3f (input_->points[row_i%N].getVector3fMap ()).cast<double> () + Eigen::Vector3f (input_->points[row_i%N].getNormalVector3fMap ()).cast<double> () * row_off * off_surface_epsilon_);
00081     }
00082 
00083     d (row_i, 0) = row_off * off_surface_epsilon_;
00084   }
00085 
00086   // Solve for the weights
00087   Eigen::MatrixXd w (2*N, 1);
00088 
00089   // Solve_linear_system (M, d, w);
00090   w = M.fullPivLu ().solve (d);
00091 
00092   std::vector<double> weights (2*N);
00093   std::vector<Eigen::Vector3d> centers (2*N);
00094   for (unsigned int i = 0; i < N; ++i)
00095   {
00096     centers[i] = Eigen::Vector3f (input_->points[i].getVector3fMap ()).cast<double> ();
00097     centers[i + N] = Eigen::Vector3f (input_->points[i].getVector3fMap ()).cast<double> () + Eigen::Vector3f (input_->points[i].getNormalVector3fMap ()).cast<double> () * off_surface_epsilon_;
00098     weights[i] = w (i, 0);
00099     weights[i + N] = w (i + N, 0);
00100   }
00101 
00102   for (int x = 0; x < res_x_; ++x)
00103     for (int y = 0; y < res_y_; ++y)
00104       for (int z = 0; z < res_z_; ++z)
00105       {
00106         Eigen::Vector3d point;
00107         point[0] = min_p_[0] + (max_p_[0] - min_p_[0]) * float (x) / float (res_x_);
00108         point[1] = min_p_[1] + (max_p_[1] - min_p_[1]) * float (y) / float (res_y_);
00109         point[2] = min_p_[2] + (max_p_[2] - min_p_[2]) * float (z) / float (res_z_);
00110 
00111         double f = 0.0;
00112         std::vector<double>::const_iterator w_it (weights.begin());
00113         for (std::vector<Eigen::Vector3d>::const_iterator c_it = centers.begin ();
00114              c_it != centers.end (); ++c_it, ++w_it)
00115           f += *w_it * kernel (*c_it, point);
00116 
00117         grid_[x * res_y_*res_z_ + y * res_z_ + z] = float (f);
00118       }
00119 }
00120 
00122 template <typename PointNT> double
00123 pcl::MarchingCubesRBF<PointNT>::kernel (Eigen::Vector3d c, Eigen::Vector3d x)
00124 {
00125   double r = (x - c).norm ();
00126   return (r * r * r);
00127 }
00128 
00129 #define PCL_INSTANTIATE_MarchingCubesRBF(T) template class PCL_EXPORTS pcl::MarchingCubesRBF<T>;
00130 
00131 #endif    // PCL_SURFACE_IMPL_MARCHING_CUBES_HOPPE_H_
00132 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:27