Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:14

0001 // Created on: 2016-07-07
0002 // Copyright (c) 2016 OPEN CASCADE SAS
0003 // Created by: Oleg AGASHIN
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BRepMesh_DelaunayNodeInsertionMeshAlgo_HeaderFile
0017 #define _BRepMesh_DelaunayNodeInsertionMeshAlgo_HeaderFile
0018 
0019 #include <BRepMesh_NodeInsertionMeshAlgo.hxx>
0020 #include <BRepMesh_GeomTool.hxx>
0021 
0022 //! Extends base Delaunay meshing algo in order to enable possibility 
0023 //! of addition of free vertices and internal nodes into the mesh.
0024 template<class RangeSplitter, class BaseAlgo>
0025 class BRepMesh_DelaunayNodeInsertionMeshAlgo : public BRepMesh_NodeInsertionMeshAlgo<RangeSplitter, BaseAlgo>
0026 {
0027 private:
0028   // Typedef for OCCT RTTI
0029   typedef BRepMesh_NodeInsertionMeshAlgo<RangeSplitter, BaseAlgo> InsertionBaseClass;
0030 
0031 public:
0032 
0033   //! Constructor.
0034   BRepMesh_DelaunayNodeInsertionMeshAlgo()
0035     : myIsPreProcessSurfaceNodes (Standard_False)
0036   {
0037   }
0038 
0039   //! Destructor.
0040   virtual ~BRepMesh_DelaunayNodeInsertionMeshAlgo()
0041   {
0042   }
0043 
0044   //! Returns PreProcessSurfaceNodes flag. 
0045   Standard_Boolean IsPreProcessSurfaceNodes () const
0046   {
0047     return myIsPreProcessSurfaceNodes;
0048   }
0049 
0050   //! Sets PreProcessSurfaceNodes flag.
0051   //! If TRUE, registers surface nodes before generation of base mesh.
0052   //! If FALSE, inserts surface nodes after generation of base mesh. 
0053   void SetPreProcessSurfaceNodes (const Standard_Boolean isPreProcessSurfaceNodes)
0054   {
0055     myIsPreProcessSurfaceNodes = isPreProcessSurfaceNodes;
0056   }
0057 
0058 protected:
0059 
0060   //! Performs initialization of data structure using existing model data.
0061   virtual Standard_Boolean initDataStructure() Standard_OVERRIDE
0062   {
0063     if (!InsertionBaseClass::initDataStructure())
0064     {
0065       return Standard_False;
0066     }
0067 
0068     if (myIsPreProcessSurfaceNodes)
0069     {
0070       const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes =
0071         this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters());
0072 
0073       registerSurfaceNodes (aSurfaceNodes);
0074     }
0075 
0076     return Standard_True;
0077   }
0078 
0079   //! Returns size of cell to be used by acceleration circles grid structure.
0080   virtual std::pair<Standard_Integer, Standard_Integer> getCellsCount (const Standard_Integer theVerticesNb) Standard_OVERRIDE
0081   {
0082     return BRepMesh_GeomTool::CellsCount (this->getDFace()->GetSurface(), theVerticesNb,
0083                                           this->getDFace()->GetDeflection(),
0084                                           &this->getRangeSplitter());
0085   }
0086 
0087   //! Performs processing of generated mesh. Generates surface nodes and inserts them into structure.
0088   virtual void postProcessMesh (BRepMesh_Delaun& theMesher,
0089                                 const Message_ProgressRange& theRange) Standard_OVERRIDE
0090   {
0091     if (!theRange.More())
0092     {
0093       return;
0094     }
0095     InsertionBaseClass::postProcessMesh (theMesher, Message_ProgressRange()); // shouldn't be range passed here?
0096 
0097     if (!myIsPreProcessSurfaceNodes)
0098     {
0099       const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes =
0100         this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters());
0101 
0102       insertNodes(aSurfaceNodes, theMesher, theRange);
0103     }
0104   }
0105 
0106   //! Inserts nodes into mesh.
0107   Standard_Boolean insertNodes(
0108     const Handle(IMeshData::ListOfPnt2d)& theNodes,
0109     BRepMesh_Delaun&                      theMesher,
0110     const Message_ProgressRange&          theRange)
0111   {
0112     if (theNodes.IsNull() || theNodes->IsEmpty())
0113     {
0114       return Standard_False;
0115     }
0116 
0117     IMeshData::VectorOfInteger aVertexIndexes(theNodes->Size(), this->getAllocator());
0118     IMeshData::ListOfPnt2d::Iterator aNodesIt(*theNodes);
0119     for (Standard_Integer aNodeIt = 1; aNodesIt.More(); aNodesIt.Next(), ++aNodeIt)
0120     {
0121       const gp_Pnt2d& aPnt2d = aNodesIt.Value();
0122       if (this->getClassifier()->Perform(aPnt2d) == TopAbs_IN)
0123       {
0124         aVertexIndexes.Append(this->registerNode(this->getRangeSplitter().Point(aPnt2d),
0125                                                  aPnt2d, BRepMesh_Free, Standard_False));
0126       }
0127     }
0128 
0129     theMesher.AddVertices (aVertexIndexes, theRange);
0130     if (!theRange.More())
0131     {
0132       return Standard_False;
0133     }
0134     return !aVertexIndexes.IsEmpty();
0135   }
0136 
0137 private:
0138   
0139   //! Registers surface nodes in data structure.
0140   Standard_Boolean registerSurfaceNodes(
0141     const Handle(IMeshData::ListOfPnt2d)& theNodes)
0142   {
0143     if (theNodes.IsNull() || theNodes->IsEmpty())
0144     {
0145       return Standard_False;
0146     }
0147 
0148     Standard_Boolean isAdded = Standard_False;
0149     IMeshData::ListOfPnt2d::Iterator aNodesIt(*theNodes);
0150     for (Standard_Integer aNodeIt = 1; aNodesIt.More(); aNodesIt.Next(), ++aNodeIt)
0151     {
0152       const gp_Pnt2d& aPnt2d = aNodesIt.Value();
0153       if (this->getClassifier()->Perform(aPnt2d) == TopAbs_IN)
0154       {
0155         isAdded = Standard_True;
0156         this->registerNode(this->getRangeSplitter().Point(aPnt2d),
0157                            aPnt2d, BRepMesh_Free, Standard_False);
0158       }
0159     }
0160 
0161     return isAdded;
0162   }
0163 
0164 private:
0165 
0166   Standard_Boolean myIsPreProcessSurfaceNodes;
0167 };
0168 
0169 #endif