SpringbackCorrection.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2007                                                    *
00003  *   Joachim Zettler <Joachim.Zettler@gmx.de>                              *
00004  *   Human Rezai <Human@web.de>                                            *
00005  *   This file is part of the FreeCAD CAx development system.              *
00006  *                                                                         *
00007  *   This library is free software; you can redistribute it and/or         *
00008  *   modify it under the terms of the GNU Library General Public           *
00009  *   License as published by the Free Software Foundation; either          *
00010  *   version 2 of the License, or (at your option) any later version.      *
00011  *                                                                         *
00012  *   This library  is distributed in the hope that it will be useful,      *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU Library General Public License for more details.                  *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Library General Public     *
00018  *   License along with this library; see the file COPYING.LIB. If not,    *
00019  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00020  *   Suite 330, Boston, MA  02111-1307, USA                                *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #ifndef _SpringbackCorrection_H_
00025 #define _SpringbackCorrection_H_
00026 
00027 
00028 #include <Mod/Mesh/App/Core/TopoAlgorithm.h>
00029 #include "cutting_tools.h"
00030 
00038 class MeshFacet;
00039 
00040 
00041 
00042 
00043 # define cMin    15.0
00044 # define toolRad  5.0
00045 
00054 struct EdgeStruct
00055 {
00056     TopoDS_Edge anEdge;
00057     std::vector<TopoDS_Face> aFace;
00058     std::vector<gp_Pnt> pntList;
00059     double MaxOffset;
00060     double MinOffset;
00061 };
00062 
00072 struct MeshPnt
00073 {
00074     int index;
00075     double minCurv;
00076     double maxCurv;
00077     double error;
00078     Base::Vector3f pnt;
00079     Base::Vector3f normal;
00080 };
00081 
00089 struct FacePnt
00090 {
00091     Base::Vector3f pnt;
00092     std::vector<double> distances;
00093     std::vector<double> MinEdgeOff;
00094     std::vector<double> MaxEdgeOff;
00095 };
00096 
00097 struct EdgeStruct_Less
00098 {
00099     bool operator()(const EdgeStruct& _Left, const EdgeStruct& _Right) const
00100     {
00101 
00102         if (_Left.anEdge.IsSame(_Right.anEdge)) return false;
00103 
00104         return true;
00105     }
00106 };
00107 
00108 struct Edge_Less
00109 {
00110     bool operator()(const TopoDS_Edge& _Left, const TopoDS_Edge& _Right) const
00111     {
00112         return(_Left.HashCode(IntegerLast())<_Right.HashCode(IntegerLast()));
00113     }
00114 };
00115 
00116 
00117 
00118 
00119 struct MeshPntLess
00120 {
00121     bool operator()(const Base::Vector3f& _Left, const Base::Vector3f& _Right) const
00122     {
00123         if ( fabs(_Left.x - _Right.x) > 0.0001 )
00124             return _Left.x < _Right.x;
00125         else if ( fabs(_Left.y - _Right.y) > 0.0001)
00126             return _Left.y < _Right.y;
00127         else if ( fabs(_Left.z - _Right.z) > 0.0001 )
00128             return _Left.z < _Right.z;
00129         return false;
00130 
00131     }
00132 };
00133 
00134 class CamExport SpringbackCorrection : public MeshCore::MeshFacetVisitor
00135 {
00136 public:
00138     SpringbackCorrection();
00144     SpringbackCorrection(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh);
00146     //SpringbackCorrection(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh, const MeshCore::MeshKernel& bMesh);
00147 
00148     ~SpringbackCorrection();
00150     bool Load(const MeshCore::MeshKernel& aMesh);
00152     bool Load(const TopoDS_Shape& aShape);
00154     bool Load(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh);
00158     bool Init();
00160     bool Init_Setting(struct CuttingToolsSettings& set);
00161 
00168     bool Perform(int deg_Tol, bool out);
00169 
00171     bool SetFixEdges();
00174     bool CalcCurv();
00175 
00182     std::vector<double> MeshCurvature(const TopoDS_Face& aFace, const MeshCore::MeshKernel& mesh);
00183 
00187     bool GetCurvature(TopoDS_Face aFace);
00188 
00189     //bool MirrorMesh(std::vector<double> error);
00190     //double LocalCorrection(std::vector<Base::Vector3f> Neib ,std::vector<Base::Vector3f> Normal,
00191     //                       bool sign, double minScale);
00192     //double GlobalCorrection(std::vector<Base::Vector3f> Neib ,std::vector<Base::Vector3f> Normal,
00193     //                        bool sign, int ind);
00194     
00195     //std::vector<Base::Vector3f> FillConvex(std::vector<Base::Vector3f> Neib,std::vector<Base::Vector3f> Normals, int n);
00196     //bool InsideCheck(Base::Vector3f pnt, Base::Vector3f normal, std::vector<Base::Vector3f> Neib);
00197 
00198     //MeshCore::MeshKernel BuildMesh(Handle_Poly_Triangulation aTri, std::vector<Base::Vector3f> TrPoints);
00205     int GetBoundary(const MeshCore::MeshKernel &mesh, MeshCore::MeshPointArray &meshPnts);
00206     //bool SmoothCurvature();
00213     bool SmoothMesh(MeshCore::MeshKernel &mesh, double maxTranslation);
00222     bool SmoothMesh(MeshCore::MeshKernel &mesh, std::vector<int> indicies, double maxTranslation);
00229     //bool GetFaceAng(MeshCore::MeshKernel &mesh, int deg_tol);
00236     std::vector<int> FaceCheck(MeshCore::MeshKernel &mesh, int deg_tol);
00243     std::vector<int> InitFaceCheck(MeshCore::MeshKernel &mesh, int deg_tol);
00244     //void ReorderNeighbourList(std::set<MeshCore::MeshPointArray::_TConstIterator> &pnt,
00245     //                          std::set<MeshCore::MeshFacetArray::_TConstIterator> &face,
00246     //                          std::vector<unsigned long> &nei,
00247     //                          unsigned long CurInd);
00248 
00250     bool FacetRegionGrowing(MeshCore::MeshKernel &mesh,
00251                             std::vector<MeshCore::MeshFacet> &arr,
00252                             MeshCore::MeshFacetArray &mFacets);
00253 
00254     //bool CorrectScale(double max_zVal);
00256     bool Visit(const MeshCore::MeshFacet &rclFacet, const MeshCore::MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
00257         
00263     bool TransferFaceTriangulationtoFreeCAD(const TopoDS_Face& aFace, MeshCore::MeshKernel& TFaceMesh);
00264         
00267     std::vector< std::pair<unsigned long, double> > RegionEvaluate(const MeshCore::MeshKernel &mesh, std::vector<unsigned long> &RegionFacets, std::vector<Base::Vector3f> &normals);
00268     
00270     MeshCore::MeshKernel m_Mesh;
00273     MeshCore::MeshKernel m_Mesh_vis;
00275     MeshCore::MeshKernel m_Mesh_vis2;
00277     MeshCore::MeshKernel m_CadMesh;
00279     std::vector<Base::Vector3f> m_dist_vec;
00280 
00281 private:
00282 
00284     TopoDS_Shape m_Shape;
00287     std::vector<double> m_CurvPos;
00290     std::vector<double> m_CurvNeg;
00292     std::vector<double> m_CurvMax;
00294     std::vector<EdgeStruct> m_EdgeStruct;
00297     std::vector<unsigned long> m_RingVector;
00300     std::vector< std::vector<unsigned long> > m_RegionVector;
00303     std::vector< std::vector<unsigned long> > m_Regions;
00305     //std::vector<MeshCore::MeshFacet> m_RegionBounds;
00307     CuttingToolsSettings m_set;
00310     int m_RingCurrent;
00311 private:
00313     std::vector<MeshCore::MeshKernel> m_MeshVec;
00315     MeshCore::MeshKernel MeshRef;
00317     //MeshCore::MeshKernel m_Mesh2Fit;
00319     std::vector<Base::Vector3f> m_normals;
00322     std::vector<double> m_error;
00324     std::vector<double> m_FaceAng;
00326     std::vector<MeshPnt> m_MeshStruct;
00329     std::vector<double> m_Offset;
00330 public:
00332     std::map<Base::Vector3f,MeshPnt,MeshPntLess > MeshMap;
00334     std::map<TopoDS_Edge, std::vector<double>, Edge_Less> EdgeMap;
00335 
00338     std::vector<TopoDS_Face> m_FixFaces;
00339 };
00340 
00341 #endif

Generated on Wed Nov 23 19:00:41 2011 for FreeCAD by  doxygen 1.6.1