1 // Created on: 1997-07-22
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1997-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 <DrawTrSurf_Triangulation2D.hxx>
22 #include <Poly_Connect.hxx>
23 #include <Poly_Triangle.hxx>
24 #include <Poly_Triangulation.hxx>
25 #include <Standard_Type.hxx>
26 #include <TColStd_Array1OfInteger.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Triangulation2D,Draw_Drawable2D)
34 //=======================================================================
35 //function : DrawTrSurf_Triangulation2D
37 //=======================================================================
39 DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
40 (const Handle(Poly_Triangulation)& T):
43 // Build the connect tool
46 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
47 Standard_Integer t[3];
49 // count the free edges
51 for (i = 1; i <= nbTriangles; i++) {
52 pc.Triangles(i,t[0],t[1],t[2]);
53 for (j = 0; j < 3; j++)
54 if (t[j] == 0) nFree++;
57 // allocate the arrays
58 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
59 nInternal = (3*nbTriangles - nFree) / 2;
60 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
62 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
63 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
65 Standard_Integer fr = 1, in = 1;
66 Standard_Integer n[3];
67 for (i = 1; i <= nbTriangles; i++) {
68 pc.Triangles(i,t[0],t[1],t[2]);
69 T->Triangle(i).Get (n[0],n[1],n[2]);
70 for (j = 0; j < 3; j++) {
71 Standard_Integer k = (j+1) % 3;
77 // internal edge if this triangle has a lower index than the adjacent
80 Internal(in+1) = n[k];
87 //=======================================================================
88 //function : Triangulation
90 //=======================================================================
92 Handle(Poly_Triangulation) DrawTrSurf_Triangulation2D::Triangulation() const
94 return myTriangulation;
97 //=======================================================================
100 //=======================================================================
102 void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
105 Standard_Integer i,n;
106 if (myTriangulation->HasUVNodes())
109 dis.SetColor(Draw_rouge);
110 const TColStd_Array1OfInteger& Free = myFree->Array1();
111 n = Free.Length() / 2;
112 for (i = 1; i <= n; i++)
114 dis.Draw (myTriangulation->UVNode (Free[2*i-1]),
115 myTriangulation->UVNode (Free[2*i]));
119 dis.SetColor(Draw_bleu);
120 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
121 n = Internal.Length() / 2;
122 for (i = 1; i <= n; i++)
124 dis.Draw (myTriangulation->UVNode (Internal[2*i-1]),
125 myTriangulation->UVNode (Internal[2*i]));
130 //=======================================================================
133 //=======================================================================
135 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const
137 return new DrawTrSurf_Triangulation2D(myTriangulation);
140 //=======================================================================
143 //=======================================================================
145 void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const
147 Poly::Dump(myTriangulation,S);
150 //=======================================================================
153 //=======================================================================
155 void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const
157 I << "triangulation";