bilateral_upsampling.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) 2009-2012, Willow Garage, Inc.
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * * Redistributions of source code must retain the above copyright
00014  * notice, this list of conditions and the following disclaimer.
00015  * * Redistributions in binary form must reproduce the above
00016  *   copyright notice, this list of conditions and the following
00017  *   disclaimer in the documentation and/or other materials provided
00018  *   with the distribution.
00019  * * Neither the name of Willow Garage, Inc. nor the names of its
00020  *   contributors may be used to endorse or promote products derived
00021  *   from this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  * POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
00037  *
00038  */
00039 
00040 
00041 #ifndef PCL_SURFACE_IMPL_BILATERAL_UPSAMPLING_H_
00042 #define PCL_SURFACE_IMPL_BILATERAL_UPSAMPLING_H_
00043 
00044 #include <pcl/surface/bilateral_upsampling.h>
00045 #include <algorithm>
00046 
00048 template <typename PointInT, typename PointOutT> void
00049 pcl::BilateralUpsampling<PointInT, PointOutT>::process (pcl::PointCloud<PointOutT> &output)
00050 {
00051   // Copy the header
00052   output.header = input_->header;
00053 
00054   if (!initCompute ())
00055   {
00056     output.width = output.height = 0;
00057     output.points.clear ();
00058     return;
00059   }
00060 
00061   if (input_->isOrganized () == false)
00062   {
00063     PCL_ERROR ("Input cloud is not organized.\n");
00064     return;
00065   }
00066 
00067   // Invert projection matrix
00068   unprojection_matrix_ = projection_matrix_.inverse ();
00069 
00070   for (int i = 0; i < 3; ++i)
00071   {
00072     for (int j = 0; j < 3; ++j)
00073       printf ("%f ", unprojection_matrix_(i, j));
00074 
00075     printf ("\n");
00076   }
00077 
00078 
00079   // Perform the actual surface reconstruction
00080   performProcessing (output);
00081 
00082   deinitCompute ();
00083 }
00084 
00086 template <typename PointInT, typename PointOutT> void
00087 pcl::BilateralUpsampling<PointInT, PointOutT>::performProcessing (PointCloudOut &output)
00088 {
00089     output.resize (input_->size ());
00090     float nan = std::numeric_limits<float>::quiet_NaN ();
00091 
00092 
00093     for (int x = 0; x < static_cast<int> (input_->width); ++x)
00094       for (int y = 0; y < static_cast<int> (input_->height); ++y)
00095       {
00096         int start_window_x = std::max (x - window_size_, 0),
00097             start_window_y = std::max (y - window_size_, 0),
00098             end_window_x = std::min (x + window_size_, static_cast<int> (input_->width)),
00099             end_window_y = std::min (y + window_size_, static_cast<int> (input_->height));
00100 
00101         float sum = 0.0f,
00102             norm_sum = 0.0f;
00103 
00104         for (int x_w = start_window_x; x_w < end_window_x; ++ x_w)
00105           for (int y_w = start_window_y; y_w < end_window_y; ++ y_w)
00106           {
00107             float dx = float (x - x_w),
00108                 dy = float (y - y_w);
00109 
00110             float val_exp_depth = expf (- (dx*dx + dy*dy) / (2.0f * static_cast<float> (sigma_depth_ * sigma_depth_)));
00111 
00112             float d_color = static_cast<float> (
00113                 abs (input_->points[y_w * input_->width + x_w].r - input_->points[y * input_->width + x].r) +
00114                 abs (input_->points[y_w * input_->width + x_w].g - input_->points[y * input_->width + x].g) +
00115                 abs (input_->points[y_w * input_->width + x_w].b - input_->points[y * input_->width + x].b));
00116             float val_exp_rgb = expf (- d_color * d_color / (2.0f * sigma_color_ * sigma_color_));
00117 
00118             if (pcl_isfinite (input_->points[y_w*input_->width + x_w].z))
00119             {
00120               sum += val_exp_depth * val_exp_rgb * input_->points[y_w*input_->width + x_w].z;
00121               norm_sum += val_exp_depth * val_exp_rgb;
00122             }
00123           }
00124 
00125         output.points[y*input_->width + x].r = input_->points[y*input_->width + x].r;
00126         output.points[y*input_->width + x].g = input_->points[y*input_->width + x].g;
00127         output.points[y*input_->width + x].b = input_->points[y*input_->width + x].b;
00128 
00129         if (norm_sum != 0.0f)
00130         {
00131           float depth = sum / norm_sum;
00132           Eigen::Vector3f pc (static_cast<float> (x) * depth, static_cast<float> (y) * depth, depth);
00133           Eigen::Vector3f pw (unprojection_matrix_ * pc);
00134           output.points[y*input_->width + x].x = pw[0];
00135           output.points[y*input_->width + x].y = pw[1];
00136           output.points[y*input_->width + x].z = pw[2];
00137         }
00138         else
00139         {
00140           output.points[y*input_->width + x].x = nan;
00141           output.points[y*input_->width + x].y = nan;
00142           output.points[y*input_->width + x].z = nan;
00143         }
00144       }
00145 
00146     output.header = input_->header;
00147     output.width = input_->width;
00148     output.height = input_->height;
00149 }
00150 
00151 
00152 
00153 #define PCL_INSTANTIATE_BilateralUpsampling(T,OutT) template class PCL_EXPORTS pcl::BilateralUpsampling<T,OutT>;
00154 
00155 
00156 #endif /* PCL_SURFACE_IMPL_BILATERAL_UPSAMPLING_H_ */


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:14:40