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