best_fit.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2007                                                    *
00003  *   Joachim Zettler <Joachim.Zettler@gmx.de>                              *
00004  *   Human Rezai <human@mytum.de>                                          *
00005  *                                                                         *
00006  *   This file is part of the FreeCAD CAx development system.              *
00007  *                                                                         *
00008  *   This library is free software; you can redistribute it and/or         *
00009  *   modify it under the terms of the GNU Library General Public           *
00010  *   License as published by the Free Software Foundation; either          *
00011  *   version 2 of the License, or (at your option) any later version.      *
00012  *                                                                         *
00013  *   This library  is distributed in the hope that it will be useful,      *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU Library General Public License for more details.                  *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU Library General Public     *
00019  *   License along with this library; see the file COPYING.LIB. If not,    *
00020  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00021  *   Suite 330, Boston, MA  02111-1307, USA                                *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #ifndef BEST_FIT_H
00026 #define BEST_FIT_H
00027 
00028 
00029 #include <Mod/Mesh/App/Core/Approximation.h>
00030 #include <Mod/Mesh/App/Core/Evaluation.h>
00031 #include <Mod/Mesh/App/Core/MeshKernel.h>
00032 #include <Base/Exception.h>
00033 #include <gp_Vec.hxx>
00034 #include <TopoDS_Shape.hxx>
00035 #include <TopoDS_Face.hxx>
00036 #include <SMESH_Mesh.hxx>
00037 #include <SMDS_VolumeTool.hxx>
00038 
00039 
00040 #define SMALL_NUM  1e-6
00041 #define ERR_TOL    0.001       // Abbruchkriterium für Least-Square-Matching (Fehleränderung zweier aufeinanderfolgenden Iterationsschritten)
00042 
00043 
00053 class CamExport best_fit
00054 {
00055 public:
00056     best_fit();
00057     ~best_fit();
00058 
00064     void Load(const MeshCore::MeshKernel &InputMesh, const TopoDS_Shape &CAD_Shape);
00065 
00066     bool Initialize_Mesh_Geometrie_1();
00067     bool Initialize_Mesh_Geometrie_2();
00068 
00072     bool MeshFit_Coarse();
00073 
00077     bool ShapeFit_Coarse();
00078 
00082     bool PointCloud_Coarse();
00083 
00085     bool Perform();
00086 
00088     bool Perform_PointCloud();
00089 
00090     bool output_best_fit_mesh();
00091 
00092     //double CompError(std::vector<Base::Vector3f> &pnts, std::vector<Base::Vector3f> &normals);
00093     //double CompError(std::vector<Base::Vector3f> &pnts, std::vector<Base::Vector3f> &normals, bool plot);
00094 
00095     //std::vector<double> CompError_GetPnts(std::vector<Base::Vector3f> pnts,
00096     //                                     std::vector<Base::Vector3f> &normals);
00097 
00101     double CompTotalError();
00102 
00107     double CompTotalError(MeshCore::MeshKernel &mesh);
00108         
00116     static bool Tesselate_Shape(const TopoDS_Shape &shape, MeshCore::MeshKernel &mesh, float deflection);
00117         
00125     static bool Tesselate_Face (const TopoDS_Face  &aface, MeshCore::MeshKernel &mesh, float deflection);
00126 
00132     static std::vector<Base::Vector3f> Comp_Normals(MeshCore::MeshKernel &Mesh);
00133         
00137     bool Coarse_correction();
00138 
00142     double ANN();
00143 
00145     TopoDS_Shape m_Cad;              // CAD-Geometrie
00146 
00148     MeshCore::MeshKernel m_Mesh;     // das zu fittende Netz
00149 
00151     MeshCore::MeshKernel m_MeshWork;
00152 
00154     MeshCore::MeshKernel m_CadMesh;  // Netz aus CAD-Triangulierung
00155 
00156 
00157         std::vector<Base::Vector3f> m_pntCloud_1;
00158         std::vector<Base::Vector3f> m_pntCloud_2;
00159 
00160 
00162     std::vector<Base::Vector3f> m_pnts;
00163 
00165     std::vector<Base::Vector3f> m_normals;
00166 
00168     std::vector<double>         m_error;
00169 
00171     std::vector<std::vector<Base::Vector3f> > m_LSPnts;  // zu fittende Punktesätze für den Least-Square
00172 
00174     std::vector<double> m_weights;                       // gewichtungen für den Least-Square bzgl. allen Netzpunkte
00175 
00177     std::vector<double> m_weights_loc;                   // gewichtungen für den Least-Square bzgl. den projezierten Netzpunkten
00178 
00180     gp_Vec m_cad2orig;                     // Translationsvektor welche die CAD-Geometrie um den Ursprung zentriert
00181     
00183     std::vector<TopoDS_Face> m_LowFaces;   // Vektor der in der GUI selektierten Faces mit geringer Gewichtung
00184 
00185 private:
00193     inline bool RotMat(Base::Matrix4D &matrix, double degree, int rotationAxis);
00194         
00202     inline bool TransMat(Base::Matrix4D &matrix, double translation, int translationAxis);
00203         
00211     inline bool PointNormalTransform(std::vector<Base::Vector3f> &pnts,
00212                                      std::vector<Base::Vector3f> &normals,
00213                                      Base::Matrix4D              &M);
00214         
00220     bool PointTransform(std::vector<Base::Vector3f> &pnts, const Base::Matrix4D &M);
00221         
00223     bool Comp_Weights();
00224 
00226     bool LSM();
00227 
00234     std::vector<double> Comp_Jacobi(const std::vector<double> &params);
00235 
00243     std::vector<std::vector<double> > Comp_Hess (const std::vector<double> &params);
00244 
00245     SMESH_Mesh *m_referencemesh;
00246     SMESH_Mesh *m_meshtobefit;
00247     SMESH_Gen *m_aMeshGen1;
00248     SMESH_Gen *m_aMeshGen2;
00249 
00250         
00251     
00252         //int intersect_RayTriangle(const Base::Vector3f &normal,const MeshCore::MeshGeomFacet &T, Base::Vector3f &P, Base::Vector3f &I);
00253         // bool Intersect(const Base::Vector3f &normal,const MeshCore::MeshKernel &mesh, Base::Vector3f &P, Base::Vector3f &I);
00254 };
00255 
00256 #endif

Generated on Wed Nov 23 18:59:58 2011 for FreeCAD by  doxygen 1.6.1