0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / DrawTrSurf / DrawTrSurf_Triangulation.cxx
CommitLineData
b311480e 1// Created on: 1995-03-06
2// Created by: Laurent PAINNOT
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Draw_Color.hxx>
19#include <Draw_Display.hxx>
20#include <Draw_Drawable3D.hxx>
21#include <DrawTrSurf_Triangulation.hxx>
22#include <gp_Pnt.hxx>
23#include <Poly.hxx>
24#include <Poly_Array1OfTriangle.hxx>
7fd59977 25#include <Poly_Connect.hxx>
26#include <Poly_Triangle.hxx>
42cf5bc1 27#include <Poly_Triangulation.hxx>
28#include <Standard_Type.hxx>
7fd59977 29#include <TColStd_Array1OfInteger.hxx>
7fd59977 30
7fd59977 31#include <stdio.h>
92efcf78 32IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Triangulation,Draw_Drawable3D)
33
7fd59977 34//=======================================================================
35//function : DrawTrSurf_Triangulation
36//purpose :
37//=======================================================================
7fd59977 38DrawTrSurf_Triangulation::DrawTrSurf_Triangulation
39(const Handle(Poly_Triangulation)& T):
40 myTriangulation(T),
41 myNodes(Standard_False),
42 myTriangles(Standard_False)
43{
44 // Build the connect tool
45 Poly_Connect pc(T);
46
47 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
48 Standard_Integer t[3];
49
50 // count the free edges
51 nFree = 0;
52 for (i = 1; i <= nbTriangles; i++) {
53 pc.Triangles(i,t[0],t[1],t[2]);
54 for (j = 0; j < 3; j++)
55 if (t[j] == 0) nFree++;
56 }
57
58 // allocate the arrays
59 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
60 nInternal = (3*nbTriangles - nFree) / 2;
61 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
62
63 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
64 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
65
66 Standard_Integer fr = 1, in = 1;
67 const Poly_Array1OfTriangle& triangles = T->Triangles();
68 Standard_Integer n[3];
69 for (i = 1; i <= nbTriangles; i++) {
70 pc.Triangles(i,t[0],t[1],t[2]);
71 triangles(i).Get(n[0],n[1],n[2]);
72 for (j = 0; j < 3; j++) {
73 Standard_Integer k = (j+1) % 3;
74 if (t[j] == 0) {
75 Free(fr) = n[j];
76 Free(fr+1) = n[k];
77 fr += 2;
78 }
79 // internal edge if this triangle has a lower index than the adjacent
80 else if (i < t[j]) {
81 Internal(in) = n[j];
82 Internal(in+1) = n[k];
83 in += 2;
84 }
85 }
86 }
87}
88
89//=======================================================================
90//function : Triangulation
91//purpose :
92//=======================================================================
93
94Handle(Poly_Triangulation) DrawTrSurf_Triangulation::Triangulation() const
95{
96 return myTriangulation;
97}
98
99//=======================================================================
100//function : ShowNodes
101//purpose :
102//=======================================================================
103
104void DrawTrSurf_Triangulation::ShowNodes(const Standard_Boolean B)
105{
106 myNodes = B;
107}
108
109//=======================================================================
110//function : ShowNodes
111//purpose :
112//=======================================================================
113
114Standard_Boolean DrawTrSurf_Triangulation::ShowNodes() const
115{
116 return myNodes;
117}
118
119//=======================================================================
120//function : ShowTriangles
121//purpose :
122//=======================================================================
123
124void DrawTrSurf_Triangulation::ShowTriangles(const Standard_Boolean B)
125{
126 myTriangles = B;
127}
128
129//=======================================================================
130//function : ShowTriangles
131//purpose :
132//=======================================================================
133
134Standard_Boolean DrawTrSurf_Triangulation::ShowTriangles() const
135{
136 return myTriangles;
137}
138
139//=======================================================================
140//function : DrawOn
141//purpose :
142//=======================================================================
143
144void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
145{
146 // Display the edges
147 Standard_Integer i,n;
148
149 const TColgp_Array1OfPnt& Nodes = myTriangulation->Nodes();
150
151 // free edges
152
153 dis.SetColor(Draw_rouge);
154 const TColStd_Array1OfInteger& Free = myFree->Array1();
155 n = Free.Length() / 2;
156 for (i = 1; i <= n; i++) {
157 dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i)));
158 }
159
160 // internal edges
161
162 dis.SetColor(Draw_bleu);
163 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
164 n = Internal.Length() / 2;
165 for (i = 1; i <= n; i++) {
166 dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i)));
167 }
168
169 // texts
170 char text[50];
171 if (myNodes) {
172 dis.SetColor(Draw_jaune);
173 n = myTriangulation->NbNodes();
174 for (i = 1; i <= n; i++) {
91322f44 175 Sprintf(text,"%d",i);
7fd59977 176 dis.DrawString(Nodes(i),text);
177 }
178 }
179
180 if (myTriangles) {
181 dis.SetColor(Draw_vert);
182 n = myTriangulation->NbTriangles();
183 Standard_Integer t[3],j;
184 const Poly_Array1OfTriangle& triangle = myTriangulation->Triangles();
185 for (i = 1; i <= n; i++) {
186 triangle(i).Get(t[0],t[1],t[2]);
187 gp_Pnt P(0,0,0);
188 gp_XYZ& bary = P.ChangeCoord();
189 for (j = 0; j < 3; j++)
190 bary.Add(Nodes(t[j]).Coord());
191 bary.Multiply(1./3.);
192
91322f44 193 Sprintf(text,"%d",i);
7fd59977 194 dis.DrawString(P,text);
195 }
196 }
197}
198
199//=======================================================================
200//function : Copy
201//purpose :
202//=======================================================================
203
204Handle(Draw_Drawable3D) DrawTrSurf_Triangulation::Copy() const
205{
206 return new DrawTrSurf_Triangulation(myTriangulation);
207}
208
209//=======================================================================
210//function : Dump
211//purpose :
212//=======================================================================
213
214void DrawTrSurf_Triangulation::Dump(Standard_OStream& S) const
215{
216 Poly::Dump(myTriangulation,S);
217}
218
219//=======================================================================
220//function : Whatis
221//purpose :
222//=======================================================================
223
224void DrawTrSurf_Triangulation::Whatis(Draw_Interpretor& I) const
225{
226 I << "triangulation";
227}
228