1 // Created on: 1995-03-06
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Draw_Color.hxx>
19 #include <Draw_Display.hxx>
20 #include <Draw_Drawable3D.hxx>
21 #include <DrawTrSurf_Triangulation.hxx>
24 #include <Poly_Array1OfTriangle.hxx>
25 #include <Poly_Connect.hxx>
26 #include <Poly_Triangle.hxx>
27 #include <Poly_Triangulation.hxx>
28 #include <Standard_Type.hxx>
29 #include <TColStd_Array1OfInteger.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Triangulation,Draw_Drawable3D)
34 //=======================================================================
35 //function : DrawTrSurf_Triangulation
37 //=======================================================================
38 DrawTrSurf_Triangulation::DrawTrSurf_Triangulation
39 (const Handle(Poly_Triangulation)& T):
41 myNodes(Standard_False),
42 myTriangles(Standard_False)
44 // Build the connect tool
47 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
48 Standard_Integer t[3];
50 // count the free edges
52 for (i = 1; i <= nbTriangles; i++) {
53 pc.Triangles(i,t[0],t[1],t[2]);
54 for (j = 0; j < 3; j++)
55 if (t[j] == 0) nFree++;
58 // allocate the arrays
59 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
60 nInternal = (3*nbTriangles - nFree) / 2;
61 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
63 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
64 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
66 Standard_Integer fr = 1, in = 1;
67 const Poly_Array1OfTriangle& triangles = T->Triangles();
68 Standard_Integer n[3];
69 for (i = 1; i <= nbTriangles; i++) {
70 pc.Triangles(i,t[0],t[1],t[2]);
71 triangles(i).Get(n[0],n[1],n[2]);
72 for (j = 0; j < 3; j++) {
73 Standard_Integer k = (j+1) % 3;
79 // internal edge if this triangle has a lower index than the adjacent
82 Internal(in+1) = n[k];
89 //=======================================================================
90 //function : Triangulation
92 //=======================================================================
94 Handle(Poly_Triangulation) DrawTrSurf_Triangulation::Triangulation() const
96 return myTriangulation;
99 //=======================================================================
100 //function : ShowNodes
102 //=======================================================================
104 void DrawTrSurf_Triangulation::ShowNodes(const Standard_Boolean B)
109 //=======================================================================
110 //function : ShowNodes
112 //=======================================================================
114 Standard_Boolean DrawTrSurf_Triangulation::ShowNodes() const
119 //=======================================================================
120 //function : ShowTriangles
122 //=======================================================================
124 void DrawTrSurf_Triangulation::ShowTriangles(const Standard_Boolean B)
129 //=======================================================================
130 //function : ShowTriangles
132 //=======================================================================
134 Standard_Boolean DrawTrSurf_Triangulation::ShowTriangles() const
139 //=======================================================================
142 //=======================================================================
144 void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
147 Standard_Integer i,n;
149 const TColgp_Array1OfPnt& Nodes = myTriangulation->Nodes();
153 dis.SetColor(Draw_rouge);
154 const TColStd_Array1OfInteger& Free = myFree->Array1();
155 n = Free.Length() / 2;
156 for (i = 1; i <= n; i++) {
157 dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i)));
162 dis.SetColor(Draw_bleu);
163 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
164 n = Internal.Length() / 2;
165 for (i = 1; i <= n; i++) {
166 dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i)));
172 dis.SetColor(Draw_jaune);
173 n = myTriangulation->NbNodes();
174 for (i = 1; i <= n; i++) {
175 Sprintf(text,"%d",i);
176 dis.DrawString(Nodes(i),text);
181 dis.SetColor(Draw_vert);
182 n = myTriangulation->NbTriangles();
183 Standard_Integer t[3],j;
184 const Poly_Array1OfTriangle& triangle = myTriangulation->Triangles();
185 for (i = 1; i <= n; i++) {
186 triangle(i).Get(t[0],t[1],t[2]);
188 gp_XYZ& bary = P.ChangeCoord();
189 for (j = 0; j < 3; j++)
190 bary.Add(Nodes(t[j]).Coord());
191 bary.Multiply(1./3.);
193 Sprintf(text,"%d",i);
194 dis.DrawString(P,text);
199 //=======================================================================
202 //=======================================================================
204 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation::Copy() const
206 return new DrawTrSurf_Triangulation(myTriangulation);
209 //=======================================================================
212 //=======================================================================
214 void DrawTrSurf_Triangulation::Dump(Standard_OStream& S) const
216 Poly::Dump(myTriangulation,S);
219 //=======================================================================
222 //=======================================================================
224 void DrawTrSurf_Triangulation::Whatis(Draw_Interpretor& I) const
226 I << "triangulation";