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
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.
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.
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.
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>
29 #include <Draw_Color.hxx>
36 //=======================================================================
37 //function : DrawTrSurf_Triangulation
39 //=======================================================================
41 DrawTrSurf_Triangulation::DrawTrSurf_Triangulation
42 (const Handle(Poly_Triangulation)& T):
44 myNodes(Standard_False),
45 myTriangles(Standard_False)
47 // Build the connect tool
50 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
51 Standard_Integer t[3];
53 // count the free edges
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++;
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);
66 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
67 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
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;
82 // internal edge if this triangle has a lower index than the adjacent
85 Internal(in+1) = n[k];
92 //=======================================================================
93 //function : Triangulation
95 //=======================================================================
97 Handle(Poly_Triangulation) DrawTrSurf_Triangulation::Triangulation() const
99 return myTriangulation;
102 //=======================================================================
103 //function : ShowNodes
105 //=======================================================================
107 void DrawTrSurf_Triangulation::ShowNodes(const Standard_Boolean B)
112 //=======================================================================
113 //function : ShowNodes
115 //=======================================================================
117 Standard_Boolean DrawTrSurf_Triangulation::ShowNodes() const
122 //=======================================================================
123 //function : ShowTriangles
125 //=======================================================================
127 void DrawTrSurf_Triangulation::ShowTriangles(const Standard_Boolean B)
132 //=======================================================================
133 //function : ShowTriangles
135 //=======================================================================
137 Standard_Boolean DrawTrSurf_Triangulation::ShowTriangles() const
142 //=======================================================================
145 //=======================================================================
147 void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
150 Standard_Integer i,n;
152 const TColgp_Array1OfPnt& Nodes = myTriangulation->Nodes();
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)));
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)));
175 dis.SetColor(Draw_jaune);
176 n = myTriangulation->NbNodes();
177 for (i = 1; i <= n; i++) {
178 Sprintf(text,"%d",i);
179 dis.DrawString(Nodes(i),text);
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]);
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.);
196 Sprintf(text,"%d",i);
197 dis.DrawString(P,text);
202 //=======================================================================
205 //=======================================================================
207 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation::Copy() const
209 return new DrawTrSurf_Triangulation(myTriangulation);
212 //=======================================================================
215 //=======================================================================
217 void DrawTrSurf_Triangulation::Dump(Standard_OStream& S) const
219 Poly::Dump(myTriangulation,S);
222 //=======================================================================
225 //=======================================================================
227 void DrawTrSurf_Triangulation::Whatis(Draw_Interpretor& I) const
229 I << "triangulation";