0030827: Add common functionality allowing to switch triangulation algorithm in runtime
[occt.git] / src / BRepMesh / BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx
CommitLineData
7bd071ed 1// Created on: 2016-07-07
2// Copyright (c) 2016 OPEN CASCADE SAS
3// Created by: Oleg AGASHIN
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _BRepMesh_DelaunayNodeInsertionMeshAlgo_HeaderFile
17#define _BRepMesh_DelaunayNodeInsertionMeshAlgo_HeaderFile
18
19#include <BRepMesh_NodeInsertionMeshAlgo.hxx>
20#include <BRepMesh_GeomTool.hxx>
21
22//! Extends base Delaunay meshing algo in order to enable possibility
23//! of addition of free vertices and internal nodes into the mesh.
4c04741d 24template<class RangeSplitter, class BaseAlgo>
25class BRepMesh_DelaunayNodeInsertionMeshAlgo : public BRepMesh_NodeInsertionMeshAlgo<RangeSplitter, BaseAlgo>
7bd071ed 26{
27private:
28 // Typedef for OCCT RTTI
4c04741d 29 typedef BRepMesh_NodeInsertionMeshAlgo<RangeSplitter, BaseAlgo> InsertionBaseClass;
7bd071ed 30
31public:
32
33 //! Constructor.
34 BRepMesh_DelaunayNodeInsertionMeshAlgo()
4c04741d 35 : myIsPreProcessSurfaceNodes (Standard_False)
7bd071ed 36 {
37 }
38
39 //! Destructor.
40 virtual ~BRepMesh_DelaunayNodeInsertionMeshAlgo()
41 {
42 }
43
4c04741d 44 //! Returns PreProcessSurfaceNodes flag.
45 inline Standard_Boolean IsPreProcessSurfaceNodes () const
46 {
47 return myIsPreProcessSurfaceNodes;
48 }
49
50 //! Sets PreProcessSurfaceNodes flag.
51 //! If TRUE, registers surface nodes before generation of base mesh.
52 //! If FALSE, inserts surface nodes after generation of base mesh.
53 inline void SetPreProcessSurfaceNodes (const Standard_Boolean isPreProcessSurfaceNodes)
54 {
55 myIsPreProcessSurfaceNodes = isPreProcessSurfaceNodes;
56 }
57
7bd071ed 58protected:
59
4c04741d 60 //! Performs initialization of data structure using existing model data.
61 virtual Standard_Boolean initDataStructure() Standard_OVERRIDE
62 {
63 if (!InsertionBaseClass::initDataStructure())
64 {
65 return Standard_False;
66 }
67
68 if (myIsPreProcessSurfaceNodes)
69 {
70 const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes =
71 this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters());
72
73 registerSurfaceNodes (aSurfaceNodes);
74 }
75
76 return Standard_True;
77 }
78
7bd071ed 79 //! Returns size of cell to be used by acceleration circles grid structure.
80 virtual std::pair<Standard_Integer, Standard_Integer> getCellsCount (const Standard_Integer theVerticesNb) Standard_OVERRIDE
81 {
82 return BRepMesh_GeomTool::CellsCount (this->getDFace()->GetSurface(), theVerticesNb,
46478ffe 83 this->getDFace()->GetDeflection(),
84 &this->getRangeSplitter());
7bd071ed 85 }
86
87 //! Perfroms processing of generated mesh. Generates surface nodes and inserts them into structure.
88 virtual void postProcessMesh(BRepMesh_Delaun& theMesher) Standard_OVERRIDE
89 {
90 InsertionBaseClass::postProcessMesh(theMesher);
91
4c04741d 92 if (!myIsPreProcessSurfaceNodes)
93 {
94 const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes =
95 this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters());
7bd071ed 96
4c04741d 97 insertNodes(aSurfaceNodes, theMesher);
98 }
7bd071ed 99 }
100
101 //! Inserts nodes into mesh.
102 Standard_Boolean insertNodes(
103 const Handle(IMeshData::ListOfPnt2d)& theNodes,
104 BRepMesh_Delaun& theMesher)
105 {
106 if (theNodes.IsNull() || theNodes->IsEmpty())
107 {
108 return Standard_False;
109 }
110
111 IMeshData::VectorOfInteger aVertexIndexes(theNodes->Size(), this->getAllocator());
112 IMeshData::ListOfPnt2d::Iterator aNodesIt(*theNodes);
113 for (Standard_Integer aNodeIt = 1; aNodesIt.More(); aNodesIt.Next(), ++aNodeIt)
114 {
115 const gp_Pnt2d& aPnt2d = aNodesIt.Value();
116 if (this->getClassifier()->Perform(aPnt2d) == TopAbs_IN)
117 {
118 aVertexIndexes.Append(this->registerNode(this->getRangeSplitter().Point(aPnt2d),
119 aPnt2d, BRepMesh_Free, Standard_False));
120 }
121 }
122
123 theMesher.AddVertices(aVertexIndexes);
124 return !aVertexIndexes.IsEmpty();
125 }
4c04741d 126
127private:
128
129 //! Registers surface nodes in data structure.
130 Standard_Boolean registerSurfaceNodes(
131 const Handle(IMeshData::ListOfPnt2d)& theNodes)
132 {
133 if (theNodes.IsNull() || theNodes->IsEmpty())
134 {
135 return Standard_False;
136 }
137
138 Standard_Boolean isAdded = Standard_False;
139 IMeshData::ListOfPnt2d::Iterator aNodesIt(*theNodes);
140 for (Standard_Integer aNodeIt = 1; aNodesIt.More(); aNodesIt.Next(), ++aNodeIt)
141 {
142 const gp_Pnt2d& aPnt2d = aNodesIt.Value();
143 if (this->getClassifier()->Perform(aPnt2d) == TopAbs_IN)
144 {
145 isAdded = Standard_True;
146 this->registerNode(this->getRangeSplitter().Point(aPnt2d),
147 aPnt2d, BRepMesh_Free, Standard_False);
148 }
149 }
150
151 return isAdded;
152 }
153
154private:
155
156 Standard_Boolean myIsPreProcessSurfaceNodes;
7bd071ed 157};
158
159#endif