OCC22138 Remove *.gxx files from Mesh algorithm
[occt.git] / src / MeshTest / MeshTest_DrawableMesh.cxx
1 // File:        MeshTest_DrawableMesh.cxx
2 // Created:     Wed Aug  3 18:30:07 1994
3 // Author:      Modeling
4 //              <modeling@bravox>
5
6
7 #include <MeshTest_DrawableMesh.ixx>
8 #include <TopoDS.hxx>
9 #include <Draw.hxx>
10 #include <Draw_ColorKind.hxx>
11 #include <Draw_Color.hxx>
12 #include <TColStd_ListIteratorOfListOfInteger.hxx>
13 #include <Standard_RangeError.hxx>
14 #include <BRepMesh_DegreeOfFreedom.hxx>
15 #include <BRepMesh_Edge.hxx>
16 #include <BRepMesh_Vertex.hxx>
17 #include <BRepMesh_Triangle.hxx>
18 #include <BRepMesh_DataStructureOfDelaun.hxx>
19 #include <Bnd_Box.hxx>
20 #include <BRepBndLib.hxx>
21
22 //=======================================================================
23 //function : MeshTest_DrawableMesh
24 //purpose  : 
25 //=======================================================================
26
27 MeshTest_DrawableMesh::MeshTest_DrawableMesh() :
28 myDeflection(1.), myinshape(Standard_False)
29 {
30 }
31
32 //=======================================================================
33 //function : MeshTest_DrawableMesh
34 //purpose  : 
35 //=======================================================================
36
37 MeshTest_DrawableMesh::MeshTest_DrawableMesh(const TopoDS_Shape&    S,
38                                              const Standard_Real    Deflect,
39                                              const Standard_Boolean Partage,
40                                              const Standard_Boolean inshape) :
41 myDeflection(Deflect), myinshape(inshape)
42 {
43   Bnd_Box B;
44   BRepBndLib::Add(S, B);
45
46   myMesh = new BRepMesh_FastDiscret(Deflect, S, B, 0.5, Partage, inshape);
47 }
48
49
50 //=======================================================================
51 //function : MeshTest_DrawableMesh
52 //purpose  : 
53 //=======================================================================
54
55 MeshTest_DrawableMesh::MeshTest_DrawableMesh(const Handle(BRepMesh_FastDiscret)& Tr):
56 myDeflection(1.0)
57 {
58   myMesh = Tr;
59 }
60
61
62 //=======================================================================
63 //function : MeshTest_DrawableMesh
64 //purpose  : 
65 //=======================================================================
66
67 void MeshTest_DrawableMesh::Add(const TopoDS_Shape& S)
68 {
69   Bnd_Box B;
70   BRepBndLib::Add(S, B);
71
72   if (myMesh.IsNull())
73     myMesh=new BRepMesh_FastDiscret(myDeflection, S, B, 0.5, myinshape);
74   else
75     myMesh->Perform(S);
76 }
77
78 //=======================================================================
79 //function : AddInShape
80 //purpose  : 
81 //=======================================================================
82
83 void MeshTest_DrawableMesh::AddInShape(const Standard_Boolean inshape) 
84 {
85   myinshape = inshape;
86 }
87
88 //=======================================================================
89 //function : DrawOn
90 //purpose  : 
91 //=======================================================================
92
93 void MeshTest_DrawableMesh::DrawOn(Draw_Display& D) const 
94 {
95   // should be reimplemented!!
96   /*  Handle(BRepMesh_DataStructureOfDelaun) struc = myMesh->Result();
97   Standard_Integer nbc;
98   D.SetColor(Draw_vert);
99
100   for (Standard_Integer iLi=1; iLi<=myMesh->NbEdges(); iLi++) {
101   const BRepMesh_Edge& ed=myMesh->Edge(iLi);
102   if (ed.Movability()!=BRepMesh_Deleted) {
103   nbc=struc->ElemConnectedTo(iLi).Extent();
104   if (nbc<=0) D.SetColor(Draw_bleu);
105   else if (nbc==1) D.SetColor(Draw_jaune);
106   else if (nbc==2) D.SetColor(Draw_vert);
107   else D.SetColor(Draw_corail);
108   D.MoveTo(myMesh->Pnt(ed.FirstNode()));
109   D.DrawTo(myMesh->Pnt(ed.LastNode()));
110   }
111   }
112
113
114   // highlighted triangles
115   D.SetColor(Draw_blanc);
116   Standard_Integer e1, e2, e3, i;
117   Standard_Boolean o1, o2, o3;
118
119   for (i = 1; i <= myTriangles.Length(); i++) {
120   const BRepMesh_Triangle& tri=struc->GetElement(myTriangles(i));
121   tri.Edges(e1, e2, e3, o1, o2, o3); 
122   const BRepMesh_Edge& ed1=myMesh->Edge(e1);
123   if (ed1.Movability()!=BRepMesh_Deleted) {
124   D.MoveTo(myMesh->Pnt(ed1.FirstNode()));
125   D.DrawTo(myMesh->Pnt(ed1.LastNode()));
126   }
127   const BRepMesh_Edge& ed2=myMesh->Edge(e2);
128   if (ed2.Movability()!=BRepMesh_Deleted) {
129   D.MoveTo(myMesh->Pnt(ed2.FirstNode()));
130   D.DrawTo(myMesh->Pnt(ed2.LastNode()));
131   }
132   const BRepMesh_Edge& ed3=myMesh->Edge(e3);
133   if (ed3.Movability()!=BRepMesh_Deleted) {
134   D.MoveTo(myMesh->Pnt(ed3.FirstNode()));
135   D.DrawTo(myMesh->Pnt(ed3.LastNode()));
136   }
137   }
138
139   // highlighted edges
140   D.SetColor(Draw_rouge);
141   for (i = 1; i <= myEdges.Length(); i++) {
142   const BRepMesh_Edge& ed=myMesh->Edge(myEdges(i));
143   if (ed.Movability()!=BRepMesh_Deleted) {
144   D.MoveTo(myMesh->Pnt(ed.FirstNode()));
145   D.DrawTo(myMesh->Pnt(ed.LastNode()));
146   }
147   }
148
149   // highlighted vertices
150   for (i = 1; i <= myVertices.Length(); i++) {
151   D.DrawMarker(myMesh->Pnt(myVertices(i)),Draw_Losange);
152   }
153
154   */
155
156 }
157
158 //=======================================================================
159 //function : Copy
160 //purpose  : 
161 //=======================================================================
162
163 Handle(Draw_Drawable3D) MeshTest_DrawableMesh::Copy() const 
164 {
165   Handle(MeshTest_DrawableMesh) D = new MeshTest_DrawableMesh();
166   return  D;
167 }
168
169 //=======================================================================
170 //function : Dump
171 //purpose  : 
172 //=======================================================================
173
174 static void printdegree(BRepMesh_DegreeOfFreedom dof)
175 {
176   switch (dof) {
177   case BRepMesh_InVolume :
178     cout << "InVolume";
179     break;
180   case BRepMesh_OnSurface :
181     cout << "OnSurface";
182     break;
183   case BRepMesh_OnCurve :
184     cout << "OnCurve";
185     break;
186   case BRepMesh_Fixed :
187     cout << "Fixed";
188     break;
189   case BRepMesh_Frontier :
190     cout << "Frontier";
191     break;
192   case BRepMesh_Deleted :
193     cout << "Deleted";
194     break;
195   case BRepMesh_Free :
196     cout << "Free";
197     break;
198   }
199 }
200
201 void MeshTest_DrawableMesh::Dump(Standard_OStream& S) const 
202 {
203   // Should be reimplemented
204
205   /*Handle(BRepMesh_DataStructureOfDelaun) struc=myMesh->Result();
206   Standard_Integer e1, e2, e3;
207   Standard_Boolean o1, o2, o3;
208   Standard_Integer in, il, ie;
209   Standard_Integer nbn=struc->NbNodes();
210   Standard_Integer nbl=struc->NbLinks();
211   Standard_Integer nbe=struc->NbElements();
212
213   for (in=1; in<=nbn; in++) {
214   BRepMesh_Vertex nod=struc->GetNode(in);
215   S<<"(node "<<in<<" (uv "<<nod.Coord().X()<<" "
216   <<nod.Coord().Y()<<") (3d "
217   <<nod.Location3d()<<") ";
218   printdegree(nod.Movability());
219   S<<" (edgeconex";
220   BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
221   for (; tati.More(); tati.Next()) S<<" "<<tati.Value();
222   S << "))\n";
223   }
224   S <<endl;
225   for (il=1; il<=nbl; il++) {
226   BRepMesh_Edge edg=struc->GetLink(il);
227   S << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
228   <<" ";
229   printdegree(edg.Movability());
230   S<<") (triconex";
231   const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il);
232   for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
233   S<<" "<<pair.Index(j);
234   S << "))\n";
235   }
236   S <<endl;
237   for (ie=1; ie<=nbe; ie++) {
238   BRepMesh_Triangle tri=struc->GetElement(ie);
239   tri.Edges(e1, e2, e3, o1, o2, o3); 
240   if (!o1) e1=-e1;
241   if (!o2) e2=-e2;
242   if (!o3) e3=-e3;
243   S<<" (maille "<<ie<<" (links "<<e1<<" "
244   <<e2<<" "<<e3<<")";
245   printdegree(tri.Movability());
246   S<<")\n";
247   }
248   S << endl;
249   */
250 }
251
252 //=======================================================================
253 //function : Whatis
254 //purpose  : 
255 //=======================================================================
256
257 void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& S) const 
258 {
259   S << " 3d mesh\n";
260   S << "    - Triangles : " << myMesh->NbTriangles() << "\n";
261   S << "    - Edges     : " << myMesh->NbEdges()     << "\n";
262   S << "    - Vertices  : " << myMesh->NbVertices()  << "\n";
263   S << "    - Point3d   : " << myMesh->NbPoint3d()   << "\n";
264 }
265
266 //=======================================================================
267 //function : Mesh
268 //purpose  : 
269 //=======================================================================
270
271 Handle(BRepMesh_FastDiscret) MeshTest_DrawableMesh::Mesh() const 
272 {
273   return myMesh;
274 }
275
276
277 //=======================================================================
278 //function : Edges
279 //purpose  : 
280 //=======================================================================
281
282 TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Edges()
283 {
284   return myEdges;
285 }
286
287
288 //=======================================================================
289 //function : Vertices
290 //purpose  : 
291 //=======================================================================
292
293 TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Vertices()
294 {
295   return myVertices;
296 }
297
298 //=======================================================================
299 //function : Triangles
300 //purpose  : 
301 //=======================================================================
302
303 TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Triangles()
304 {
305   return myTriangles;
306 }
307