0022972: Eliminate macro definitions that has compiler-provided analogs (WNT and...
[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 <Draw_Drawable3D.hxx>
21 #include <DrawTrSurf_Triangulation2D.hxx>
22 #include <gp_Pnt2d.hxx>
23 #include <Poly.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>
31
32 #ifdef _MSC_VER
33 #include <stdio.h>
34 #endif
35
36 //=======================================================================
37 //function : DrawTrSurf_Triangulation2D
38 //purpose  : 
39 //=======================================================================
40
41 DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
42 (const Handle(Poly_Triangulation)& T): 
43     myTriangulation(T)
44 {
45   // Build the connect tool
46   Poly_Connect pc(T);
47
48   Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
49   Standard_Integer t[3];
50
51   // count the free edges
52   nFree = 0;
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++;
57   }
58
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);
63
64   TColStd_Array1OfInteger& Free     = myFree->ChangeArray1();
65   TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
66
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;
75       if (t[j] == 0) {
76         Free(fr)   = n[j];
77         Free(fr+1) = n[k];
78         fr += 2;
79       }
80       // internal edge if this triangle has a lower index than the adjacent
81       else if (i < t[j]) {
82         Internal(in)   = n[j];
83         Internal(in+1) = n[k];
84         in += 2;
85       }
86     }
87   }
88 }
89
90 //=======================================================================
91 //function : Triangulation
92 //purpose  : 
93 //=======================================================================
94
95 Handle(Poly_Triangulation) DrawTrSurf_Triangulation2D::Triangulation() const 
96 {
97   return myTriangulation;
98 }
99
100 //=======================================================================
101 //function : DrawOn
102 //purpose  : 
103 //=======================================================================
104
105 void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const 
106 {
107   // Display the edges
108   Standard_Integer i,n;
109   if (myTriangulation->HasUVNodes()) {
110     
111     const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes();
112     
113     // free edges
114     
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)));
120     }
121     
122     // internal edges
123     
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)));
129     }
130     
131   }
132 }
133
134 //=======================================================================
135 //function : Copy
136 //purpose  : 
137 //=======================================================================
138
139 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const 
140 {
141   return new DrawTrSurf_Triangulation2D(myTriangulation);
142 }
143
144 //=======================================================================
145 //function : Dump
146 //purpose  : 
147 //=======================================================================
148
149 void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const 
150 {
151   Poly::Dump(myTriangulation,S);
152 }
153
154 //=======================================================================
155 //function : Whatis
156 //purpose  : 
157 //=======================================================================
158
159 void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const 
160 {
161   I << "triangulation";
162 }
163