Algorithm.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Imetric 3D GmbH                                    *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef MESHALGORITHM_H
00025 #define MESHALGORITHM_H
00026 
00027 #include <set>
00028 #include <vector>
00029 #include <map>
00030 
00031 #include "MeshKernel.h"
00032 #include "Elements.h"
00033 #include <Base/Vector3D.h>
00034 
00035 // forward declarations
00036 
00037 namespace Base{
00038   class ViewProjMethod;
00039   class Polygon2D;
00040 }
00041 
00042 namespace MeshCore {
00043 
00044 class MeshGeomFacet;
00045 class MeshGeomEdge;
00046 class MeshKernel;
00047 class MeshFacetGrid;
00048 class MeshFacetArray;
00049 class MeshRefPointToFacets;
00050 class AbstractPolygonTriangulator;
00051 
00055 class MeshExport MeshAlgorithm
00056 {
00057 public:
00059   MeshAlgorithm (const MeshKernel &rclM) : _rclMesh(rclM) { }
00061   ~MeshAlgorithm (void) { }
00062 
00063 public:
00072   bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, Base::Vector3f &rclRes,
00073                           unsigned long &rulFacet) const;
00082   bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const MeshFacetGrid &rclGrid,
00083                           Base::Vector3f &rclRes, unsigned long &rulFacet) const;
00093   bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector<unsigned long> &raulFacets,
00094                           Base::Vector3f &rclRes, unsigned long &rulFacet) const;
00101   bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxSearchArea,
00102                           const MeshFacetGrid &rclGrid, Base::Vector3f &rclRes, unsigned long &rulFacet) const;
00108   bool FirstFacetToVertex(const Base::Vector3f &rclPt, float fMaxDistance, const MeshFacetGrid &rclGrid, unsigned long &rulFacet) const;
00113   bool IsVertexVisible (const Base::Vector3f &rcVertex, const Base::Vector3f &rcView, const MeshFacetGrid &rclGrid ) const;
00117   float GetAverageEdgeLength() const;
00121   void GetMeshBorders (std::list<std::vector<Base::Vector3f> > &rclBorders) const;
00126   void GetMeshBorders (std::list<std::vector<unsigned long> > &rclBorders) const;
00130   void GetFacetBorders (const std::vector<unsigned long> &raulInd, std::list<std::vector<Base::Vector3f> > &rclBorders) const;
00139   void GetFacetBorders (const std::vector<unsigned long> &raulInd, std::list<std::vector<unsigned long> > &rclBorders,
00140                         bool ignoreOrientation = false) const;
00145   void GetMeshBorder(unsigned long uFacet, std::list<unsigned long>& rBorder) const;
00150   void SplitBoundaryLoops( std::list<std::vector<unsigned long> >& aBorders );
00163   bool FillupHole(const std::vector<unsigned long>& boundary,
00164                   AbstractPolygonTriangulator& cTria,
00165                   MeshFacetArray& rFaces, MeshPointArray& rPoints,
00166                   int level, const MeshRefPointToFacets* pP2FStructure=0) const;
00170   void SetFacetsProperty(const std::vector<unsigned long> &raulInds, const std::vector<unsigned long> &raulProps) const;
00172   void SetFacetFlag (MeshFacet::TFlagType tF) const;
00174   void SetPointFlag (MeshPoint::TFlagType tF) const;
00176   void ResetFacetFlag (MeshFacet::TFlagType tF) const;
00178   void ResetPointFlag (MeshPoint::TFlagType tF) const;
00180   void SetFacetsFlag (const std::vector<unsigned long> &raulInds, MeshFacet::TFlagType tF) const;
00182   void SetPointsFlag (const std::vector<unsigned long> &raulInds, MeshPoint::TFlagType tF) const;
00184   void GetFacetsFlag (std::vector<unsigned long> &raulInds, MeshFacet::TFlagType tF) const;
00186   void GetPointsFlag (std::vector<unsigned long> &raulInds, MeshPoint::TFlagType tF) const;
00188   void ResetFacetsFlag (const std::vector<unsigned long> &raulInds, MeshFacet::TFlagType tF) const;
00190   void ResetPointsFlag (const std::vector<unsigned long> &raulInds, MeshPoint::TFlagType tF) const;
00192   unsigned long CountFacetFlag (MeshFacet::TFlagType tF) const;
00194   unsigned long CountPointFlag (MeshPoint::TFlagType tF) const;
00196   void PointsFromFacetsIndices (const std::vector<unsigned long> &rvecIndices, std::vector<Base::Vector3f> &rvecPoints) const;
00204   void GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector<unsigned long> &raclCutted ) const;
00208   void GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, const MeshFacetGrid& rGrid, std::vector<unsigned long> &raclCutted ) const;
00216   int Surround( const Base::BoundBox3f& rBox, const Base::Vector3f& rcDir );
00224   void CheckFacets (const MeshFacetGrid &rclGrid, const Base::ViewProjMethod* pclProj, const Base::Polygon2D& rclPoly,
00225                     bool bInner, std::vector<unsigned long> &rclRes) const;
00229   void CheckFacets (const Base::ViewProjMethod* pclProj, const Base::Polygon2D& rclPoly,
00230                     bool bInner, std::vector<unsigned long> &rclRes) const;
00237   void CheckBorderFacets (const std::vector<unsigned long> &raclFacetIndices, 
00238                           std::vector<unsigned long> &raclResultIndices, unsigned short usLevel = 1) const;
00244   void CutBorderFacets (std::vector<unsigned long> &raclFacetIndices, unsigned short usLevel = 1) const;
00246   unsigned long CountBorderEdges() const;
00250   void GetBorderPoints (const std::vector<unsigned long> &raclFacetIndices, std::set<unsigned long> &raclResultPointsIndices) const;
00252   float Surface (void) const;
00254   void SubSampleByDist  (float fDist, std::vector<Base::Vector3f> &rclPoints) const;
00259   void SubSampleByCount (unsigned long ulCtPoints, std::vector<Base::Vector3f> &rclPoints) const;
00261   void SubSampleAllPoints(std::vector<Base::Vector3f> &rclPoints) const;
00265   void SearchFacetsFromPolyline (const std::vector<Base::Vector3f> &rclPolyline, float fRadius,
00266                                  const MeshFacetGrid& rclGrid, std::vector<unsigned long> &rclResultFacetsIndices) const;
00270   bool NearestPointFromPoint (const Base::Vector3f &rclPt, unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const;
00271   bool NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid,
00272                               unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const;
00273   bool NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid, float fMaxSearchArea,
00274                               unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const;
00276   bool CutWithPlane (const Base::Vector3f &clBase, const Base::Vector3f &clNormal, const MeshFacetGrid &rclGrid,
00277                      std::list<std::vector<Base::Vector3f> > &rclResult, float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const;
00282   void GetFacetsFromPlane (const MeshFacetGrid &rclGrid, const Base::Vector3f& clNormal, float dist, 
00283       const Base::Vector3f &rclLeft, const Base::Vector3f &rclRight, std::vector<unsigned long> &rclRes) const;
00284 
00288   bool Distance (const Base::Vector3f &rclPt, unsigned long ulFacetIdx, float fMaxDistance, float &rfDistance) const;
00293   float CalculateMinimumGridLength(float fLength, const Base::BoundBox3f& rBBox, unsigned long maxElements) const;
00294    
00295 protected:
00297   bool ConnectLines (std::list<std::pair<Base::Vector3f, Base::Vector3f> > &rclLines, std::list<std::vector<Base::Vector3f> >&rclPolylines,
00298                     float fMinEps) const;
00299   bool ConnectPolygons(std::list<std::vector<Base::Vector3f> > &clPolyList, std::list<std::pair<Base::Vector3f,
00300                        Base::Vector3f> > &rclLines) const;
00302   bool RayNearestField (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector<unsigned long> &raulFacets,
00303                         Base::Vector3f &rclRes, unsigned long &rulFacet, float fMaxAngle = F_PI) const;
00307   void SplitBoundaryLoops( const std::vector<unsigned long>& rBound, std::list<std::vector<unsigned long> >& aBorders );
00308 
00309 protected:
00310   const MeshKernel      &_rclMesh; 
00311 };
00312 
00319 class MeshExport MeshRefPointToFacets
00320 {
00321 public:
00323     MeshRefPointToFacets (const MeshKernel &rclM) : _rclMesh(rclM) 
00324     { Rebuild(); }
00326     ~MeshRefPointToFacets (void)
00327     { }
00328 
00330     void Rebuild (void);
00331     const std::set<unsigned long>& operator[] (unsigned long) const;
00332     MeshFacetArray::_TConstIterator getFacet (unsigned long) const;
00333     std::set<unsigned long> NeighbourPoints(const std::vector<unsigned long>& , int level) const;
00334     void Neighbours (unsigned long ulFacetInd, float fMaxDist, std::vector<MeshFacetArray::_TConstIterator> &rclNb);
00335     Base::Vector3f GetNormal(unsigned long) const;
00336 
00337 protected:
00338     void SearchNeighbours(MeshFacetArray::_TConstIterator pFIter, const Base::Vector3f &rclCenter, 
00339         float fMaxDist, std::vector<MeshFacetArray::_TConstIterator> &rclNb);
00340 
00341 protected:
00342     const MeshKernel  &_rclMesh; 
00343     std::vector<std::set<unsigned long> > _map;
00344 };
00345 
00352 class MeshExport MeshRefFacetToFacets
00353 {
00354 public:
00356     MeshRefFacetToFacets (const MeshKernel &rclM) : _rclMesh(rclM)
00357     { Rebuild(); }
00359     ~MeshRefFacetToFacets (void)
00360     { }
00362     void Rebuild (void);
00363 
00366     const std::set<unsigned long>& operator[] (unsigned long) const;
00367 
00368 protected:
00369     const MeshKernel  &_rclMesh; 
00370     std::vector<std::set<unsigned long> > _map;
00371 };
00372 
00379 class MeshExport MeshRefPointToPoints
00380 {
00381 public:
00383     MeshRefPointToPoints (const MeshKernel &rclM) : _rclMesh(rclM) 
00384     { Rebuild(); }
00386     ~MeshRefPointToPoints (void)
00387     { }
00388 
00390     void Rebuild (void);
00391     const std::set<unsigned long>& operator[] (unsigned long) const;
00392     Base::Vector3f GetNormal(unsigned long) const;
00393     float GetAverageEdgeLength(unsigned long) const;
00394 
00395 protected:
00396     const MeshKernel  &_rclMesh; 
00397     std::vector<std::set<unsigned long> > _map;
00398 };
00399 
00406 class MeshExport MeshRefEdgeToFacets
00407 {
00408 public:
00410     MeshRefEdgeToFacets (const MeshKernel &rclM) : _rclMesh(rclM) 
00411     { Rebuild(); }
00413     ~MeshRefEdgeToFacets (void)
00414     { }
00415 
00417     void Rebuild (void);
00418     const std::pair<unsigned long, unsigned long>& operator[] (const MeshEdge&) const;
00419 
00420 protected:
00421     class EdgeOrder {
00422     public:
00423         bool operator () (const MeshEdge &e1, const MeshEdge &e2) const
00424         {
00425             if (e1.first < e2.first)
00426                 return true;
00427             else if (e1.first > e2.first)
00428                 return false;
00429             else if (e1.second < e2.second)
00430                 return true;
00431             else
00432                 return false;
00433         }
00434     };
00435     typedef std::pair<unsigned long, unsigned long> MeshFacetPair;
00436     const MeshKernel  &_rclMesh; 
00437     std::map<MeshEdge, MeshFacetPair, EdgeOrder> _map;
00438 };
00439 
00445 class MeshExport MeshRefNormalToPoints
00446 {
00447 public:
00449     MeshRefNormalToPoints (const MeshKernel &rclM) : _rclMesh(rclM) 
00450     { Rebuild(); }
00452     ~MeshRefNormalToPoints (void)
00453     { }
00454 
00456     void Rebuild (void);
00457     const Base::Vector3f& operator[] (unsigned long) const;
00458 
00459 protected:
00460     const MeshKernel  &_rclMesh; 
00461     std::vector<Base::Vector3f> _norm;
00462 };
00463 
00464 }; // namespace MeshCore 
00465 
00466 #endif  // MESH_ALGORITHM_H 

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