c57b8aeaade8979c3cfc368aed1dac4d106d1814
[occt.git] / src / StdPrs / StdPrs_ShadedPoleSurface.cxx
1 // Created on: 1995-08-01
2 // Created by: Modelistation
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
21
22 #define G005    //ATS,GG 04/01/01 Use PrimitiveArray instead Sets of primitives
23 //              for performance improvment
24
25 #include <StdPrs_ShadedPoleSurface.ixx>
26
27 #include <Graphic3d_Group.hxx>
28 #include <Graphic3d_Vertex.hxx>
29 #include <Graphic3d_Array2OfVertex.hxx>
30 #include <TColgp_Array2OfPnt.hxx>
31 #include <gp_Pnt.hxx>
32 #include <Prs3d_ShadingAspect.hxx>
33 #include <Graphic3d_AspectFillArea3d.hxx>
34
35 #include <Geom_BezierSurface.hxx>
36 #include <Geom_BSplineSurface.hxx>
37 #ifdef G005
38 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
39 #endif
40
41 //=======================================================================
42 //function : Add
43 //purpose  : 
44 //=======================================================================
45
46 void StdPrs_ShadedPoleSurface::Add(
47                         const Handle(Prs3d_Presentation)& aPresentation,
48                         const Adaptor3d_Surface&            aSurface,
49                         const Handle (Prs3d_Drawer)&      aDrawer)
50 {
51   if ( ! aDrawer->ShadingAspectGlobal() ) {
52
53 // If the surface is closed, the faces from back-side are not traced:
54
55
56     Handle(Graphic3d_AspectFillArea3d) Asp = aDrawer->ShadingAspect()->Aspect();
57     if(aSurface.IsUClosed() && aSurface.IsVClosed()) {
58       Asp->SuppressBackFace();
59     } else {
60       Asp->AllowBackFace();
61     }
62     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Asp);
63   }
64
65   Standard_Integer i,j,n = aSurface.NbUPoles(), m = aSurface.NbVPoles();
66
67   if (aSurface.GetType() == GeomAbs_BezierSurface) {
68     Handle(Geom_BezierSurface) surface = aSurface.Bezier();
69 #ifdef G005
70     if( Graphic3d_ArrayOfPrimitives::IsEnable() ) {
71       Handle(Graphic3d_ArrayOfQuadrangleStrips) parray =
72                 new Graphic3d_ArrayOfQuadrangleStrips(n*m,n,
73                 Standard_False,Standard_False,Standard_False,Standard_False);
74       for ( i=1; i<=n; i++) {
75         parray->AddBound(m);
76         for ( j=1; j<=m; j++) {
77           parray->AddVertex(surface->Pole(i,j));
78         }
79       }
80       Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(parray);
81       return;
82     }
83 #endif    
84     TColgp_Array2OfPnt A(1,n,1,m);
85     surface->Poles(A);
86     Graphic3d_Array2OfVertex V(1,n,1,m);
87     Standard_Real x,y,z;
88     for ( i=1; i<=n; i++) {
89       for ( j=1; j<=m; j++) {
90         A(i,j).Coord(x,y,z);
91         V(i,j).SetCoord(x,y,z);
92       }
93     }
94     Prs3d_Root::CurrentGroup(aPresentation)->QuadrangleMesh(V);
95   }
96   else if (aSurface.GetType() == GeomAbs_BSplineSurface) {
97       Handle(Geom_BSplineSurface) surface = aSurface.BSpline();
98 #ifdef G005
99     if( Graphic3d_ArrayOfPrimitives::IsEnable() ) {
100       Handle(Graphic3d_ArrayOfQuadrangleStrips) parray =
101                 new Graphic3d_ArrayOfQuadrangleStrips(n*m,n,
102                 Standard_False,Standard_False,Standard_False,Standard_False);
103       for ( i=1; i<=n; i++) {
104         parray->AddBound(m);
105         for ( j=1; j<=m; j++) {
106           parray->AddVertex(surface->Pole(i,j));
107         }
108       }
109       Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(parray);
110       return;
111     }
112 #endif    
113     TColgp_Array2OfPnt A(1,n,1,m);
114     surface->Poles(A);
115     Graphic3d_Array2OfVertex V(1,n,1,m);
116     Standard_Real x,y,z;
117     for ( i=1; i<=n; i++) {
118       for ( j=1; j<=m; j++) {
119         A(i,j).Coord(x,y,z);
120         V(i,j).SetCoord(x,y,z);
121       }
122     }
123     Prs3d_Root::CurrentGroup(aPresentation)->QuadrangleMesh(V);
124   }
125 }