b311480e |
1 | // Created on: 1995-07-27 |
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 | |
7fd59977 |
21 | |
22 | #define G005 //ATS,GG 04/01/01 Use PrimitiveArray instead Sets of primitives |
23 | // for performance improvment |
24 | |
25 | #include <StdPrs_ShadedSurface.ixx> |
26 | |
2bd4c032 |
27 | #include <Graphic3d_ArrayOfTriangleStrips.hxx> |
28 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 |
29 | #include <Graphic3d_Group.hxx> |
2bd4c032 |
30 | #include <gp_Pnt.hxx> |
7fd59977 |
31 | #include <gp_Vec.hxx> |
32 | #include <Prs3d_ShadingAspect.hxx> |
33 | #include <Prs3d_IsoAspect.hxx> |
7fd59977 |
34 | #include <Precision.hxx> |
35 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
36 | |
37 | //======================================================================= |
38 | //function : Add |
2bd4c032 |
39 | //purpose : |
7fd59977 |
40 | //======================================================================= |
41 | |
2bd4c032 |
42 | void StdPrs_ShadedSurface::Add (const Handle(Prs3d_Presentation)& thePrs, |
43 | const Adaptor3d_Surface& theSurface, |
44 | const Handle(Prs3d_Drawer)& theDrawer) |
7fd59977 |
45 | { |
2bd4c032 |
46 | Standard_Integer N1 = theDrawer->UIsoAspect()->Number(); |
47 | Standard_Integer N2 = theDrawer->VIsoAspect()->Number(); |
7fd59977 |
48 | N1 = N1 < 3 ? 3 : N1; |
49 | N2 = N2 < 3 ? 3 : N2; |
7fd59977 |
50 | |
2bd4c032 |
51 | if (!theDrawer->ShadingAspectGlobal()) |
52 | { |
53 | // If the surface is closed, the faces from back-side are not traced: |
54 | Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect(); |
55 | if (theSurface.IsUClosed() && theSurface.IsVClosed()) |
56 | { |
57 | anAsp->SuppressBackFace(); |
58 | } |
59 | else |
60 | { |
61 | anAsp->AllowBackFace(); |
7fd59977 |
62 | } |
2bd4c032 |
63 | Prs3d_Root::CurrentGroup (thePrs)->SetGroupPrimitivesAspect (anAsp); |
7fd59977 |
64 | } |
65 | |
2bd4c032 |
66 | Standard_Integer aNBUintv = theSurface.NbUIntervals (GeomAbs_C1); |
67 | Standard_Integer aNBVintv = theSurface.NbVIntervals (GeomAbs_C1); |
68 | TColStd_Array1OfReal anInterU (1, aNBUintv + 1); |
69 | TColStd_Array1OfReal anInterV (1, aNBVintv + 1); |
70 | |
71 | theSurface.UIntervals (anInterU, GeomAbs_C1); |
72 | theSurface.VIntervals (anInterV, GeomAbs_C1); |
73 | |
74 | Standard_Real U1, U2, V1, V2, DU, DV; |
75 | |
76 | gp_Pnt P1, P2; |
77 | gp_Vec D1U, D1V, D1, D2; |
78 | |
2bd4c032 |
79 | for (Standard_Integer NU = 1; NU <= aNBUintv; ++NU) |
80 | { |
81 | for (Standard_Integer NV = 1; NV <= aNBVintv; ++NV) |
82 | { |
83 | U1 = anInterU (NU); U2 = anInterU (NU + 1); |
84 | V1 = anInterV (NV); V2 = anInterV (NV + 1); |
85 | |
86 | U1 = (Precision::IsNegativeInfinite (U1)) ? - theDrawer->MaximalParameterValue() : U1; |
87 | U2 = (Precision::IsPositiveInfinite (U2)) ? theDrawer->MaximalParameterValue() : U2; |
88 | |
89 | V1 = (Precision::IsNegativeInfinite (V1)) ? - theDrawer->MaximalParameterValue() : V1; |
90 | V2 = (Precision::IsPositiveInfinite (V2)) ? theDrawer->MaximalParameterValue() : V2; |
91 | |
92 | DU = (U2 - U1) / N1; |
93 | DV = (V2 - V1) / N2; |
94 | |
95 | Handle(Graphic3d_ArrayOfTriangleStrips) aPArray |
96 | = new Graphic3d_ArrayOfTriangleStrips (2 * (N1 + 1) * (N2 + 1), N1 + 1, |
97 | Standard_True, Standard_False, Standard_False, Standard_False); |
98 | for (Standard_Integer i = 1; i <= N1 + 1; ++i) |
99 | { |
100 | aPArray->AddBound (N2 + 1); |
101 | for (Standard_Integer j = 1; j <= N2 + 1; ++j) |
102 | { |
103 | theSurface.D1 (U1 + DU * (i - 1), V1 + DV * (j - 1), P2, D1U, D1V); |
104 | D1 = D1U ^ D1V; |
105 | D1.Normalize(); |
106 | theSurface.D1 (U1 + DU * i, V1 + DV * (j - 1), P2, D1U, D1V); |
107 | D2 = D1U ^ D1V; |
108 | D2.Normalize(); |
109 | aPArray->AddVertex (P1, D1); |
110 | aPArray->AddVertex (P2, D2); |
7fd59977 |
111 | } |
7fd59977 |
112 | } |
2bd4c032 |
113 | Prs3d_Root::CurrentGroup (thePrs)->AddPrimitiveArray (aPArray); |
7fd59977 |
114 | } |
115 | } |
7fd59977 |
116 | } |