0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / DrawTrSurf / DrawTrSurf_Triangulation2D.cxx
CommitLineData
b311480e 1// Created on: 1997-07-22
2// Created by: Laurent PAINNOT
3// Copyright (c) 1997-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_Triangulation2D.hxx>
22#include <gp_Pnt2d.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 <TColgp_Array1OfPnt2d.hxx>
42cf5bc1 30#include <TColStd_Array1OfInteger.hxx>
7fd59977 31
92efcf78 32IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Triangulation2D,Draw_Drawable2D)
33
57c28b61 34#ifdef _MSC_VER
7fd59977 35#include <stdio.h>
36#endif
37
38//=======================================================================
39//function : DrawTrSurf_Triangulation2D
40//purpose :
41//=======================================================================
42
43DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
44(const Handle(Poly_Triangulation)& T):
45 myTriangulation(T)
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_Triangulation2D::Triangulation() const
98{
99 return myTriangulation;
100}
101
102//=======================================================================
103//function : DrawOn
104//purpose :
105//=======================================================================
106
107void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
108{
109 // Display the edges
110 Standard_Integer i,n;
111 if (myTriangulation->HasUVNodes()) {
112
113 const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes();
114
115 // free edges
116
117 dis.SetColor(Draw_rouge);
118 const TColStd_Array1OfInteger& Free = myFree->Array1();
119 n = Free.Length() / 2;
120 for (i = 1; i <= n; i++) {
121 dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i)));
122 }
123
124 // internal edges
125
126 dis.SetColor(Draw_bleu);
127 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
128 n = Internal.Length() / 2;
129 for (i = 1; i <= n; i++) {
130 dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i)));
131 }
132
133 }
134}
135
136//=======================================================================
137//function : Copy
138//purpose :
139//=======================================================================
140
141Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const
142{
143 return new DrawTrSurf_Triangulation2D(myTriangulation);
144}
145
146//=======================================================================
147//function : Dump
148//purpose :
149//=======================================================================
150
151void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const
152{
153 Poly::Dump(myTriangulation,S);
154}
155
156//=======================================================================
157//function : Whatis
158//purpose :
159//=======================================================================
160
161void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const
162{
163 I << "triangulation";
164}
165