1 // Created on: 1995-08-04
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.
17 #include <StdPrs_WFSurface.ixx>
20 #include <Graphic3d_Group.hxx>
21 #include <Graphic3d_ArrayOfPolylines.hxx>
22 #include <GeomAbs_IsoType.hxx>
23 #include <Prs3d_IsoAspect.hxx>
24 #include <Bnd_Box.hxx>
25 #include <Precision.hxx>
26 #include <BndLib_AddSurface.hxx>
27 #include <Adaptor3d_IsoCurve.hxx>
28 #include <StdPrs_Curve.hxx>
29 #include <TColgp_SequenceOfPnt.hxx>
31 #include <Prs3d_NListOfSequenceOfPnt.hxx>
32 #include <Prs3d_NListIteratorOfListOfSequenceOfPnt.hxx>
35 static void FindLimits(const Handle(Adaptor3d_HSurface)& surf ,
36 const Standard_Real aLimit,
37 Standard_Real& UFirst,
39 Standard_Real& VFirst,
42 UFirst = surf->FirstUParameter();
43 ULast = surf->LastUParameter();
44 VFirst = surf->FirstVParameter();
45 VLast = surf->LastVParameter();
47 Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
48 Standard_Boolean UlastInf = Precision::IsPositiveInfinite(ULast);
49 Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
50 Standard_Boolean VlastInf = Precision::IsPositiveInfinite(VLast);
52 if (UfirstInf || UlastInf) {
55 if (VfirstInf && VlastInf)
62 v = (VFirst + VLast) / 2;
64 Standard_Real delta = aLimit * 2;
66 if (UfirstInf && UlastInf) {
71 surf->D0(UFirst,v,P1);
73 } while (P1.Distance(P2) > aLimit);
79 UFirst = ULast - delta;
80 surf->D0(UFirst,v,P1);
81 } while (P1.Distance(P2) > aLimit);
84 surf->D0(UFirst,v,P1);
87 ULast = UFirst + delta;
89 } while (P1.Distance(P2) > aLimit);
93 if (VfirstInf || VlastInf) {
95 Standard_Real u = (UFirst + ULast) /2 ;
97 Standard_Real delta = aLimit * 2;
99 if (VfirstInf && VlastInf) {
104 surf->D0(u,VFirst,P1);
105 surf->D0(u,VLast,P2);
106 } while (P1.Distance(P2) > aLimit);
108 else if (VfirstInf) {
109 surf->D0(u,VLast,P2);
112 VFirst = VLast - delta;
113 surf->D0(u,VFirst,P1);
114 } while (P1.Distance(P2) > aLimit);
117 surf->D0(u,VFirst,P1);
120 VLast = VFirst + delta;
121 surf->D0(u,VLast,P2);
122 } while (P1.Distance(P2) > aLimit);
128 //=======================================================================
131 //=======================================================================
133 void StdPrs_WFSurface::Add (const Handle(Prs3d_Presentation)& aPresentation,
134 const Handle(Adaptor3d_HSurface)& aSurface,
135 const Handle(Prs3d_Drawer)& aDrawer)
138 Standard_Real U1, U2, V1, V2;
139 Standard_Real MaxP = aDrawer->MaximalParameterValue();
141 FindLimits(aSurface, MaxP, U1, U2, V1, V2);
143 Prs3d_NListOfSequenceOfPnt freeCurves;
144 Prs3d_NListOfSequenceOfPnt UIsoCurves;
145 Prs3d_NListOfSequenceOfPnt VIsoCurves;
147 Standard_Boolean UClosed = aSurface->IsUClosed();
148 Standard_Boolean VClosed = aSurface->IsVClosed();
150 Standard_Real TheDeflection;
151 Aspect_TypeOfDeflection TOD = aDrawer->TypeOfDeflection();
152 if (TOD == Aspect_TOD_RELATIVE) {
153 // On calcule la fleche en fonction des min max globaux de la piece:
155 BndLib_AddSurface::Add(aSurface->Surface(),U1, U2, V1, V2, 0.,Total);
156 Standard_Real m = aDrawer->MaximalChordialDeviation()/
157 aDrawer->DeviationCoefficient();
158 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
159 Total.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
160 if ( ! (Total.IsOpenXmin() || Total.IsOpenXmax() ))
161 m = Min ( m , Abs (aXmax-aXmin));
162 if ( ! (Total.IsOpenYmin() || Total.IsOpenYmax() ))
163 m = Min ( m , Abs (aYmax-aYmin));
164 if ( ! (Total.IsOpenZmin() || Total.IsOpenZmax() ))
165 m = Min ( m , Abs (aZmax-aZmin));
167 TheDeflection = m * aDrawer->DeviationCoefficient();
170 TheDeflection = aDrawer->MaximalChordialDeviation();
172 Adaptor3d_IsoCurve anIso;
173 anIso.Load(aSurface);
175 // Trace des frontieres.
176 // *********************
178 if ( !(UClosed && VClosed) ) {
180 (Prs3d_Root::CurrentGroup(aPresentation))->SetPrimitivesAspect
181 (aDrawer->FreeBoundaryAspect()->Aspect());
184 anIso.Load(GeomAbs_IsoU,U1,V1,V2);
185 Handle(TColgp_HSequenceOfPnt) aPntsU1 = new TColgp_HSequenceOfPnt;
186 StdPrs_Curve::Add(aPresentation,anIso,TheDeflection, aDrawer, aPntsU1->ChangeSequence(), Standard_False);
187 freeCurves.Append(aPntsU1);
188 anIso.Load(GeomAbs_IsoU,U2,V1,V2);
189 Handle(TColgp_HSequenceOfPnt) aPntsU2 = new TColgp_HSequenceOfPnt;
190 StdPrs_Curve::Add(aPresentation,anIso,TheDeflection, aDrawer, aPntsU2->ChangeSequence(), Standard_False);
191 freeCurves.Append(aPntsU2);
195 anIso.Load(GeomAbs_IsoV,V1,U1,U2);
196 Handle(TColgp_HSequenceOfPnt) aPntsV1 = new TColgp_HSequenceOfPnt;
197 StdPrs_Curve::Add(aPresentation,anIso,TheDeflection, aDrawer, aPntsV1->ChangeSequence(), Standard_False);
198 freeCurves.Append(aPntsV1);
199 anIso.Load(GeomAbs_IsoV,V2,U1,U2);
200 Handle(TColgp_HSequenceOfPnt) aPntsV2 = new TColgp_HSequenceOfPnt;
201 StdPrs_Curve::Add(aPresentation,anIso,TheDeflection, aDrawer, aPntsV2->ChangeSequence(), Standard_False);
202 freeCurves.Append(aPntsV2);
206 // Trace des isoparametriques.
207 // ***************************
209 Standard_Integer fin = aDrawer->UIsoAspect()->Number();
212 (Prs3d_Root::CurrentGroup(aPresentation))->SetPrimitivesAspect
213 (aDrawer->UIsoAspect()->Aspect());
215 Standard_Real du= UClosed ? (U2-U1)/fin : (U2-U1)/(1+fin);
216 for (Standard_Integer i=1; i<=fin;i++){
217 anIso.Load(GeomAbs_IsoU,U1+du*i,V1,V2);
218 Handle(TColgp_HSequenceOfPnt) Pnts = new TColgp_HSequenceOfPnt;
219 StdPrs_Curve::Add(aPresentation,anIso,TheDeflection, aDrawer, Pnts->ChangeSequence(), Standard_False);
220 UIsoCurves.Append(Pnts);
223 fin = aDrawer->VIsoAspect()->Number();
226 (Prs3d_Root::CurrentGroup(aPresentation))->SetPrimitivesAspect
227 (aDrawer->VIsoAspect()->Aspect());
229 Standard_Real dv= VClosed ?(V2-V1)/fin : (V2-V1)/(1+fin);
230 for (Standard_Integer i=1; i<=fin;i++){
231 anIso.Load(GeomAbs_IsoV,V1+dv*i,U1,U2);
232 Handle(TColgp_HSequenceOfPnt) Pnts = new TColgp_HSequenceOfPnt;
233 StdPrs_Curve::Add(aPresentation,anIso,TheDeflection, aDrawer, Pnts->ChangeSequence(), Standard_False);
234 VIsoCurves.Append(Pnts);
238 Standard_Integer nbVertices = 0, nbBounds = 0;
239 //Draw surface via primitive array
240 if(UIsoCurves.Size() > 0) {
241 nbBounds = UIsoCurves.Size();
242 Prs3d_NListIteratorOfListOfSequenceOfPnt It;
243 for( It.Init(UIsoCurves); It.More(); It.Next())
244 nbVertices += It.Value()->Length();
245 Handle(Graphic3d_ArrayOfPolylines) UIsoArray =
246 new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds);
247 for( It.Init(UIsoCurves); It.More(); It.Next()) {
248 const Handle(TColgp_HSequenceOfPnt)& Pnts = It.Value();
249 UIsoArray->AddBound(Pnts->Length());
250 for(int i=1; i<=Pnts->Length(); i++)
251 UIsoArray->AddVertex(Pnts->Value(i));
253 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation);
254 TheGroup->SetPrimitivesAspect(aDrawer->UIsoAspect()->Aspect());
255 TheGroup->AddPrimitiveArray(UIsoArray);
258 if(VIsoCurves.Size() > 0) {
259 nbBounds = VIsoCurves.Size();
260 Prs3d_NListIteratorOfListOfSequenceOfPnt It;
261 for( It.Init(VIsoCurves); It.More(); It.Next())
262 nbVertices += It.Value()->Length();
263 Handle(Graphic3d_ArrayOfPolylines) VIsoArray =
264 new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds);
265 for( It.Init(VIsoCurves); It.More(); It.Next()) {
266 const Handle(TColgp_HSequenceOfPnt)& Pnts = It.Value();
267 VIsoArray->AddBound(Pnts->Length());
268 for(int i=1; i<=Pnts->Length(); i++)
269 VIsoArray->AddVertex(Pnts->Value(i));
271 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation);
272 TheGroup->SetPrimitivesAspect(aDrawer->VIsoAspect()->Aspect());
273 TheGroup->AddPrimitiveArray(VIsoArray);
275 if(freeCurves.Size() > 0) {
276 nbBounds = freeCurves.Size();
277 Prs3d_NListIteratorOfListOfSequenceOfPnt It;
278 for( It.Init(freeCurves); It.More(); It.Next())
279 nbVertices += It.Value()->Length();
280 Handle(Graphic3d_ArrayOfPolylines) freeArray =
281 new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds);
282 for( It.Init(freeCurves); It.More(); It.Next()) {
283 const Handle(TColgp_HSequenceOfPnt)& Pnts = It.Value();
284 freeArray->AddBound(Pnts->Length());
285 for(int i=1; i<=Pnts->Length(); i++)
286 freeArray->AddVertex(Pnts->Value(i));
288 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation);
289 TheGroup->SetPrimitivesAspect(aDrawer->FreeBoundaryAspect()->Aspect());
290 TheGroup->AddPrimitiveArray(freeArray);