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.
17 #include <DrawTrSurf_Triangulation.ixx>
18 #include <Poly_Connect.hxx>
19 #include <Poly_Triangle.hxx>
20 #include <Poly_Array1OfTriangle.hxx>
21 #include <TColStd_Array1OfInteger.hxx>
23 #include <Draw_Color.hxx>
30 //=======================================================================
31 //function : DrawTrSurf_Triangulation
33 //=======================================================================
35 DrawTrSurf_Triangulation::DrawTrSurf_Triangulation
36 (const Handle(Poly_Triangulation)& T):
38 myNodes(Standard_False),
39 myTriangles(Standard_False)
41 // Build the connect tool
44 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
45 Standard_Integer t[3];
47 // count the free edges
49 for (i = 1; i <= nbTriangles; i++) {
50 pc.Triangles(i,t[0],t[1],t[2]);
51 for (j = 0; j < 3; j++)
52 if (t[j] == 0) nFree++;
55 // allocate the arrays
56 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
57 nInternal = (3*nbTriangles - nFree) / 2;
58 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
60 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
61 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
63 Standard_Integer fr = 1, in = 1;
64 Standard_Integer n[3];
65 for (i = 1; i <= nbTriangles; i++) {
66 pc.Triangles(i,t[0],t[1],t[2]);
67 T->Triangle (i).Get(n[0],n[1],n[2]);
68 for (j = 0; j < 3; j++) {
69 Standard_Integer k = (j+1) % 3;
75 // internal edge if this triangle has a lower index than the adjacent
78 Internal(in+1) = n[k];
85 //=======================================================================
86 //function : Triangulation
88 //=======================================================================
90 Handle(Poly_Triangulation) DrawTrSurf_Triangulation::Triangulation() const
92 return myTriangulation;
95 //=======================================================================
96 //function : ShowNodes
98 //=======================================================================
100 void DrawTrSurf_Triangulation::ShowNodes(const Standard_Boolean B)
105 //=======================================================================
106 //function : ShowNodes
108 //=======================================================================
110 Standard_Boolean DrawTrSurf_Triangulation::ShowNodes() const
115 //=======================================================================
116 //function : ShowTriangles
118 //=======================================================================
120 void DrawTrSurf_Triangulation::ShowTriangles(const Standard_Boolean B)
125 //=======================================================================
126 //function : ShowTriangles
128 //=======================================================================
130 Standard_Boolean DrawTrSurf_Triangulation::ShowTriangles() const
135 //=======================================================================
138 //=======================================================================
140 void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
143 Standard_Integer i,n;
147 dis.SetColor(Draw_rouge);
148 const TColStd_Array1OfInteger& Free = myFree->Array1();
149 n = Free.Length() / 2;
150 for (i = 1; i <= n; i++) {
151 dis.Draw(myTriangulation->Node (Free(2*i-1)),myTriangulation->Node (Free(2*i)));
156 dis.SetColor(Draw_bleu);
157 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
158 n = Internal.Length() / 2;
159 for (i = 1; i <= n; i++) {
160 dis.Draw(myTriangulation->Node (Internal(2*i-1)),myTriangulation->Node (Internal(2*i)));
166 dis.SetColor(Draw_jaune);
167 n = myTriangulation->NbNodes();
168 for (i = 1; i <= n; i++) {
169 Sprintf(text,"%d",i);
170 dis.DrawString(myTriangulation->Node (i),text);
175 dis.SetColor(Draw_vert);
176 n = myTriangulation->NbTriangles();
177 Standard_Integer t[3],j;
178 for (i = 1; i <= n; i++) {
179 myTriangulation->Triangle (i).Get(t[0],t[1],t[2]);
181 gp_XYZ& bary = P.ChangeCoord();
182 for (j = 0; j < 3; j++)
183 bary.Add(myTriangulation->Node (t[j]).Coord());
184 bary.Multiply(1./3.);
186 Sprintf(text,"%d",i);
187 dis.DrawString(P,text);
192 //=======================================================================
195 //=======================================================================
197 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation::Copy() const
199 return new DrawTrSurf_Triangulation(myTriangulation);
202 //=======================================================================
205 //=======================================================================
207 void DrawTrSurf_Triangulation::Dump(Standard_OStream& S) const
209 Poly::Dump(myTriangulation,S);
212 //=======================================================================
215 //=======================================================================
217 void DrawTrSurf_Triangulation::Whatis(Draw_Interpretor& I) const
219 I << "triangulation";