Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-23 09:16:31

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
0026     : public BRepMesh_NodeInsertionMeshAlgo<RangeSplitter, BaseAlgo>
0027 {
0028 private:
0029   // Typedef for OCCT RTTI
0030   typedef BRepMesh_NodeInsertionMeshAlgo<RangeSplitter, BaseAlgo> InsertionBaseClass;
0031 
0032 public:
0033   //! Constructor.
0034   BRepMesh_DelaunayNodeInsertionMeshAlgo()
0035       : myIsPreProcessSurfaceNodes(Standard_False)
0036   {
0037   }
0038 
0039   //! Destructor.
0040   virtual ~BRepMesh_DelaunayNodeInsertionMeshAlgo() {}
0041 
0042   //! Returns PreProcessSurfaceNodes flag.
0043   Standard_Boolean IsPreProcessSurfaceNodes() const { return myIsPreProcessSurfaceNodes; }
0044 
0045   //! Sets PreProcessSurfaceNodes flag.
0046   //! If TRUE, registers surface nodes before generation of base mesh.
0047   //! If FALSE, inserts surface nodes after generation of base mesh.
0048   void SetPreProcessSurfaceNodes(const Standard_Boolean isPreProcessSurfaceNodes)
0049   {
0050     myIsPreProcessSurfaceNodes = isPreProcessSurfaceNodes;
0051   }
0052 
0053 protected:
0054   //! Performs initialization of data structure using existing model data.
0055   virtual Standard_Boolean initDataStructure() Standard_OVERRIDE
0056   {
0057     if (!InsertionBaseClass::initDataStructure())
0058     {
0059       return Standard_False;
0060     }
0061 
0062     if (myIsPreProcessSurfaceNodes)
0063     {
0064       const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes =
0065         this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters());
0066 
0067       registerSurfaceNodes(aSurfaceNodes);
0068     }
0069 
0070     return Standard_True;
0071   }
0072 
0073   //! Returns size of cell to be used by acceleration circles grid structure.
0074   virtual std::pair<Standard_Integer, Standard_Integer> getCellsCount(
0075     const Standard_Integer theVerticesNb) Standard_OVERRIDE
0076   {
0077     return BRepMesh_GeomTool::CellsCount(this->getDFace()->GetSurface(),
0078                                          theVerticesNb,
0079                                          this->getDFace()->GetDeflection(),
0080                                          &this->getRangeSplitter());
0081   }
0082 
0083   //! Performs processing of generated mesh. Generates surface nodes and inserts them into
0084   //! structure.
0085   virtual void postProcessMesh(BRepMesh_Delaun&             theMesher,
0086                                const Message_ProgressRange& theRange) Standard_OVERRIDE
0087   {
0088     if (!theRange.More())
0089     {
0090       return;
0091     }
0092     // clang-format off
0093     InsertionBaseClass::postProcessMesh (theMesher, Message_ProgressRange()); // shouldn't be range passed here?
0094     // clang-format on
0095 
0096     if (!myIsPreProcessSurfaceNodes)
0097     {
0098       const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes =
0099         this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters());
0100 
0101       insertNodes(aSurfaceNodes, theMesher, theRange);
0102     }
0103   }
0104 
0105   //! Inserts nodes into mesh.
0106   Standard_Boolean insertNodes(const Handle(IMeshData::ListOfPnt2d)& theNodes,
0107                                BRepMesh_Delaun&                      theMesher,
0108                                const Message_ProgressRange&          theRange)
0109   {
0110     if (theNodes.IsNull() || theNodes->IsEmpty())
0111     {
0112       return Standard_False;
0113     }
0114 
0115     IMeshData::VectorOfInteger       aVertexIndexes(theNodes->Size(), this->getAllocator());
0116     IMeshData::ListOfPnt2d::Iterator aNodesIt(*theNodes);
0117     for (Standard_Integer aNodeIt = 1; aNodesIt.More(); aNodesIt.Next(), ++aNodeIt)
0118     {
0119       const gp_Pnt2d& aPnt2d = aNodesIt.Value();
0120       if (this->getClassifier()->Perform(aPnt2d) == TopAbs_IN)
0121       {
0122         aVertexIndexes.Append(this->registerNode(this->getRangeSplitter().Point(aPnt2d),
0123                                                  aPnt2d,
0124                                                  BRepMesh_Free,
0125                                                  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   //! Registers surface nodes in data structure.
0139   Standard_Boolean registerSurfaceNodes(const Handle(IMeshData::ListOfPnt2d)& theNodes)
0140   {
0141     if (theNodes.IsNull() || theNodes->IsEmpty())
0142     {
0143       return Standard_False;
0144     }
0145 
0146     Standard_Boolean                 isAdded = Standard_False;
0147     IMeshData::ListOfPnt2d::Iterator aNodesIt(*theNodes);
0148     for (Standard_Integer aNodeIt = 1; aNodesIt.More(); aNodesIt.Next(), ++aNodeIt)
0149     {
0150       const gp_Pnt2d& aPnt2d = aNodesIt.Value();
0151       if (this->getClassifier()->Perform(aPnt2d) == TopAbs_IN)
0152       {
0153         isAdded = Standard_True;
0154         this->registerNode(this->getRangeSplitter().Point(aPnt2d),
0155                            aPnt2d,
0156                            BRepMesh_Free,
0157                            Standard_False);
0158       }
0159     }
0160 
0161     return isAdded;
0162   }
0163 
0164 private:
0165   Standard_Boolean myIsPreProcessSurfaceNodes;
0166 };
0167 
0168 #endif