1 // Created on: 1995-07-27
2 // Created by: Modelistation
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.
18 #include <Adaptor3d_Surface.hxx>
21 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
22 #include <Graphic3d_AspectFillArea3d.hxx>
23 #include <Graphic3d_Group.hxx>
24 #include <Precision.hxx>
25 #include <Prs3d_IsoAspect.hxx>
26 #include <Prs3d_Presentation.hxx>
27 #include <Prs3d_ShadingAspect.hxx>
28 #include <StdPrs_ShadedSurface.hxx>
29 #include <TColStd_Array1OfReal.hxx>
31 //=======================================================================
34 //=======================================================================
35 void StdPrs_ShadedSurface::Add (const Handle(Prs3d_Presentation)& thePrs,
36 const Adaptor3d_Surface& theSurface,
37 const Handle(Prs3d_Drawer)& theDrawer)
39 Standard_Integer N1 = theDrawer->UIsoAspect()->Number();
40 Standard_Integer N2 = theDrawer->VIsoAspect()->Number();
44 // If the surface is closed, the faces from back-side are not traced:
45 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePrs);
46 aGroup->SetGroupPrimitivesAspect (theDrawer->ShadingAspect()->Aspect());
47 aGroup->SetClosed (theSurface.IsUClosed() && theSurface.IsVClosed());
49 Standard_Integer aNBUintv = theSurface.NbUIntervals (GeomAbs_C1);
50 Standard_Integer aNBVintv = theSurface.NbVIntervals (GeomAbs_C1);
51 TColStd_Array1OfReal anInterU (1, aNBUintv + 1);
52 TColStd_Array1OfReal anInterV (1, aNBVintv + 1);
54 theSurface.UIntervals (anInterU, GeomAbs_C1);
55 theSurface.VIntervals (anInterV, GeomAbs_C1);
57 Standard_Real U1, U2, V1, V2, DU, DV;
60 gp_Vec D1U, D1V, D1, D2;
62 for (Standard_Integer NU = 1; NU <= aNBUintv; ++NU)
64 for (Standard_Integer NV = 1; NV <= aNBVintv; ++NV)
66 U1 = anInterU (NU); U2 = anInterU (NU + 1);
67 V1 = anInterV (NV); V2 = anInterV (NV + 1);
69 U1 = (Precision::IsNegativeInfinite (U1)) ? - theDrawer->MaximalParameterValue() : U1;
70 U2 = (Precision::IsPositiveInfinite (U2)) ? theDrawer->MaximalParameterValue() : U2;
72 V1 = (Precision::IsNegativeInfinite (V1)) ? - theDrawer->MaximalParameterValue() : V1;
73 V2 = (Precision::IsPositiveInfinite (V2)) ? theDrawer->MaximalParameterValue() : V2;
78 Handle(Graphic3d_ArrayOfTriangleStrips) aPArray
79 = new Graphic3d_ArrayOfTriangleStrips (2 * (N1 + 1) * (N2 + 1), N1 + 1,
80 Standard_True, Standard_False, Standard_False, Standard_False);
81 for (Standard_Integer i = 1; i <= N1 + 1; ++i)
83 aPArray->AddBound (N2 + 1);
84 for (Standard_Integer j = 1; j <= N2 + 1; ++j)
86 theSurface.D1 (U1 + DU * (i - 1), V1 + DV * (j - 1), P2, D1U, D1V);
89 theSurface.D1 (U1 + DU * i, V1 + DV * (j - 1), P2, D1U, D1V);
92 aPArray->AddVertex (P1, D1);
93 aPArray->AddVertex (P2, D2);
96 aGroup->AddPrimitiveArray (aPArray);