1 // Created on: 1995-03-06
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <DrawTrSurf_Triangulation.hxx>
19 #include <Draw_Color.hxx>
20 #include <Draw_Display.hxx>
23 #include <Poly_Array1OfTriangle.hxx>
24 #include <Poly_Connect.hxx>
25 #include <Poly_Triangle.hxx>
26 #include <Poly_Triangulation.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
31 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Triangulation,Draw_Drawable3D)
33 //=======================================================================
34 //function : DrawTrSurf_Triangulation
36 //=======================================================================
37 DrawTrSurf_Triangulation::DrawTrSurf_Triangulation (const Handle(Poly_Triangulation)& T)
39 myNodes(Standard_False),
40 myTriangles(Standard_False)
42 // Build the connect tool
45 Standard_Integer i,j,nFree, nInternal, nbTriangles = T->NbTriangles();
46 Standard_Integer t[3];
48 // count the free edges
50 for (i = 1; i <= nbTriangles; i++) {
51 pc.Triangles(i,t[0],t[1],t[2]);
52 for (j = 0; j < 3; j++)
53 if (t[j] == 0) nFree++;
56 // allocate the arrays
57 myFree = new TColStd_HArray1OfInteger(1,2*nFree);
58 nInternal = (3*nbTriangles - nFree) / 2;
59 myInternals = new TColStd_HArray1OfInteger(1,2*nInternal);
61 TColStd_Array1OfInteger& Free = myFree->ChangeArray1();
62 TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
64 Standard_Integer fr = 1, in = 1;
65 Standard_Integer n[3];
66 for (i = 1; i <= nbTriangles; i++) {
67 pc.Triangles(i,t[0],t[1],t[2]);
68 T->Triangle (i).Get (n[0],n[1],n[2]);
69 for (j = 0; j < 3; j++) {
70 Standard_Integer k = (j+1) % 3;
76 // internal edge if this triangle has a lower index than the adjacent
79 Internal(in+1) = n[k];
86 //=======================================================================
89 //=======================================================================
90 void DrawTrSurf_Triangulation::DrawOn (Draw_Display& dis) const
97 dis.SetColor(Draw_rouge);
98 const TColStd_Array1OfInteger& Free = myFree->Array1();
99 n = Free.Length() / 2;
100 for (i = 1; i <= n; i++) {
101 dis.Draw (myTriangulation->Node (Free[2*i-1]),
102 myTriangulation->Node (Free[2*i]));
107 dis.SetColor(Draw_bleu);
108 const TColStd_Array1OfInteger& Internal = myInternals->Array1();
109 n = Internal.Length() / 2;
110 for (i = 1; i <= n; i++) {
111 dis.Draw (myTriangulation->Node (Internal[2*i-1]),
112 myTriangulation->Node (Internal[2*i]));
118 dis.SetColor(Draw_jaune);
119 n = myTriangulation->NbNodes();
120 for (i = 1; i <= n; i++) {
121 Sprintf(text,"%d",i);
122 dis.DrawString (myTriangulation->Node (i), text);
127 dis.SetColor(Draw_vert);
128 n = myTriangulation->NbTriangles();
129 Standard_Integer t[3],j;
130 for (i = 1; i <= n; i++) {
131 myTriangulation->Triangle (i).Get (t[0],t[1],t[2]);
133 gp_XYZ& bary = P.ChangeCoord();
134 for (j = 0; j < 3; j++)
135 bary.Add (myTriangulation->Node (t[j]).Coord());
136 bary.Multiply(1./3.);
138 Sprintf(text,"%d",i);
139 dis.DrawString(P,text);
144 //=======================================================================
147 //=======================================================================
148 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation::Copy() const
150 return new DrawTrSurf_Triangulation(myTriangulation);
153 //=======================================================================
156 //=======================================================================
157 void DrawTrSurf_Triangulation::Dump (Standard_OStream& S) const
159 Poly::Dump(myTriangulation,S);
162 //=======================================================================
165 //=======================================================================
166 void DrawTrSurf_Triangulation::Save (Standard_OStream& theStream) const
168 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
169 std::ios::fmtflags aFlags = theStream.flags();
170 theStream.setf (std::ios::scientific, std::ios::floatfield);
171 theStream.precision (15);
173 long aForm = theStream.setf (std::ios::scientific);
174 std::streamsize aPrec = theStream.precision (15);
176 Poly::Write (myTriangulation, theStream);
177 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
178 theStream.setf (aFlags);
180 theStream.setf (aForm);
181 theStream.precision (aPrec);
185 //=======================================================================
188 //=======================================================================
189 Handle(Draw_Drawable3D) DrawTrSurf_Triangulation::Restore (Standard_IStream& theStream)
191 return new DrawTrSurf_Triangulation (Poly::ReadTriangulation (theStream));
194 //=======================================================================
197 //=======================================================================
198 void DrawTrSurf_Triangulation::Whatis (Draw_Interpretor& I) const
200 I << "triangulation";