0032806: Coding - get rid of unused headers [Contap to Extrema]
[occt.git] / src / DrawTrSurf / DrawTrSurf_Triangulation2D.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Draw_Color.hxx>
19 #include <Draw_Display.hxx>
20 #include <DrawTrSurf_Triangulation2D.hxx>
21 #include <Poly.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>
27
28 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Triangulation2D,Draw_Drawable2D)
29
30 #ifdef _MSC_VER
31 #include <stdio.h>
32 #endif
33
34 //=======================================================================
35 //function : DrawTrSurf_Triangulation2D
36 //purpose  : 
37 //=======================================================================
38
39 DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
40 (const Handle(Poly_Triangulation)& T): 
41     myTriangulation(T)
42 {
43   // Build the connect tool
44   Poly_Connect pc(T);
45
46   Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
47   Standard_Integer t[3];
48
49   // count the free edges
50   nFree = 0;
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++;
55   }
56
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);
61
62   TColStd_Array1OfInteger& Free     = myFree->ChangeArray1();
63   TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
64
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;
72       if (t[j] == 0) {
73         Free(fr)   = n[j];
74         Free(fr+1) = n[k];
75         fr += 2;
76       }
77       // internal edge if this triangle has a lower index than the adjacent
78       else if (i < t[j]) {
79         Internal(in)   = n[j];
80         Internal(in+1) = n[k];
81         in += 2;
82       }
83     }
84   }
85 }
86
87 //=======================================================================
88 //function : Triangulation
89 //purpose  : 
90 //=======================================================================
91
92 Handle(Poly_Triangulation) DrawTrSurf_Triangulation2D::Triangulation() const 
93 {
94   return myTriangulation;
95 }
96
97 //=======================================================================
98 //function : DrawOn
99 //purpose  : 
100 //=======================================================================
101
102 void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const 
103 {
104   // Display the edges
105   Standard_Integer i,n;
106   if (myTriangulation->HasUVNodes())
107   {
108     // free edges
109     dis.SetColor(Draw_rouge);
110     const TColStd_Array1OfInteger& Free = myFree->Array1();
111     n = Free.Length() / 2;
112     for (i = 1; i <= n; i++)
113     {
114       dis.Draw (myTriangulation->UVNode (Free[2*i-1]),
115                 myTriangulation->UVNode (Free[2*i]));
116     }
117
118     // internal edges
119     dis.SetColor(Draw_bleu);
120     const TColStd_Array1OfInteger& Internal = myInternals->Array1();
121     n = Internal.Length() / 2;
122     for (i = 1; i <= n; i++)
123     {
124       dis.Draw (myTriangulation->UVNode (Internal[2*i-1]),
125                 myTriangulation->UVNode (Internal[2*i]));
126     }
127   }
128 }
129
130 //=======================================================================
131 //function : Copy
132 //purpose  : 
133 //=======================================================================
134
135 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const 
136 {
137   return new DrawTrSurf_Triangulation2D(myTriangulation);
138 }
139
140 //=======================================================================
141 //function : Dump
142 //purpose  : 
143 //=======================================================================
144
145 void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const 
146 {
147   Poly::Dump(myTriangulation,S);
148 }
149
150 //=======================================================================
151 //function : Whatis
152 //purpose  : 
153 //=======================================================================
154
155 void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const 
156 {
157   I << "triangulation";
158 }
159