PLearn 0.1
|
00001 %// -*- C++ -*- 00002 00003 // ICP.h 00004 // 00005 // Copyright (C) 2004 Pascal Lamblin 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: ICP.h,v 1.9 2005/12/29 13:44:35 lamblinp Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Pascal Lamblin 00040 00044 #ifndef ICP_INC 00045 #define ICP_INC 00046 00047 #include <plearn/base/Object.h> 00048 #include <plearn/math/pl_math.h> // for MISSING_VALUE 00049 #include <plearn_learners/nearest_neighbors/BallTreeNearestNeighbors.h> 00050 //#include "../balltrees/BTreeLearner.h" 00051 #include "SurfaceMesh.h" 00052 #include "MeshMatch.h" 00053 #include "geometry.h" 00054 00055 namespace PLearn { 00056 using namespace std; 00057 00058 // And now, the ICP class 00059 00060 class ICP: public Object 00061 { 00062 00063 private: 00064 00065 typedef Object inherited; 00066 00067 protected: 00068 // ********************* 00069 // * protected options * 00070 // ********************* 00071 00072 real delta_trans_length; 00073 real delta_angle_length; 00074 real dynamic_dmax0; 00075 00076 public: 00077 00078 // ************************ 00079 // * public build options * 00080 // ************************ 00081 00082 // weighting parameters 00083 // enum Weight_method{ SIGMOID, LORENTZ, DYNAMIC, STATIC }; 00084 string weight_method; 00085 real sigmoid_dmid; 00086 real sigmoid_k; 00087 real lorentz_sigma; 00088 real dynamic_d; 00089 real static_thresh; 00090 00091 // stopping criteria 00092 real error_t; 00093 real dist_t; 00094 real angle_t; 00095 real trans_t; 00096 int max_iter; 00097 00098 // other controls 00099 real normal_t; 00100 real normal_t_deg; 00101 bool area_weight; 00102 bool overlap_filter; 00103 int overlap_delay; 00104 bool smart_overlap; 00105 real smart_overlap_t; 00106 int n_per; 00107 bool fine_matching; 00108 00109 // build parameters 00110 string model_file; 00111 string scene_file; 00112 string output_file; 00113 00114 string initial_transform; 00115 bool read_trans_file; 00116 bool write_trans_file; 00117 string trans_file; 00118 00119 // match 00120 MMatch match; 00121 Mat vtx_matching; 00122 bool write_vtx_match; 00123 bool write_all_vtx_match; 00124 string vtx_match_file; 00125 00126 /* 00127 real tx, ty, tz; 00128 real rx, ry, rz; 00129 */ 00130 SurfMesh model; 00131 SurfMesh scene; 00132 GenericNN btl; 00133 Mat model_features; 00134 Mat scene_features; 00135 00139 int verbosity; 00140 00141 // **************** 00142 // * Constructors * 00143 // **************** 00144 00146 ICP(); 00147 00149 ICP( SurfMesh a_model, SurfMesh a_scene, GenericNN btl_init ); 00150 00152 virtual ~ICP() {} 00153 00154 00155 // ****************** 00156 // * Object methods * 00157 // ****************** 00158 00159 private: 00161 void build_(); 00162 void buildMeshes(); 00163 00164 protected: 00166 static void declareOptions(OptionList& ol); 00167 00168 void meshVertexAreas( const SurfMesh& mesh, Vec& areas ); 00169 00170 real dynamicDistanceThreshold( const Mat model_pts, const Mat scene_pts, 00171 const real d, const real d_max ); 00172 00173 real computeWeightedDistance( const Mat m1_pts, const Mat m2_pts, 00174 const Vec weights ); 00175 00176 void computeWeights( const Mat model_pts, const Mat scene_pts, 00177 const Vec areas, Vec weights, 00178 real& min_wt, real& max_wt ); 00179 00180 bool iterativeReweight( Mat model_pts, const Mat scene_pts, 00181 const Vec areas, Vec weights, 00182 const Mat init_corners, const int max_iter, 00183 Mat total_delta_rot, Vec total_delta_trans ); 00184 00185 // Mat computeVertexMatches(); 00186 real weightOracle( int, Vec, int, Vec ); 00187 00188 public: 00189 // Declares other standard object methods. 00190 PLEARN_DECLARE_OBJECT(ICP); 00191 00192 // simply calls inherited::build() then build_() 00193 virtual void build(); 00194 00196 // (PLEASE IMPLEMENT IN .cc) 00197 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00198 00199 int iterate(); 00200 00201 void run(); 00202 }; 00203 00204 // Declares a few other classes and functions related to this class 00205 DECLARE_OBJECT_PTR(ICP); 00206 00207 } // end of namespace PLearn 00208 00209 #endif