0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / MeshTest / MeshTest_DrawableMesh.cxx
CommitLineData
b311480e 1// Created on: 1994-08-03
2// Created by: Modeling
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
fc9b36d6 17#include <MeshTest_DrawableMesh.hxx>
7fd59977 18#include <TopoDS.hxx>
19#include <Draw.hxx>
20#include <Draw_ColorKind.hxx>
21#include <Draw_Color.hxx>
22#include <TColStd_ListIteratorOfListOfInteger.hxx>
fcf15f5c 23#include <TColStd_Array1OfInteger.hxx>
24#include <Poly_Triangulation.hxx>
7fd59977 25#include <Standard_RangeError.hxx>
0d88155b 26#include <BRepMesh_DegreeOfFreedom.hxx>
7fd59977 27#include <BRepMesh_Edge.hxx>
28#include <BRepMesh_Vertex.hxx>
29#include <BRepMesh_Triangle.hxx>
30#include <BRepMesh_DataStructureOfDelaun.hxx>
ceb418e1 31#include <TopExp_Explorer.hxx>
7fd59977 32
fc9b36d6 33
fcf15f5c 34typedef NCollection_Map<BRepMesh_Edge> BRepMesh_MapOfLinks;
35
36static inline void addLink(const Standard_Integer theIndex1,
37 const Standard_Integer theIndex2,
38 BRepMesh_MapOfLinks& theMap)
39{
40 BRepMesh_Edge anEdge(theIndex1, theIndex2, BRepMesh_Free);
41 theMap.Add(anEdge);
42}
43
7fd59977 44//=======================================================================
45//function : MeshTest_DrawableMesh
46//purpose :
47//=======================================================================
ceb418e1 48MeshTest_DrawableMesh::MeshTest_DrawableMesh()
49 : myDeflection(1.)
7fd59977 50{
51}
52
53//=======================================================================
54//function : MeshTest_DrawableMesh
55//purpose :
56//=======================================================================
ceb418e1 57MeshTest_DrawableMesh::MeshTest_DrawableMesh(const TopoDS_Shape& theShape,
58 const Standard_Real theDeflection)
59 : myDeflection(theDeflection)
7fd59977 60{
ceb418e1 61 Add(theShape);
7fd59977 62}
63
7fd59977 64//=======================================================================
65//function : MeshTest_DrawableMesh
66//purpose :
67//=======================================================================
ceb418e1 68MeshTest_DrawableMesh::MeshTest_DrawableMesh(
69 const Handle(BRepMesh_IncrementalMesh)& theMesher)
70 : myDeflection(1.)
7fd59977 71{
ceb418e1 72 myMesher = theMesher;
73 if (!myMesher.IsNull())
74 myDeflection = myMesher->Deflection();
7fd59977 75}
76
7fd59977 77//=======================================================================
78//function : MeshTest_DrawableMesh
79//purpose :
80//=======================================================================
ceb418e1 81void MeshTest_DrawableMesh::Add(const TopoDS_Shape& theShape)
7fd59977 82{
ceb418e1 83 if (myMesher.IsNull())
84 {
85 myMesher = new BRepMesh_IncrementalMesh;
86 myMesher->SetDeflection(myDeflection);
87 myMesher->SetAngle(0.5);
88 }
89
90 myMesher->SetShape(theShape);
91 myMesher->Perform();
7fd59977 92}
93
94//=======================================================================
95//function : DrawOn
96//purpose :
97//=======================================================================
98
35e08fe8 99void MeshTest_DrawableMesh::DrawOn(Draw_Display& /*D*/) const
7fd59977 100{
101 // should be reimplemented!!
102 /* Handle(BRepMesh_DataStructureOfDelaun) struc = myMesh->Result();
103 Standard_Integer nbc;
104 D.SetColor(Draw_vert);
0d88155b 105
7fd59977 106 for (Standard_Integer iLi=1; iLi<=myMesh->NbEdges(); iLi++) {
0d88155b
O
107 const BRepMesh_Edge& ed=myMesh->Edge(iLi);
108 if (ed.Movability()!=BRepMesh_Deleted) {
109 nbc=struc->ElemConnectedTo(iLi).Extent();
110 if (nbc<=0) D.SetColor(Draw_bleu);
111 else if (nbc==1) D.SetColor(Draw_jaune);
112 else if (nbc==2) D.SetColor(Draw_vert);
113 else D.SetColor(Draw_corail);
114 D.MoveTo(myMesh->Pnt(ed.FirstNode()));
115 D.DrawTo(myMesh->Pnt(ed.LastNode()));
116 }
7fd59977 117 }
118
119
120 // highlighted triangles
121 D.SetColor(Draw_blanc);
122 Standard_Integer e1, e2, e3, i;
123 Standard_Boolean o1, o2, o3;
124
125 for (i = 1; i <= myTriangles.Length(); i++) {
0d88155b
O
126 const BRepMesh_Triangle& tri=struc->GetElement(myTriangles(i));
127 tri.Edges(e1, e2, e3, o1, o2, o3);
128 const BRepMesh_Edge& ed1=myMesh->Edge(e1);
129 if (ed1.Movability()!=BRepMesh_Deleted) {
130 D.MoveTo(myMesh->Pnt(ed1.FirstNode()));
131 D.DrawTo(myMesh->Pnt(ed1.LastNode()));
132 }
133 const BRepMesh_Edge& ed2=myMesh->Edge(e2);
134 if (ed2.Movability()!=BRepMesh_Deleted) {
135 D.MoveTo(myMesh->Pnt(ed2.FirstNode()));
136 D.DrawTo(myMesh->Pnt(ed2.LastNode()));
137 }
138 const BRepMesh_Edge& ed3=myMesh->Edge(e3);
139 if (ed3.Movability()!=BRepMesh_Deleted) {
140 D.MoveTo(myMesh->Pnt(ed3.FirstNode()));
141 D.DrawTo(myMesh->Pnt(ed3.LastNode()));
142 }
7fd59977 143 }
144
145 // highlighted edges
146 D.SetColor(Draw_rouge);
147 for (i = 1; i <= myEdges.Length(); i++) {
0d88155b
O
148 const BRepMesh_Edge& ed=myMesh->Edge(myEdges(i));
149 if (ed.Movability()!=BRepMesh_Deleted) {
150 D.MoveTo(myMesh->Pnt(ed.FirstNode()));
151 D.DrawTo(myMesh->Pnt(ed.LastNode()));
152 }
7fd59977 153 }
154
155 // highlighted vertices
156 for (i = 1; i <= myVertices.Length(); i++) {
0d88155b 157 D.DrawMarker(myMesh->Pnt(myVertices(i)),Draw_Losange);
7fd59977 158 }
159
160 */
161
162}
163
164//=======================================================================
165//function : Copy
166//purpose :
167//=======================================================================
7fd59977 168Handle(Draw_Drawable3D) MeshTest_DrawableMesh::Copy() const
169{
ceb418e1 170 return new MeshTest_DrawableMesh(myMesher);
7fd59977 171}
172
173//=======================================================================
174//function : Dump
175//purpose :
176//=======================================================================
35e08fe8 177void MeshTest_DrawableMesh::Dump(Standard_OStream&) const
7fd59977 178{
179 // Should be reimplemented
0d88155b 180
7fd59977 181 /*Handle(BRepMesh_DataStructureOfDelaun) struc=myMesh->Result();
182 Standard_Integer e1, e2, e3;
183 Standard_Boolean o1, o2, o3;
184 Standard_Integer in, il, ie;
185 Standard_Integer nbn=struc->NbNodes();
186 Standard_Integer nbl=struc->NbLinks();
187 Standard_Integer nbe=struc->NbElements();
0d88155b 188
7fd59977 189 for (in=1; in<=nbn; in++) {
0d88155b
O
190 BRepMesh_Vertex nod=struc->GetNode(in);
191 S<<"(node "<<in<<" (uv "<<nod.Coord().X()<<" "
192 <<nod.Coord().Y()<<") (3d "
193 <<nod.Location3d()<<") ";
194 printdegree(nod.Movability());
195 S<<" (edgeconex";
196 BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
197 for (; tati.More(); tati.Next()) S<<" "<<tati.Value();
198 S << "))\n";
7fd59977 199 }
200 S <<endl;
201 for (il=1; il<=nbl; il++) {
0d88155b
O
202 BRepMesh_Edge edg=struc->GetLink(il);
203 S << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
204 <<" ";
205 printdegree(edg.Movability());
206 S<<") (triconex";
207 const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il);
208 for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
209 S<<" "<<pair.Index(j);
210 S << "))\n";
7fd59977 211 }
212 S <<endl;
213 for (ie=1; ie<=nbe; ie++) {
0d88155b
O
214 BRepMesh_Triangle tri=struc->GetElement(ie);
215 tri.Edges(e1, e2, e3, o1, o2, o3);
216 if (!o1) e1=-e1;
217 if (!o2) e2=-e2;
218 if (!o3) e3=-e3;
219 S<<" (maille "<<ie<<" (links "<<e1<<" "
220 <<e2<<" "<<e3<<")";
221 printdegree(tri.Movability());
222 S<<")\n";
7fd59977 223 }
224 S << endl;
225 */
226}
227
228//=======================================================================
229//function : Whatis
230//purpose :
231//=======================================================================
ceb418e1 232void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& theStream) const
7fd59977 233{
2caff0b3 234 const TopoDS_Shape& aShape = myMesher->Shape();
fcf15f5c 235
2caff0b3 236 Standard_Integer aPointsNb = 0;
ceb418e1 237 Standard_Integer aTrianglesNb = 0;
238 Standard_Integer aEdgesNb = 0;
239
fcf15f5c 240 TopLoc_Location aLocation;
241 Handle(Poly_Triangulation) aTriangulation;
242
ceb418e1 243 TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
244 for (; aFaceIt.More(); aFaceIt.Next())
245 {
246 const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
247
fcf15f5c 248 aTriangulation = BRep_Tool::Triangulation(aFace, aLocation);
249 if (aTriangulation.IsNull())
ceb418e1 250 continue;
251
fcf15f5c 252 // Count number of links
253 BRepMesh_MapOfLinks aMap;
254 const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
255 for (Standard_Integer i = 1, v[3]; i <= aTriangles.Length(); ++i)
256 {
257 aTriangles(i).Get(v[0], v[1], v[2]);
ceb418e1 258
fcf15f5c 259 addLink(v[0], v[1], aMap);
260 addLink(v[1], v[2], aMap);
261 addLink(v[2], v[0], aMap);
262 }
ceb418e1 263
fcf15f5c 264 aPointsNb += aTriangulation->NbNodes();
265 aTrianglesNb += aTriangulation->NbTriangles();
266 aEdgesNb += aMap.Extent();
ceb418e1 267 }
268
269 theStream << " 3d mesh\n";
270 theStream << " - Triangles : " << aTrianglesNb << "\n";
271 theStream << " - Edges : " << aEdgesNb << "\n";
272 theStream << " - Point3d : " << aPointsNb << "\n";
7fd59977 273}
274
275//=======================================================================
ceb418e1 276//function : Mesher
7fd59977 277//purpose :
278//=======================================================================
ceb418e1 279const Handle(BRepMesh_IncrementalMesh)& MeshTest_DrawableMesh::Mesher() const
7fd59977 280{
ceb418e1 281 return myMesher;
7fd59977 282}
283
284
285//=======================================================================
286//function : Edges
287//purpose :
288//=======================================================================
7fd59977 289TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Edges()
290{
291 return myEdges;
292}
293
294
295//=======================================================================
296//function : Vertices
297//purpose :
298//=======================================================================
7fd59977 299TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Vertices()
300{
301 return myVertices;
302}
303
304//=======================================================================
305//function : Triangles
306//purpose :
307//=======================================================================
7fd59977 308TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Triangles()
309{
310 return myTriangles;
311}
312