1 /***********************************************************************
7 HISTORIQUE DES MODIFICATIONS :
8 --------------------------------
9 00-09-92 : GG ; Creation.
10 02-10-96 : FMN ; Suppression appel Redraw sans MustBeResized()
11 05-06-97 : FMN ; Correction FitAll()
12 30-06-97 : GG ; Correction + Optimisation de Panning(...)
13 On fait la translation + le zoom en une seule
14 operation au lieu de 2 precedemment qui etait buggee.
15 09-07-97 : FMN ; Correction FitAll() sur le Ratio
16 16-07-97 : FMN ; Correction FitAll() sur le calcul de la Box
17 22-07-97 : FMN ; Ajout mode RetainMode pour le Transient
18 15-12-97 : FMN ; Ajout texture mapping
19 17-12-97 : FMN ; CTS19129 Correction FitAll() multiple
20 18-12-97 : FMN ; Ajout mode Ajout
21 24-12-97 : FMN ; Remplacement de math par MathGra
22 24-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window
23 31-12-97 : CAL ; Remplacement de MathGra par Array2OfReal
24 07-01-98 : CAL ; Ajout de la methode DoMapping.
25 07-01-98 : CAL ; Retrait de tous les "this->" inutiles
26 21-01-98 : CAL ; Remplacement des Window->Position () par Window->Size ()
27 27-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
28 12-02-98 : GG ; Reactivation du Redraw dans MustBeResized()
29 23-02-98 : FMN ; Remplacement PI par Standard_PI
30 25-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view
31 11-03-98 : STT ; S3558
32 19-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
34 08-04-98 : STT ; suppr. S3558
35 10-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef
36 13-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
37 ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
38 16-08-98 : CAL ; S3892. Ajout grilles 3d.
39 09-09-98 : CAL ; S3892. Generalisation de TrsPoint.
40 24-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
41 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
42 16-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
43 06-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
44 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
45 29-OCT-98 : DCB : Adding ScreenCopy () method.
46 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
47 10-11-99 : GG ; PRO19603 Add Redraw( area ) method
49 -> Don't increase too much the ZSize.
50 -> Initialize correctly the Z clipping and D cueing
52 IMP100701 : SZV ; Add ToPixMap() method
56 About FitAll() multiple. This probleme is caused by missing
57 precision of transformation matrices. If it is supposed that
58 projection is made in the plane (U,V), there is a difference
59 after several Zoom - compared to the exact value (cf ZoomX).
60 Don't forget that the matrices work in float and not in double.
61 To solve the problem (for lack of a better solution) I make 2 passes.
63 ************************************************************************/
65 #define GER61351 //GG_15/12/99 Add SetBackgroundColor()
66 // and BackgroundColor() methods
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.
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
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.
96 #define IMP210200 //GG Add Transparency() method
98 #define IMP250200 //GG With SetDepth() method, when the requested
100 // move the view ref point and the eye,instead
103 #define IMP020300 //GG Don't use ZFitAll in during Rotation
104 // for perf improvment
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.
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)
118 #define BUC60952 //GG Enable to rotate around the view axis
119 // and the required view point
121 #define RIC120302 //GG Add a NEW SetWindow method which enable
122 // to connect a graphic widget and context to OGL.
124 #define IMP260302 //GG To avoid conflicting in Window destructor
125 // nullify this handle in Remove method
127 #define OCC280 //SAV fix for FitAll problem in the perspective view.
129 #define OCC1188 //SAV Added methods to set background image
131 /*----------------------------------------------------------------------*/
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>
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>
155 #include <Graphic3d_AspectMarker3d.hxx>
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>
166 # include <WNT_WDriver.hxx>
168 # include <Xw_Driver.hxx>
172 # define V3d_FLAG_ANIMATION 0x00000001
173 # define V3d_FLAG_DEGENERATION 0x00000002
174 # define V3d_FLAG_COMPUTATION 0x00000004
178 #include <OSD_Timer.hxx>
179 static OSD_Timer FullTimer;
182 #include <OSD_Environment.hxx>
184 /*----------------------------------------------------------------------*/
190 #define DEUXPI (2. * M_PI)
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
197 /*----------------------------------------------------------------------*/
199 * Local data definitions
203 static Standard_Real MyXwindowCenter ;
204 static Standard_Real MyYwindowCenter ;
205 static Standard_Real MyWindowWidth ;
206 static Standard_Real MyWindowHeight ;
210 static Graphic3d_Vector MyXscreenAxis ;
211 static Graphic3d_Vector MyYscreenAxis ;
212 static Graphic3d_Vector MyZscreenAxis ;
213 static Graphic3d_Vector MyViewReferencePlane ;
214 static Graphic3d_Vector MyViewReferenceUp ;
215 static Graphic3d_Vector MyViewAxis ;
216 static Graphic3d_Vertex MyViewReferencePoint ;
217 static Graphic3d_Vertex MyGravityReferencePoint ;
218 static Graphic3d_Vertex MyProjReferencePoint ;
220 static Graphic3d_Vector& _MyXscreenAxis() {
221 static Graphic3d_Vector MyXscreenAxis;
222 return MyXscreenAxis;
224 #define MyXscreenAxis _MyXscreenAxis()
226 static Graphic3d_Vector& _MyYscreenAxis() {
227 static Graphic3d_Vector MyYscreenAxis;
228 return MyYscreenAxis;
230 #define MyYscreenAxis _MyYscreenAxis()
232 static Graphic3d_Vector& _MyZscreenAxis() {
233 static Graphic3d_Vector MyZscreenAxis;
234 return MyZscreenAxis;
236 #define MyZscreenAxis _MyZscreenAxis()
238 static Graphic3d_Vector& _MyViewReferencePlane() {
239 static Graphic3d_Vector MyViewReferencePlane;
240 return MyViewReferencePlane;
242 #define MyViewReferencePlane _MyViewReferencePlane()
244 static Graphic3d_Vector& _MyViewReferenceUp() {
245 static Graphic3d_Vector MyViewReferenceUp;
246 return MyViewReferenceUp;
248 #define MyViewReferenceUp _MyViewReferenceUp()
250 static Graphic3d_Vector& _MyViewAxis() {
251 static Graphic3d_Vector MyViewAxis;
254 #define MyViewAxis _MyViewAxis()
256 static Graphic3d_Vertex& _MyViewReferencePoint() {
257 static Graphic3d_Vertex MyViewReferencePoint;
258 return MyViewReferencePoint;
260 #define MyViewReferencePoint _MyViewReferencePoint()
262 static Graphic3d_Vertex& _MyGravityReferencePoint() {
263 static Graphic3d_Vertex MyGravityReferencePoint;
264 return MyGravityReferencePoint;
266 #define MyGravityReferencePoint _MyGravityReferencePoint()
268 static Graphic3d_Vertex& _MyProjReferencePoint() {
269 static Graphic3d_Vertex MyProjReferencePoint;
270 return MyProjReferencePoint;
272 #define MyProjReferencePoint _MyProjReferencePoint()
275 /*----------------------------------------------------------------------*/
278 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
280 MyViewer(VM.operator->()),
284 myActiveLightsIterator(),
285 myActivePlanesIterator(),
286 SwitchSetFront(Standard_False),
287 MyTrsf (1, 4, 1, 4), // S3892
288 MyProjModel(V3d_TPM_SCREEN)
289 #if defined(TRACE_POINTS)
290 ,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
291 MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
295 myImmediateUpdate = Standard_False;
296 MyView = new Visual3d_View(MyViewer->Viewer());
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.
308 if ((MyView->Context ()).AliasingIsOn ())
309 MyViewContext.SetAliasingOn ();
311 MyViewContext.SetAliasingOff ();
314 MyViewContext.SetDepthCueingBackPlane
315 ((MyView->Context ()).DepthCueingBackPlane ());
316 MyViewContext.SetDepthCueingFrontPlane
317 ((MyView->Context ()).DepthCueingFrontPlane ());
319 if ((MyView->Context ()).DepthCueingIsOn ())
320 MyViewContext.SetDepthCueingOn ();
322 MyViewContext.SetDepthCueingOff ();
325 MyViewContext.SetZClippingBackPlane
326 ((MyView->Context ()).ZClippingBackPlane ());
327 MyViewContext.SetZClippingFrontPlane
328 ((MyView->Context ()).ZClippingFrontPlane ());
330 if ((MyView->Context ()).FrontZClippingIsOn ())
331 MyViewContext.SetFrontZClippingOn ();
333 MyViewContext.SetFrontZClippingOff ();
335 if ((MyView->Context ()).BackZClippingIsOn ())
336 MyViewContext.SetBackZClippingOn ();
338 MyViewContext.SetBackZClippingOff ();
340 // Visualisation and Shading Model
341 MyViewContext.SetModel ((MyView->Context ()).Model ());
342 MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
345 MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
346 MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
347 // } End of retrieval of the definition of ViewContext.
349 MyViewMapping = MyView->ViewMapping() ;
350 MyViewOrientation = MyView->ViewOrientation() ;
351 MyBackground = VM->GetBackgroundColor() ;
352 MyGradientBackground = VM->GetGradientBackground() ;
354 SetAxis(0.,0.,0.,1.,1.,1.) ;
355 SetVisualization(VM->DefaultVisualization()) ;
356 SetShadingModel(VM->DefaultShadingModel()) ;
357 SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
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);
367 SetZCueingWidth(zsize);
368 SetDepth(VM->DefaultViewSize()/2.) ;
370 SetViewMappingDefault();
373 myImmediateUpdate = Standard_True;
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);
387 MyAnimationFlags = 0;
391 MyTransparencyFlag = Standard_False;
396 /*----------------------------------------------------------------------*/
398 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
400 MyViewer(VM.operator->()),
404 myActiveLightsIterator(),
405 myActivePlanesIterator(),
406 SwitchSetFront(Standard_False),
407 MyTrsf (1, 4, 1, 4), // S3892
408 MyProjModel(V3d_TPM_SCREEN)
409 #if defined(TRACE_POINTS)
410 ,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
411 MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
415 Handle(Visual3d_View) FromView = V->View() ;
417 myImmediateUpdate = Standard_False;
418 MyView = new Visual3d_View(MyViewer->Viewer());
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());}
425 MyViewContext = FromView->Context() ;
427 MyViewMapping = FromView->ViewMapping() ;
428 MyViewOrientation = FromView->ViewOrientation() ;
429 MyBackground = FromView->Background() ;
430 MyGradientBackground = FromView->GradientBackground();
432 MyView->SetContext(MyViewContext) ;
434 SetAxis(0.,0.,0.,1.,1.,1.) ;
437 myImmediateUpdate = Standard_True;
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);
451 MyAnimationFlags = 0;
456 /*----------------------------------------------------------------------*/
460 void 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)
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;
480 SetViewMappingDefault();
485 /*----------------------------------------------------------------------*/
487 void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
490 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
491 "V3d_View::SetWindow, window of view already defined");
493 MyView->SetWindow(TheWindow) ;
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;
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) ;
508 MyGridEchoStructure->SetInfiniteState (Standard_True); // S3892
509 MyGridEchoStructure->Display (); // S3892
516 /*----------------------------------------------------------------------*/
518 void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
519 const Aspect_RenderingContext aContext,
520 const Aspect_GraphicCallbackProc& aDisplayCB,
521 const Standard_Address aClientData)
524 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
525 "V3d_View::SetWindow, "
526 "window of view already defined");
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.
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) ;
544 /*----------------------------------------------------------------------*/
546 void V3d_View::Remove() const {
548 MyViewer->DelView(this) ;
556 /*----------------------------------------------------------------------*/
558 void V3d_View::Update() const {
559 if( MyView->IsDefined() ) MyView->Update() ;
562 /*----------------------------------------------------------------------*/
564 void V3d_View::Redraw() const {
565 if( MyView->IsDefined() ) MyView->Redraw() ;
567 /*----------------------------------------------------------------------*/
569 void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
570 const Standard_Integer width,const Standard_Integer height) const
572 if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
575 /*----------------------------------------------------------------------*/
577 Standard_Boolean V3d_View::IsEmpty() const {
579 Standard_Boolean TheStatus = Standard_True ;
580 if( MyView->IsDefined() ) {
581 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
582 if( Nstruct > 0 ) TheStatus = Standard_False ;
588 /*----------------------------------------------------------------------*/
590 void V3d_View::UpdateLights() const {
591 MyView->SetContext(MyViewContext);
595 /*----------------------------------------------------------------------*/
597 void V3d_View::DoMapping() {
598 if( MyView->IsDefined() ) {
599 (MyView->Window())->DoMapping() ;
603 /*----------------------------------------------------------------------*/
605 void V3d_View::MustBeResized() {
607 if ( !MyLayerMgr.IsNull() )
608 MyLayerMgr->Resized();
610 if( MyView->IsDefined() ) {
612 MyViewMapping = MyView->ViewMapping();
618 /*----------------------------------------------------------------------*/
620 void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
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 );
626 Quantity_Color C( V1, V2, V3, Type );
628 SetBackgroundColor( C );
630 MyBackground.SetColor( C );
631 if ( MyView->IsDefined() )
632 MyView->SetBackground( MyBackground );
633 if ( !MyLayerMgr.IsNull() )
634 MyLayerMgr->Resized();
639 /*----------------------------------------------------------------------*/
641 void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
643 MyBackground.SetColor( Color );
644 if ( MyView->IsDefined() )
645 MyView->SetBackground( MyBackground );
647 if ( !MyLayerMgr.IsNull() )
648 MyLayerMgr->Resized();
652 /*----------------------------------------------------------------------*/
654 void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
656 Quantity_Color C( Name );
658 SetBackgroundColor( C );
660 MyBackground.SetColor( C );
661 if ( MyView->IsDefined() )
662 MyView->SetBackground( MyBackground );
663 if ( !MyColorScale.IsNull() )
664 MyColorScale->Resized();
668 /*----------------------------------------------------------------------*/
670 void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
671 const Quantity_Color& Color2,
672 const Aspect_GradientFillMethod FillStyle,
673 const Standard_Boolean status)
676 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
677 if ( MyView->IsDefined() )
678 MyView->SetGradientBackground( MyGradientBackground, status );
682 /*----------------------------------------------------------------------*/
684 void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
685 const Quantity_NameOfColor Color2,
686 const Aspect_GradientFillMethod FillStyle,
687 const Standard_Boolean status )
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 );
696 /*----------------------------------------------------------------------*/
698 void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
699 const Standard_Boolean update) const
701 if( MyView->IsDefined() )
702 MyView->SetBgGradientStyle( FillStyle , update ) ;
705 /*----------------------------------------------------------------------*/
707 void V3d_View::SetBackgroundImage( const Standard_CString FileName,
708 const Aspect_FillMethod FillStyle,
709 const Standard_Boolean update )
712 if( MyView->IsDefined() )
713 MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
717 /*----------------------------------------------------------------------*/
719 void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
720 const Standard_Boolean update )
723 if( MyView->IsDefined() )
724 MyView->SetBgImageStyle( FillStyle, update ) ;
728 /*----------------------------------------------------------------------*/
730 void 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) {
732 Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
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() ;
743 /*----------------------------------------------------------------------*/
745 void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) {
747 MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
748 MyView->SetContext(MyViewContext) ;
752 /*----------------------------------------------------------------------*/
754 void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) {
756 MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
757 MyView->SetContext(MyViewContext) ;
761 /*----------------------------------------------------------------------*/
763 void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) {
765 MyViewContext.SetTextureEnv(ATexture) ;
766 MyView->SetContext(MyViewContext) ;
770 /*----------------------------------------------------------------------*/
772 void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) {
774 MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
775 MyView->SetContext(MyViewContext) ;
779 /*----------------------------------------------------------------------*/
781 void V3d_View::SetFront() {
783 gp_Ax3 a = MyViewer->PrivilegedPlane();
784 Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
786 a.Direction().Coord(vx,vy,vz);
787 a.YDirection().Coord(xu,yu,zu);
788 a.Location().Coord(xo,yo,zo);
791 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
793 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
795 SwitchSetFront = !SwitchSetFront;
797 MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
798 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
800 MyView->SetViewOrientation(MyViewOrientation) ;
806 /*----------------------------------------------------------------------*/
808 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) {
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) ;
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 ;
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");
835 if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
837 RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
838 Multiply(Matrix, Rmatrix, Matrix);
841 RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
842 Multiply(Matrix, Rmatrix, Matrix);
844 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
845 MyViewOrientation.SetViewReferencePlane(Vpn) ;
846 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
847 MyViewOrientation.SetViewReferenceUp(Vup) ;
848 MyView->SetViewOrientation(MyViewOrientation) ;
856 /*----------------------------------------------------------------------*/
858 void 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)
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) ;
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 ;
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");
889 if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
891 RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
892 Multiply(Matrix, Rmatrix, Matrix);
895 RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
896 Multiply(Matrix, Rmatrix, Matrix);
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) ;
912 /*----------------------------------------------------------------------*/
914 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) {
918 Rotate(angle,0.,0.,Start);
921 Rotate(0.,angle,0.,Start);
924 Rotate(0.,0.,angle,Start);
930 /*----------------------------------------------------------------------*/
932 void 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)
936 Standard_Real Angle = angle ;
937 Graphic3d_Vector Vpn,Vup ;
938 Graphic3d_Vertex Vrp ;
939 TColStd_Array2OfReal Matrix(0,3,0,3) ;
941 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
942 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
945 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
946 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
947 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
948 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
951 MyViewAxis.SetCoord(1.,0.,0.) ;
954 MyViewAxis.SetCoord(0.,1.,0.) ;
957 MyViewAxis.SetCoord(0.,0.,1.) ;
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) ;
977 /*----------------------------------------------------------------------*/
979 void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) {
981 Standard_Real Angle = angle ;
982 Graphic3d_Vector Vpn,Vup ;
983 TColStd_Array2OfReal Matrix(0,3,0,3) ;
985 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
986 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
989 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
990 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
991 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
994 RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
996 Graphic3d_Vertex Vrp ;
997 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
998 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1000 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1001 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1002 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1003 MyViewOrientation.SetViewReferenceUp(Vup) ;
1004 MyView->SetViewOrientation(MyViewOrientation) ;
1012 /*----------------------------------------------------------------------*/
1014 void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
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) ;
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 ;
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");
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) ;
1051 RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
1052 Multiply(Matrix, Rmatrix, Matrix);
1055 RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
1056 Multiply(Matrix, Rmatrix, Matrix);
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) ;
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) ;
1081 /*----------------------------------------------------------------------*/
1083 void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1088 Turn(angle,0.,0.,Start);
1091 Turn(0.,angle,0.,Start);
1094 Turn(0.,0.,angle,Start);
1099 void 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) ;
1106 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1107 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1110 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1111 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1112 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1113 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
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) ;
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) ;
1144 void V3d_View::SetTwist(const Standard_Real angle) {
1146 Standard_Real Angle = angle ;
1147 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1148 Standard_Boolean TheStatus ;
1150 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1151 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1153 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1154 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1155 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1156 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1158 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1159 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1160 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1163 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1164 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1165 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1168 Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
1170 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1171 RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
1172 MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
1173 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1174 MyView->SetViewOrientation(MyViewOrientation) ;
1180 void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
1183 MyProjModel = aModel;
1187 V3d_TypeOfProjectionModel V3d_View::ProjModel() const {
1194 void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1196 Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
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");
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);
1213 Standard_Boolean update = myImmediateUpdate;
1214 myImmediateUpdate = Standard_False;
1215 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1216 //FMN desactivation temp SetTwist(Angle) ;
1218 MyView->SetViewOrientation(MyViewOrientation) ;
1219 MyView->SetViewMapping(MyViewMapping) ;
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) ;
1232 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1233 MyView->SetViewMapping(MyViewMapping);
1236 myImmediateUpdate = update;
1241 void V3d_View::SetDepth(const Standard_Real Depth) {
1243 Standard_Real Xrp,Yrp,Zrp ;
1245 Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
1247 Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
1251 Standard_Real twist =
1254 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1255 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1256 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1257 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1263 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1264 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
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) ;
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 ;
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);
1283 MyView->SetViewMapping(MyViewMapping) ;
1286 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1287 Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1289 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1290 MyProjModel == V3d_TPM_SCREEN ) {
1291 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1293 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1297 MyView->SetViewMapping(MyViewMapping) ;
1306 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1309 Standard_Real Angle ;
1311 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1312 "V3d_View::SetProj, null projection vector");
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) ;
1324 myImmediateUpdate = update;
1329 void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) {
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;
1339 switch (Orientation) {
1357 void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1359 Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
1360 Standard_Real Xeye,Yeye,Zeye ;
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");
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) ;
1387 MyView->SetViewOrientation(MyViewOrientation) ;
1388 MyView->SetViewMapping(MyViewMapping) ;
1393 MyView->SetViewMapping(MyViewMapping);
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) ;
1403 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1404 MyView->SetViewMapping(MyViewMapping);
1407 myImmediateUpdate = update;
1412 void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) {
1414 Standard_Boolean TheStatus ;
1415 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
1416 "V3d_View::SetUp, nullUp vector");
1418 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1419 MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
1420 MyViewReferenceUp.Normalize() ;
1421 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1422 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1424 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1425 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1426 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1429 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1430 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1431 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1434 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1435 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1436 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1438 Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
1440 MyViewReferenceUp = MyYscreenAxis ;
1441 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1442 MyView->SetViewOrientation(MyViewOrientation) ;
1447 void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) {
1449 Standard_Boolean TheStatus ;
1451 MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
1452 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1453 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1454 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1456 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1457 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1458 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1461 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1462 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1463 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1466 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1467 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1468 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1470 Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
1472 MyViewReferenceUp = MyYscreenAxis ;
1473 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1474 MyView->SetViewOrientation(MyViewOrientation) ;
1479 void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
1481 MyViewOrientation = VO;
1482 MyView->SetViewOrientation(MyViewOrientation) ;
1486 void V3d_View::SetViewOrientationDefault() {
1488 MyView->SetViewOrientation(MyViewOrientation) ;
1489 MyView->SetViewOrientationDefault() ;
1493 void V3d_View::ResetViewOrientation() {
1495 MyView->ViewOrientationReset() ;
1496 MyViewOrientation = MyView->ViewOrientation() ;
1500 void V3d_View::Reset( const Standard_Boolean update ) {
1502 MyView->ViewOrientationReset() ;
1503 MyViewOrientation = MyView->ViewOrientation() ;
1504 MyView->ViewMappingReset();
1505 MyViewMapping = MyView->ViewMapping() ;
1508 SwitchSetFront = Standard_False;
1510 if( !myImmediateUpdate && update ) Update();
1517 void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
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");
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");
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) ;
1544 MyView->SetViewMapping(MyViewMapping) ;
1548 void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) {
1554 void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc){
1556 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
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");
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) ;
1573 MyView->SetViewMapping(MyViewMapping) ;
1578 void V3d_View::SetSize(const Standard_Real Size)
1581 Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
1583 Viewer_BadValue_Raise_if( Size <= 0.,
1584 "V3d_View::SetSize, Window Size is NULL");
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 ;
1596 MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
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) ;
1608 void V3d_View::SetZSize(const Standard_Real Size)
1611 Standard_Real Zmax = Size/2.;
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;
1624 Viewer_BadValue_Raise_if( Size <= 0.,
1625 "V3d_View::SetZSize, Window ZSize is NULL");
1628 Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
1629 Standard_Real Back = MyViewContext.ZClippingBackPlane() ;
1630 Standard_Real focale= Focale();
1632 MyViewMapping.SetFrontPlaneDistance(Zmax) ;
1633 MyViewMapping.SetBackPlaneDistance(-Zmax) ;
1636 if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
1637 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
1640 MyView->SetViewMapping(MyViewMapping) ;
1641 if( MyViewContext.FrontZClippingIsOn() ||
1642 MyViewContext.BackZClippingIsOn() ) {
1643 MyViewContext.SetZClippingFrontPlane(Front) ;
1644 MyViewContext.SetZClippingBackPlane(Back) ;
1645 MyView->SetContext(MyViewContext) ;
1650 void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
1653 Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
1654 Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
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) ;
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;
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) ;
1684 void V3d_View::SetScale( const Standard_Real Coef ) {
1685 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
1686 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
1688 Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
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) ;
1703 void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) {
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");
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);
1715 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
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 ) {
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)) ;
1749 SetZSize(2.*Wmax + Wmax) ;
1754 void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
1755 const Standard_Boolean update)
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();
1762 if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
1770 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1771 MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
1772 if (MyView->IsDefined())
1774 Standard_Integer Xpixel, Ypixel;
1775 MyWindow->Size (Xpixel, Ypixel);
1781 MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
1782 DxvOld = Abs (Umax - Umin);
1783 DyvOld = Abs (Vmax - Vmin);
1785 if ((DxvOld == 0.0) || (DyvOld == 0.0))
1790 Standard_Real aWinRatio = DxvOld / DyvOld;
1792 // retrieve min / max values for current displayed objects
1793 MyView->MinMaxValues (Xmin, Ymin, Zmin,
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)
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)
1810 MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
1811 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1813 MyView->SetViewMapping (MyViewMapping);
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)
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);
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);
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);
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);
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);
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);
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);
1848 DxvNew = Abs (Umax - Umin);
1849 DyvNew = Abs (Vmax - Vmin);
1851 if (DyvNew < 10.0 * Precision::Confusion())
1853 if (DxvNew < 10.0 * Precision::Confusion())
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())
1859 // this is really just one (!) point and zooming has no any effect
1860 // just center the view
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;
1874 // whole scene projected to horizontal line
1875 DxvNew += Coef * DxvNew;
1876 DyvNew = DxvNew / aWinRatio;
1881 // general case (or DxvNew == 0.0 - vertical line)
1882 // safe original ratio
1883 Standard_Real aFitRatio = DxvNew / DyvNew;
1884 if (aFitRatio >= aWinRatio)
1886 DxvNew += Coef * DxvNew;
1887 DyvNew = DxvNew / aWinRatio;
1891 DyvNew += Coef * DyvNew;
1892 DxvNew = DyvNew * aWinRatio;
1897 Xrp = 0.5 * (Umin + Umax);
1898 Yrp = 0.5 * (Vmin + Vmax);
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);
1907 if (MyType != V3d_PERSPECTIVE)
1910 MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
1911 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1913 MyView->SetViewMapping (MyViewMapping);
1927 if (!myImmediateUpdate && update)
1934 void V3d_View::ZFitAll(const Standard_Real Coef) {
1936 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1937 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1939 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1941 if( MyType == V3d_PERSPECTIVE ) {
1946 if( (Nstruct <= 0) || (Coef < 0.) ) {
1951 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
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 ) {
1961 // Case when view contains only a point
1962 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
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)) ;
1982 SetZSize(2.*Wmax + Coef * Wmax) ;
1987 void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
1988 const Quantity_Coefficient Margin)
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;
1994 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1996 if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
2001 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2002 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2004 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
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 ) {
2013 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
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) ;
2048 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
2049 Dz = 2.*Wmax + Margin * Wmax;
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);
2057 SetDepth( Aspect * Size / 2.);
2063 void 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);
2070 void 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);
2074 void 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);
2081 void V3d_View::SetViewMapping(const Visual3d_ViewMapping& 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;
2091 MyView->SetViewMapping(MyViewMapping) ;
2095 void V3d_View::SetViewMappingDefault() {
2096 MyView->SetViewMapping(MyViewMapping) ;
2097 MyView->SetViewMappingDefault();
2101 void V3d_View::ResetViewMapping() {
2103 MyView->ViewMappingReset();
2104 MyViewMapping = MyView->ViewMapping() ;
2113 Standard_Real V3d_View::Convert(const Standard_Integer Vp) const {
2114 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
2115 Standard_Integer Dxw,Dyw ;
2117 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2119 MyWindow->Size(Dxw,Dyw);
2120 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2122 Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
2127 void 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 ;
2131 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
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 ;
2140 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
2142 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2144 Standard_Integer Dxw, Dyw;
2145 MyWindow->Size(Dxw,Dyw);
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 );
2153 void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
2155 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2157 Standard_Integer Dxw, Dyw;
2158 MyWindow->Size(Dxw,Dyw);
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;
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);
2171 void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2173 Graphic3d_Vertex Vrp ;
2174 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2177 if( MyViewer->Grid()->IsActive() ) {
2178 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2179 NewVrp.Coord(X,Y,Z) ;
2184 void 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
2186 Graphic3d_Vertex Vrp ;
2187 Graphic3d_Vector Proj ;
2188 (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
2190 Proj.Coord(Dx,Dy,Dz) ;
2192 if( MyViewer->Grid()->IsActive() ) {
2193 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2194 NewVrp.Coord(X,Y,Z) ;
2200 void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
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) ;
2208 Vrp.Coord(Xg,Yg,Zg) ;
2211 void 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 {
2213 if( MyViewer->Grid()->IsActive() ) {
2214 Graphic3d_Vertex Vrp(X,Y,Z) ;
2215 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2216 NewVrp.Coord(Xg,Yg,Zg) ;
2218 Xg = X; Yg = Y; Zg = Z;
2224 void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2226 Graphic3d_Vertex Vrp ;
2227 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2229 if( MyViewer->Grid()->IsActive() ) {
2230 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2231 NewVrp.Coord(X,Y,Z) ;
2237 void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2239 void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2242 Graphic3d_Vertex Vrp(X,Y,Z) ;
2243 (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
2246 void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
2248 if ( MyType != V3d_PERSPECTIVE )
2250 // use old implementation
2252 MyView->Projects( X, Y, Z, Xp, Yp, Zp );
2256 // NKV - Using raster projection
2257 Standard_Integer Xpx, Ypx;
2258 Convert(X, Y, Z, Xpx, Ypx);
2259 Convert(Xpx, Ypx, Xp, Yp);
2263 void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3)const {
2266 Quantity_Color C = BackgroundColor() ;
2269 C = MyBackground.Color() ;
2271 C.Values(V1,V2,V3,Type) ;
2275 Quantity_Color V3d_View::BackgroundColor() const {
2277 return MyBackground.Color() ;
2281 void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
2282 MyGradientBackground.Colors(Color1, Color2);
2285 Aspect_GradientBackground V3d_View::GradientBackground() const {
2286 return MyGradientBackground;
2289 Standard_Real V3d_View::Scale()const {
2290 Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
2291 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
2292 Standard_Real S = 0. ;
2294 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2296 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2297 if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
2301 void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const {
2302 MyViewOrientation.AxialScale( Sx, Sy, Sz );
2305 void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const {
2307 Standard_Real Umin,Vmin,Umax,Vmax ;
2309 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2310 Xc = (Umin + Umax)/2. ;
2311 Yc = (Vmin + Vmax)/2. ;
2314 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const {
2316 Standard_Real Umin,Vmin,Umax,Vmax ;
2318 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2319 Width = Umax - Umin ;
2320 Height = Vmax - Vmin ;
2323 Standard_Real V3d_View::ZSize() const {
2325 Standard_Real Wmin,Wmax,Depth ;
2327 Wmax = MyViewMapping.FrontPlaneDistance() ;
2328 Wmin = MyViewMapping.BackPlaneDistance() ;
2329 Depth = 2. * Max(Wmin,Wmax) ;
2333 Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
2335 Standard_Real Wmin,Wmax,U,V,W ;
2336 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2338 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
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) ;
2372 Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const {
2374 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2375 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2378 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2383 Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
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;
2390 MyView->DisplayedStructures (MySetOfStructures);
2391 Nstruct = MySetOfStructures.Extent() ;
2393 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
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,
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 )) {
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 ;
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 ;
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 ;
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 ;
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 ;
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 ;
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 ;
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 ;
2442 X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
2448 void 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 ;
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;
2462 void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const {
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;
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;
2484 void 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 {
2486 Standard_Real Xo,Yo,Zo;
2488 Convert(Xpix,Ypix,XP,YP,ZP);
2489 if ( MyType == V3d_PERSPECTIVE ) {
2490 FocalReferencePoint(Xo,Yo,Zo);
2501 Standard_Real V3d_View::Depth() const {
2502 Graphic3d_Vertex Prp ;
2503 Standard_Real Xrp,Yrp,Zrp ;
2505 Prp = MyViewMapping.ProjectionReferencePoint() ;
2506 Prp.Coord(Xrp,Yrp,Zrp) ;
2510 void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const {
2511 Graphic3d_Vector Vpn ;
2513 Vpn = MyViewOrientation.ViewReferencePlane() ;
2514 Vpn.Coord(Dx,Dy,Dz) ;
2517 void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2518 Graphic3d_Vertex Vrp ;
2520 Vrp = MyViewOrientation.ViewReferencePoint() ;
2524 void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const {
2525 Graphic3d_Vector Vup ;
2527 Vup = MyViewOrientation.ViewReferenceUp() ;
2528 Vup.Coord(Vx,Vy,Vz) ;
2531 Standard_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 ;
2537 Vpn = MyViewOrientation.ViewReferencePlane() ;
2538 Vpn.Coord(Xpn,Ypn,Zpn) ;
2539 Vup.SetCoord(0.,0.,1.) ;
2540 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2542 Vup.SetCoord(0.,1.,0.) ;
2543 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2546 Vup.SetCoord(1.,0.,0.) ;
2547 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
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 ;
2560 if( angle > 1. ) angle = 1. ;
2561 else if( angle < -1. ) angle = -1. ;
2562 angle = asin(angle) ;
2563 if( sca < 0. ) angle = M_PI - angle ;
2564 if( angle > 0. && angle < M_PI ) {
2565 sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
2566 if( sca < 0. ) angle = DEUXPI - angle ;
2571 V3d_TypeOfShadingModel V3d_View::ShadingModel()const {
2572 V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
2576 V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail()const {
2577 V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
2582 Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const {
2583 Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
2587 V3d_TypeOfVisualization V3d_View::Visualization()const {
2588 V3d_TypeOfVisualization V =
2589 (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
2593 Standard_Boolean V3d_View::Antialiasing()const {
2594 Standard_Boolean A = MyViewContext.AliasingIsOn() ;
2598 Handle(V3d_Viewer) V3d_View::Viewer() const {
2602 Standard_Boolean V3d_View::IfWindow() const {
2603 Standard_Boolean TheStatus = MyView->IsDefined() ;
2607 Handle(Aspect_Window) V3d_View::Window() const {
2611 V3d_TypeOfView V3d_View::Type() const {
2616 void V3d_View::SetFocale( const Standard_Real focale ) {
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 ;
2627 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2628 ViewPlane = FrontPlane + Zrp - focale ;
2630 MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
2631 MyView->SetViewMapping(MyViewMapping) ;
2636 Standard_Real V3d_View::Focale( ) const {
2637 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2638 Standard_Real focale = 0.0 ;
2639 Graphic3d_Vertex Prp ;
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 ;
2648 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2649 focale = FrontPlane + Zrp - ViewPlane ;
2655 void 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)
2659 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
2661 Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
2663 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2664 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2667 Standard_Real size = (ZFar - ZNear) / 2.;
2669 MyViewMapping.SetFrontPlaneDistance(size);
2670 MyViewMapping.SetBackPlaneDistance(-size);
2672 // keep view plane at front plane distance
2673 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
2675 // set window limits
2676 Umin = Left; Umax = Right;
2677 Vmin = Bottom; Vmax = Top;
2678 MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
2680 // Update window center
2681 if ( MyType == V3d_PERSPECTIVE ) {
2685 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
2687 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
2688 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2690 MyView->SetViewMapping(MyViewMapping) ;
2695 Handle(Visual3d_View) V3d_View::View() const
2700 Visual3d_ViewMapping V3d_View::ViewMapping() const
2702 return MyViewMapping;
2705 Visual3d_ViewOrientation V3d_View::ViewOrientation() const
2707 return MyViewOrientation;
2710 Standard_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 ;
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;
2734 return Standard_True ;
2737 void 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 ;
2744 for( I=LR ; I<=UR ; I++ ) {
2745 for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
2747 for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
2750 Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) {
2752 Standard_Integer llr = Left.LowerRow ();
2753 Standard_Integer llc = Left.LowerCol ();
2754 Standard_Integer luc = Left.UpperCol ();
2756 Standard_Integer rlr = Right.LowerRow ();
2757 Standard_Integer rur = Right.UpperRow ();
2758 Standard_Integer rlc = Right.LowerCol ();
2760 Standard_Integer mlr = Matrix.LowerRow ();
2761 Standard_Integer mur = Matrix.UpperRow ();
2762 Standard_Integer mlc = Matrix.LowerCol ();
2763 Standard_Integer muc = Matrix.UpperCol ();
2765 TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
2767 InitMatrix (Result);
2769 // Left et Right incompatibles
2770 if (luc - llc + 1 != rur - rlr + 1)
2771 return Standard_False;
2773 Standard_Integer i, j, k;
2776 Standard_Integer I1 = llr;
2778 for (i=mlr; i<=mur; i++) {
2779 Standard_Integer J2 = rlc;
2780 for (j=mlc; j<=muc; j++) {
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);
2789 Result (i, j) = Som;
2795 for (i=mlr; i<=mur; i++)
2796 for (j=mlc; j<=muc; j++)
2797 Matrix (i, j) = Result (i, j);
2799 return Standard_True;
2802 /*----------------------------------------------------------------------*/
2804 void 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) ;
2811 InitMatrix(Matrix) ;
2812 InitMatrix(Tmatrix) ;
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 ;
2827 vcal = Xaxe * Xaxe ;
2828 Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
2829 Rmatrix(1,0) = termc12 + terms3 ;
2830 Rmatrix(2,0) = termc13 - terms2 ;
2832 Rmatrix(0,1) = termc12 - terms3 ;
2833 vcal = Yaxe * Yaxe ;
2834 Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
2835 Rmatrix(2,1) = termc23 + terms1 ;
2837 Rmatrix(0,2) = termc13 + terms2 ;
2838 Rmatrix(1,2) = termc23 - terms1 ;
2839 vcal = Zaxe * Zaxe ;
2840 Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
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;
2853 Multiply(Matrix, Tmatrix, Matrix);
2856 /*----------------------------------------------------------------------*/
2858 Graphic3d_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 ;
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) ) {
2870 PP.SetCoord(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) ;
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) ;
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) ;
2886 Graphic3d_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 ;
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) ) {
2898 VV.SetCoord(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() ;
2910 void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) {
2912 Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
2916 void V3d_View::Zoom (const Standard_Integer X1,
2917 const Standard_Integer Y1,
2918 const Standard_Integer X2,
2919 const Standard_Integer Y2)
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);
2931 void V3d_View::Zoom (const Standard_Integer X1,
2932 const Standard_Integer Y1)
2936 Standard_Integer ix,iy;
2941 // Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
2942 void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
2944 MyZoomAtPointX = xpix;
2945 MyZoomAtPointY = ypix;
2948 // Zooms the model at a pixel defined by the method StartZoomAtPoint().
2949 void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
2950 const Standard_Integer mouseStartY,
2951 const Standard_Integer mouseEndX,
2952 const Standard_Integer mouseEndY)
2954 Standard_Boolean update;
2955 V3d_Coordinate X0, Y0, XS, YS;
2957 // Forbid any update.
2958 update = SetImmediateUpdate(Standard_False);
2963 // Pan the point to the center of window.
2964 Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
2965 Panning(X0-XS, Y0-YS);
2968 Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
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");
2974 Standard_Real Umin,Vmin,Umax,Vmax;
2975 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
2977 MyXwindowCenter = (Umin + Umax) / 2.0;
2978 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2979 MyWindowWidth = Abs(Umax - Umin);
2980 MyWindowHeight = Abs(Vmax - Vmin);
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;
2993 Standard_Real Dxv = MyWindowWidth / coef;
2994 Standard_Real Dyv = MyWindowHeight / coef;
2996 Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
2997 Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
2999 // Pan the point backwards.
3000 Dxv = (XS - X0) / coef;
3001 Dyv = (YS - Y0) / coef;
3003 MyXwindowCenter = (Umin + Umax) / 2.0;
3004 MyYwindowCenter = (Vmin + Vmax) / 2.0;
3005 MyWindowWidth = Abs(Umax - Umin);
3006 MyWindowHeight = Abs(Vmax - Vmin);
3008 Standard_Real Xrp,Yrp,Zrp;
3009 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
3010 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
3012 Xrp = MyXwindowCenter - Dxv;
3013 Yrp = MyYwindowCenter - Dyv;
3015 Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
3016 Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
3018 // Set new reference plane coordintes of the window.
3019 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
3020 if (MyType != V3d_PERSPECTIVE)
3022 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
3023 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3025 MyView->SetViewMapping(MyViewMapping);
3028 SetImmediateUpdate(update);
3032 void V3d_View::AxialScale (const Standard_Integer Dx,
3033 const Standard_Integer Dy,
3034 const V3d_TypeOfAxe Axis)
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 );
3048 void 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)
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 ;
3060 Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
3061 "V3d_View::FitAll, Window Size is NULL");
3063 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
3064 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
3065 aWindow->Size(Xpixel,Ypixel);
3066 DxvOld = Xpixel; DyvOld = Ypixel;
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 ;
3075 DxvNew = DyvNew*RapOld ;
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);
3085 MyView->SetViewMapping(MyViewMapping) ;
3094 static Standard_Boolean zRotation = Standard_False;
3096 void V3d_View::StartRotation(const Standard_Integer X,
3097 const Standard_Integer Y,
3098 const Quantity_Ratio zRotationThreshold)
3104 rx = Standard_Real(Convert(x));
3105 ry = Standard_Real(Convert(y));
3107 Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
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;
3121 void V3d_View::Rotation(const Standard_Integer X,
3122 const Standard_Integer Y)
3126 if( rx == 0. || ry == 0. ) {
3132 Standard_Real dx=0.,dy=0.,dz=0.;
3134 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
3135 atan2(sx-rx/2.,ry/2.-sy);
3137 dx = (Standard_Real(X) - sx) * M_PI / rx;
3138 dy = (sy - Standard_Real(Y)) * M_PI / ry;
3140 Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
3142 Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
3143 Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
3144 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3147 if( !myImmediateUpdate ) Update();
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;
3157 void V3d_View::SetAnimationModeOn () {
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;
3167 MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
3170 MyView->SetAnimationModeOn();
3174 void V3d_View::SetAnimationModeOff () {
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 ) {
3187 MyView->SetAnimationModeOff();
3191 Standard_Boolean V3d_View::AnimationModeIsOn () const {
3192 return MyView->AnimationModeIsOn();
3196 void V3d_View :: SetAnimationMode
3198 const Standard_Boolean anAnimationFlag,
3199 const Standard_Boolean aDegenerationFlag
3203 if ( anAnimationFlag )
3204 MyAnimationFlags |= V3d_FLAG_ANIMATION;
3206 MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
3208 if ( aDegenerationFlag )
3209 MyAnimationFlags |= V3d_FLAG_DEGENERATION;
3211 MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
3213 } // end V3d_View :: SetAnimationMode
3215 Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
3218 isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
3219 return MyAnimationFlags & V3d_FLAG_ANIMATION;
3223 void V3d_View::SetDegenerateModeOn() {
3225 SetComputedMode(Standard_False);
3227 MyView->SetDegenerateModeOn();
3232 void V3d_View::SetDegenerateModeOff()
3235 SetComputedMode(Standard_True);
3237 if(myComputedMode) {
3238 MyView->SetDegenerateModeOff();
3244 Standard_Boolean V3d_View::DegenerateModeIsOn() const
3247 return !ComputedMode();
3249 return MyView->DegenerateModeIsOn();
3254 void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3258 if( myComputedMode ) {
3259 MyView -> SetComputedMode ( Standard_True );
3263 MyView -> SetComputedMode ( Standard_False );
3267 } // end V3d_View :: SetComputedMode
3269 Standard_Boolean V3d_View :: ComputedMode () const
3272 return MyView -> ComputedMode ();
3274 } // end V3d_View :: ComputedMode
3276 void V3d_View :: SetBackFacingModel (
3277 const V3d_TypeOfBackfacingModel aModel)
3280 MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
3282 } // end V3d_View :: SetBackFacingModel
3284 V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const {
3286 return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
3288 } // end V3d_View :: BackFacingModel
3291 Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const {
3292 return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
3295 void V3d_View::TransientManagerClearDraw() const {
3296 Visual3d_TransientManager::ClearDraw(MyView);
3299 Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const {
3300 return Visual3d_TransientManager::BeginAddDraw(MyView);
3303 void V3d_View::Init() {
3304 myComputedMode = MyViewer->ComputedMode();
3306 if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
3307 SetComputedMode(Standard_False);
3311 MyView->SetDegenerateModeOn();
3313 if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
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;
3325 void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) {
3326 MyPlotter = aPlotter;
3329 void V3d_View::Plot()
3332 Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
3334 MyView->Plot(MyPlotter);
3337 Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
3343 if (AnimationMode) MyView->SetAnimationModeOn();
3345 Standard_Real delta = 0.01;
3346 Standard_Real xangle, yangle;
3347 xangle = yangle = delta*int(NbImages/3);
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();
3359 cout << "For " << NbImages << " Images : " << endl;
3360 FullTimer.Show (cout);
3363 Standard_Real Seconds, CPUtime;
3364 Standard_Integer Minutes, Hours;
3366 FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
3367 cout << "Result " << (AnimationMode ? "with " : "without ")
3368 << "display list : " << NbImages/CPUtime << " images/Second."
3371 return NbImages/CPUtime;
3375 #define SCREENCOPY_FILENAME "screencopy3d.gif"
3376 void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
3377 const Standard_Boolean fWhiteBackground,
3378 const Quantity_Factor aPlotScale)
3380 TCollection_AsciiString aFileToDump;
3381 Handle(Aspect_WindowDriver) aWindowDriver =
3383 new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
3385 new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
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);
3395 if (theWWidth * theWHeight != 0.) {
3396 if (aPlotScale == 0.) {
3397 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3399 // To be changed !!!!!!!!!!!!!!!
3400 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
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 () );
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 ();
3426 theFlags -> Append (0);
3433 if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
3434 aFileToDump = aPlotterDriver->PlotFileName();
3436 aFileToDump = aPlotterDriver->SpoolDirectory();
3437 aFileToDump += SCREENCOPY_FILENAME;
3439 MyWindow -> Dump (aFileToDump.ToCString());
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);
3449 if (fWhiteBackground)
3450 SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
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 ();
3461 #undef SCREENCOPY_FILENAME
3463 #include <Aspect.hxx>
3464 #include <Visual3d_Layer.hxx>
3466 ////////////////////////////////////////////////////////////////
3467 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3468 const Image_TypeOfImage theBufferType)
3470 Standard_Integer aWinWidth, aWinHeight;
3471 MyWindow->Size (aWinWidth, aWinHeight);
3473 Handle(Aspect_PixMap) aPixMap = ToPixMap (aWinWidth, aWinHeight, theBufferType);
3474 return !aPixMap.IsNull() && aPixMap->Dump (theFile);
3477 ////////////////////////////////////////////////////////////////
3478 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3479 const Aspect_FormatOfSheetPaper theFormat,
3480 const Image_TypeOfImage theBufferType)
3482 Standard_Boolean isDone = Standard_False;
3483 // convert Aspect_FormatOfSheetPaper size to pixel ...
3484 Quantity_Length anSPWidth, anSPHeight;
3485 Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
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);
3493 Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
3494 aPixelWidth = Standard_Integer (aPixelWidth * aScale);
3495 aPixelHeight = Standard_Integer (aPixelHeight * aScale);
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);
3507 ////////////////////////////////////////////////////////////////
3508 Handle(Image_PixMap) V3d_View::ToPixMap (const Standard_Integer theWidth,
3509 const Standard_Integer theHeight,
3510 const Image_TypeOfImage theBufferType,
3511 const Standard_Boolean theIsForceCentred)
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)
3520 MyView->FBOGetDimensions (aPrevFBOPtr,
3521 aPrevFBOVPSizeX, aPrevFBOVPSizeY,
3522 aPrevFBOSizeXMax, aPrevFBOSizeYMax);
3523 if (theWidth <= aPrevFBOSizeXMax && theHeight <= aPrevFBOSizeYMax)
3525 MyView->FBOChangeViewport (aPrevFBOPtr, theWidth, theHeight);
3526 aFBOPtr = aPrevFBOPtr;
3530 if (aFBOPtr == NULL)
3532 // Try to create hardware accelerated buffer
3533 aFBOPtr = MyView->FBOCreate (theWidth, theHeight);
3535 cView->ptrFBO = aFBOPtr;
3537 // If hardware accelerated buffer - try to use onscreen buffer
3538 // Results may be bad!
3539 if (aFBOPtr == NULL)
3541 // retrieve window sizes
3542 Standard_Integer aWinWidth, aWinHeight;
3543 MyWindow->Size (aWinWidth, aWinHeight);
3545 // technically we can reduce existing viewport...
3546 // but currently allow only dumping the window itself
3547 if (theWidth != aWinWidth || theHeight != aWinHeight)
3549 return Handle(Image_PixMap)();
3554 Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
3555 Standard_Real Umin, Vmin, Umax, Vmax;
3557 if (theIsForceCentred)
3559 //szv: get mapping frame
3560 Standard_Real PUmin, PVmin, PUmax, PVmax;
3561 prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
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)
3569 Standard_Real newHeight = (oldWidth * theHeight) / theWidth;
3571 Standard_Real delta = 0.5 * (newHeight - oldHeight);
3572 Vmin = PVmin - delta;
3573 Vmax = PVmax + delta;
3578 Standard_Real delta = 0.5 * (newWidth - oldWidth);
3579 Umin = PUmin - delta;
3580 Umax = PUmax + delta;
3583 //szv: apply expanded mapping
3584 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
3585 MyView->SetViewMapping (MyViewMapping);
3588 //workround for rendering list of Over and Under Layers
3589 if (!MyLayerMgr.IsNull())
3591 MyLayerMgr->Compute();
3595 //szv: restore mapping
3596 MyViewMapping = prevMapping;
3597 MyView->SetViewMapping (prevMapping);
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))
3606 anImageBitmap = Handle(Image_PixMap)();
3609 // FBO now useless, free resources
3610 if (aFBOPtr != aPrevFBOPtr)
3612 MyView->FBORelease (aFBOPtr);
3614 else if (aPrevFBOPtr != NULL)
3616 MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
3618 cView->ptrFBO = aPrevFBOPtr;
3619 return anImageBitmap;