0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / StdPrs / StdPrs_WFSurface.cxx
CommitLineData
b311480e 1// Created on: 1995-08-04
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <Adaptor3d_HSurface.hxx>
19#include <Adaptor3d_IsoCurve.hxx>
7fd59977 20#include <Bnd_Box.hxx>
7fd59977 21#include <BndLib_AddSurface.hxx>
42cf5bc1 22#include <GeomAbs_IsoType.hxx>
23#include <Graphic3d_ArrayOfPolylines.hxx>
24#include <Graphic3d_Group.hxx>
25#include <Precision.hxx>
26#include <Prs3d_IsoAspect.hxx>
27#include <Prs3d_NListIteratorOfListOfSequenceOfPnt.hxx>
28#include <Prs3d_NListOfSequenceOfPnt.hxx>
29#include <Prs3d_Presentation.hxx>
7fd59977 30#include <StdPrs_Curve.hxx>
42cf5bc1 31#include <StdPrs_WFSurface.hxx>
7fd59977 32#include <TColgp_SequenceOfPnt.hxx>
33
7fd59977 34static void FindLimits(const Handle(Adaptor3d_HSurface)& surf ,
35 const Standard_Real aLimit,
36 Standard_Real& UFirst,
37 Standard_Real& ULast,
38 Standard_Real& VFirst,
39 Standard_Real& VLast)
40{
41 UFirst = surf->FirstUParameter();
42 ULast = surf->LastUParameter();
43 VFirst = surf->FirstVParameter();
44 VLast = surf->LastVParameter();
45
46 Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
47 Standard_Boolean UlastInf = Precision::IsPositiveInfinite(ULast);
48 Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
49 Standard_Boolean VlastInf = Precision::IsPositiveInfinite(VLast);
50
51 if (UfirstInf || UlastInf) {
52 gp_Pnt P1,P2;
53 Standard_Real v;
54 if (VfirstInf && VlastInf)
55 v = 0;
56 else if (VfirstInf)
57 v = VLast;
58 else if (VlastInf)
59 v = VFirst;
60 else
61 v = (VFirst + VLast) / 2;
62
63 Standard_Real delta = aLimit * 2;
64
65 if (UfirstInf && UlastInf) {
66 do {
67 delta /= 2;
68 UFirst = - delta;
69 ULast = delta;
70 surf->D0(UFirst,v,P1);
71 surf->D0(ULast,v,P2);
72 } while (P1.Distance(P2) > aLimit);
73 }
74 else if (UfirstInf) {
75 surf->D0(ULast,v,P2);
76 do {
77 delta /= 2;
78 UFirst = ULast - delta;
79 surf->D0(UFirst,v,P1);
80 } while (P1.Distance(P2) > aLimit);
81 }
82 else if (UlastInf) {
83 surf->D0(UFirst,v,P1);
84 do {
85 delta /= 2;
86 ULast = UFirst + delta;
87 surf->D0(ULast,v,P2);
88 } while (P1.Distance(P2) > aLimit);
89 }
90 }
91
92 if (VfirstInf || VlastInf) {
93 gp_Pnt P1,P2;
94 Standard_Real u = (UFirst + ULast) /2 ;
95
96 Standard_Real delta = aLimit * 2;
97
98 if (VfirstInf && VlastInf) {
99 do {
100 delta /= 2;
101 VFirst = - delta;
102 VLast = delta;
103 surf->D0(u,VFirst,P1);
104 surf->D0(u,VLast,P2);
105 } while (P1.Distance(P2) > aLimit);
106 }
107 else if (VfirstInf) {
108 surf->D0(u,VLast,P2);
109 do {
110 delta /= 2;
111 VFirst = VLast - delta;
112 surf->D0(u,VFirst,P1);
113 } while (P1.Distance(P2) > aLimit);
114 }
115 else if (VlastInf) {
116 surf->D0(u,VFirst,P1);
117 do {
118 delta /= 2;
119 VLast = VFirst + delta;
120 surf->D0(u,VLast,P2);
121 } while (P1.Distance(P2) > aLimit);
122 }
123 }
124}
125
126
127//=======================================================================
128//function : Add
129//purpose :
130//=======================================================================
131
132void StdPrs_WFSurface::Add (const Handle(Prs3d_Presentation)& aPresentation,
133 const Handle(Adaptor3d_HSurface)& aSurface,
134 const Handle(Prs3d_Drawer)& aDrawer)
135{
136
137 Standard_Real U1, U2, V1, V2;
138 Standard_Real MaxP = aDrawer->MaximalParameterValue();
139
7fd59977 140 FindLimits(aSurface, MaxP, U1, U2, V1, V2);
141
142 Prs3d_NListOfSequenceOfPnt freeCurves;
143 Prs3d_NListOfSequenceOfPnt UIsoCurves;
144 Prs3d_NListOfSequenceOfPnt VIsoCurves;
7fd59977 145
146 Standard_Boolean UClosed = aSurface->IsUClosed();
147 Standard_Boolean VClosed = aSurface->IsVClosed();
7fd59977 148
149 Adaptor3d_IsoCurve anIso;
150 anIso.Load(aSurface);
151
152 // Trace des frontieres.
153 // *********************
154 //
5ad8c033 155 if (!(UClosed && VClosed))
156 {
157 Prs3d_Root::CurrentGroup (aPresentation)->SetPrimitivesAspect (aDrawer->FreeBoundaryAspect()->Aspect());
158 if (!UClosed)
159 {
160 anIso.Load (GeomAbs_IsoU, U1, V1, V2);
161 Handle(TColgp_HSequenceOfPnt) aPntsU1 = new TColgp_HSequenceOfPnt;
162 StdPrs_Curve::Add (aPresentation, anIso, aDrawer, aPntsU1->ChangeSequence(), Standard_False);
163 freeCurves.Append (aPntsU1);
164
165 anIso.Load (GeomAbs_IsoU,U2,V1,V2);
166 Handle(TColgp_HSequenceOfPnt) aPntsU2 = new TColgp_HSequenceOfPnt;
167 StdPrs_Curve::Add (aPresentation, anIso, aDrawer, aPntsU2->ChangeSequence(), Standard_False);
168 freeCurves.Append(aPntsU2);
169 }
170 if (!VClosed)
171 {
172 anIso.Load (GeomAbs_IsoV, V1, U1, U2);
173 Handle(TColgp_HSequenceOfPnt) aPntsV1 = new TColgp_HSequenceOfPnt;
174 StdPrs_Curve::Add (aPresentation, anIso, aDrawer, aPntsV1->ChangeSequence(), Standard_False);
175 freeCurves.Append (aPntsV1);
176
177 anIso.Load (GeomAbs_IsoV, V2, U1, U2);
178 Handle(TColgp_HSequenceOfPnt) aPntsV2 = new TColgp_HSequenceOfPnt;
179 StdPrs_Curve::Add (aPresentation, anIso, aDrawer, aPntsV2->ChangeSequence(), Standard_False);
180 freeCurves.Append(aPntsV2);
181 }
7fd59977 182 }
183 //
184 // Trace des isoparametriques.
185 // ***************************
186 //
187 Standard_Integer fin = aDrawer->UIsoAspect()->Number();
5ad8c033 188 if (fin != 0)
189 {
190 Prs3d_Root::CurrentGroup (aPresentation)->SetPrimitivesAspect (aDrawer->UIsoAspect()->Aspect());
191
192 Standard_Real du= UClosed ? (U2-U1) / fin : (U2-U1) / (1 + fin);
193 for (Standard_Integer i = 1; i <= fin; i++)
194 {
195 anIso.Load (GeomAbs_IsoU, U1 + du * i, V1, V2);
e3a6386d 196 Handle(TColgp_HSequenceOfPnt) Pnts = new TColgp_HSequenceOfPnt;
5ad8c033 197 StdPrs_Curve::Add (aPresentation, anIso, aDrawer, Pnts->ChangeSequence(), Standard_False);
198 UIsoCurves.Append (Pnts);
7fd59977 199 }
200 }
201 fin = aDrawer->VIsoAspect()->Number();
5ad8c033 202 if (fin != 0)
203 {
204 Prs3d_Root::CurrentGroup (aPresentation)->SetPrimitivesAspect (aDrawer->VIsoAspect()->Aspect());
7fd59977 205
5ad8c033 206 Standard_Real dv = VClosed ? (V2 - V1) / fin : (V2 - V1) / (1 + fin);
207 for (Standard_Integer i = 1; i <= fin; i++)
208 {
209 anIso.Load (GeomAbs_IsoV, V1 + dv * i, U1, U2);
e3a6386d 210 Handle(TColgp_HSequenceOfPnt) Pnts = new TColgp_HSequenceOfPnt;
5ad8c033 211 StdPrs_Curve::Add (aPresentation, anIso, aDrawer, Pnts->ChangeSequence(), Standard_False);
212 VIsoCurves.Append (Pnts);
7fd59977 213 }
214 }
5ad8c033 215
7fd59977 216 Standard_Integer nbVertices = 0, nbBounds = 0;
217 //Draw surface via primitive array
218 if(UIsoCurves.Size() > 0) {
219 nbBounds = UIsoCurves.Size();
220 Prs3d_NListIteratorOfListOfSequenceOfPnt It;
221 for( It.Init(UIsoCurves); It.More(); It.Next())
e3a6386d 222 nbVertices += It.Value()->Length();
7fd59977 223 Handle(Graphic3d_ArrayOfPolylines) UIsoArray =
224 new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds);
225 for( It.Init(UIsoCurves); It.More(); It.Next()) {
e3a6386d 226 const Handle(TColgp_HSequenceOfPnt)& Pnts = It.Value();
227 UIsoArray->AddBound(Pnts->Length());
228 for(int i=1; i<=Pnts->Length(); i++)
229 UIsoArray->AddVertex(Pnts->Value(i));
7fd59977 230 }
231 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation);
232 TheGroup->SetPrimitivesAspect(aDrawer->UIsoAspect()->Aspect());
7fd59977 233 TheGroup->AddPrimitiveArray(UIsoArray);
7fd59977 234 }
235
236 if(VIsoCurves.Size() > 0) {
237 nbBounds = VIsoCurves.Size();
238 Prs3d_NListIteratorOfListOfSequenceOfPnt It;
239 for( It.Init(VIsoCurves); It.More(); It.Next())
e3a6386d 240 nbVertices += It.Value()->Length();
7fd59977 241 Handle(Graphic3d_ArrayOfPolylines) VIsoArray =
242 new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds);
243 for( It.Init(VIsoCurves); It.More(); It.Next()) {
e3a6386d 244 const Handle(TColgp_HSequenceOfPnt)& Pnts = It.Value();
245 VIsoArray->AddBound(Pnts->Length());
246 for(int i=1; i<=Pnts->Length(); i++)
247 VIsoArray->AddVertex(Pnts->Value(i));
7fd59977 248 }
249 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation);
250 TheGroup->SetPrimitivesAspect(aDrawer->VIsoAspect()->Aspect());
7fd59977 251 TheGroup->AddPrimitiveArray(VIsoArray);
7fd59977 252 }
253 if(freeCurves.Size() > 0) {
254 nbBounds = freeCurves.Size();
255 Prs3d_NListIteratorOfListOfSequenceOfPnt It;
256 for( It.Init(freeCurves); It.More(); It.Next())
e3a6386d 257 nbVertices += It.Value()->Length();
7fd59977 258 Handle(Graphic3d_ArrayOfPolylines) freeArray =
259 new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds);
260 for( It.Init(freeCurves); It.More(); It.Next()) {
e3a6386d 261 const Handle(TColgp_HSequenceOfPnt)& Pnts = It.Value();
262 freeArray->AddBound(Pnts->Length());
263 for(int i=1; i<=Pnts->Length(); i++)
264 freeArray->AddVertex(Pnts->Value(i));
7fd59977 265 }
266 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation);
267 TheGroup->SetPrimitivesAspect(aDrawer->FreeBoundaryAspect()->Aspect());
7fd59977 268 TheGroup->AddPrimitiveArray(freeArray);
7fd59977 269 }
270 }
271
272