Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-08-03 |
2 | // Created by: Modeling | |
3 | // Copyright (c) 1994-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | ||
23 | #include <MeshTest_DrawableMesh.ixx> | |
24 | #include <TopoDS.hxx> | |
25 | #include <Draw.hxx> | |
26 | #include <Draw_ColorKind.hxx> | |
27 | #include <Draw_Color.hxx> | |
28 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
29 | #include <Standard_RangeError.hxx> | |
0d88155b | 30 | #include <BRepMesh_DegreeOfFreedom.hxx> |
7fd59977 | 31 | #include <BRepMesh_Edge.hxx> |
32 | #include <BRepMesh_Vertex.hxx> | |
33 | #include <BRepMesh_Triangle.hxx> | |
34 | #include <BRepMesh_DataStructureOfDelaun.hxx> | |
35 | #include <Bnd_Box.hxx> | |
36 | #include <BRepBndLib.hxx> | |
37 | ||
38 | //======================================================================= | |
39 | //function : MeshTest_DrawableMesh | |
40 | //purpose : | |
41 | //======================================================================= | |
42 | ||
43 | MeshTest_DrawableMesh::MeshTest_DrawableMesh() : | |
0d88155b | 44 | myDeflection(1.), myinshape(Standard_False) |
7fd59977 | 45 | { |
46 | } | |
47 | ||
48 | //======================================================================= | |
49 | //function : MeshTest_DrawableMesh | |
50 | //purpose : | |
51 | //======================================================================= | |
52 | ||
53 | MeshTest_DrawableMesh::MeshTest_DrawableMesh(const TopoDS_Shape& S, | |
0d88155b O |
54 | const Standard_Real Deflect, |
55 | const Standard_Boolean Partage, | |
56 | const Standard_Boolean inshape) : | |
57 | myDeflection(Deflect), myinshape(inshape) | |
7fd59977 | 58 | { |
59 | Bnd_Box B; | |
60 | BRepBndLib::Add(S, B); | |
0d88155b | 61 | |
7fd59977 | 62 | myMesh = new BRepMesh_FastDiscret(Deflect, S, B, 0.5, Partage, inshape); |
63 | } | |
64 | ||
65 | ||
66 | //======================================================================= | |
67 | //function : MeshTest_DrawableMesh | |
68 | //purpose : | |
69 | //======================================================================= | |
70 | ||
71 | MeshTest_DrawableMesh::MeshTest_DrawableMesh(const Handle(BRepMesh_FastDiscret)& Tr): | |
0d88155b | 72 | myDeflection(1.0) |
7fd59977 | 73 | { |
0d88155b | 74 | myMesh = Tr; |
7fd59977 | 75 | } |
76 | ||
77 | ||
78 | //======================================================================= | |
79 | //function : MeshTest_DrawableMesh | |
80 | //purpose : | |
81 | //======================================================================= | |
82 | ||
83 | void MeshTest_DrawableMesh::Add(const TopoDS_Shape& S) | |
84 | { | |
85 | Bnd_Box B; | |
86 | BRepBndLib::Add(S, B); | |
87 | ||
88 | if (myMesh.IsNull()) | |
89 | myMesh=new BRepMesh_FastDiscret(myDeflection, S, B, 0.5, myinshape); | |
90 | else | |
91 | myMesh->Perform(S); | |
92 | } | |
93 | ||
94 | //======================================================================= | |
95 | //function : AddInShape | |
96 | //purpose : | |
97 | //======================================================================= | |
98 | ||
99 | void MeshTest_DrawableMesh::AddInShape(const Standard_Boolean inshape) | |
100 | { | |
101 | myinshape = inshape; | |
102 | } | |
103 | ||
104 | //======================================================================= | |
105 | //function : DrawOn | |
106 | //purpose : | |
107 | //======================================================================= | |
108 | ||
35e08fe8 | 109 | void MeshTest_DrawableMesh::DrawOn(Draw_Display& /*D*/) const |
7fd59977 | 110 | { |
111 | // should be reimplemented!! | |
112 | /* Handle(BRepMesh_DataStructureOfDelaun) struc = myMesh->Result(); | |
113 | Standard_Integer nbc; | |
114 | D.SetColor(Draw_vert); | |
0d88155b | 115 | |
7fd59977 | 116 | for (Standard_Integer iLi=1; iLi<=myMesh->NbEdges(); iLi++) { |
0d88155b O |
117 | const BRepMesh_Edge& ed=myMesh->Edge(iLi); |
118 | if (ed.Movability()!=BRepMesh_Deleted) { | |
119 | nbc=struc->ElemConnectedTo(iLi).Extent(); | |
120 | if (nbc<=0) D.SetColor(Draw_bleu); | |
121 | else if (nbc==1) D.SetColor(Draw_jaune); | |
122 | else if (nbc==2) D.SetColor(Draw_vert); | |
123 | else D.SetColor(Draw_corail); | |
124 | D.MoveTo(myMesh->Pnt(ed.FirstNode())); | |
125 | D.DrawTo(myMesh->Pnt(ed.LastNode())); | |
126 | } | |
7fd59977 | 127 | } |
128 | ||
129 | ||
130 | // highlighted triangles | |
131 | D.SetColor(Draw_blanc); | |
132 | Standard_Integer e1, e2, e3, i; | |
133 | Standard_Boolean o1, o2, o3; | |
134 | ||
135 | for (i = 1; i <= myTriangles.Length(); i++) { | |
0d88155b O |
136 | const BRepMesh_Triangle& tri=struc->GetElement(myTriangles(i)); |
137 | tri.Edges(e1, e2, e3, o1, o2, o3); | |
138 | const BRepMesh_Edge& ed1=myMesh->Edge(e1); | |
139 | if (ed1.Movability()!=BRepMesh_Deleted) { | |
140 | D.MoveTo(myMesh->Pnt(ed1.FirstNode())); | |
141 | D.DrawTo(myMesh->Pnt(ed1.LastNode())); | |
142 | } | |
143 | const BRepMesh_Edge& ed2=myMesh->Edge(e2); | |
144 | if (ed2.Movability()!=BRepMesh_Deleted) { | |
145 | D.MoveTo(myMesh->Pnt(ed2.FirstNode())); | |
146 | D.DrawTo(myMesh->Pnt(ed2.LastNode())); | |
147 | } | |
148 | const BRepMesh_Edge& ed3=myMesh->Edge(e3); | |
149 | if (ed3.Movability()!=BRepMesh_Deleted) { | |
150 | D.MoveTo(myMesh->Pnt(ed3.FirstNode())); | |
151 | D.DrawTo(myMesh->Pnt(ed3.LastNode())); | |
152 | } | |
7fd59977 | 153 | } |
154 | ||
155 | // highlighted edges | |
156 | D.SetColor(Draw_rouge); | |
157 | for (i = 1; i <= myEdges.Length(); i++) { | |
0d88155b O |
158 | const BRepMesh_Edge& ed=myMesh->Edge(myEdges(i)); |
159 | if (ed.Movability()!=BRepMesh_Deleted) { | |
160 | D.MoveTo(myMesh->Pnt(ed.FirstNode())); | |
161 | D.DrawTo(myMesh->Pnt(ed.LastNode())); | |
162 | } | |
7fd59977 | 163 | } |
164 | ||
165 | // highlighted vertices | |
166 | for (i = 1; i <= myVertices.Length(); i++) { | |
0d88155b | 167 | D.DrawMarker(myMesh->Pnt(myVertices(i)),Draw_Losange); |
7fd59977 | 168 | } |
169 | ||
170 | */ | |
171 | ||
172 | } | |
173 | ||
174 | //======================================================================= | |
175 | //function : Copy | |
176 | //purpose : | |
177 | //======================================================================= | |
178 | ||
179 | Handle(Draw_Drawable3D) MeshTest_DrawableMesh::Copy() const | |
180 | { | |
181 | Handle(MeshTest_DrawableMesh) D = new MeshTest_DrawableMesh(); | |
182 | return D; | |
183 | } | |
184 | ||
185 | //======================================================================= | |
186 | //function : Dump | |
187 | //purpose : | |
188 | //======================================================================= | |
189 | ||
0d88155b | 190 | static void printdegree(BRepMesh_DegreeOfFreedom dof) |
7fd59977 | 191 | { |
192 | switch (dof) { | |
0d88155b | 193 | case BRepMesh_InVolume : |
7fd59977 | 194 | cout << "InVolume"; |
195 | break; | |
0d88155b | 196 | case BRepMesh_OnSurface : |
7fd59977 | 197 | cout << "OnSurface"; |
198 | break; | |
0d88155b | 199 | case BRepMesh_OnCurve : |
7fd59977 | 200 | cout << "OnCurve"; |
201 | break; | |
0d88155b | 202 | case BRepMesh_Fixed : |
7fd59977 | 203 | cout << "Fixed"; |
204 | break; | |
0d88155b | 205 | case BRepMesh_Frontier : |
7fd59977 | 206 | cout << "Frontier"; |
207 | break; | |
0d88155b | 208 | case BRepMesh_Deleted : |
7fd59977 | 209 | cout << "Deleted"; |
210 | break; | |
0d88155b | 211 | case BRepMesh_Free : |
7fd59977 | 212 | cout << "Free"; |
213 | break; | |
214 | } | |
215 | } | |
216 | ||
35e08fe8 | 217 | void MeshTest_DrawableMesh::Dump(Standard_OStream&) const |
7fd59977 | 218 | { |
219 | // Should be reimplemented | |
0d88155b | 220 | |
7fd59977 | 221 | /*Handle(BRepMesh_DataStructureOfDelaun) struc=myMesh->Result(); |
222 | Standard_Integer e1, e2, e3; | |
223 | Standard_Boolean o1, o2, o3; | |
224 | Standard_Integer in, il, ie; | |
225 | Standard_Integer nbn=struc->NbNodes(); | |
226 | Standard_Integer nbl=struc->NbLinks(); | |
227 | Standard_Integer nbe=struc->NbElements(); | |
0d88155b | 228 | |
7fd59977 | 229 | for (in=1; in<=nbn; in++) { |
0d88155b O |
230 | BRepMesh_Vertex nod=struc->GetNode(in); |
231 | S<<"(node "<<in<<" (uv "<<nod.Coord().X()<<" " | |
232 | <<nod.Coord().Y()<<") (3d " | |
233 | <<nod.Location3d()<<") "; | |
234 | printdegree(nod.Movability()); | |
235 | S<<" (edgeconex"; | |
236 | BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in)); | |
237 | for (; tati.More(); tati.Next()) S<<" "<<tati.Value(); | |
238 | S << "))\n"; | |
7fd59977 | 239 | } |
240 | S <<endl; | |
241 | for (il=1; il<=nbl; il++) { | |
0d88155b O |
242 | BRepMesh_Edge edg=struc->GetLink(il); |
243 | S << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode() | |
244 | <<" "; | |
245 | printdegree(edg.Movability()); | |
246 | S<<") (triconex"; | |
247 | const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il); | |
248 | for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++) | |
249 | S<<" "<<pair.Index(j); | |
250 | S << "))\n"; | |
7fd59977 | 251 | } |
252 | S <<endl; | |
253 | for (ie=1; ie<=nbe; ie++) { | |
0d88155b O |
254 | BRepMesh_Triangle tri=struc->GetElement(ie); |
255 | tri.Edges(e1, e2, e3, o1, o2, o3); | |
256 | if (!o1) e1=-e1; | |
257 | if (!o2) e2=-e2; | |
258 | if (!o3) e3=-e3; | |
259 | S<<" (maille "<<ie<<" (links "<<e1<<" " | |
260 | <<e2<<" "<<e3<<")"; | |
261 | printdegree(tri.Movability()); | |
262 | S<<")\n"; | |
7fd59977 | 263 | } |
264 | S << endl; | |
265 | */ | |
266 | } | |
267 | ||
268 | //======================================================================= | |
269 | //function : Whatis | |
270 | //purpose : | |
271 | //======================================================================= | |
272 | ||
273 | void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& S) const | |
274 | { | |
275 | S << " 3d mesh\n"; | |
276 | S << " - Triangles : " << myMesh->NbTriangles() << "\n"; | |
277 | S << " - Edges : " << myMesh->NbEdges() << "\n"; | |
278 | S << " - Vertices : " << myMesh->NbVertices() << "\n"; | |
279 | S << " - Point3d : " << myMesh->NbPoint3d() << "\n"; | |
280 | } | |
281 | ||
282 | //======================================================================= | |
283 | //function : Mesh | |
284 | //purpose : | |
285 | //======================================================================= | |
286 | ||
287 | Handle(BRepMesh_FastDiscret) MeshTest_DrawableMesh::Mesh() const | |
288 | { | |
289 | return myMesh; | |
290 | } | |
291 | ||
292 | ||
293 | //======================================================================= | |
294 | //function : Edges | |
295 | //purpose : | |
296 | //======================================================================= | |
297 | ||
298 | TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Edges() | |
299 | { | |
300 | return myEdges; | |
301 | } | |
302 | ||
303 | ||
304 | //======================================================================= | |
305 | //function : Vertices | |
306 | //purpose : | |
307 | //======================================================================= | |
308 | ||
309 | TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Vertices() | |
310 | { | |
311 | return myVertices; | |
312 | } | |
313 | ||
314 | //======================================================================= | |
315 | //function : Triangles | |
316 | //purpose : | |
317 | //======================================================================= | |
318 | ||
319 | TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Triangles() | |
320 | { | |
321 | return myTriangles; | |
322 | } | |
323 |