1 // Created on: 1997-07-22
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <DrawTrSurf_Triangulation2D.ixx>
24 #include <Poly_Connect.hxx>
25 #include <Poly_Triangle.hxx>
26 #include <Poly_Array1OfTriangle.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
28 #include <TColgp_Array1OfPnt2d.hxx>
29 #include <gp_Pnt2d.hxx>
30 #include <Draw_Color.hxx>
37 //=======================================================================
38 //function : DrawTrSurf_Triangulation2D
40 //=======================================================================
42 DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
43 (const Handle(Poly_Triangulation)& T):
46 // Build the connect tool
49 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
50 Standard_Integer t[3];
52 // count the free edges
54 for (i = 1; i <= nbTriangles; i++) {
55 pc.Triangles(i,t[0],t[1],t[2]);
56 for (j = 0; j < 3; j++)
57 if (t[j] == 0) nFree++;
60 // allocate the arrays
61 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
62 nInternal = (3*nbTriangles - nFree) / 2;
63 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
65 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
66 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
68 Standard_Integer fr = 1, in = 1;
69 const Poly_Array1OfTriangle& triangles = T->Triangles();
70 Standard_Integer n[3];
71 for (i = 1; i <= nbTriangles; i++) {
72 pc.Triangles(i,t[0],t[1],t[2]);
73 triangles(i).Get(n[0],n[1],n[2]);
74 for (j = 0; j < 3; j++) {
75 Standard_Integer k = (j+1) % 3;
81 // internal edge if this triangle has a lower index than the adjacent
84 Internal(in+1) = n[k];
91 //=======================================================================
92 //function : Triangulation
94 //=======================================================================
96 Handle(Poly_Triangulation) DrawTrSurf_Triangulation2D::Triangulation() const
98 return myTriangulation;
101 //=======================================================================
104 //=======================================================================
106 void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
109 Standard_Integer i,n;
110 if (myTriangulation->HasUVNodes()) {
112 const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes();
116 dis.SetColor(Draw_rouge);
117 const TColStd_Array1OfInteger& Free = myFree->Array1();
118 n = Free.Length() / 2;
119 for (i = 1; i <= n; i++) {
120 dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i)));
125 dis.SetColor(Draw_bleu);
126 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
127 n = Internal.Length() / 2;
128 for (i = 1; i <= n; i++) {
129 dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i)));
135 //=======================================================================
138 //=======================================================================
140 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const
142 return new DrawTrSurf_Triangulation2D(myTriangulation);
145 //=======================================================================
148 //=======================================================================
150 void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const
152 Poly::Dump(myTriangulation,S);
155 //=======================================================================
158 //=======================================================================
160 void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const
162 I << "triangulation";