summaryrefslogtreecommitdiff
path: root/src/MeshTest/MeshTest_DrawableMesh.cxx
blob: 60beb93cc50cc0e826c3d66611f98e5476971378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// File:	MeshTest_DrawableMesh.cxx
// Created:	Wed Aug  3 18:30:07 1994
// Author:	Modeling
//		<modeling@bravox>


#include <MeshTest_DrawableMesh.ixx>
#include <TopoDS.hxx>
#include <Draw.hxx>
#include <Draw_ColorKind.hxx>
#include <Draw_Color.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <Standard_RangeError.hxx>
#include <BRepMesh_DegreeOfFreedom.hxx>
#include <BRepMesh_Edge.hxx>
#include <BRepMesh_Vertex.hxx>
#include <BRepMesh_Triangle.hxx>
#include <BRepMesh_DataStructureOfDelaun.hxx>
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>

//=======================================================================
//function : MeshTest_DrawableMesh
//purpose  : 
//=======================================================================

MeshTest_DrawableMesh::MeshTest_DrawableMesh() :
myDeflection(1.), myinshape(Standard_False)
{
}

//=======================================================================
//function : MeshTest_DrawableMesh
//purpose  : 
//=======================================================================

MeshTest_DrawableMesh::MeshTest_DrawableMesh(const TopoDS_Shape&    S,
                                             const Standard_Real    Deflect,
                                             const Standard_Boolean Partage,
                                             const Standard_Boolean inshape) :
myDeflection(Deflect), myinshape(inshape)
{
  Bnd_Box B;
  BRepBndLib::Add(S, B);

  myMesh = new BRepMesh_FastDiscret(Deflect, S, B, 0.5, Partage, inshape);
}


//=======================================================================
//function : MeshTest_DrawableMesh
//purpose  : 
//=======================================================================

MeshTest_DrawableMesh::MeshTest_DrawableMesh(const Handle(BRepMesh_FastDiscret)& Tr):
myDeflection(1.0)
{
  myMesh = Tr;
}


//=======================================================================
//function : MeshTest_DrawableMesh
//purpose  : 
//=======================================================================

void MeshTest_DrawableMesh::Add(const TopoDS_Shape& S)
{
  Bnd_Box B;
  BRepBndLib::Add(S, B);

  if (myMesh.IsNull())
    myMesh=new BRepMesh_FastDiscret(myDeflection, S, B, 0.5, myinshape);
  else
    myMesh->Perform(S);
}

//=======================================================================
//function : AddInShape
//purpose  : 
//=======================================================================

void MeshTest_DrawableMesh::AddInShape(const Standard_Boolean inshape) 
{
  myinshape = inshape;
}

//=======================================================================
//function : DrawOn
//purpose  : 
//=======================================================================

void MeshTest_DrawableMesh::DrawOn(Draw_Display& D) const 
{
  // should be reimplemented!!
  /*  Handle(BRepMesh_DataStructureOfDelaun) struc = myMesh->Result();
  Standard_Integer nbc;
  D.SetColor(Draw_vert);

  for (Standard_Integer iLi=1; iLi<=myMesh->NbEdges(); iLi++) {
  const BRepMesh_Edge& ed=myMesh->Edge(iLi);
  if (ed.Movability()!=BRepMesh_Deleted) {
  nbc=struc->ElemConnectedTo(iLi).Extent();
  if (nbc<=0) D.SetColor(Draw_bleu);
  else if (nbc==1) D.SetColor(Draw_jaune);
  else if (nbc==2) D.SetColor(Draw_vert);
  else D.SetColor(Draw_corail);
  D.MoveTo(myMesh->Pnt(ed.FirstNode()));
  D.DrawTo(myMesh->Pnt(ed.LastNode()));
  }
  }


  // highlighted triangles
  D.SetColor(Draw_blanc);
  Standard_Integer e1, e2, e3, i;
  Standard_Boolean o1, o2, o3;

  for (i = 1; i <= myTriangles.Length(); i++) {
  const BRepMesh_Triangle& tri=struc->GetElement(myTriangles(i));
  tri.Edges(e1, e2, e3, o1, o2, o3); 
  const BRepMesh_Edge& ed1=myMesh->Edge(e1);
  if (ed1.Movability()!=BRepMesh_Deleted) {
  D.MoveTo(myMesh->Pnt(ed1.FirstNode()));
  D.DrawTo(myMesh->Pnt(ed1.LastNode()));
  }
  const BRepMesh_Edge& ed2=myMesh->Edge(e2);
  if (ed2.Movability()!=BRepMesh_Deleted) {
  D.MoveTo(myMesh->Pnt(ed2.FirstNode()));
  D.DrawTo(myMesh->Pnt(ed2.LastNode()));
  }
  const BRepMesh_Edge& ed3=myMesh->Edge(e3);
  if (ed3.Movability()!=BRepMesh_Deleted) {
  D.MoveTo(myMesh->Pnt(ed3.FirstNode()));
  D.DrawTo(myMesh->Pnt(ed3.LastNode()));
  }
  }

  // highlighted edges
  D.SetColor(Draw_rouge);
  for (i = 1; i <= myEdges.Length(); i++) {
  const BRepMesh_Edge& ed=myMesh->Edge(myEdges(i));
  if (ed.Movability()!=BRepMesh_Deleted) {
  D.MoveTo(myMesh->Pnt(ed.FirstNode()));
  D.DrawTo(myMesh->Pnt(ed.LastNode()));
  }
  }

  // highlighted vertices
  for (i = 1; i <= myVertices.Length(); i++) {
  D.DrawMarker(myMesh->Pnt(myVertices(i)),Draw_Losange);
  }

  */

}

//=======================================================================
//function : Copy
//purpose  : 
//=======================================================================

Handle(Draw_Drawable3D) MeshTest_DrawableMesh::Copy() const 
{
  Handle(MeshTest_DrawableMesh) D = new MeshTest_DrawableMesh();
  return  D;
}

void MeshTest_DrawableMesh::Dump(Standard_OStream& S) const 
{
  // Should be reimplemented

  /*Handle(BRepMesh_DataStructureOfDelaun) struc=myMesh->Result();
  Standard_Integer e1, e2, e3;
  Standard_Boolean o1, o2, o3;
  Standard_Integer in, il, ie;
  Standard_Integer nbn=struc->NbNodes();
  Standard_Integer nbl=struc->NbLinks();
  Standard_Integer nbe=struc->NbElements();

  for (in=1; in<=nbn; in++) {
  BRepMesh_Vertex nod=struc->GetNode(in);
  S<<"(node "<<in<<" (uv "<<nod.Coord().X()<<" "
  <<nod.Coord().Y()<<") (3d "
  <<nod.Location3d()<<") ";
  printdegree(nod.Movability());
  S<<" (edgeconex";
  BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
  for (; tati.More(); tati.Next()) S<<" "<<tati.Value();
  S << "))\n";
  }
  S <<endl;
  for (il=1; il<=nbl; il++) {
  BRepMesh_Edge edg=struc->GetLink(il);
  S << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
  <<" ";
  printdegree(edg.Movability());
  S<<") (triconex";
  const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il);
  for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
  S<<" "<<pair.Index(j);
  S << "))\n";
  }
  S <<endl;
  for (ie=1; ie<=nbe; ie++) {
  BRepMesh_Triangle tri=struc->GetElement(ie);
  tri.Edges(e1, e2, e3, o1, o2, o3); 
  if (!o1) e1=-e1;
  if (!o2) e2=-e2;
  if (!o3) e3=-e3;
  S<<" (maille "<<ie<<" (links "<<e1<<" "
  <<e2<<" "<<e3<<")";
  printdegree(tri.Movability());
  S<<")\n";
  }
  S << endl;
  */
}

//=======================================================================
//function : Whatis
//purpose  : 
//=======================================================================

void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& S) const 
{
  S << " 3d mesh\n";
  S << "    - Triangles : " << myMesh->NbTriangles() << "\n";
  S << "    - Edges     : " << myMesh->NbEdges()     << "\n";
  S << "    - Vertices  : " << myMesh->NbVertices()  << "\n";
  S << "    - Point3d   : " << myMesh->NbPoint3d()   << "\n";
}

//=======================================================================
//function : Mesh
//purpose  : 
//=======================================================================

Handle(BRepMesh_FastDiscret) MeshTest_DrawableMesh::Mesh() const 
{
  return myMesh;
}


//=======================================================================
//function : Edges
//purpose  : 
//=======================================================================

TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Edges()
{
  return myEdges;
}


//=======================================================================
//function : Vertices
//purpose  : 
//=======================================================================

TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Vertices()
{
  return myVertices;
}

//=======================================================================
//function : Triangles
//purpose  : 
//=======================================================================

TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Triangles()
{
  return myTriangles;
}