b311480e |
1 | // Created on: 1997-07-22 |
2 | // Created by: Laurent PAINNOT |
3 | // Copyright (c) 1997-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_Triangulation2D.ixx> |
24 | #include <Poly_Connect.hxx> |
25 | #include <Poly_Triangle.hxx> |
26 | #include <Poly_Array1OfTriangle.hxx> |
27 | #include <TColStd_Array1OfInteger.hxx> |
28 | #include <TColgp_Array1OfPnt2d.hxx> |
29 | #include <gp_Pnt2d.hxx> |
30 | #include <Draw_Color.hxx> |
31 | #include <Poly.hxx> |
32 | |
33 | #ifdef WNT |
34 | #include <stdio.h> |
35 | #endif |
36 | |
37 | //======================================================================= |
38 | //function : DrawTrSurf_Triangulation2D |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D |
43 | (const Handle(Poly_Triangulation)& T): |
44 | myTriangulation(T) |
45 | { |
46 | // Build the connect tool |
47 | Poly_Connect pc(T); |
48 | |
49 | Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles(); |
50 | Standard_Integer t[3]; |
51 | |
52 | // count the free edges |
53 | nFree = 0; |
54 | for (i = 1; i <= nbTriangles; i++) { |
55 | pc.Triangles(i,t[0],t[1],t[2]); |
56 | for (j = 0; j < 3; j++) |
57 | if (t[j] == 0) nFree++; |
58 | } |
59 | |
60 | // allocate the arrays |
61 | myFree = new TColStd_HArray1OfInteger(1,2*nFree); |
62 | nInternal = (3*nbTriangles - nFree) / 2; |
63 | myInternals = new TColStd_HArray1OfInteger(1,2*nInternal); |
64 | |
65 | TColStd_Array1OfInteger& Free = myFree->ChangeArray1(); |
66 | TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1(); |
67 | |
68 | Standard_Integer fr = 1, in = 1; |
69 | const Poly_Array1OfTriangle& triangles = T->Triangles(); |
70 | Standard_Integer n[3]; |
71 | for (i = 1; i <= nbTriangles; i++) { |
72 | pc.Triangles(i,t[0],t[1],t[2]); |
73 | triangles(i).Get(n[0],n[1],n[2]); |
74 | for (j = 0; j < 3; j++) { |
75 | Standard_Integer k = (j+1) % 3; |
76 | if (t[j] == 0) { |
77 | Free(fr) = n[j]; |
78 | Free(fr+1) = n[k]; |
79 | fr += 2; |
80 | } |
81 | // internal edge if this triangle has a lower index than the adjacent |
82 | else if (i < t[j]) { |
83 | Internal(in) = n[j]; |
84 | Internal(in+1) = n[k]; |
85 | in += 2; |
86 | } |
87 | } |
88 | } |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Triangulation |
93 | //purpose : |
94 | //======================================================================= |
95 | |
96 | Handle(Poly_Triangulation) DrawTrSurf_Triangulation2D::Triangulation() const |
97 | { |
98 | return myTriangulation; |
99 | } |
100 | |
101 | //======================================================================= |
102 | //function : DrawOn |
103 | //purpose : |
104 | //======================================================================= |
105 | |
106 | void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const |
107 | { |
108 | // Display the edges |
109 | Standard_Integer i,n; |
110 | if (myTriangulation->HasUVNodes()) { |
111 | |
112 | const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes(); |
113 | |
114 | // free edges |
115 | |
116 | dis.SetColor(Draw_rouge); |
117 | const TColStd_Array1OfInteger& Free = myFree->Array1(); |
118 | n = Free.Length() / 2; |
119 | for (i = 1; i <= n; i++) { |
120 | dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i))); |
121 | } |
122 | |
123 | // internal edges |
124 | |
125 | dis.SetColor(Draw_bleu); |
126 | const TColStd_Array1OfInteger& Internal = myInternals->Array1(); |
127 | n = Internal.Length() / 2; |
128 | for (i = 1; i <= n; i++) { |
129 | dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i))); |
130 | } |
131 | |
132 | } |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : Copy |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | Handle(Draw_Drawable3D) DrawTrSurf_Triangulation2D::Copy() const |
141 | { |
142 | return new DrawTrSurf_Triangulation2D(myTriangulation); |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : Dump |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | void DrawTrSurf_Triangulation2D::Dump(Standard_OStream& S) const |
151 | { |
152 | Poly::Dump(myTriangulation,S); |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : Whatis |
157 | //purpose : |
158 | //======================================================================= |
159 | |
160 | void DrawTrSurf_Triangulation2D::Whatis(Draw_Interpretor& I) const |
161 | { |
162 | I << "triangulation"; |
163 | } |
164 | |