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