0022807: Loading of STEP entities in model during reading of STEP file requires redun...
[occt.git] / src / V3d / V3d_View.cxx
CommitLineData
7fd59977 1/***********************************************************************
2
3FONCTION :
4----------
5Classe V3d_View :
6
7HISTORIQUE DES MODIFICATIONS :
8--------------------------------
900-09-92 : GG ; Creation.
1002-10-96 : FMN ; Suppression appel Redraw sans MustBeResized()
1105-06-97 : FMN ; Correction FitAll()
1230-06-97 : GG ; Correction + Optimisation de Panning(...)
13On fait la translation + le zoom en une seule
14operation au lieu de 2 precedemment qui etait buggee.
1509-07-97 : FMN ; Correction FitAll() sur le Ratio
1616-07-97 : FMN ; Correction FitAll() sur le calcul de la Box
1722-07-97 : FMN ; Ajout mode RetainMode pour le Transient
1815-12-97 : FMN ; Ajout texture mapping
1917-12-97 : FMN ; CTS19129 Correction FitAll() multiple
2018-12-97 : FMN ; Ajout mode Ajout
2124-12-97 : FMN ; Remplacement de math par MathGra
2224-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window
2331-12-97 : CAL ; Remplacement de MathGra par Array2OfReal
2407-01-98 : CAL ; Ajout de la methode DoMapping.
2507-01-98 : CAL ; Retrait de tous les "this->" inutiles
2621-01-98 : CAL ; Remplacement des Window->Position () par Window->Size ()
2727-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
2812-02-98 : GG ; Reactivation du Redraw dans MustBeResized()
2923-02-98 : FMN ; Remplacement PI par Standard_PI
3025-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view
3111-03-98 : STT ; S3558
3219-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
33ne marche pas.
3408-04-98 : STT ; suppr. S3558
3510-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef
3613-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
37ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
3816-08-98 : CAL ; S3892. Ajout grilles 3d.
3909-09-98 : CAL ; S3892. Generalisation de TrsPoint.
4024-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
4106-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
4216-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
4306-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
4413-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
4529-OCT-98 : DCB : Adding ScreenCopy () method.
4622-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
4710-11-99 : GG ; PRO19603 Add Redraw( area ) method
48IMP130100 : GG
49-> Don't increase too much the ZSize.
50-> Initialize correctly the Z clipping and D cueing
51planes.
52IMP100701 : SZV ; Add ToPixMap() method
53
54REMARQUES :
55-----------
56About FitAll() multiple. This probleme is caused by missing
57precision of transformation matrices. If it is supposed that
58projection is made in the plane (U,V), there is a difference
59after several Zoom - compared to the exact value (cf ZoomX).
60Don't forget that the matrices work in float and not in double.
61To solve the problem (for lack of a better solution) I make 2 passes.
62
63************************************************************************/
64
65#define GER61351 //GG_15/12/99 Add SetBackgroundColor()
66// and BackgroundColor() methods
67
68
69#define IMP240100 //GG
70// -> Remove PixToRef() method ,use
71// instead the equivalent Convert() method.
72// -> Rename RefToPix() to Convert() method.
73// -> Remove the grid computation in Convert()
74// method. Use instead the NEW ConvertToGrid() methods.
75// Reason is the Convert() method is call by
76// StdSelect_ViewSelector3d_Pick() from
77// AIS_InteractiveContext() and it's not possible
78// to select an object vertex when the grid is active!
79// -> Remove grid echo marker definition
80// (reported in the viewer)
81// -> Add SetProjModel() methods.
82
83#define G003 //EUG 04-10-99
84// -> computed mode management
85// Add SetComputedMode(..) method
86// -> animation mode management
87// Add SetAnimationMode()
88// -> backfacing management
89// Add SetBackFacingModel() method
90
91#define G004 //VKH 15-11-99
92// -> Add Dump() methods
93// -> GG 07/03/00 Use the new MMSize()
94// method from Aspect_Window class.
95
96#define IMP210200 //GG Add Transparency() method
97
98#define IMP250200 //GG With SetDepth() method, when the requested
99// depth is < 0.,
100// move the view ref point and the eye,instead
101// only the eye.
102
103#define IMP020300 //GG Don't use ZFitAll in during Rotation
104// for perf improvment
105
106#define IMP210600 //GG Avoid to have infinite loop when call Rotation() method
107// without call before StartRotation().
108// This problem occurs when CTRL MB3 is maintain press betwwen 2 views.
109
110#define IMP250900 //GG Enable rotation around screen Z axis when
111// rotation begin far the center of the screen.
112// Thanks to Patrick REGINSTER (SAMTECH)
113// GG 21/12/00 Due to a regression on the previous specifications
114// this new functionnality is right now deactivated
115// by default (see StartRotation(...,zRotationThreshold)
116// method.
117
118#define BUC60952 //GG Enable to rotate around the view axis
119// and the required view point
120
121#define RIC120302 //GG Add a NEW SetWindow method which enable
122// to connect a graphic widget and context to OGL.
123
124#define IMP260302 //GG To avoid conflicting in Window destructor
125// nullify this handle in Remove method
126
127#define OCC280 //SAV fix for FitAll problem in the perspective view.
128
129#define OCC1188 //SAV Added methods to set background image
130
131/*----------------------------------------------------------------------*/
132/*
133* Includes
134*/
135
136#include <Standard_TypeMismatch.hxx>
137#include <Visual3d_ViewManager.hxx>
138#include <Visual3d_Light.hxx>
139#include <Visual3d_ClipPlane.hxx>
140#include <Graphic3d_Structure.hxx>
141#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
142#include <Graphic3d_MapOfStructure.hxx>
143#include <Graphic3d_TextureEnv.hxx>
144#include <Image_PixMap.hxx>
145#include <V3d.hxx>
146#include <V3d_View.ixx>
147#include <Viewer_BadValue.hxx>
148#include <Standard_ShortReal.hxx>
149#include <gp_Dir.hxx>
150#include <TColStd_Array2OfReal.hxx>
151#include <Visual3d_TransientManager.hxx>
152#include <Precision.hxx>
153
154// S3892
155#include <Graphic3d_AspectMarker3d.hxx>
156
157// S3603
158#include <Aspect_GenericColorMap.hxx>
159#include <Aspect_TypeMap.hxx>
160#include <Aspect_WidthMap.hxx>
161#include <Aspect_MarkMap.hxx>
162#include <Aspect_FontMap.hxx>
163#include <PlotMgt_ImageDriver.hxx>
164#include <TColStd_HSequenceOfInteger.hxx>
165#ifdef WNT
166# include <WNT_WDriver.hxx>
167#else
168# include <Xw_Driver.hxx>
169#endif
170
171#ifdef G003
172# define V3d_FLAG_ANIMATION 0x00000001
173# define V3d_FLAG_DEGENERATION 0x00000002
174# define V3d_FLAG_COMPUTATION 0x00000004
175#endif // G003
176
177// Tumble
178#include <OSD_Timer.hxx>
179static OSD_Timer FullTimer;
180
181// Perspective
182#include <OSD_Environment.hxx>
183
184/*----------------------------------------------------------------------*/
185/*
186* Constant
187*/
188
189#define Zmargin 1.
190#define DEUXPI (2.*Standard_PI)
191
192// in case of NO_TRACE_ECHO and NO_TRACE_POINTS, in V3d_View_4.cxx and in
193// V3d_View.cxx, change MyGridEchoStructure and MyGridEchoGroup in cdl
194#define NO_TRACE_ECHO
195#define NO_TRACE_POINTS
196
197/*----------------------------------------------------------------------*/
198/*
199* Local data definitions
200*/
201
202
203static Standard_Real MyXwindowCenter ;
204static Standard_Real MyYwindowCenter ;
205static Standard_Real MyWindowWidth ;
206static Standard_Real MyWindowHeight ;
207
208#define LOPTIM
209#ifndef LOPTIM
210static Graphic3d_Vector MyXscreenAxis ;
211static Graphic3d_Vector MyYscreenAxis ;
212static Graphic3d_Vector MyZscreenAxis ;
213static Graphic3d_Vector MyViewReferencePlane ;
214static Graphic3d_Vector MyViewReferenceUp ;
215static Graphic3d_Vector MyViewAxis ;
216static Graphic3d_Vertex MyViewReferencePoint ;
217static Graphic3d_Vertex MyGravityReferencePoint ;
218static Graphic3d_Vertex MyProjReferencePoint ;
219#else
220static Graphic3d_Vector& _MyXscreenAxis() {
221 static Graphic3d_Vector MyXscreenAxis;
222 return MyXscreenAxis;
223}
224#define MyXscreenAxis _MyXscreenAxis()
225
226static Graphic3d_Vector& _MyYscreenAxis() {
227 static Graphic3d_Vector MyYscreenAxis;
228 return MyYscreenAxis;
229}
230#define MyYscreenAxis _MyYscreenAxis()
231
232static Graphic3d_Vector& _MyZscreenAxis() {
233 static Graphic3d_Vector MyZscreenAxis;
234 return MyZscreenAxis;
235}
236#define MyZscreenAxis _MyZscreenAxis()
237
238static Graphic3d_Vector& _MyViewReferencePlane() {
239 static Graphic3d_Vector MyViewReferencePlane;
240 return MyViewReferencePlane;
241}
242#define MyViewReferencePlane _MyViewReferencePlane()
243
244static Graphic3d_Vector& _MyViewReferenceUp() {
245 static Graphic3d_Vector MyViewReferenceUp;
246 return MyViewReferenceUp;
247}
248#define MyViewReferenceUp _MyViewReferenceUp()
249
250static Graphic3d_Vector& _MyViewAxis() {
251 static Graphic3d_Vector MyViewAxis;
252 return MyViewAxis;
253}
254#define MyViewAxis _MyViewAxis()
255
256static Graphic3d_Vertex& _MyViewReferencePoint() {
257 static Graphic3d_Vertex MyViewReferencePoint;
258 return MyViewReferencePoint;
259}
260#define MyViewReferencePoint _MyViewReferencePoint()
261
262static Graphic3d_Vertex& _MyGravityReferencePoint() {
263 static Graphic3d_Vertex MyGravityReferencePoint;
264 return MyGravityReferencePoint;
265}
266#define MyGravityReferencePoint _MyGravityReferencePoint()
267
268static Graphic3d_Vertex& _MyProjReferencePoint() {
269 static Graphic3d_Vertex MyProjReferencePoint;
270 return MyProjReferencePoint;
271}
272#define MyProjReferencePoint _MyProjReferencePoint()
273#endif // LOPTIM
274
275/*----------------------------------------------------------------------*/
276//-Constructors
277
278V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
279MyType ( Type ),
280MyViewer(VM.operator->()),
281MyActiveLights(),
282MyActivePlanes(),
283MyViewContext (),
284myActiveLightsIterator(),
285myActivePlanesIterator(),
286SwitchSetFront(Standard_False),
287MyTrsf (1, 4, 1, 4), // S3892
288MyProjModel(V3d_TPM_SCREEN)
289#if defined(TRACE_POINTS)
290,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
291MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
292#endif
293{
294
295 myImmediateUpdate = Standard_False;
296 MyView = new Visual3d_View(MyViewer->Viewer());
297
298 // { Begin to retrieve the definition from ViewContext.
299 // Step MyViewContext = MyView->Context() ;
300 // to permit MyView->SetContext to compare
301 // the old and the new context.
302 // No problem for MyViewMapping, MyViewOrientation
303 // as MyView->SetViewMapping and MyView->SetViewOrientation
304 // don't try to optimize the modifications introduced to
305 // viewmapping and vieworientation.
306
307 // Aliasing
308 if ((MyView->Context ()).AliasingIsOn ())
309 MyViewContext.SetAliasingOn ();
310 else
311 MyViewContext.SetAliasingOff ();
312
313 // DepthCueing
314 MyViewContext.SetDepthCueingBackPlane
315 ((MyView->Context ()).DepthCueingBackPlane ());
316 MyViewContext.SetDepthCueingFrontPlane
317 ((MyView->Context ()).DepthCueingFrontPlane ());
318
319 if ((MyView->Context ()).DepthCueingIsOn ())
320 MyViewContext.SetDepthCueingOn ();
321 else
322 MyViewContext.SetDepthCueingOff ();
323
324 // ZClipping
325 MyViewContext.SetZClippingBackPlane
326 ((MyView->Context ()).ZClippingBackPlane ());
327 MyViewContext.SetZClippingFrontPlane
328 ((MyView->Context ()).ZClippingFrontPlane ());
329
330 if ((MyView->Context ()).FrontZClippingIsOn ())
331 MyViewContext.SetFrontZClippingOn ();
332 else
333 MyViewContext.SetFrontZClippingOff ();
334
335 if ((MyView->Context ()).BackZClippingIsOn ())
336 MyViewContext.SetBackZClippingOn ();
337 else
338 MyViewContext.SetBackZClippingOff ();
339
340 // Visualisation and Shading Model
341 MyViewContext.SetModel ((MyView->Context ()).Model ());
342 MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
343
344 // Texture Mapping
345 MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
346 MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
347 // } End of retrieval of the definition of ViewContext.
348
349 MyViewMapping = MyView->ViewMapping() ;
350 MyViewOrientation = MyView->ViewOrientation() ;
351 MyBackground = VM->GetBackgroundColor() ;
352 MyGradientBackground = VM->GetGradientBackground() ;
353
354 SetAxis(0.,0.,0.,1.,1.,1.) ;
355 SetVisualization(VM->DefaultVisualization()) ;
356 SetShadingModel(VM->DefaultShadingModel()) ;
357 SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
358 SetTwist(0.) ;
359 SetAt(0.,0.,0.) ;
360 SetProj(VM->DefaultViewProj()) ;
361 SetSize(VM->DefaultViewSize()) ;
362 Standard_Real zsize = VM->DefaultViewSize();
363 SetZSize(2.*zsize+zsize*Zmargin) ;
364 SetZClippingDepth(0.);
365 SetZClippingWidth(zsize);
366 SetZCueingDepth(0.);
367 SetZCueingWidth(zsize);
368 SetDepth(VM->DefaultViewSize()/2.) ;
369 SetCenter(0.,0.) ;
370 SetViewMappingDefault();
371 VM->AddView(this) ;
372 Init();
373 myImmediateUpdate = Standard_True;
374
375 // S3892
376#ifndef IMP240100
377#if defined(TRACE_POINTS)
378 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
379 MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
380 MarkerAttrib->SetScale (3.0);
381 MarkerAttrib->SetType (Aspect_TOM_STAR);
382 MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
383#endif
384#endif //IMP240100
385
386#ifdef G003
387 MyAnimationFlags = 0;
388#endif // G003
389
390#ifdef IMP210200
391 MyTransparencyFlag = Standard_False;
392#endif
393
394}
395
396/*----------------------------------------------------------------------*/
397
398V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
399MyType ( Type ),
400MyViewer(VM.operator->()),
401MyActiveLights(),
402MyActivePlanes(),
403MyViewContext (),
404myActiveLightsIterator(),
405myActivePlanesIterator(),
406SwitchSetFront(Standard_False),
407MyTrsf (1, 4, 1, 4), // S3892
408MyProjModel(V3d_TPM_SCREEN)
409#if defined(TRACE_POINTS)
410,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
411MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
412#endif
413{
414
415 Handle(Visual3d_View) FromView = V->View() ;
416
417 myImmediateUpdate = Standard_False;
418 MyView = new Visual3d_View(MyViewer->Viewer());
419
420 for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){
421 MyActiveLights.Append(V->ActiveLight());}
422 for (V->InitActivePlanes();V->MoreActivePlanes();V->NextActivePlanes()){
423 MyActivePlanes.Append(V->ActivePlane());}
424
425 MyViewContext = FromView->Context() ;
426
427 MyViewMapping = FromView->ViewMapping() ;
428 MyViewOrientation = FromView->ViewOrientation() ;
429 MyBackground = FromView->Background() ;
430 MyGradientBackground = FromView->GradientBackground();
431
432 MyView->SetContext(MyViewContext) ;
433
434 SetAxis(0.,0.,0.,1.,1.,1.) ;
435 VM->AddView(this) ;
436 Init();
437 myImmediateUpdate = Standard_True;
438
439 // S3892
440#ifndef IMP240100
441#if defined(TRACE_ECHO)
442 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
443 MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
444 MarkerAttrib->SetScale (3.0);
445 MarkerAttrib->SetType (Aspect_TOM_STAR);
446 MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
447#endif
448#endif //IMP240100
449
450#ifdef G003
451 MyAnimationFlags = 0;
452#endif
453
454}
455
456/*----------------------------------------------------------------------*/
457
458//-Methods, in order
459
460void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
461 const Handle(V3d_View)& aPreviousView,
462 const Standard_Integer x1,
463 const Standard_Integer y1,
464 const Standard_Integer x2,
465 const Standard_Integer y2)
466{
467
468 if( !MyView->IsDefined() ) {
469 Standard_Real a,b,c,d;
470 aPreviousView->Convert(x1,y1,a,b);
471 aPreviousView->Convert(x2,y2,c,d);
472 MyView->SetWindow(TheWindow) ;
473 FitAll(TheWindow,a,b,c,d);
474 MyView->SetContext(MyViewContext) ;
475 MyView->SetViewOrientation(MyViewOrientation) ;
476 MyView->SetBackground(MyBackground) ;
477 MyViewer->SetViewOn(this) ;
478 MyWindow = TheWindow;
479 MyView->Redraw() ;
480 SetViewMappingDefault();
481 }
482
483}
484
485/*----------------------------------------------------------------------*/
486
487void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
488{
489
490 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
491 "V3d_View::SetWindow, window of view already defined");
492
493 MyView->SetWindow(TheWindow) ;
cdc2203b
M
494 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
495 // calling Redraw(). Otherwise it is impossible to call certain methods of
496 // V3d_View like Convert() inside the context of Redraw(),
497 // particularly in class NIS_View.
498 MyWindow = TheWindow;
7fd59977 499 // SetWindow carries out SetRatio and modifies
500 // ViewMapping and ViewMappingDefault of MyView.
501 MyViewMapping = MyView->ViewMapping() ;
502 MyView->SetContext(MyViewContext) ;
503 MyView->SetViewMapping(MyViewMapping) ;
504 MyView->SetViewOrientation(MyViewOrientation) ;
505 MyView->SetBackground(MyBackground) ;
506 MyViewer->SetViewOn(this) ;
507#ifdef TRACE_POINTS
508 MyGridEchoStructure->SetInfiniteState (Standard_True); // S3892
509 MyGridEchoStructure->Display (); // S3892
510#endif
511 MyView->Redraw() ;
7fd59977 512
513}
514
515// RIC120302
516/*----------------------------------------------------------------------*/
517
518void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
519 const Aspect_RenderingContext aContext,
520 const Aspect_GraphicCallbackProc& aDisplayCB,
521 const Standard_Address aClientData)
522{
523
524 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
525 "V3d_View::SetWindow, "
526 "window of view already defined");
cdc2203b
M
527 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
528 // calling Redraw(). Otherwise it is impossible to call certain methods of
529 // V3d_View like Convert() inside the context of Redraw(),
530 // particularly in class NIS_View.
531 MyWindow = aWindow;
7fd59977 532 MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
533 MyViewMapping = MyView->ViewMapping() ;
534 MyView->SetContext(MyViewContext) ;
535 MyView->SetViewMapping(MyViewMapping) ;
536 MyView->SetViewOrientation(MyViewOrientation) ;
537 MyView->SetBackground(MyBackground) ;
538 MyViewer->SetViewOn(this) ;
539 MyView->Redraw() ;
7fd59977 540
541}
542// RIC120302
543
544/*----------------------------------------------------------------------*/
545
546void V3d_View::Remove() const {
547
548 MyViewer->DelView(this) ;
549 MyView->Remove() ;
550#ifdef IMP260303
551 MyWindow.Nullify();
552#endif
553
554}
555
556/*----------------------------------------------------------------------*/
557
558void V3d_View::Update() const {
559 if( MyView->IsDefined() ) MyView->Update() ;
560}
561
562/*----------------------------------------------------------------------*/
563
564void V3d_View::Redraw() const {
565 if( MyView->IsDefined() ) MyView->Redraw() ;
566}
567/*----------------------------------------------------------------------*/
568
569void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
570 const Standard_Integer width,const Standard_Integer height) const
571{
572 if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
573}
574
575/*----------------------------------------------------------------------*/
576
577Standard_Boolean V3d_View::IsEmpty() const {
578
579 Standard_Boolean TheStatus = Standard_True ;
580 if( MyView->IsDefined() ) {
581 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
582 if( Nstruct > 0 ) TheStatus = Standard_False ;
583 }
584 return (TheStatus) ;
585
586}
587
588/*----------------------------------------------------------------------*/
589
590void V3d_View::UpdateLights() const {
591 MyView->SetContext(MyViewContext);
592 Update();
593}
594
595/*----------------------------------------------------------------------*/
596
597void V3d_View::DoMapping() {
598 if( MyView->IsDefined() ) {
599 (MyView->Window())->DoMapping() ;
600 }
601}
602
603/*----------------------------------------------------------------------*/
604
605void V3d_View::MustBeResized() {
606
607 if ( !MyLayerMgr.IsNull() )
608 MyLayerMgr->Resized();
609
610 if( MyView->IsDefined() ) {
611 MyView->Resized() ;
612 MyViewMapping = MyView->ViewMapping();
613 MyView->Redraw();
614 }
615
616}
617
618/*----------------------------------------------------------------------*/
619
620void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
621{
622 Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
623 Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 );
624 Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 );
625
626 Quantity_Color C( V1, V2, V3, Type );
627#ifdef GER61351
628 SetBackgroundColor( C );
629#else
630 MyBackground.SetColor( C );
631 if ( MyView->IsDefined() )
632 MyView->SetBackground( MyBackground );
633 if ( !MyLayerMgr.IsNull() )
634 MyLayerMgr->Resized();
635#endif
636}
637
638#ifdef GER61351
639/*----------------------------------------------------------------------*/
640
641void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
642{
643 MyBackground.SetColor( Color );
644 if ( MyView->IsDefined() )
645 MyView->SetBackground( MyBackground );
646 //szv: Why?
647 if ( !MyLayerMgr.IsNull() )
648 MyLayerMgr->Resized();
649}
650#endif
651
652/*----------------------------------------------------------------------*/
653
654void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
655{
656 Quantity_Color C( Name );
657#ifdef GER61351
658 SetBackgroundColor( C );
659#else
660 MyBackground.SetColor( C );
661 if ( MyView->IsDefined() )
662 MyView->SetBackground( MyBackground );
663 if ( !MyColorScale.IsNull() )
664 MyColorScale->Resized();
665#endif
666}
667
668/*----------------------------------------------------------------------*/
669
670void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
671 const Quantity_Color& Color2,
672 const Aspect_GradientFillMethod FillStyle,
673 const Standard_Boolean status)
674{
675
676 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
677 if ( MyView->IsDefined() )
678 MyView->SetGradientBackground( MyGradientBackground, status );
679
680}
681
682/*----------------------------------------------------------------------*/
683
684void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
685 const Quantity_NameOfColor Color2,
686 const Aspect_GradientFillMethod FillStyle,
687 const Standard_Boolean status )
688{
689 Quantity_Color C1( Color1 );
690 Quantity_Color C2( Color2 );
691 MyGradientBackground.SetColors( C1, C2, FillStyle );
692 if ( MyView->IsDefined() )
693 MyView->SetGradientBackground( MyGradientBackground, status );
694}
695
696/*----------------------------------------------------------------------*/
697
698void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
699 const Standard_Boolean update) const
700{
701 if( MyView->IsDefined() )
702 MyView->SetBgGradientStyle( FillStyle , update ) ;
703}
704
705/*----------------------------------------------------------------------*/
706
707void V3d_View::SetBackgroundImage( const Standard_CString FileName,
708 const Aspect_FillMethod FillStyle,
709 const Standard_Boolean update )
710{
711#ifdef OCC1188
712 if( MyView->IsDefined() )
713 MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
714#endif
715}
716
717/*----------------------------------------------------------------------*/
718
719void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
720 const Standard_Boolean update )
721{
722#ifdef OCC1188
723 if( MyView->IsDefined() )
724 MyView->SetBgImageStyle( FillStyle, update ) ;
725#endif
726}
727
728/*----------------------------------------------------------------------*/
729
730void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
731
732 Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
733
734 D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ;
735 Viewer_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis");
736 Nx /= D ; Ny /= D ; Nz /= D ;
737 MyDefaultViewPoint.SetCoord(X,Y,Z) ;
738 MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
739 MyDefaultViewAxis.Normalize() ;
740
741}
742
743/*----------------------------------------------------------------------*/
744
745void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) {
746
747 MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
748 MyView->SetContext(MyViewContext) ;
749
750}
751
752/*----------------------------------------------------------------------*/
753
754void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) {
755
756 MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
757 MyView->SetContext(MyViewContext) ;
758
759}
760
761/*----------------------------------------------------------------------*/
762
763void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) {
764
765 MyViewContext.SetTextureEnv(ATexture) ;
766 MyView->SetContext(MyViewContext) ;
767
768}
769
770/*----------------------------------------------------------------------*/
771
772void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) {
773
774 MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
775 MyView->SetContext(MyViewContext) ;
776
777}
778
779/*----------------------------------------------------------------------*/
780
781void V3d_View::SetFront() {
782
783 gp_Ax3 a = MyViewer->PrivilegedPlane();
784 Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
785
786 a.Direction().Coord(vx,vy,vz);
787 a.YDirection().Coord(xu,yu,zu);
788 a.Location().Coord(xo,yo,zo);
789
790 if(SwitchSetFront)
791 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
792 else
793 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
794
795 SwitchSetFront = !SwitchSetFront;
796
797 MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
798 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
799
800 MyView->SetViewOrientation(MyViewOrientation) ;
801
802 ImmediateUpdate();
803
804}
805
806/*----------------------------------------------------------------------*/
807
808void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) {
809
810 Standard_Real Ax = ax ;
811 Standard_Real Ay = ay ;
812 Standard_Real Az = az ;
813 Graphic3d_Vector Vpn,Vup ;
814 TColStd_Array2OfReal Matrix(0,3,0,3) ;
815 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
816
817 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
818 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
819 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
820 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
821 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
822 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
823
824 if( Start ) {
825 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
826 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
827 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
828 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
829 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
830 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
831 }
832
833 InitMatrix(Matrix) ;
834
835 if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
836 if( Ay != 0. ) {
837 RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
838 Multiply(Matrix, Rmatrix, Matrix);
839 }
840 if( Az != 0. ) {
841 RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
842 Multiply(Matrix, Rmatrix, Matrix);
843 }
844 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
845 MyViewOrientation.SetViewReferencePlane(Vpn) ;
846 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
847 MyViewOrientation.SetViewReferenceUp(Vup) ;
848 MyView->SetViewOrientation(MyViewOrientation) ;
849#ifdef IMP020300
850 SetZSize(0.) ;
851#endif
852 ImmediateUpdate();
853
854}
855
856/*----------------------------------------------------------------------*/
857
858void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
859 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
860{
861
862 Standard_Real Ax = ax ;
863 Standard_Real Ay = ay ;
864 Standard_Real Az = az ;
865 Graphic3d_Vector Vpn,Vup ;
866 Graphic3d_Vertex Vrp ;
867 TColStd_Array2OfReal Matrix(0,3,0,3) ;
868 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
869
870 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
871 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
872 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
873 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
874 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
875 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
876
877 if( Start ) {
878 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
879 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
880 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
881 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
882 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
883 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
884 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
885 }
886
887 InitMatrix(Matrix) ;
888
889 if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
890 if( Ay != 0. ) {
891 RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
892 Multiply(Matrix, Rmatrix, Matrix);
893 }
894 if( Az != 0. ) {
895 RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
896 Multiply(Matrix, Rmatrix, Matrix);
897 }
898 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
899 MyViewOrientation.SetViewReferencePoint(Vrp) ;
900 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
901 MyViewOrientation.SetViewReferencePlane(Vpn) ;
902 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
903 MyViewOrientation.SetViewReferenceUp(Vup) ;
904 MyView->SetViewOrientation(MyViewOrientation) ;
905#ifdef IMP020300
906 SetZSize(0.) ;
907#endif
908 ImmediateUpdate();
909
910}
911
912/*----------------------------------------------------------------------*/
913
914void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) {
915
916 switch (Axe) {
917 case V3d_X :
918 Rotate(angle,0.,0.,Start);
919 break ;
920 case V3d_Y :
921 Rotate(0.,angle,0.,Start);
922 break ;
923 case V3d_Z :
924 Rotate(0.,0.,angle,Start);
925 break ;
926 }
927
928}
929
930/*----------------------------------------------------------------------*/
931
932void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
933 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
934{
935
936 Standard_Real Angle = angle ;
937 Graphic3d_Vector Vpn,Vup ;
938 Graphic3d_Vertex Vrp ;
939 TColStd_Array2OfReal Matrix(0,3,0,3) ;
940
941 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
942 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
943
944 if( Start ) {
945 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
946 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
947 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
948 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
949 switch (Axe) {
950 case V3d_X :
951 MyViewAxis.SetCoord(1.,0.,0.) ;
952 break ;
953 case V3d_Y :
954 MyViewAxis.SetCoord(0.,1.,0.) ;
955 break ;
956 case V3d_Z :
957 MyViewAxis.SetCoord(0.,0.,1.) ;
958 break ;
959 }
960 }
961
962 RotAxis(MyGravityReferencePoint,MyViewAxis,Angle,Matrix) ;
963 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
964 MyViewOrientation.SetViewReferencePoint(Vrp) ;
965 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
966 MyViewOrientation.SetViewReferencePlane(Vpn) ;
967 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
968 MyViewOrientation.SetViewReferenceUp(Vup) ;
969 MyView->SetViewOrientation(MyViewOrientation) ;
970#ifdef IMP020300
971 SetZSize(0.) ;
972#endif
973 ImmediateUpdate();
974
975}
976
977/*----------------------------------------------------------------------*/
978
979void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) {
980
981 Standard_Real Angle = angle ;
982 Graphic3d_Vector Vpn,Vup ;
983 TColStd_Array2OfReal Matrix(0,3,0,3) ;
984
985 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
986 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
987
988 if( Start ) {
989 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
990 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
991 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
992 }
993
994 RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
995#ifdef BUC60952
996 Graphic3d_Vertex Vrp ;
997 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
998 MyViewOrientation.SetViewReferencePoint(Vrp) ;
999#endif
1000 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1001 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1002 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1003 MyViewOrientation.SetViewReferenceUp(Vup) ;
1004 MyView->SetViewOrientation(MyViewOrientation) ;
1005#ifdef IMP020300
1006 SetZSize(0.) ;
1007#endif
1008 ImmediateUpdate();
1009
1010}
1011
1012/*----------------------------------------------------------------------*/
1013
1014void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
1015{
1016
1017 Standard_Real Ax = ax ;
1018 Standard_Real Ay = ay ;
1019 Standard_Real Az = az ;
1020 Graphic3d_Vertex Vrp,Eye ;
1021 Graphic3d_Vector Vpn,Vup ;
1022 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1023 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1024 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
1025
1026 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
1027 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
1028 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
1029 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
1030 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
1031 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
1032
1033 if( Start ) {
1034 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1035 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1036 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1037 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1038 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1039 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
1040 Viewer_BadValue::Raise ("V3d_View::Turn, alignment of Eye,At,Up");
1041 }
1042
1043 InitMatrix(Matrix) ;
1044 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1045 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1046 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1047 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1048 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1049 if( Ax != 0. ) RotAxis(Eye,MyYscreenAxis,-Ax,Matrix) ;
1050 if( Ay != 0. ) {
1051 RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
1052 Multiply(Matrix, Rmatrix, Matrix);
1053 }
1054 if( Az != 0. ) {
1055 RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
1056 Multiply(Matrix, Rmatrix, Matrix);
1057 }
1058 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1059 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1060 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1061 MyViewOrientation.SetViewReferenceUp(Vpn) ;
1062 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1063 MyViewOrientation.SetViewReferenceUp(Vup) ;
1064 MyView->SetViewOrientation(MyViewOrientation) ;
1065#ifdef IMP020300
1066 SetZSize(0.) ;
1067#else
1068 // Check ZClipping planes
1069 Standard_Real Zmax ;
1070 Vrp.Coord(Xat,Yat,Zat) ;
1071 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat) ;
1072 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1073 MyProjModel == V3d_TPM_SCREEN ) {
1074 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1075 }
1076#endif
1077 ImmediateUpdate();
1078
1079}
1080
1081/*----------------------------------------------------------------------*/
1082
1083void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1084{
1085
1086 switch (Axe) {
1087 case V3d_X :
1088 Turn(angle,0.,0.,Start);
1089 break ;
1090 case V3d_Y :
1091 Turn(0.,angle,0.,Start);
1092 break ;
1093 case V3d_Z :
1094 Turn(0.,0.,angle,Start);
1095 break ;
1096 }
1097}
1098
1099void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) {
1100 Standard_Real Angle = angle ;
1101 Graphic3d_Vertex Vrp,Eye ;
1102 Graphic3d_Vector Vpn,Vup ;
1103 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1104 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1105
1106 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1107 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1108
1109 if( Start ) {
1110 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1111 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1112 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1113 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1114 }
1115 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1116 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1117 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1118 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1119 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1120 RotAxis(Eye,MyDefaultViewAxis,Angle,Matrix) ;
1121 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1122 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1123 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1124 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1125 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1126 MyViewOrientation.SetViewReferenceUp(Vup) ;
1127 MyView->SetViewOrientation(MyViewOrientation) ;
1128#ifdef IMP020300
1129 SetZSize(0.) ;
1130#else
1131 // Check ZClipping planes
1132 Standard_Real Zmax ;
1133 Vrp.Coord(Xat,Yat,Zat) ;
1134 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat ) ;
1135 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1136 MyProjModel == V3d_TPM_SCREEN ) {
1137 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1138 }
1139#endif
1140 ImmediateUpdate();
1141
1142}
1143
1144void V3d_View::SetTwist(const Standard_Real angle) {
1145
1146 Standard_Real Angle = angle ;
1147 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1148 Standard_Boolean TheStatus ;
1149
1150 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1151 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1152
1153 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1154 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1155 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1156 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1157 if( !TheStatus ) {
1158 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1159 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1160 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1161 }
1162 if( !TheStatus ) {
1163 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1164 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1165 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1166 }
1167
1168 Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
1169
1170 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1171 RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
1172 MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
1173 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1174 MyView->SetViewOrientation(MyViewOrientation) ;
1175 ImmediateUpdate();
1176
1177}
1178
1179#ifdef IMP240100
1180void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
1181{
1182
1183 MyProjModel = aModel;
1184
1185}
1186
1187V3d_TypeOfProjectionModel V3d_View::ProjModel() const {
1188
1189 return MyProjModel;
1190
1191}
1192#endif
1193
1194void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1195
1196 Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
1197 Angle = Twist() ;
1198 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1199 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1200 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1201 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1202 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1203 Xpn = X - Xat ; Ypn = Y - Yat ; Zpn = Z - Zat ;
1204 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1205 Viewer_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused");
1206
1207 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1208 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1209 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1210 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1211 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1212
1213 Standard_Boolean update = myImmediateUpdate;
1214 myImmediateUpdate = Standard_False;
1215 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1216 //FMN desactivation temp SetTwist(Angle) ;
1217 // Set infos.
1218 MyView->SetViewOrientation(MyViewOrientation) ;
1219 MyView->SetViewMapping(MyViewMapping) ;
1220 } else {
1221 SetTwist(Angle) ;
1222 }
1223#ifdef IMP020300
1224 SetZSize(0.) ;
1225#else
1226 // Check ZClipping planes
1227 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1228 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1229 MyProjModel == V3d_TPM_SCREEN ) {
1230 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1231 } else {
1232 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1233 MyView->SetViewMapping(MyViewMapping);
1234 }
1235#endif
1236 myImmediateUpdate = update;
1237 ImmediateUpdate();
1238
1239}
1240
1241void V3d_View::SetDepth(const Standard_Real Depth) {
1242
1243 Standard_Real Xrp,Yrp,Zrp ;
1244#ifdef IMP250200
1245 Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
1246#else
1247 Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
1248#endif
1249
1250#ifdef DEB
1251 Standard_Real twist =
1252#endif
1253 Twist();
1254 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1255 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1256 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1257 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1258#ifdef IMP250200
1259 if( Depth > 0. )
1260#endif
1261 {
1262 Zrp = Depth;
1263 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1264 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1265 }
1266
1267 // Check ZClipping planes
1268 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
1269 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1270 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1271#ifdef IMP250200
1272 if( Depth < 0. ) { // Move the view ref point instead of the eye.
1273 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1274 Zrp = Abs(Depth) ;
1275 Xat = Xeye - Xpn*Zrp ; Yat = Yeye - Ypn*Zrp ; Zat = Zeye - Zpn*Zrp;
1276 MyViewReferencePoint.SetCoord(Xat,Yat,Zat) ;
1277 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1278 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1279 MyView->SetViewOrientation(MyViewOrientation);
1280 }
1281#endif
1282#ifdef IMP020300
1283 MyView->SetViewMapping(MyViewMapping) ;
1284 SetZSize(0.) ;
1285#else
1286 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1287 Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1288
1289 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1290 MyProjModel == V3d_TPM_SCREEN ) {
1291 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1292 } else {
1293 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1294#ifdef IMP250200
1295 if( Depth > 0. )
1296#endif
1297 MyView->SetViewMapping(MyViewMapping) ;
1298 }
1299#endif
1300
1301 ImmediateUpdate();
1302
1303}
1304
1305
1306void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1307{
1308
1309 Standard_Real Angle ;
1310
1311 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1312 "V3d_View::SetProj, null projection vector");
1313
1314 Angle = Twist() ;
1315 MyViewReferencePlane.SetCoord(Vx,Vy,Vz) ;
1316 MyViewReferencePlane.Normalize() ;
1317 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1318 Standard_Boolean update = myImmediateUpdate;
1319 myImmediateUpdate = Standard_False;
1320 if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ;
1321#ifdef IMP020300
1322 SetZSize(0.) ;
1323#endif
1324 myImmediateUpdate = update;
1325 ImmediateUpdate();
1326
1327}
1328
1329void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) {
1330
1331 MyViewReferencePlane = V3d::GetProjAxis(Orientation) ;
1332 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1333 // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955
1334 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(0,0,0));
1335 Standard_Real Xpn=0;
1336 Standard_Real Ypn=0;
1337 Standard_Real Zpn=0;
1338
1339 switch (Orientation) {
1340 case V3d_Zpos :
1341 Ypn = 1. ;
1342 break ;
1343 case V3d_Zneg :
1344 Ypn = -1. ;
1345 break ;
1346 default:
1347 Zpn = 1.;
1348 }
1349 SetUp(Xpn,Ypn,Zpn);
1350#ifdef IMP020300
1351 SetZSize(0.) ;
1352#endif
1353 ImmediateUpdate();
1354
1355}
1356
1357void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1358
1359 Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
1360 Standard_Real Xeye,Yeye,Zeye ;
1361
1362 Angle = Twist() ;
1363 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1364 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1365 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1366 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1367 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1368 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1369 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1370 Xpn = Xeye - X ; Ypn = Yeye - Y ; Zpn = Zeye - Z ;
1371 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1372 Viewer_BadValue_Raise_if( Zrp <= 0.,
1373 "V3d_View::SetAt, Eye,At are Confused");
1374
1375 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1376 MyViewReferencePoint.SetCoord(X,Y,Z) ;
1377 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1378 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1379 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1380 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1381 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1382 Standard_Boolean update = myImmediateUpdate;
1383 myImmediateUpdate = Standard_False;
1384 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1385 //FMN desactivation temp SetTwist(Angle) ;
1386 // Set infos.
1387 MyView->SetViewOrientation(MyViewOrientation) ;
1388 MyView->SetViewMapping(MyViewMapping) ;
1389 } else {
1390 SetTwist(Angle) ;
1391 }
1392#ifdef IMP020300
1393 MyView->SetViewMapping(MyViewMapping);
1394 SetZSize(0.) ;
1395#else
1396 ImmediateUpdate();
1397 // Check ZClipping planes
1398 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1399 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1400 MyProjModel == V3d_TPM_SCREEN ) {
1401 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1402 } else {
1403 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1404 MyView->SetViewMapping(MyViewMapping);
1405 }
1406#endif
1407 myImmediateUpdate = update;
1408 ImmediateUpdate();
1409
1410}
1411
1412void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) {
1413
1414 Standard_Boolean TheStatus ;
1415 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
1416 "V3d_View::SetUp, nullUp vector");
1417
1418 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1419 MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
1420 MyViewReferenceUp.Normalize() ;
1421 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1422 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1423 if( !TheStatus ) {
1424 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1425 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1426 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1427 }
1428 if( !TheStatus ) {
1429 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1430 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1431 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1432 }
1433 if( !TheStatus ) {
1434 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1435 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1436 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1437 }
1438 Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
1439
1440 MyViewReferenceUp = MyYscreenAxis ;
1441 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1442 MyView->SetViewOrientation(MyViewOrientation) ;
1443 ImmediateUpdate();
1444
1445}
1446
1447void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) {
1448
1449 Standard_Boolean TheStatus ;
1450
1451 MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
1452 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1453 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1454 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1455 if( !TheStatus ) {
1456 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1457 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1458 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1459 }
1460 if( !TheStatus ) {
1461 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1462 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1463 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1464 }
1465 if( !TheStatus ) {
1466 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1467 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1468 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1469 }
1470 Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
1471
1472 MyViewReferenceUp = MyYscreenAxis ;
1473 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1474 MyView->SetViewOrientation(MyViewOrientation) ;
1475 ImmediateUpdate();
1476
1477}
1478
1479void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
1480{
1481 MyViewOrientation = VO;
1482 MyView->SetViewOrientation(MyViewOrientation) ;
1483 ImmediateUpdate();
1484}
1485
1486void V3d_View::SetViewOrientationDefault() {
1487
1488 MyView->SetViewOrientation(MyViewOrientation) ;
1489 MyView->SetViewOrientationDefault() ;
1490 ImmediateUpdate();
1491}
1492
1493void V3d_View::ResetViewOrientation() {
1494
1495 MyView->ViewOrientationReset() ;
1496 MyViewOrientation = MyView->ViewOrientation() ;
1497 ImmediateUpdate();
1498}
1499
1500void V3d_View::Reset( const Standard_Boolean update ) {
1501
1502 MyView->ViewOrientationReset() ;
1503 MyViewOrientation = MyView->ViewOrientation() ;
1504 MyView->ViewMappingReset();
1505 MyViewMapping = MyView->ViewMapping() ;
1506
1507 ZFitAll (Zmargin);
1508 SwitchSetFront = Standard_False;
1509#ifdef IMP020300
1510 if( !myImmediateUpdate && update ) Update();
1511#else
1512 ImmediateUpdate();
1513#endif
1514
1515}
1516
1517void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
1518{
1519
1520 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ;
1521 Viewer_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
1522
1523 if( Start ) {
1524 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1525 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1526 MyXwindowCenter = (Umin + Umax)/2. ;
1527 MyYwindowCenter = (Vmin + Vmax)/2. ;
1528 MyWindowWidth = Abs(Umax - Umin) ;
1529 MyWindowHeight = Abs(Vmax - Vmin) ;
1530 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1531 "V3d_View::Panning, Window Size is NULL");
1532 }
1533 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1534 Xrp = MyXwindowCenter - Dx ;
1535 Yrp = MyYwindowCenter - Dy ;
1536 Dxv = MyWindowWidth/aZoomFactor ; Dyv = MyWindowHeight/aZoomFactor ;
1537 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1538 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1539 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1540 if( MyType != V3d_PERSPECTIVE ) {
1541 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1542 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1543 }
1544 MyView->SetViewMapping(MyViewMapping) ;
1545 ImmediateUpdate();
1546
1547}
1548void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) {
1549 Standard_Real x,y;
1550 Convert(X,Y,x,y);
1551 SetCenter(x,y);
1552}
1553
1554void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc){
1555
1556 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
1557
1558 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1559 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1560 MyXwindowCenter = Xrp = Xc ; MyYwindowCenter = Yrp = Yc ;
1561 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1562 MyWindowWidth = Abs(Umax - Umin) ; MyWindowHeight = Abs(Vmax - Vmin) ;
1563 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1564 "V3d_View::SetCenter, Window Size is NULL");
1565
1566 Umin = Xc - MyWindowWidth/2. ; Vmin = Yc - MyWindowHeight/2. ;
1567 Umax = Xc + MyWindowWidth/2. ; Vmax = Yc + MyWindowHeight/2. ;
1568 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1569 if( MyType != V3d_PERSPECTIVE ) {
1570 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1571 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1572 }
1573 MyView->SetViewMapping(MyViewMapping) ;
1574 ImmediateUpdate();
1575
1576}
1577
1578void V3d_View::SetSize(const Standard_Real Size)
1579{
1580
1581 Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
1582
1583 Viewer_BadValue_Raise_if( Size <= 0.,
1584 "V3d_View::SetSize, Window Size is NULL");
1585
1586
1587 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1588 MyWindowWidth = Abs(Umax - Umin) ;
1589 MyWindowHeight = Abs(Vmax - Vmin) ;
1590 MyXwindowCenter = (Umin + Umax)/2. ;
1591 MyYwindowCenter = (Vmin + Vmax)/2. ;
1592 Rap = MyWindowWidth/MyWindowHeight ;
1593 if( MyWindowWidth >= MyWindowHeight ) {
1594 MyWindowWidth = Size ; MyWindowHeight = Size/Rap ;
1595 } else {
1596 MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
1597 }
1598 Umin = MyXwindowCenter - MyWindowWidth/2. ;
1599 Vmin = MyYwindowCenter - MyWindowHeight/2. ;
1600 Umax = MyXwindowCenter + MyWindowWidth/2. ;
1601 Vmax = MyYwindowCenter + MyWindowHeight/2. ;
1602 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1603 MyView->SetViewMapping(MyViewMapping) ;
1604 ImmediateUpdate();
1605
1606}
1607
1608void V3d_View::SetZSize(const Standard_Real Size)
1609{
1610
1611 Standard_Real Zmax = Size/2.;
1612
1613#ifdef IMP020300
1614 if( Size <= 0. ) {
1615 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye;
1616 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1617 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1618 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1619 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat;
1620 Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1621 if( Zmax <= MyViewMapping.FrontPlaneDistance() ) return;
1622 }
1623#else
1624 Viewer_BadValue_Raise_if( Size <= 0.,
1625 "V3d_View::SetZSize, Window ZSize is NULL");
1626#endif
1627
1628 Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
1629 Standard_Real Back = MyViewContext.ZClippingBackPlane() ;
1630 Standard_Real focale= Focale();
1631
1632 MyViewMapping.SetFrontPlaneDistance(Zmax) ;
1633 MyViewMapping.SetBackPlaneDistance(-Zmax) ;
1634
1635 // OCC18942
1636 if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
1637 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
1638 }
1639
1640 MyView->SetViewMapping(MyViewMapping) ;
1641 if( MyViewContext.FrontZClippingIsOn() ||
1642 MyViewContext.BackZClippingIsOn() ) {
1643 MyViewContext.SetZClippingFrontPlane(Front) ;
1644 MyViewContext.SetZClippingBackPlane(Back) ;
1645 MyView->SetContext(MyViewContext) ;
1646 }
1647
1648}
1649
1650void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
1651{
1652
1653 Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
1654 Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
1655
1656 if( Start ) {
1657 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1658 MyXwindowCenter = (Umin + Umax)/2. ;
1659 MyYwindowCenter = (Vmin + Vmax)/2. ;
1660 MyWindowWidth = Abs(Umax - Umin) ;
1661 MyWindowHeight = Abs(Vmax - Vmin) ;
1662 }
1663
1664 // ensure that zoom will not be too small or too big
1665 Standard_Real coef = Coef;
1666 if ( MyWindowWidth < coef * Precision::Confusion() )
1667 coef = MyWindowWidth / Precision::Confusion();
1668 else if ( MyWindowWidth > coef * 1e12 )
1669 coef = MyWindowWidth / 1e12;
1670 if ( MyWindowHeight < coef * Precision::Confusion() )
1671 coef = MyWindowHeight / Precision::Confusion();
1672 else if ( MyWindowHeight > coef * 1e12 )
1673 coef = MyWindowHeight / 1e12;
1674
1675 Dxv = MyWindowWidth/coef;
1676 Dyv = MyWindowHeight/coef;
1677 Umin = MyXwindowCenter - Dxv/2. ; Umax = MyXwindowCenter + Dxv/2. ;
1678 Vmin = MyYwindowCenter - Dyv/2. ; Vmax = MyYwindowCenter + Dyv/2. ;
1679 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1680 MyView->SetViewMapping(MyViewMapping) ;
1681 ImmediateUpdate();
1682}
1683
1684void V3d_View::SetScale( const Standard_Real Coef ) {
1685 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
1686 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
1687
1688 Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1689
1690 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1691 Dxv = Abs(Umax - Umin) ; Dyv = Abs(Vmax - Vmin) ;
1692 Dxv /= Coef ; Dyv /= Coef ;
1693 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1694 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
1695 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1696 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1697 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1698 MyView->SetViewMapping(MyViewMapping) ;
1699 ImmediateUpdate();
1700
1701}
1702
1703void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) {
1704
1705 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1706 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1707 Viewer_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
1708
1709 MyViewOrientation.SetAxialScale( Sx, Sy, Sz );
1710 Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode();
1711 MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP);
1712 MyView->SetViewOrientation(MyViewOrientation);
1713 MyView->ViewManager()->SetUpdateMode(updateMode);
1714
1715 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1716
1717 Standard_Real LIM = ShortRealLast() -1.;
1718 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1719 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1720 return;
1721 }
1722
1723 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1724 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1725 Umax = Max(Umin,Umax) ; Vmax = Max(Vmin,Vmax) ;
1726 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1727 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1728 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1729 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1730 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1731 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1732 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1733 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1734 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1735 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1736 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1737 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1738 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1739 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1740 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1741 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1742 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1743 Umax = Max(Umax,Vmax) ;
1744 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1745 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1746 Wmax = Max(Abs(Umax),Abs(Wmax)) ;
1747
1748 if( Wmax > 0. ) {
1749 SetZSize(2.*Wmax + Wmax) ;
1750 }
1751
1752}
1753
1754void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
1755 const Standard_Boolean update)
1756{
35617823
K
1757 Standard_Real Umin, Umax, Vmin, Vmax, Xrp, Yrp, Zrp, U, V, W, U1, V1, W1;
1758 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
1759 Standard_Real DxvOld, DyvOld, DxvNew, DyvNew;
1760 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures();
7fd59977 1761
35617823
K
1762 if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
1763 {
7fd59977 1764#ifndef IMP020300
1765 ImmediateUpdate();
1766#endif
35617823 1767 return;
7fd59977 1768 }
7fd59977 1769
35617823
K
1770 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1771 MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
1772 if (MyView->IsDefined())
1773 {
1774 Standard_Integer Xpixel, Ypixel;
1775 MyWindow->Size (Xpixel, Ypixel);
1776 DxvOld = Xpixel;
1777 DyvOld = Ypixel;
7fd59977 1778 }
35617823
K
1779 else
1780 {
1781 MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
1782 DxvOld = Abs (Umax - Umin);
1783 DyvOld = Abs (Vmax - Vmin);
7fd59977 1784 }
35617823
K
1785 if ((DxvOld == 0.0) || (DyvOld == 0.0))
1786 {
1787 return;
7fd59977 1788 }
1789
35617823
K
1790 Standard_Real aWinRatio = DxvOld / DyvOld;
1791
1792 // retrieve min / max values for current displayed objects
1793 MyView->MinMaxValues (Xmin, Ymin, Zmin,
1794 Xmax, Ymax, Zmax);
1795
1796 Standard_Real LIM = ShortRealLast() - 1.0;
1797 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1798 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM)
1799 {
7fd59977 1800#ifndef IMP020300
35617823 1801 ImmediateUpdate();
7fd59977 1802#endif
35617823
K
1803 return;
1804 }
7fd59977 1805
35617823
K
1806 // eliminate fluctuations between sequential FitAll() calls
1807 MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0);
1808 if (MyType != V3d_PERSPECTIVE)
1809 {
1810 MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
1811 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1812 }
1813 MyView->SetViewMapping (MyViewMapping);
1814
1815 // iterate 2 times to find optimal view plane size
1816 // (use view plane values computed on previous iteration)
1817 for (Standard_Integer aIteration = 2; aIteration > 0; --aIteration)
1818 {
1819 MyView->Projects (Xmin, Ymin, Zmin, U, V, W);
1820 MyView->Projects (Xmax, Ymax, Zmax, U1, V1, W1);
1821 Umin = Min (U, U1); Umax = Max (U, U1);
1822 Vmin = Min (V, V1); Vmax = Max (V, V1);
1823
1824 MyView->Projects (Xmin, Ymin, Zmax, U, V, W);
1825 Umin = Min (U, Umin); Umax = Max (U, Umax);
1826 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1827
1828 MyView->Projects (Xmax, Ymin, Zmax, U, V, W);
1829 Umin = Min (U, Umin); Umax = Max (U, Umax);
1830 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1831
1832 MyView->Projects (Xmax, Ymin, Zmin, U, V, W);
1833 Umin = Min (U, Umin); Umax = Max (U, Umax);
1834 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1835
1836 MyView->Projects (Xmax, Ymax, Zmin, U, V, W);
1837 Umin = Min (U, Umin); Umax = Max (U, Umax);
1838 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
7fd59977 1839
35617823
K
1840 MyView->Projects (Xmin, Ymax, Zmax, U, V, W);
1841 Umin = Min (U, Umin); Umax = Max (U, Umax);
1842 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
7fd59977 1843
35617823
K
1844 MyView->Projects (Xmin, Ymax, Zmin, U, V, W);
1845 Umin = Min (U, Umin); Umax = Max (U, Umax);
1846 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1847
1848 DxvNew = Abs (Umax - Umin);
1849 DyvNew = Abs (Vmax - Vmin);
1850
1851 if (DyvNew < 10.0 * Precision::Confusion())
1852 {
1853 if (DxvNew < 10.0 * Precision::Confusion())
1854 {
1855 // whole scene projected to point
1856 DxvNew = Max (Abs (Zmax - Zmin), (Max (Abs (Xmax - Xmin), Abs (Ymax - Ymin))));
1857 if (DxvNew < 10.0 * Precision::Confusion())
1858 {
1859 // this is really just one (!) point and zooming has no any effect
1860 // just center the view
1861 DyvNew = DyvOld;
1862 DxvNew = DxvOld;
7fd59977 1863 }
35617823
K
1864 else
1865 {
1866 // we look along some line
1867 // fit view like that to see whole scene on rotation
1868 DxvNew += Coef * DxvNew;
1869 DyvNew = DxvNew / aWinRatio;
1870 }
1871 }
1872 else
1873 {
1874 // whole scene projected to horizontal line
1875 DxvNew += Coef * DxvNew;
1876 DyvNew = DxvNew / aWinRatio;
7fd59977 1877 }
35617823
K
1878 }
1879 else
1880 {
1881 // general case (or DxvNew == 0.0 - vertical line)
1882 // safe original ratio
1883 Standard_Real aFitRatio = DxvNew / DyvNew;
1884 if (aFitRatio >= aWinRatio)
1885 {
1886 DxvNew += Coef * DxvNew;
1887 DyvNew = DxvNew / aWinRatio;
1888 }
1889 else
1890 {
1891 DyvNew += Coef * DyvNew;
1892 DxvNew = DyvNew * aWinRatio;
1893 }
1894 }
7fd59977 1895
35617823
K
1896 // new scene center
1897 Xrp = 0.5 * (Umin + Umax);
1898 Yrp = 0.5 * (Vmin + Vmax);
7fd59977 1899
35617823
K
1900 // new window limits
1901 Umin = Xrp - 0.5 * DxvNew;
1902 Umax = Xrp + 0.5 * DxvNew;
1903 Vmin = Yrp - 0.5 * DyvNew;
1904 Vmax = Yrp + 0.5 * DyvNew;
1905 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
1906
1907 if (MyType != V3d_PERSPECTIVE)
1908 {
1909 // center the view
1910 MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
1911 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1912 }
1913 MyView->SetViewMapping (MyViewMapping);
1914 }
1915
1916 if (FitZ)
1917 {
1918 ZFitAll (Zmargin);
7fd59977 1919#ifdef IMP020300
35617823
K
1920 }
1921 else
1922 {
1923 ImmediateUpdate();
7fd59977 1924#endif
35617823 1925 }
7fd59977 1926#ifdef IMP020300
35617823
K
1927 if (!myImmediateUpdate && update)
1928 {
1929 Update();
1930 }
7fd59977 1931#endif
1932}
1933
1934void V3d_View::ZFitAll(const Standard_Real Coef) {
1935
1936 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1937 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1938 // CAL 6/11/98
1939 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1940
1941 if( MyType == V3d_PERSPECTIVE ) {
1942 ImmediateUpdate();
1943 return ;
1944 }
1945
1946 if( (Nstruct <= 0) || (Coef < 0.) ) {
1947 ImmediateUpdate();
1948 return ;
1949 }
1950
1951 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1952
1953 Standard_Real LIM = ShortRealLast() -1.;
1954 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1955 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1956 ImmediateUpdate();
1957 return ;
1958 }
1959
7fd59977 1960 // CAL 6/11/98
1961 // Case when view contains only a point
1962 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
1963 ImmediateUpdate();
1964 return ;
1965 }
1966 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1967 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1968 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1969 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1970 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1971 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1972 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1973 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1974 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1975 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1976 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1977 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1978 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1979 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1980 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1981 if( Wmax > 0. ) {
1982 SetZSize(2.*Wmax + Coef * Wmax) ;
1983 }
1984 ImmediateUpdate();
1985}
1986
1987void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
1988 const Quantity_Coefficient Margin)
1989{
1990 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
1991 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1992 Standard_Real Xrp,Yrp,Zrp,Dx,Dy,Dz,Size;
1993
1994 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1995
1996 if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
1997 ImmediateUpdate();
1998 return ;
1999 }
2000
2001 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2002 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2003
2004 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2005
2006 Standard_Real LIM = ShortRealLast() -1.;
2007 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2008 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
2009 ImmediateUpdate();
2010 return ;
2011 }
2012
7fd59977 2013 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
2014 ImmediateUpdate();
2015 return ;
2016 }
2017 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2018 MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
2019 Umin = Min(U,U1) ; Umax = Max(U,U1) ;
2020 Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
2021 Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
2022 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2023 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2024 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2025 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2026 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2027 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2028 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2029 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2030 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2031 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2032 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2033 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2034 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2035 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2036 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2037 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2038 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2039 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2040 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2041 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2042 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2043 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2044 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2045 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2046
2047 // Adjust Z size
2048 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
2049 Dz = 2.*Wmax + Margin * Wmax;
2050
2051 // Compute depth value
2052 Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
2053 Dx += Margin * Dx; Dy += Margin * Dy;
2054 Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
2055 if( Size > 0. ) {
2056 SetZSize(Size) ;
2057 SetDepth( Aspect * Size / 2.);
2058 }
2059
2060 ImmediateUpdate();
2061}
2062
2063void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax) {
2064 FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
2065#ifndef IMP020300
2066 ImmediateUpdate();
2067#endif
2068}
2069
2070void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
2071 WindowFit(Xmin,Ymin,Xmax,Ymax);
2072
2073}
2074void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
2075 Standard_Real x1,y1,x2,y2;
2076 Convert(Xmin,Ymin,x1,y1);
2077 Convert(Xmax,Ymax,x2,y2);
2078 FitAll(x1,y1,x2,y2);
2079}
2080
2081void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
2082{
2083 MyViewMapping = VM;
2084 // ajust view type according to mapping projection
2085 // NOTE: Might be dangerous, potentially conflicts with the C++ view class
2086 // (orthographic or perspective)! Use with care!
2087 if ( VM.Projection() == Visual3d_TOP_PERSPECTIVE )
2088 MyType = V3d_PERSPECTIVE;
2089 else MyType = V3d_ORTHOGRAPHIC;
2090
2091 MyView->SetViewMapping(MyViewMapping) ;
2092 ImmediateUpdate();
2093}
2094
2095void V3d_View::SetViewMappingDefault() {
2096 MyView->SetViewMapping(MyViewMapping) ;
2097 MyView->SetViewMappingDefault();
2098 ImmediateUpdate();
2099}
2100
2101void V3d_View::ResetViewMapping() {
2102
2103 MyView->ViewMappingReset();
2104 MyViewMapping = MyView->ViewMapping() ;
2105#ifdef IMP020300
2106 ZFitAll (Zmargin);
2107 Update();
2108#else
2109 ImmediateUpdate();
2110#endif
2111}
2112
2113Standard_Real V3d_View::Convert(const Standard_Integer Vp) const {
2114 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
2115 Standard_Integer Dxw,Dyw ;
2116
2117 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2118
2119 MyWindow->Size(Dxw,Dyw);
2120 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2121 Dxv = Umax - Umin ;
2122 Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
2123
2124 return Vv ;
2125}
2126
2127void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const {
2128 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Dyv ;
2129 Standard_Integer Dxw,Dyw ;
2130
2131 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2132
2133 MyWindow->Size(Dxw,Dyw);
2134 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2135 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
2136 Xv = Umin + Dxv*(Standard_Real)Xp/(Standard_Real)Dxw ;
2137 Yv = Vmin + Dyv*(Standard_Real)(Dyw-Yp)/(Standard_Real)Dyw ;
2138}
2139
2140Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
2141{
2142 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2143
2144 Standard_Integer Dxw, Dyw;
2145 MyWindow->Size(Dxw,Dyw);
2146
2147 Standard_Real Umin,Umax,Vmin,Vmax;
2148 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2149 Standard_Real Dxv = Umax - Umin;
2150 return RealToInt ( Dxw * Vv / Dxv );
2151}
2152
2153void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
2154{
2155 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2156
2157 Standard_Integer Dxw, Dyw;
2158 MyWindow->Size(Dxw,Dyw);
2159
2160 Standard_Real Umin,Umax,Vmin,Vmax;
2161 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2162 Standard_Real Dxv = Umax - Umin;
2163 Standard_Real Dyv = Vmax - Vmin;
2164
2165 // CAL 15/12/93 warning: double assigned to int
2166 Xp = RealToInt (Dxw*(Xv - Umin)/Dxv);
2167 // CAL 15/12/93 warning: double assigned to int
2168 Yp = Dyw - RealToInt (Dyw*(Yv - Vmin)/Dyv);
2169}
2170
2171void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2172
2173 Graphic3d_Vertex Vrp ;
2174 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2175 Vrp.Coord(X,Y,Z) ;
2176#ifndef IMP240100
2177 if( MyViewer->Grid()->IsActive() ) {
2178 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2179 NewVrp.Coord(X,Y,Z) ;
2180 }
2181#endif
2182}
2183
2184void V3d_View::ConvertWithProj(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
2185{
2186 Graphic3d_Vertex Vrp ;
2187 Graphic3d_Vector Proj ;
2188 (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
2189 Vrp.Coord(X,Y,Z) ;
2190 Proj.Coord(Dx,Dy,Dz) ;
2191#ifndef IMP240100
2192 if( MyViewer->Grid()->IsActive() ) {
2193 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2194 NewVrp.Coord(X,Y,Z) ;
2195 }
2196#endif
2197}
2198
2199#ifdef IMP240100
2200void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
2201
2202 Graphic3d_Vertex Vrp ;
2203 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2204 if( MyViewer->Grid()->IsActive() ) {
2205 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2206 NewVrp.Coord(Xg,Yg,Zg) ;
2207 } else
2208 Vrp.Coord(Xg,Yg,Zg) ;
2209}
2210
2211void V3d_View::ConvertToGrid(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
2212
2213 if( MyViewer->Grid()->IsActive() ) {
2214 Graphic3d_Vertex Vrp(X,Y,Z) ;
2215 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2216 NewVrp.Coord(Xg,Yg,Zg) ;
2217 } else {
2218 Xg = X; Yg = Y; Zg = Z;
2219 }
2220}
2221#endif
2222
2223#ifndef IMP240100
2224void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2225
2226 Graphic3d_Vertex Vrp ;
2227 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2228 Vrp.Coord(X,Y,Z) ;
2229 if( MyViewer->Grid()->IsActive() ) {
2230 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2231 NewVrp.Coord(X,Y,Z) ;
2232 }
2233}
2234#endif
2235
2236#ifdef IMP240100
2237void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2238#else
2239void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2240#endif
2241
2242 Graphic3d_Vertex Vrp(X,Y,Z) ;
2243 (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
2244}
2245
2246void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
2247{
2248 if ( MyType != V3d_PERSPECTIVE )
2249 {
2250 // use old implementation
2251 Standard_Real Zp;
2252 MyView->Projects( X, Y, Z, Xp, Yp, Zp );
2253 }
2254 else
2255 {
2256 // NKV - Using raster projection
2257 Standard_Integer Xpx, Ypx;
2258 Convert(X, Y, Z, Xpx, Ypx);
2259 Convert(Xpx, Ypx, Xp, Yp);
2260 }
2261}
2262
2263void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3)const {
2264
2265#ifdef GER61351
2266 Quantity_Color C = BackgroundColor() ;
2267#else
2268 Quantity_Color C ;
2269 C = MyBackground.Color() ;
2270#endif
2271 C.Values(V1,V2,V3,Type) ;
2272}
2273
2274#ifdef GER61351
2275Quantity_Color V3d_View::BackgroundColor() const {
2276
2277 return MyBackground.Color() ;
2278}
2279#endif
2280
2281void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
2282 MyGradientBackground.Colors(Color1, Color2);
2283}
2284
2285Aspect_GradientBackground V3d_View::GradientBackground() const {
2286 return MyGradientBackground;
2287}
2288
2289Standard_Real V3d_View::Scale()const {
2290 Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
2291 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
2292 Standard_Real S = 0. ;
2293
2294 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2295 Dxv = Umax - Umin ;
2296 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2297 if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
2298 return S ;
2299}
2300
2301void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const {
2302 MyViewOrientation.AxialScale( Sx, Sy, Sz );
2303}
2304
2305void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const {
2306
2307 Standard_Real Umin,Vmin,Umax,Vmax ;
2308
2309 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2310 Xc = (Umin + Umax)/2. ;
2311 Yc = (Vmin + Vmax)/2. ;
2312}
2313
2314void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const {
2315
2316 Standard_Real Umin,Vmin,Umax,Vmax ;
2317
2318 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2319 Width = Umax - Umin ;
2320 Height = Vmax - Vmin ;
2321}
2322
2323Standard_Real V3d_View::ZSize() const {
2324
2325 Standard_Real Wmin,Wmax,Depth ;
2326
2327 Wmax = MyViewMapping.FrontPlaneDistance() ;
2328 Wmin = MyViewMapping.BackPlaneDistance() ;
2329 Depth = 2. * Max(Wmin,Wmax) ;
2330 return (Depth) ;
2331}
2332
2333Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
2334
2335 Standard_Real Wmin,Wmax,U,V,W ;
2336 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2337 // CAL 6/11/98
2338 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2339
2340 if( Nstruct ) {
2341 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2342 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
2343 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
2344 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2345 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2346 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2347 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2348 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2349 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2350 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2351 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2352 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2353 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2354 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2355 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2356 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2357 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2358 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2359 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2360 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2361 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2362 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2363 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2364 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2365 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2366 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2367 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2368 }
2369 return Nstruct ;
2370}
2371
2372Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const {
2373 // CAL 6/11/98
2374 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2375 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2376
2377 if( Nstruct ) {
2378 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2379 }
2380 return Nstruct ;
2381}
2382
2383Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2384
2385 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
2386 Standard_Real Umin,Vmin,Umax,Vmax ;
2387 Standard_Integer Nstruct,Npoint ;
2388 Graphic3d_MapOfStructure MySetOfStructures;
2389
2390 MyView->DisplayedStructures (MySetOfStructures);
2391 Nstruct = MySetOfStructures.Extent() ;
2392
2393 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
2394
2395 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2396 Npoint = 0 ; X = Y = Z = 0. ;
2397 for( ; MyIterator.More(); MyIterator.Next()) {
2398 if (!(MyIterator.Key())->IsEmpty()) {
2399 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
2400 Xmax,Ymax,Zmax) ;
2401
2402 Standard_Real LIM = ShortRealLast() -1.;
2403 if (! (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2404 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM )) {
2405
2406 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2407 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2408 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmin ;
2409 }
2410 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2411 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2412 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmin ;
2413 }
2414 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2415 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2416 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmin ;
2417 }
2418 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2419 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2420 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmin ;
2421 }
2422 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2423 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2424 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmax ;
2425 }
2426 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2427 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2428 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmax ;
2429 }
2430 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2431 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2432 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmax ;
2433 }
2434 MyView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
2435 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2436 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmax ;
2437 }
2438 }
2439 }
2440 }
2441 if( Npoint > 0 ) {
2442 X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
2443 }
2444
2445 return Nstruct ;
2446}
2447
2448void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2449 Graphic3d_Vertex Prp ;
2450 Graphic3d_Vector Vpn ;
2451 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
2452
2453 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
2454 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
2455 Prp = MyViewMapping.ProjectionReferencePoint() ;
2456 Prp.Coord(Xrp,Yrp,Zrp) ;
2457 Vpn = MyViewOrientation.ViewReferencePlane() ;
2458 Vpn.Coord(Xpn,Ypn,Zpn) ;
2459 X = Zrp*Xpn + Xat; Y = Zrp*Ypn + Yat; Z = Zrp*Zpn + Zat;
2460}
2461
2462void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const {
2463
2464 Graphic3d_Vertex PRP,VRPoint;
2465 Graphic3d_Vector VRPlane;
2466 Standard_Real FPD,Xprp,Yprp,Zprp;
2467 Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp;
2468
2469 if ( MyType == V3d_PERSPECTIVE ) {
2470 PRP = MyViewMapping.ProjectionReferencePoint() ;
2471 FPD = MyViewMapping.FrontPlaneDistance();
2472 PRP.Coord(Xprp,Yprp,Zprp);
2473 VRPoint = MyViewOrientation.ViewReferencePoint();
2474 VRPoint.Coord(Xvrp,Yvrp,Zvrp);
2475 VRPlane = MyViewOrientation.ViewReferencePlane();
2476 VRPlane.Coord(DXvrp,DYvrp,DZvrp);
2477 X = (FPD + Zprp) * DXvrp + Xvrp;
2478 Y = (FPD + Zprp) * DYvrp + Yvrp;
2479 Z = (FPD + Zprp) * DZvrp + Zvrp;
2480 }
2481 else Eye(X,Y,Z);
2482}
2483
2484void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, const Standard_Integer Ypix, Standard_Real& XP, Standard_Real& YP, Standard_Real& ZP, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ) const {
2485
2486 Standard_Real Xo,Yo,Zo;
2487
2488 Convert(Xpix,Ypix,XP,YP,ZP);
2489 if ( MyType == V3d_PERSPECTIVE ) {
2490 FocalReferencePoint(Xo,Yo,Zo);
2491 VX = Xo - XP;
2492 VY = Yo - YP;
2493 VZ = Zo - ZP;
2494 }
2495 else {
2496 Proj(VX,VY,VZ);
2497 }
2498}
2499
2500
2501Standard_Real V3d_View::Depth() const {
2502 Graphic3d_Vertex Prp ;
2503 Standard_Real Xrp,Yrp,Zrp ;
2504
2505 Prp = MyViewMapping.ProjectionReferencePoint() ;
2506 Prp.Coord(Xrp,Yrp,Zrp) ;
2507 return Zrp ;
2508}
2509
2510void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const {
2511 Graphic3d_Vector Vpn ;
2512
2513 Vpn = MyViewOrientation.ViewReferencePlane() ;
2514 Vpn.Coord(Dx,Dy,Dz) ;
2515}
2516
2517void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2518 Graphic3d_Vertex Vrp ;
2519
2520 Vrp = MyViewOrientation.ViewReferencePoint() ;
2521 Vrp.Coord(X,Y,Z) ;
2522}
2523
2524void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const {
2525 Graphic3d_Vector Vup ;
2526
2527 Vup = MyViewOrientation.ViewReferenceUp() ;
2528 Vup.Coord(Vx,Vy,Vz) ;
2529}
2530
2531Standard_Real V3d_View::Twist()const {
2532 Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ;
2533 Standard_Real pvx,pvy,pvz,pvn,sca,angle ;
2534 Graphic3d_Vector Vpn,Vup,Xaxis,Yaxis,Zaxis ;
2535 Standard_Boolean TheStatus ;
2536
2537 Vpn = MyViewOrientation.ViewReferencePlane() ;
2538 Vpn.Coord(Xpn,Ypn,Zpn) ;
2539 Vup.SetCoord(0.,0.,1.) ;
2540 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2541 if( !TheStatus ) {
2542 Vup.SetCoord(0.,1.,0.) ;
2543 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2544 }
2545 if( !TheStatus ) {
2546 Vup.SetCoord(1.,0.,0.) ;
2547 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2548 }
2549 Yaxis.Coord(X0,Y0,Z0) ;
2550 Vup = MyViewOrientation.ViewReferenceUp() ;
2551 Vup.Coord(Xup,Yup,Zup) ;
2552 /* Compute Cross Vector From Up & Origin */
2553 pvx = Y0*Zup - Z0*Yup ;
2554 pvy = Z0*Xup - X0*Zup ;
2555 pvz = X0*Yup - Y0*Xup ;
2556 pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
2557 sca = X0*Xup + Y0*Yup + Z0*Zup ;
2558 /* Compute Angle */
2559 angle = Sqrt(pvn) ;
2560 if( angle > 1. ) angle = 1. ;
2561 else if( angle < -1. ) angle = -1. ;
2562 angle = asin(angle) ;
2563 if( sca < 0. ) angle = Standard_PI - angle ;
2564 if( angle > 0. && angle < Standard_PI ) {
2565 sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
2566 if( sca < 0. ) angle = DEUXPI - angle ;
2567 }
2568 return angle ;
2569}
2570
2571V3d_TypeOfShadingModel V3d_View::ShadingModel()const {
2572 V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
2573 return SM ;
2574}
2575
2576V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail()const {
2577 V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
2578 return SM ;
2579}
2580
2581
2582Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const {
2583 Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
2584 return SM ;
2585}
2586
2587V3d_TypeOfVisualization V3d_View::Visualization()const {
2588 V3d_TypeOfVisualization V =
2589 (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
2590 return V ;
2591}
2592
2593Standard_Boolean V3d_View::Antialiasing()const {
2594 Standard_Boolean A = MyViewContext.AliasingIsOn() ;
2595 return A ;
2596}
2597
2598Handle(V3d_Viewer) V3d_View::Viewer() const {
2599 return MyViewer ;
2600}
2601
2602Standard_Boolean V3d_View::IfWindow() const {
2603 Standard_Boolean TheStatus = MyView->IsDefined() ;
2604 return TheStatus ;
2605}
2606
2607Handle(Aspect_Window) V3d_View::Window() const {
2608 return MyWindow;
2609}
2610
2611V3d_TypeOfView V3d_View::Type() const {
2612
2613 return (MyType) ;
2614}
2615
2616void V3d_View::SetFocale( const Standard_Real focale ) {
2617
2618 Standard_TypeMismatch_Raise_if (MyType != V3d_PERSPECTIVE,
2619 "the view is not a perspective view");
2620 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2621 Graphic3d_Vertex Prp ;
2622 Prp = MyViewMapping.ProjectionReferencePoint() ;
2623 Prp.Coord(Xrp,Yrp,Zrp) ;
2624 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2625 ViewPlane = Zrp - focale ;
2626 } else {
2627 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2628 ViewPlane = FrontPlane + Zrp - focale ;
2629 }
2630 MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
2631 MyView->SetViewMapping(MyViewMapping) ;
2632
2633 ImmediateUpdate();
2634}
2635
2636Standard_Real V3d_View::Focale( ) const {
2637 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2638 Standard_Real focale = 0.0 ;
2639 Graphic3d_Vertex Prp ;
2640
2641 if( MyType == V3d_PERSPECTIVE ) {
2642 Prp = MyViewMapping.ProjectionReferencePoint() ;
2643 Prp.Coord(Xrp,Yrp,Zrp) ;
2644 ViewPlane = MyViewMapping.ViewPlaneDistance() ;
2645 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2646 focale = Zrp - ViewPlane ;
2647 } else {
2648 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2649 focale = FrontPlane + Zrp - ViewPlane ;
2650 }
2651 }
2652 return (focale) ;
2653}
2654
2655void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right,
2656 const Standard_Real Bottom, const Standard_Real Top,
2657 const Standard_Real ZNear, const Standard_Real ZFar)
2658{
2659 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
2660
2661 Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
2662
2663 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2664 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2665 Zrp = ZNear;
2666
2667 Standard_Real size = (ZFar - ZNear) / 2.;
2668
2669 MyViewMapping.SetFrontPlaneDistance(size);
2670 MyViewMapping.SetBackPlaneDistance(-size);
2671
2672 // keep view plane at front plane distance
2673 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
2674
2675 // set window limits
2676 Umin = Left; Umax = Right;
2677 Vmin = Bottom; Vmax = Top;
2678 MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
2679
2680 // Update window center
2681 if ( MyType == V3d_PERSPECTIVE ) {
2682 Xrp = Yrp = 0.0;
2683 }
2684 else {
2685 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
2686 }
2687 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
2688 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2689
2690 MyView->SetViewMapping(MyViewMapping) ;
2691 // SetZSize(0.);
2692 ImmediateUpdate();
2693}
2694
2695Handle(Visual3d_View) V3d_View::View() const
2696{
2697 return MyView ;
2698}
2699
2700Visual3d_ViewMapping V3d_View::ViewMapping() const
2701{
2702 return MyViewMapping;
2703}
2704
2705Visual3d_ViewOrientation V3d_View::ViewOrientation() const
2706{
2707 return MyViewOrientation;
2708}
2709
2710Standard_Boolean V3d_View::ScreenAxis( const Graphic3d_Vector &Vpn, const Graphic3d_Vector &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe) {
2711 Standard_Real Xpn,Ypn,Zpn,Xup,Yup,Zup ;
2712 Standard_Real dx1,dy1,dz1,dx2,dy2,dz2,xx,yy,zz ;
2713
2714 Vpn.Coord(Xpn,Ypn,Zpn) ;
2715 Vup.Coord(Xup,Yup,Zup) ;
2716 xx = Yup*Zpn - Zup*Ypn ;
2717 yy = Zup*Xpn - Xup*Zpn ;
2718 zz = Xup*Ypn - Yup*Xpn ;
2719 Xaxe.SetCoord(xx,yy,zz) ;
2720 if( Xaxe.LengthZero() ) return Standard_False;
2721 Xaxe.Normalize() ; Xaxe.Coord(dx1,dy1,dz1) ;
2722 xx = Ypn*dz1 - Zpn*dy1 ;
2723 yy = Zpn*dx1 - Xpn*dz1 ;
2724 zz = Xpn*dy1 - Ypn*dx1 ;
2725 Yaxe.SetCoord(xx,yy,zz) ;
2726 if( Yaxe.LengthZero() ) return Standard_False;
2727 Yaxe.Normalize() ; Yaxe.Coord(dx2,dy2,dz2) ;
2728 xx = dy1*dz2 - dz1*dy2 ;
2729 yy = dz1*dx2 - dx1*dz2 ;
2730 zz = dx1*dy2 - dy1*dx2 ;
2731 Zaxe.SetCoord(xx,yy,zz) ;
2732 if( Zaxe.LengthZero() ) return Standard_False;
2733 Zaxe.Normalize() ;
2734 return Standard_True ;
2735}
2736
2737void V3d_View::InitMatrix( TColStd_Array2OfReal& Matrix ) {
2738 Standard_Integer LR = Matrix.LowerRow() ;
2739 Standard_Integer UR = Matrix.UpperRow() ;
2740 Standard_Integer LC = Matrix.LowerCol() ;
2741 Standard_Integer UC = Matrix.UpperCol() ;
2742 Standard_Integer I,J ;
2743
2744 for( I=LR ; I<=UR ; I++ ) {
2745 for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
2746 }
2747 for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
2748}
2749
2750Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) {
2751
2752 Standard_Integer llr = Left.LowerRow ();
2753 Standard_Integer llc = Left.LowerCol ();
2754 Standard_Integer luc = Left.UpperCol ();
2755
2756 Standard_Integer rlr = Right.LowerRow ();
2757 Standard_Integer rur = Right.UpperRow ();
2758 Standard_Integer rlc = Right.LowerCol ();
2759
2760 Standard_Integer mlr = Matrix.LowerRow ();
2761 Standard_Integer mur = Matrix.UpperRow ();
2762 Standard_Integer mlc = Matrix.LowerCol ();
2763 Standard_Integer muc = Matrix.UpperCol ();
2764
2765 TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
2766
2767 InitMatrix (Result);
2768
2769 // Left et Right incompatibles
2770 if (luc - llc + 1 != rur - rlr + 1)
2771 return Standard_False;
2772
2773 Standard_Integer i, j, k;
2774
2775 Standard_Real Som;
2776 Standard_Integer I1 = llr;
2777
2778 for (i=mlr; i<=mur; i++) {
2779 Standard_Integer J2 = rlc;
2780 for (j=mlc; j<=muc; j++) {
2781 Som = 0.0;
2782 Standard_Integer J1 = llc;
2783 Standard_Integer I2 = rlr;
2784 for (k=llc; k<=luc; k++) {
2785 Som = Som + Left (I1, J1) * Right (I2, J2);
2786 J1++;
2787 I2++;
2788 }
2789 Result (i, j) = Som;
2790 J2++;
2791 }
2792 I1++;
2793 }
2794
2795 for (i=mlr; i<=mur; i++)
2796 for (j=mlc; j<=muc; j++)
2797 Matrix (i, j) = Result (i, j);
2798
2799 return Standard_True;
2800}
2801
2802/*----------------------------------------------------------------------*/
2803
2804void V3d_View::RotAxis( const Graphic3d_Vertex &Vrp, const Graphic3d_Vector &Axe, const Standard_Real angle, TColStd_Array2OfReal& Matrix ) {
2805 Standard_Real Xrp,Yrp,Zrp,Xaxe,Yaxe,Zaxe ;
2806 Standard_Real sina,cosa,cos1m,terms1,terms2,terms3 ;
2807 Standard_Real termc12,termc13,termc23,vcal ;
2808 TColStd_Array2OfReal Tmatrix(0,3,0,3) ;
2809 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
2810
2811 InitMatrix(Matrix) ;
2812 InitMatrix(Tmatrix) ;
2813
2814 Vrp.Coord(Xrp,Yrp,Zrp) ;
2815 Axe.Coord(Xaxe,Yaxe,Zaxe) ;
2816 /* translation of x,y,z */
2817 Tmatrix(0,3) = Xrp ; Tmatrix(1,3) = Yrp ; Tmatrix(2,3) = Zrp ;
2818 /* rotation around an axis */
2819 cosa = cos(angle); sina = sin(angle); cos1m = 1. - cosa ;
2820 termc12 = Xaxe * Yaxe * cos1m ;
2821 termc13 = Xaxe * Zaxe * cos1m ;
2822 termc23 = Yaxe * Zaxe * cos1m ;
2823 terms1 = Xaxe * sina ;
2824 terms2 = Yaxe * sina ;
2825 terms3 = Zaxe * sina ;
2826
2827 vcal = Xaxe * Xaxe ;
2828 Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
2829 Rmatrix(1,0) = termc12 + terms3 ;
2830 Rmatrix(2,0) = termc13 - terms2 ;
2831 Rmatrix(3,0) = 0. ;
2832 Rmatrix(0,1) = termc12 - terms3 ;
2833 vcal = Yaxe * Yaxe ;
2834 Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
2835 Rmatrix(2,1) = termc23 + terms1 ;
2836 Rmatrix(3,1) = 0. ;
2837 Rmatrix(0,2) = termc13 + terms2 ;
2838 Rmatrix(1,2) = termc23 - terms1 ;
2839 vcal = Zaxe * Zaxe ;
2840 Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
2841 Rmatrix(3,2) = 0. ;
2842 Rmatrix(0,3) = 0. ;
2843 Rmatrix(1,3) = 0. ;
2844 Rmatrix(2,3) = 0. ;
2845 Rmatrix(3,3) = 1. ;
2846 /* produced by two matrices */
2847 Multiply(Tmatrix, Rmatrix, Matrix);
2848 /* translation invert */
2849 Tmatrix(0,3) = -Xrp;
2850 Tmatrix(1,3) = -Yrp;
2851 Tmatrix(2,3) = -Zrp;
2852 /* product final */
2853 Multiply(Matrix, Tmatrix, Matrix);
2854}
2855
2856/*----------------------------------------------------------------------*/
2857
2858Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix ) {
2859 Graphic3d_Vertex PP ;
2860 Standard_Real X,Y,Z,XX,YY,ZZ ;
2861
2862 // CAL. S3892
2863 Standard_Integer lr, ur, lc, uc;
2864 lr = Matrix.LowerRow ();
2865 ur = Matrix.UpperRow ();
2866 lc = Matrix.LowerCol ();
2867 uc = Matrix.UpperCol ();
2868 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2869 P.Coord(X,Y,Z) ;
2870 PP.SetCoord(X,Y,Z) ;
2871 return PP ;
2872 }
2873 P.Coord(X,Y,Z) ;
2874 XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+
2875 Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ;
2876
2877 YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) +
2878 Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ;
2879
2880 ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) +
2881 Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ;
2882 PP.SetCoord(XX,YY,ZZ) ;
2883 return PP ;
2884}
2885
2886Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix ) {
2887 Graphic3d_Vector VV ;
2888 Standard_Real X,Y,Z,XX,YY,ZZ ;
2889
2890 // CAL. S3892
2891 Standard_Integer lr, ur, lc, uc;
2892 lr = Matrix.LowerRow ();
2893 ur = Matrix.UpperRow ();
2894 lc = Matrix.LowerCol ();
2895 uc = Matrix.UpperCol ();
2896 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2897 V.Coord(X,Y,Z) ;
2898 VV.SetCoord(X,Y,Z) ;
2899 return VV ;
2900 }
2901 V.Coord(X,Y,Z) ;
2902 XX = X*Matrix(lr,lc)+Y*Matrix(lr,lc+1)+Z*Matrix(lr,lc+2) ;
2903 YY = X*Matrix(lr+1,lc)+Y*Matrix(lr+1,lc+1)+Z*Matrix(lr+1,lc+2) ;
2904 ZZ = X*Matrix(lr+2,lc)+Y*Matrix(lr+2,lc+1)+Z*Matrix(lr+2,lc+2) ;
2905 VV.SetCoord(XX,YY,ZZ) ; VV.Normalize() ;
2906 return VV ;
2907}
2908
2909
2910void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) {
2911
2912 Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
2913
2914}
2915
2916void V3d_View::Zoom (const Standard_Integer X1,
2917 const Standard_Integer Y1,
2918 const Standard_Integer X2,
2919 const Standard_Integer Y2)
2920{
2921
2922 Standard_Real dx = Standard_Real (X2-X1);
2923 Standard_Real dy = Standard_Real (Y2-Y1);
2924 if ( dx != 0. || dy != 0. ) {
2925 Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1;
2926 dzoom = (dx > 0) ? dzoom : 1./dzoom;
2927 SetZoom(dzoom, Standard_True);
2928 }
2929}
2930
2931void V3d_View::Zoom (const Standard_Integer X1,
2932 const Standard_Integer Y1)
2933{
2934 Standard_Real x,y;
2935 Center(x,y);
2936 Standard_Integer ix,iy;
2937 Convert(x,y,ix,iy);
2938 Zoom(ix,iy,X1,Y1);
2939}
2940
2941// Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
2942void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
2943{
2944 MyZoomAtPointX = xpix;
2945 MyZoomAtPointY = ypix;
2946}
2947
2948// Zooms the model at a pixel defined by the method StartZoomAtPoint().
2949void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
2950 const Standard_Integer mouseStartY,
2951 const Standard_Integer mouseEndX,
2952 const Standard_Integer mouseEndY)
2953{
2954 Standard_Boolean update;
2955 V3d_Coordinate X0, Y0, XS, YS;
2956
2957 // Forbid any update.
2958 update = SetImmediateUpdate(Standard_False);
2959
2960 // Get center point
2961 Center(X0, Y0);
2962
2963 // Pan the point to the center of window.
2964 Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
2965 Panning(X0-XS, Y0-YS);
2966
2967 // Zoom
2968 Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
2969
2970 Standard_Real dzoom = fabs(d) / 100.0 + 1.0;
2971 dzoom = (d > 0) ? dzoom : 1.0 / dzoom;
2972 Viewer_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
2973
2974 Standard_Real Umin,Vmin,Umax,Vmax;
2975 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
2976
2977 MyXwindowCenter = (Umin + Umax) / 2.0;
2978 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2979 MyWindowWidth = Abs(Umax - Umin);
2980 MyWindowHeight = Abs(Vmax - Vmin);
2981
2982 // Ensure that zoom will not be too small or too big.
2983 Standard_Real coef = dzoom;
2984 if (MyWindowWidth < coef * Precision::Confusion())
2985 coef = MyWindowWidth / Precision::Confusion();
2986 else if (MyWindowWidth > coef * 1e12)
2987 coef = MyWindowWidth / 1e12;
2988 if (MyWindowHeight < coef * Precision::Confusion())
2989 coef = MyWindowHeight / Precision::Confusion();
2990 else if (MyWindowHeight > coef * 1e12)
2991 coef = MyWindowHeight / 1e12;
2992
2993 Standard_Real Dxv = MyWindowWidth / coef;
2994 Standard_Real Dyv = MyWindowHeight / coef;
2995
2996 Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
2997 Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
2998
2999 // Pan the point backwards.
3000 Dxv = (XS - X0) / coef;
3001 Dyv = (YS - Y0) / coef;
3002
3003 MyXwindowCenter = (Umin + Umax) / 2.0;
3004 MyYwindowCenter = (Vmin + Vmax) / 2.0;
3005 MyWindowWidth = Abs(Umax - Umin);
3006 MyWindowHeight = Abs(Vmax - Vmin);
3007
3008 Standard_Real Xrp,Yrp,Zrp;
3009 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
3010 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
3011
3012 Xrp = MyXwindowCenter - Dxv;
3013 Yrp = MyYwindowCenter - Dyv;
3014
3015 Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
3016 Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
3017
3018 // Set new reference plane coordintes of the window.
3019 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
3020 if (MyType != V3d_PERSPECTIVE)
3021 {
3022 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
3023 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3024 }
3025 MyView->SetViewMapping(MyViewMapping);
3026
3027 // Update the view.
3028 SetImmediateUpdate(update);
3029 ImmediateUpdate();
3030}
3031
3032void V3d_View::AxialScale (const Standard_Integer Dx,
3033 const Standard_Integer Dy,
3034 const V3d_TypeOfAxe Axis)
3035{
3036 if( Dx != 0. || Dy != 0. ) {
3037 Standard_Real Sx, Sy, Sz;
3038 AxialScale( Sx, Sy, Sz );
3039 Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
3040 dscale = (Dx > 0) ? dscale : 1./dscale;
3041 if( Axis == V3d_X ) Sx = dscale;
3042 if( Axis == V3d_Y ) Sy = dscale;
3043 if( Axis == V3d_Z ) Sz = dscale;
3044 SetAxialScale( Sx, Sy, Sz );
3045 }
3046}
3047
3048void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
3049 const Standard_Real Xmin,
3050 const Standard_Real Ymin,
3051 const Standard_Real Xmax,
3052 const Standard_Real Ymax)
3053{
3054
3055 Standard_Real Umin,Umax,Vmin,Vmax,Xrp,Yrp,Zrp ;
3056 Standard_Real DxvOld,DyvOld,DxvNew,DyvNew,RapOld,RapNew ;
3057 Standard_Integer Xpixel,Ypixel;
3058 //Standard_Integer Xleft,Yup,Xright,Ylow ;
3059
3060 Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
3061 "V3d_View::FitAll, Window Size is NULL");
3062
3063 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
3064 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
3065 aWindow->Size(Xpixel,Ypixel);
3066 DxvOld = Xpixel; DyvOld = Ypixel;
3067
3068 if( (DxvOld == 0.) || (DyvOld == 0.) ) return ;
3069 RapOld = DxvOld/DyvOld ;
3070 DxvNew = Abs(Xmax - Xmin) ; DyvNew = Abs(Ymax - Ymin) ;
3071 RapNew = DxvNew/DyvNew ;
3072 if( RapNew >= RapOld ) {
3073 DyvNew = DxvNew/RapOld ;
3074 } else {
3075 DxvNew = DyvNew*RapOld ;
3076 }
3077 Xrp = (Xmin + Xmax)/2. ; Yrp = (Ymin + Ymax)/2. ;
3078 Umin = Xrp - DxvNew/2. ; Vmin = Yrp - DyvNew/2. ;
3079 Umax = Xrp + DxvNew/2. ; Vmax = Yrp + DyvNew/2. ;
3080 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
3081 if( MyType != V3d_PERSPECTIVE ) {
3082 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
3083 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3084 }
3085 MyView->SetViewMapping(MyViewMapping) ;
3086#ifdef IMP020300
3087 Update();
3088#else
3089 ImmediateUpdate();
3090#endif
3091}
3092
3093#ifdef IMP250900
3094static Standard_Boolean zRotation = Standard_False;
3095#endif
3096void V3d_View::StartRotation(const Standard_Integer X,
3097 const Standard_Integer Y,
3098 const Quantity_Ratio zRotationThreshold)
3099{
3100
3101 sx = X; sy = Y;
3102 Standard_Real x,y;
3103 Size(x,y);
3104 rx = Standard_Real(Convert(x));
3105 ry = Standard_Real(Convert(y));
3106 Gravity(gx,gy,gz);
3107 Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
3108#ifdef IMP250900
3109 zRotation = Standard_False;
3110 if( zRotationThreshold > 0. ) {
3111 Standard_Real dx = Abs(sx - rx/2.);
3112 Standard_Real dy = Abs(sy - ry/2.);
3113 // if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True;
3114 Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
3115 if( dx > dd || dy > dd ) zRotation = Standard_True;
3116 }
3117#endif
3118
3119}
3120
3121void V3d_View::Rotation(const Standard_Integer X,
3122 const Standard_Integer Y)
3123{
3124
3125#ifdef IMP210600
3126 if( rx == 0. || ry == 0. ) {
3127 StartRotation(X,Y);
3128 return;
3129 }
3130#endif
3131#ifdef IMP250900
3132 Standard_Real dx=0.,dy=0.,dz=0.;
3133 if( zRotation ) {
3134 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
3135 atan2(sx-rx/2.,ry/2.-sy);
3136 } else {
3137 dx = (Standard_Real(X) - sx) * Standard_PI/rx;
3138 dy = (sy - Standard_Real(Y)) * Standard_PI/ry;
3139 }
3140 Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
3141#else
3142 Standard_Real dx = (Standard_Real(X - sx)) * Standard_PI;
3143 Standard_Real dy = (Standard_Real(sy - Y)) * Standard_PI;
3144 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3145#endif
3146#ifdef IMP020300
3147 if( !myImmediateUpdate ) Update();
3148#else
3149 myImmediateUpdate = Standard_False;
3150 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3151 ZFitAll (Zmargin); //Don't do that, perf improvment
3152 myImmediateUpdate = Standard_True;
3153 ImmediateUpdate();
3154#endif
3155}
3156
3157void V3d_View::SetAnimationModeOn () {
3158#ifdef G003
3159 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3160 if( ComputedMode() ) { // Deactivates computed mode during animation
3161 MyAnimationFlags |= V3d_FLAG_COMPUTATION;
3162 Standard_Boolean immediatUpdate = myImmediateUpdate;
3163 myImmediateUpdate = Standard_False;
3164 SetComputedMode(Standard_False);
3165 myImmediateUpdate = immediatUpdate;
3166 }
3167 MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
3168 }
3169#else
3170 MyView->SetAnimationModeOn();
3171#endif
3172}
3173
3174void V3d_View::SetAnimationModeOff () {
3175#ifdef G003
3176 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3177 MyView -> SetAnimationModeOff ();
3178 if ( MyAnimationFlags & V3d_FLAG_COMPUTATION ) {
3179 // Reactivates computed mode after animation
3180 MyAnimationFlags &= ~V3d_FLAG_COMPUTATION;
3181 SetComputedMode(Standard_True);
3182 } else if( MyAnimationFlags & V3d_FLAG_DEGENERATION ) {
3183 Update();
3184 }
3185 }
3186#else
3187 MyView->SetAnimationModeOff();
3188#endif
3189}
3190
3191Standard_Boolean V3d_View::AnimationModeIsOn () const {
3192 return MyView->AnimationModeIsOn();
3193}
3194
3195#ifdef G003
3196void V3d_View :: SetAnimationMode
3197(
3198 const Standard_Boolean anAnimationFlag,
3199 const Standard_Boolean aDegenerationFlag
3200 )
3201{
3202
3203 if ( anAnimationFlag )
3204 MyAnimationFlags |= V3d_FLAG_ANIMATION;
3205 else
3206 MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
3207
3208 if ( aDegenerationFlag )
3209 MyAnimationFlags |= V3d_FLAG_DEGENERATION;
3210 else
3211 MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
3212
3213} // end V3d_View :: SetAnimationMode
3214
3215Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
3216{
3217
3218 isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
3219 return MyAnimationFlags & V3d_FLAG_ANIMATION;
3220}
3221#endif
3222
3223void V3d_View::SetDegenerateModeOn() {
3224#ifdef G003
3225 SetComputedMode(Standard_False);
3226#else
3227 MyView->SetDegenerateModeOn();
3228 ImmediateUpdate();
3229#endif
3230}
3231
3232void V3d_View::SetDegenerateModeOff()
3233{
3234#ifdef G003
3235 SetComputedMode(Standard_True);
3236#else
3237 if(myComputedMode) {
3238 MyView->SetDegenerateModeOff();
3239 ImmediateUpdate();
3240 }
3241#endif
3242}
3243
3244Standard_Boolean V3d_View::DegenerateModeIsOn() const
3245{
3246#ifdef G003
3247 return !ComputedMode();
3248#else
3249 return MyView->DegenerateModeIsOn();
3250#endif
3251}
3252
3253#ifdef G003
3254void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3255{
3256
3257 if( aMode ) {
3258 if( myComputedMode ) {
3259 MyView -> SetComputedMode ( Standard_True );
3260 Update ();
3261 }
3262 } else {
3263 MyView -> SetComputedMode ( Standard_False );
3264 Update ();
3265 }
3266
3267} // end V3d_View :: SetComputedMode
3268
3269Standard_Boolean V3d_View :: ComputedMode () const
3270{
3271
3272 return MyView -> ComputedMode ();
3273
3274} // end V3d_View :: ComputedMode
3275
3276void V3d_View :: SetBackFacingModel (
3277 const V3d_TypeOfBackfacingModel aModel)
3278{
3279
3280 MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
3281 Redraw();
3282} // end V3d_View :: SetBackFacingModel
3283
3284V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const {
3285
3286 return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
3287
3288} // end V3d_View :: BackFacingModel
3289#endif
3290
3291Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const {
3292 return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
3293}
3294
3295void V3d_View::TransientManagerClearDraw() const {
3296 Visual3d_TransientManager::ClearDraw(MyView);
3297}
3298
3299Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const {
3300 return Visual3d_TransientManager::BeginAddDraw(MyView);
3301}
3302
3303void V3d_View::Init() {
3304 myComputedMode = MyViewer->ComputedMode();
3305#ifdef G003
3306 if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
3307 SetComputedMode(Standard_False);
3308 }
3309#else
3310 if(!myComputedMode)
3311 MyView->SetDegenerateModeOn();
3312 else
3313 if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
3314#endif
3315
3316#ifdef IMP240100
3317 OSD_Environment env_walkthrow("CSF_WALKTHROUGH");
3318 env_walkthrow.SetName( "CSF_WALKTHROUGH" );
3319 if ( env_walkthrow.Value () != "" ) MyProjModel = V3d_TPM_WALKTHROUGH;
3320 else MyProjModel = V3d_TPM_SCREEN;
3321#endif
3322
3323}
3324
3325void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) {
3326 MyPlotter = aPlotter;
3327}
3328
3329void V3d_View::Plot()
3330{
3331
3332 Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
3333
3334 MyView->Plot(MyPlotter);
3335}
3336
3337Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
3338{
3339
3340 FullTimer.Reset ();
3341 FullTimer.Start ();
3342
3343 if (AnimationMode) MyView->SetAnimationModeOn();
3344 Standard_Integer i;
3345 Standard_Real delta = 0.01;
3346 Standard_Real xangle, yangle;
3347 xangle = yangle = delta*int(NbImages/3);
3348
3349 Rotate (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_True);
3350 for (i=1; i<=int(NbImages/3); i++)
3351 Rotate (delta*i, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_False);
3352 for (i=1; i<=int(NbImages/3); i++)
3353 Rotate (xangle, delta*i, 0.0, 0.0, 0.0, 0.0, Standard_False);
3354 for (i=1; i<=int(NbImages/3); i++)
3355 Rotate (xangle, yangle, delta*i, 0.0, 0.0, 0.0, Standard_False);
3356 if (AnimationMode) MyView->SetAnimationModeOff();
3357
3358 FullTimer.Stop ();
3359 cout << "For " << NbImages << " Images : " << endl;
3360 FullTimer.Show (cout);
3361 cout << flush;
3362
3363 Standard_Real Seconds, CPUtime;
3364 Standard_Integer Minutes, Hours;
3365
3366 FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
3367 cout << "Result " << (AnimationMode ? "with " : "without ")
3368 << "display list : " << NbImages/CPUtime << " images/Second."
3369 << endl;
3370
3371 return NbImages/CPUtime;
3372
3373}
3374
3375#define SCREENCOPY_FILENAME "screencopy3d.gif"
3376void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
3377 const Standard_Boolean fWhiteBackground,
3378 const Quantity_Factor aPlotScale)
3379{
3380 TCollection_AsciiString aFileToDump;
3381 Handle(Aspect_WindowDriver) aWindowDriver =
3382#ifdef WNT
3383 new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
3384#else
3385 new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
3386#endif // WNT
3387 Quantity_Factor aScale;
3388 Quantity_Length thePixel;
3389 Quantity_Parameter theWWidth, theWHeight;
3390 Quantity_Parameter thePWidth, thePHeight;
3391 aPlotterDriver -> WorkSpace (thePWidth, thePHeight);
3392 aWindowDriver -> WorkSpace (theWWidth, theWHeight);
3393 thePixel = aWindowDriver -> Convert (1);
3394
3395 if (theWWidth * theWHeight != 0.) {
3396 if (aPlotScale == 0.) {
3397 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3398 } else {
3399 // To be changed !!!!!!!!!!!!!!!
3400 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3401 }
3402
3403 // Set default maps (color, type, etc) for plotter driver
3404 aPlotterDriver -> SetColorMap ( new Aspect_GenericColorMap () );
3405 aPlotterDriver -> SetTypeMap ( new Aspect_TypeMap () );
3406 aPlotterDriver -> SetWidthMap ( new Aspect_WidthMap () );
3407 aPlotterDriver -> SetFontMap ( new Aspect_FontMap () );
3408 aPlotterDriver -> SetMarkMap ( new Aspect_MarkMap () );
3409
3410 // Set backgroung to white, unihiglight if any
3411 Quantity_Parameter theRed, theGreen, theBlue;
3412 Handle(TColStd_HSequenceOfInteger) theFlags;
3413 Graphic3d_MapOfStructure theStructures;
3414 BackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3415 if (fWhiteBackground)
3416 SetBackgroundColor (Quantity_NOC_WHITE);
3417 MyView -> DisplayedStructures (theStructures);
3418 theFlags = new TColStd_HSequenceOfInteger ();
3419 Graphic3d_MapIteratorOfMapOfStructure Iterator (theStructures);
3420 while (Iterator.More ()) {
3421 Handle(Graphic3d_Structure) aStructure = Iterator.Key();
3422 if (aStructure -> IsHighlighted()) {
3423 theFlags -> Append (1);
3424 aStructure -> UnHighlight ();
3425 } else {
3426 theFlags -> Append (0);
3427 }
3428 Iterator.Next ();
3429 }
3430 Redraw ();
3431
3432 // Dump the view
3433 if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
3434 aFileToDump = aPlotterDriver->PlotFileName();
3435 } else {
3436 aFileToDump = aPlotterDriver->SpoolDirectory();
3437 aFileToDump += SCREENCOPY_FILENAME;
3438 }
3439 MyWindow -> Dump (aFileToDump.ToCString());
3440
3441 Standard_Integer theCurStruct = 1;
3442 Iterator = Graphic3d_MapIteratorOfMapOfStructure (theStructures);
3443 while (Iterator.More ()) {
3444 if (theFlags -> Value(theCurStruct))
3445 Iterator.Key() -> Highlight (Aspect_TOHM_COLOR);
3446 Iterator.Next ();
3447 theCurStruct++;
3448 }
3449 if (fWhiteBackground)
3450 SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3451 Redraw ();
3452
3453 // Draw imagefile by plotter driver
3454 aPlotterDriver -> SetPixelSize (thePixel);
3455 aPlotterDriver -> BeginDraw ();
3456 aPlotterDriver -> DrawImageFile (
3457 aFileToDump.ToCString(), (float)(thePWidth / 2.), (float)(thePHeight / 2.), aScale);
3458 aPlotterDriver -> EndDraw ();
3459 }
3460}
3461#undef SCREENCOPY_FILENAME
3462
3463#include <Aspect.hxx>
3464#include <Visual3d_Layer.hxx>
3465
3466////////////////////////////////////////////////////////////////
3467Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3468 const Image_TypeOfImage theBufferType)
3469{
3470 Standard_Integer aWinWidth, aWinHeight;
3471 MyWindow->Size (aWinWidth, aWinHeight);
3472
3473 Handle(Aspect_PixMap) aPixMap = ToPixMap (aWinWidth, aWinHeight, theBufferType);
3474 return !aPixMap.IsNull() && aPixMap->Dump (theFile);
3475}
3476
3477////////////////////////////////////////////////////////////////
3478Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3479 const Aspect_FormatOfSheetPaper theFormat,
3480 const Image_TypeOfImage theBufferType)
3481{
3482 Standard_Boolean isDone = Standard_False;
3483 // convert Aspect_FormatOfSheetPaper size to pixel ...
3484 Quantity_Length anSPWidth, anSPHeight;
3485 Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
3486
3487 // adjusting to the ratio width/height ...
3488 Quantity_Length aWinWidth, aWinHeight;
3489 MyWindow->MMSize (aWinWidth, aWinHeight);
3490 Standard_Integer aPixelWidth, aPixelHeight;
3491 MyWindow->Size (aPixelWidth, aPixelHeight);
3492
3493 Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
3494 aPixelWidth = Standard_Integer (aPixelWidth * aScale);
3495 aPixelHeight = Standard_Integer (aPixelHeight * aScale);
3496 {
3497 Handle(Aspect_PixMap) aBitmap = ToPixMap (aPixelWidth, aPixelHeight, theBufferType);
3498 Standard_Real aGammaValue = 1.0;
3499 OSD_Environment anEnvGamma ("CSF_GAMMA_CORRECTION");
3500 TCollection_AsciiString strGamma (anEnvGamma.Value());
3501 if (!strGamma.IsEmpty()) aGammaValue = strGamma.RealValue();
3502 isDone = !aBitmap.IsNull() && aBitmap->Dump (theFile, aGammaValue);
3503 }
3504 return isDone;
3505}
3506
3507////////////////////////////////////////////////////////////////
3508Handle(Image_PixMap) V3d_View::ToPixMap (const Standard_Integer theWidth,
3509 const Standard_Integer theHeight,
3510 const Image_TypeOfImage theBufferType,
3511 const Standard_Boolean theIsForceCentred)
3512{
3513 // always prefer hardware accelerated offscreen buffer
3514 Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
3515 Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
3516 Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
3517 Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
3518 if (aPrevFBOPtr != NULL)
3519 {
3520 MyView->FBOGetDimensions (aPrevFBOPtr,
3521 aPrevFBOVPSizeX, aPrevFBOVPSizeY,
3522 aPrevFBOSizeXMax, aPrevFBOSizeYMax);
3523 if (theWidth <= aPrevFBOSizeXMax && theHeight <= aPrevFBOSizeYMax)
3524 {
3525 MyView->FBOChangeViewport (aPrevFBOPtr, theWidth, theHeight);
3526 aFBOPtr = aPrevFBOPtr;
3527 }
3528 }
3529
3530 if (aFBOPtr == NULL)
3531 {
3532 // Try to create hardware accelerated buffer
3533 aFBOPtr = MyView->FBOCreate (theWidth, theHeight);
3534 }
3535 cView->ptrFBO = aFBOPtr;
3536
3537 // If hardware accelerated buffer - try to use onscreen buffer
3538 // Results may be bad!
3539 if (aFBOPtr == NULL)
3540 {
3541 // retrieve window sizes
3542 Standard_Integer aWinWidth, aWinHeight;
3543 MyWindow->Size (aWinWidth, aWinHeight);
3544
3545 // technically we can reduce existing viewport...
3546 // but currently allow only dumping the window itself
3547 if (theWidth != aWinWidth || theHeight != aWinHeight)
3548 {
3549 return Handle(Image_PixMap)();
3550 }
3551 }
3552
3553 //szv: save mapping
3554 Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
3555 Standard_Real Umin, Vmin, Umax, Vmax;
3556
3557 if (theIsForceCentred)
3558 {
3559 //szv: get mapping frame
3560 Standard_Real PUmin, PVmin, PUmax, PVmax;
3561 prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
3562
3563 //szv: calculate expansion
3564 Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
3565 Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
3566 Standard_Real newWidth = (oldHeight * theWidth) / theHeight;
3567 if (newWidth < oldWidth)
3568 {
3569 Standard_Real newHeight = (oldWidth * theHeight) / theWidth;
3570 // Expand height
3571 Standard_Real delta = 0.5 * (newHeight - oldHeight);
3572 Vmin = PVmin - delta;
3573 Vmax = PVmax + delta;
3574 }
3575 else
3576 {
3577 // Expand width
3578 Standard_Real delta = 0.5 * (newWidth - oldWidth);
3579 Umin = PUmin - delta;
3580 Umax = PUmax + delta;
3581 }
3582
3583 //szv: apply expanded mapping
3584 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
3585 MyView->SetViewMapping (MyViewMapping);
3586 }
3587
3588 //workround for rendering list of Over and Under Layers
3589 if (!MyLayerMgr.IsNull())
3590 {
3591 MyLayerMgr->Compute();
3592 }
3593 Redraw();
3594
3595 //szv: restore mapping
3596 MyViewMapping = prevMapping;
3597 MyView->SetViewMapping (prevMapping);
3598
3599 // allocate image buffer for dumping
3600 Image_CRawBufferData aRawBuffer;
3601 Handle(Image_PixMap) anImageBitmap = new Image_PixMap (theWidth, theHeight, theBufferType);
3602 anImageBitmap->AccessBuffer (aRawBuffer);
3603 if (!MyView->BufferDump (aRawBuffer))
3604 {
3605 // dump is failed!
3606 anImageBitmap = Handle(Image_PixMap)();
3607 }
3608
3609 // FBO now useless, free resources
3610 if (aFBOPtr != aPrevFBOPtr)
3611 {
3612 MyView->FBORelease (aFBOPtr);
3613 }
3614 else if (aPrevFBOPtr != NULL)
3615 {
3616 MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
3617 }
3618 cView->ptrFBO = aPrevFBOPtr;
3619 return anImageBitmap;
3620}