sequential_fitter.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2012-, Open Perception, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder(s) nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * 
00035  *
00036  */
00037 
00038 #ifndef SEQUENTIAL_FITTER_H
00039 #define SEQUENTIAL_FITTER_H
00040 
00041 //#include <opencv2/core/core.hpp>
00042 //#include "v4r/TomGine/tgTomGine.h"
00043 //#include "v4r/NurbsConvertion/NurbsConvertion.h"
00044 
00045 // remove multiple #defines from xlib and OpenMesh
00046 #undef True
00047 #undef False
00048 #undef None
00049 #undef Status
00050 
00051 #include <pcl/surface/on_nurbs/fitting_surface_pdm.h>
00052 #include <pcl/surface/on_nurbs/nurbs_data.h>
00053 
00054 #include <pcl/pcl_base.h>
00055 #include <pcl/point_types.h>
00056 
00057 //#include "v4r/NurbsConvertion/DataLoading.h"
00058 
00059 namespace pcl
00060 {
00061   namespace on_nurbs
00062   {
00063     class SequentialFitter
00064     {
00065       public:
00066         struct Parameter
00067         {
00068           int order;
00069           int refinement;
00070           int iterationsQuad;
00071           int iterationsBoundary;
00072           int iterationsAdjust;
00073           int iterationsInterior;
00074           double forceBoundary;
00075           double forceBoundaryInside;
00076           double forceInterior;
00077           double stiffnessBoundary;
00078           double stiffnessInterior;
00079           int resolution;
00080           Parameter (int order = 3, int refinement = 1, int iterationsQuad = 5, int iterationsBoundary = 5,
00081                      int iterationsAdjust = 5, int iterationsInterior = 2, double forceBoundary = 200.0,
00082                      double forceBoundaryInside = 400.0, double forceInterior = 1.0, double stiffnessBoundary = 20.0,
00083                      double stiffnessInterior = 0.1, int resolution = 16);
00084         };
00085 
00086       private:
00087         Parameter m_params;
00088 
00089         NurbsDataSurface m_data;
00090         ON_NurbsSurface m_nurbs;
00091 
00092         ON_3dPoint m_corners[4];
00093         pcl::PointCloud<pcl::PointXYZRGB>::Ptr m_cloud;
00094         pcl::PointIndices::Ptr m_boundary_indices;
00095         pcl::PointIndices::Ptr m_interior_indices;
00096 
00097         Eigen::Matrix4d m_intrinsic;
00098         Eigen::Matrix4d m_extrinsic;
00099 
00100         bool m_have_cloud;
00101         bool m_have_corners;
00102 
00103         int m_surf_id;
00104 
00105         void
00106         compute_quadfit ();
00107         void
00108         compute_refinement (FittingSurface* fitting);
00109         void
00110         compute_boundary (FittingSurface* fitting);
00111         void
00112         compute_interior (FittingSurface* fitting);
00113 
00114         Eigen::Vector2d
00115         project (const Eigen::Vector3d &pt);
00116 
00117         bool
00118         is_back_facing (const Eigen::Vector3d &v0, 
00119                         const Eigen::Vector3d &v1, 
00120                         const Eigen::Vector3d &v2,
00121                         const Eigen::Vector3d &v3);
00122 
00123       public:
00124         SequentialFitter (Parameter p = Parameter ());
00125 
00126         inline void
00127         setParams (const Parameter &p)
00128         {
00129           m_params = p;
00130         }
00131 
00133         void
00134         setInputCloud (pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pcl_cloud);
00135 
00137         void
00138         setBoundary (pcl::PointIndices::Ptr &pcl_cloud_indices);
00139 
00141         void
00142         setInterior (pcl::PointIndices::Ptr &pcl_cloud_indices);
00143 
00145         void
00146         setCorners (pcl::PointIndices::Ptr &corners, bool flip_on_demand = true);
00147 
00151         void
00152         setProjectionMatrix (const Eigen::Matrix4d &intrinsic, 
00153                              const Eigen::Matrix4d &extrinsic);
00154 
00156         ON_NurbsSurface
00157         compute (bool assemble = false);
00158 
00161         ON_NurbsSurface
00162         compute_boundary (const ON_NurbsSurface &nurbs);
00163 
00166         ON_NurbsSurface
00167         compute_interior (const ON_NurbsSurface &nurbs);
00168 
00170         inline ON_NurbsSurface
00171         getNurbs ()
00172         {
00173           return m_nurbs;
00174         }
00175 
00177         void
00178         getInteriorError (std::vector<double> &error);
00179 
00181         void
00182         getBoundaryError (std::vector<double> &error);
00183 
00185         void
00186         getInteriorParams (std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d> > &params);
00187 
00189         void
00190         getBoundaryParams (std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d> > &params);
00191 
00193         void
00194         getInteriorNormals (std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &normal);
00195 
00197         void
00198         getBoundaryNormals (std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &normals);
00199 
00206         static void
00207         getClosestPointOnNurbs (ON_NurbsSurface nurbs, 
00208                                 const Eigen::Vector3d &pt, 
00209                                 Eigen::Vector2d& params, 
00210                                 int maxSteps = 100,
00211                                 double accuracy = 1e-4);
00212 
00214         ON_NurbsSurface
00215         grow (float max_dist = 1.0f, float max_angle = M_PI_4, unsigned min_length = 0, unsigned max_length = 10);
00216 
00218         static unsigned
00219         PCL2ON (pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pcl_cloud, const std::vector<int> &indices, vector_vec3d &cloud);
00220 
00221       public:
00222         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00223     };
00224 
00225   }
00226 }
00227 
00228 #endif


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