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 <Draw_Drawable3D.hxx>
21 #include <DrawTrSurf_Triangulation2D.hxx>
22 #include <gp_Pnt2d.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 <TColgp_Array1OfPnt2d.hxx>
30 #include <TColStd_Array1OfInteger.hxx>
36 //=======================================================================
37 //function : DrawTrSurf_Triangulation2D
39 //=======================================================================
41 DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
42 (const Handle(Poly_Triangulation)& T):
45 // Build the connect tool
48 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
49 Standard_Integer t[3];
51 // count the free edges
53 for (i = 1; i <= nbTriangles; i++) {
54 pc.Triangles(i,t[0],t[1],t[2]);
55 for (j = 0; j < 3; j++)
56 if (t[j] == 0) nFree++;
59 // allocate the arrays
60 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
61 nInternal = (3*nbTriangles - nFree) / 2;
62 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
64 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
65 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
67 Standard_Integer fr = 1, in = 1;
68 const Poly_Array1OfTriangle& triangles = T->Triangles();
69 Standard_Integer n[3];
70 for (i = 1; i <= nbTriangles; i++) {
71 pc.Triangles(i,t[0],t[1],t[2]);
72 triangles(i).Get(n[0],n[1],n[2]);
73 for (j = 0; j < 3; j++) {
74 Standard_Integer k = (j+1) % 3;
80 // internal edge if this triangle has a lower index than the adjacent
83 Internal(in+1) = n[k];
90 //=======================================================================
91 //function : Triangulation
93 //=======================================================================
95 Handle(Poly_Triangulation) DrawTrSurf_Triangulation2D::Triangulation() const
97 return myTriangulation;
100 //=======================================================================
103 //=======================================================================
105 void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
108 Standard_Integer i,n;
109 if (myTriangulation->HasUVNodes()) {
111 const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes();
115 dis.SetColor(Draw_rouge);
116 const TColStd_Array1OfInteger& Free = myFree->Array1();
117 n = Free.Length() / 2;
118 for (i = 1; i <= n; i++) {
119 dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i)));
124 dis.SetColor(Draw_bleu);
125 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
126 n = Internal.Length() / 2;
127 for (i = 1; i <= n; i++) {
128 dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i)));
134 //=======================================================================
137 //=======================================================================
139 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const
141 return new DrawTrSurf_Triangulation2D(myTriangulation);
144 //=======================================================================
147 //=======================================================================
149 void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const
151 Poly::Dump(myTriangulation,S);
154 //=======================================================================
157 //=======================================================================
159 void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const
161 I << "triangulation";