0026106: BRepMesh - revision of data model
[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   initParameters();
91
92   Handle(BRepMesh_Context) aContext = new BRepMesh_Context;
93   aContext->SetShape(Shape());
94   aContext->ChangeParameters()            = myParameters;
95   aContext->ChangeParameters().CleanModel = Standard_False;
96
97   IMeshTools_MeshBuilder aIncMesh(aContext);
98   aIncMesh.Perform();
99
100   myStatus = IMeshData_NoError;
101   const Handle(IMeshData_Model)& aModel = aContext->GetModel();
102   for (Standard_Integer aFaceIt = 0; aFaceIt < aModel->FacesNb(); ++aFaceIt)
103   {
104     const IMeshData::IFaceHandle& aDFace = aModel->GetFace(aFaceIt);
105     myStatus |= aDFace->GetStatusMask();
106
107     for (Standard_Integer aWireIt = 0; aWireIt < aDFace->WiresNb(); ++aWireIt)
108     {
109       const IMeshData::IWireHandle& aDWire = aDFace->GetWire(aWireIt);
110       myStatus |= aDWire->GetStatusMask();
111     }
112   }
113
114   setDone();
115 }
116
117 //=======================================================================
118 //function : Discret
119 //purpose  :
120 //=======================================================================
121 Standard_Integer BRepMesh_IncrementalMesh::Discret(
122   const TopoDS_Shape&    theShape,
123   const Standard_Real    theDeflection,
124   const Standard_Real    theAngle,
125   BRepMesh_DiscretRoot* &theAlgo)
126 {
127   BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh();
128   anAlgo->ChangeParameters().Deflection = theDeflection;
129   anAlgo->ChangeParameters().Angle      = theAngle;
130   anAlgo->ChangeParameters().InParallel = IS_IN_PARALLEL;
131   anAlgo->SetShape (theShape);
132   theAlgo = anAlgo;
133   return 0; // no error
134 }
135
136 //=======================================================================
137 //function : IsParallelDefault
138 //purpose  :
139 //=======================================================================
140 Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault()
141 {
142   return IS_IN_PARALLEL;
143 }
144
145 //=======================================================================
146 //function : Discret
147 //purpose  :
148 //=======================================================================
149 void BRepMesh_IncrementalMesh::SetParallelDefault(
150   const Standard_Boolean theInParallel)
151 {
152   IS_IN_PARALLEL = theInParallel;
153 }
154
155 //! Export Mesh Plugin entry function
156 DISCRETPLUGIN(BRepMesh_IncrementalMesh)