0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BRepMesh / BRepMesh_IncrementalMesh.cxx
1 // Created on: 1995-06-20
2 // Created by: Stagiaire Alain JOURDAIN
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepMesh_IncrementalMesh.hxx>
18 #include <BRepMesh_Context.hxx>
19 #include <BRepMesh_PluginMacro.hxx>
20 #include <IMeshData_Status.hxx>
21 #include <IMeshData_Face.hxx>
22 #include <IMeshData_Wire.hxx>
23 #include <IMeshTools_MeshBuilder.hxx>
24
25 namespace
26 {
27   //! Default flag to control parallelization for BRepMesh_IncrementalMesh
28   //! tool returned for Mesh Factory
29   static Standard_Boolean IS_IN_PARALLEL = Standard_False;
30 }
31
32 //=======================================================================
33 //function : Default constructor
34 //purpose  : 
35 //=======================================================================
36 BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh()
37 : myModified(Standard_False),
38   myStatus(IMeshData_NoError)
39 {
40 }
41
42 //=======================================================================
43 //function : Constructor
44 //purpose  : 
45 //=======================================================================
46 BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( const TopoDS_Shape&    theShape,
47                                                     const Standard_Real    theLinDeflection,
48                                                     const Standard_Boolean isRelative,
49                                                     const Standard_Real    theAngDeflection,
50                                                     const Standard_Boolean isInParallel)
51 : myModified(Standard_False),
52   myStatus(IMeshData_NoError)
53 {
54   myParameters.Deflection = theLinDeflection;
55   myParameters.Angle      = theAngDeflection;
56   myParameters.Relative   = isRelative;
57   myParameters.InParallel = isInParallel;
58
59   myShape = theShape;
60   Perform();
61 }
62
63 //=======================================================================
64 //function : Constructor
65 //purpose  : 
66 //=======================================================================
67 BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh(
68   const TopoDS_Shape&          theShape,
69   const IMeshTools_Parameters& theParameters)
70   : myParameters(theParameters)
71 {
72   myShape = theShape;
73   Perform();
74 }
75
76 //=======================================================================
77 //function : Destructor
78 //purpose  : 
79 //=======================================================================
80 BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh()
81 {
82 }
83
84 //=======================================================================
85 //function : Perform
86 //purpose  : 
87 //=======================================================================
88 void BRepMesh_IncrementalMesh::Perform()
89 {
90   Handle(BRepMesh_Context) aContext = new BRepMesh_Context;
91   Perform (aContext);
92 }
93
94 //=======================================================================
95 //function : Perform
96 //purpose  : 
97 //=======================================================================
98 void BRepMesh_IncrementalMesh::Perform(const Handle(IMeshTools_Context)& theContext)
99 {
100   initParameters();
101
102   theContext->SetShape(Shape());
103   theContext->ChangeParameters()            = myParameters;
104   theContext->ChangeParameters().CleanModel = Standard_False;
105
106   IMeshTools_MeshBuilder aIncMesh(theContext);
107   aIncMesh.Perform();
108
109   myStatus = IMeshData_NoError;
110   const Handle(IMeshData_Model)& aModel = theContext->GetModel();
111   if (!aModel.IsNull())
112   {
113     for (Standard_Integer aFaceIt = 0; aFaceIt < aModel->FacesNb(); ++aFaceIt)
114     {
115       const IMeshData::IFaceHandle& aDFace = aModel->GetFace(aFaceIt);
116       myStatus |= aDFace->GetStatusMask();
117
118       for (Standard_Integer aWireIt = 0; aWireIt < aDFace->WiresNb(); ++aWireIt)
119       {
120         const IMeshData::IWireHandle& aDWire = aDFace->GetWire(aWireIt);
121         myStatus |= aDWire->GetStatusMask();
122       }
123     }
124   }
125
126   setDone();
127 }
128
129 //=======================================================================
130 //function : Discret
131 //purpose  :
132 //=======================================================================
133 Standard_Integer BRepMesh_IncrementalMesh::Discret(
134   const TopoDS_Shape&    theShape,
135   const Standard_Real    theDeflection,
136   const Standard_Real    theAngle,
137   BRepMesh_DiscretRoot* &theAlgo)
138 {
139   BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh();
140   anAlgo->ChangeParameters().Deflection = theDeflection;
141   anAlgo->ChangeParameters().Angle      = theAngle;
142   anAlgo->ChangeParameters().InParallel = IS_IN_PARALLEL;
143   anAlgo->SetShape (theShape);
144   theAlgo = anAlgo;
145   return 0; // no error
146 }
147
148 //=======================================================================
149 //function : IsParallelDefault
150 //purpose  :
151 //=======================================================================
152 Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault()
153 {
154   return IS_IN_PARALLEL;
155 }
156
157 //=======================================================================
158 //function : Discret
159 //purpose  :
160 //=======================================================================
161 void BRepMesh_IncrementalMesh::SetParallelDefault(
162   const Standard_Boolean theInParallel)
163 {
164   IS_IN_PARALLEL = theInParallel;
165 }
166
167 //! Export Mesh Plugin entry function
168 DISCRETPLUGIN(BRepMesh_IncrementalMesh)