PLearn 0.1
geometry.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // geometry.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: geometry.h,v 1.9 2005/03/04 21:02:57 lamblinp Exp $ 
00037    ******************************************************* */
00038 
00039 // Authors: Pascal Lamblin
00040 
00044 #ifndef geometry_INC
00045 #define geometry_INC
00046 
00047 #include <plearn/math/TMat_maths.h>
00048 #include <plearn/math/random.h>
00049 #include "SurfaceMesh.h"
00050 #include <plearn_learners/nearest_neighbors/BallTreeNearestNeighbors.h>
00051 //#include "../balltrees/BTreeLearner.h"
00052 
00053 namespace PLearn {
00054 using namespace std;
00055 
00056 typedef enum {FACE, VERTEX1, VERTEX2, VERTEX3, EDGE1, EDGE2, EDGE3} TriType;
00057 
00058 Vec fixedAnglesFromRotation( const Mat& m );
00059 
00060 Mat rotationFromFixedAngles( real rx, real ry, real rz );
00061 
00062 Mat rotationFromAxisAngle( Vec& K, real th );
00063 
00064 void transformPoints( const Mat& rot, const Vec& trans,
00065                       const Mat& points_in, Mat& points_out );
00066 
00067 void transformMesh( const Mat& rot, const Vec& trans, SurfMesh& sm );
00068 
00069 void weightedTransformationFromMatchedPoints( const Mat& mp, const Mat& sp,
00070                                               const Vec& weights, Mat& rot,
00071                                               Vec& trans, real& error );
00072 
00073 Vec weightedCentroid( const Mat& pts, const Vec& weights );
00074 
00075 Mat weightedRotationFromMatchedPoints( const Mat& mp, const Mat& sp,
00076                                        const Vec& weights, real& error );
00077 
00078 int jacobi( Mat& a, Vec& d, Mat& v, int& nrot );
00079 
00080 void rotate( Mat& a, int i, int j, int  k, int l,
00081                           const real& s, const real& tau );
00082 
00083 void eigsrt( Vec& d, Mat& v, int n );
00084 
00085 real maxPointMotion( const Mat& old_points, const Mat& new_points );
00086 
00087 real calcNormal( graph& mesh, const vertex_descriptor& vtx, Vec& norm );
00088 
00089 Vec calcNormal( const Vec& v1, const Vec& v2, const Vec& v3,
00090                 const Vec& n1, const Vec& n2, const Vec& n3,
00091                 const Vec& target);
00092 
00093 
00094 void findSumsFromPts( const graph& mesh, const set<vertex_descriptor>& points,
00095                       Vec& sums );
00096 
00097 void calcPlaneParams(const Vec& sums, Vec& norm, real& d, real& err);
00098 
00099 int getNormFromEigVecs( const Vec& ev, const Mat& e, Vec& norm);
00100 
00101 Vec cross( const Vec& v1, const Vec& v2 );
00102 
00103 Mat randomRotation( real max_angle );
00104 
00105 void randomTransformation( real max_angle, real max_dist,
00106                            Mat& rot, Vec& trans );
00107 
00108 Mat boundingBoxToVertices( const Mat& bbox );
00109 
00110 void getNearestVertex( const Vec& test_pt, const SurfMesh& mesh2,
00111                        const GenericNN& btl,
00112                        int& closest_vertex, Vec& closest_pt,
00113                        real& closest_dist );
00114 
00115 bool isOverlapping( Vec& test_pt,
00116                     Vec& test_normal,
00117                     const SurfMesh& mesh2,
00118                     const TVec< set<int> >& face_cache,
00119                     GenericNN& btl,
00120                     const real init_dist_t,
00121                     const real normal_t, //rads
00122                     int& closest_vertex,
00123                     Vec& closest_pt,
00124                     real& closest_dist );
00125 
00126 bool pointIsInterior( const TriType tri_type, const int m2face,
00127                       const SurfMesh& mesh2 );
00128 
00129 bool closestFacePoint( const Vec& m1pt,
00130                        const set<int>& m2faces,
00131                        const SurfMesh& mesh2,
00132                        const real dist_t,
00133                        Vec& closest_pt,
00134                        real& closest_dist,
00135                        int& closest_face,
00136                        TriType& closest_tri_type );
00137 
00138 bool closestPointOnTriangle( const Vec& p,
00139                              const Vec& v1, const Vec& v2, const Vec& v3,
00140                              const real dist_t, Vec& closest,
00141                              TriType& tri_type, real& dist );
00142 
00143 inline int region1ClosestPoint( const Vec& planep,
00144                                 const Vec& va, const  Vec& vb, const Vec& ea,
00145                                 Vec& closest );
00146 
00147 inline int region2ClosestPoint( const Vec& planep,
00148                                 const Vec& va, const Vec& vb, const Vec& vc,
00149                                 const Vec& ea, const Vec& eb, Vec closest );
00150 
00151 
00152 } // end of namespace PLearn
00153 
00154 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines