1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 02-10-96 : FMN ; Suppression appel Redraw sans MustBeResized()
28 05-06-97 : FMN ; Correction FitAll()
29 30-06-97 : GG ; Correction + Optimisation de Panning(...)
30 On fait la translation + le zoom en une seule
31 operation au lieu de 2 precedemment qui etait buggee.
32 09-07-97 : FMN ; Correction FitAll() sur le Ratio
33 16-07-97 : FMN ; Correction FitAll() sur le calcul de la Box
34 22-07-97 : FMN ; Ajout mode RetainMode pour le Transient
35 15-12-97 : FMN ; Ajout texture mapping
36 17-12-97 : FMN ; CTS19129 Correction FitAll() multiple
37 18-12-97 : FMN ; Ajout mode Ajout
38 24-12-97 : FMN ; Remplacement de math par MathGra
39 24-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window
40 31-12-97 : CAL ; Remplacement de MathGra par Array2OfReal
41 07-01-98 : CAL ; Ajout de la methode DoMapping.
42 07-01-98 : CAL ; Retrait de tous les "this->" inutiles
43 21-01-98 : CAL ; Remplacement des Window->Position () par Window->Size ()
44 27-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
45 12-02-98 : GG ; Reactivation du Redraw dans MustBeResized()
46 23-02-98 : FMN ; Remplacement PI par Standard_PI
47 25-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view
48 11-03-98 : STT ; S3558
49 19-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
51 08-04-98 : STT ; suppr. S3558
52 10-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef
53 13-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
54 ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
55 16-08-98 : CAL ; S3892. Ajout grilles 3d.
56 09-09-98 : CAL ; S3892. Generalisation de TrsPoint.
57 24-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
58 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
59 16-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
60 06-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
61 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
62 29-OCT-98 : DCB : Adding ScreenCopy () method.
63 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
64 10-11-99 : GG ; PRO19603 Add Redraw( area ) method
66 -> Don't increase too much the ZSize.
67 -> Initialize correctly the Z clipping and D cueing
69 IMP100701 : SZV ; Add ToPixMap() method
73 About FitAll() multiple. This probleme is caused by missing
74 precision of transformation matrices. If it is supposed that
75 projection is made in the plane (U,V), there is a difference
76 after several Zoom - compared to the exact value (cf ZoomX).
77 Don't forget that the matrices work in float and not in double.
78 To solve the problem (for lack of a better solution) I make 2 passes.
80 ************************************************************************/
82 //GER61351 //GG_15/12/99 Add SetBackgroundColor() and BackgroundColor() methods
85 #define IMP240100 //GG
86 // -> Remove PixToRef() method ,use
87 // instead the equivalent Convert() method.
88 // -> Rename RefToPix() to Convert() method.
89 // -> Remove the grid computation in Convert()
90 // method. Use instead the NEW ConvertToGrid() methods.
91 // Reason is the Convert() method is call by
92 // StdSelect_ViewSelector3d_Pick() from
93 // AIS_InteractiveContext() and it's not possible
94 // to select an object vertex when the grid is active!
95 // -> Remove grid echo marker definition
96 // (reported in the viewer)
97 // -> Add SetProjModel() methods.
99 #define G003 //EUG 04-10-99
100 // -> computed mode management
101 // Add SetComputedMode(..) method
102 // -> animation mode management
103 // Add SetAnimationMode()
104 // -> backfacing management
105 // Add SetBackFacingModel() method
107 #define G004 //VKH 15-11-99
108 // -> Add Dump() methods
109 // -> GG 07/03/00 Use the new MMSize()
110 // method from Aspect_Window class.
112 #define IMP210200 //GG Add Transparency() method
114 #define IMP250200 //GG With SetDepth() method, when the requested
116 // move the view ref point and the eye,instead
119 #define IMP020300 //GG Don't use ZFitAll in during Rotation
120 // for perf improvment
122 #define IMP210600 //GG Avoid to have infinite loop when call Rotation() method
123 // without call before StartRotation().
124 // This problem occurs when CTRL MB3 is maintain press betwwen 2 views.
126 #define IMP250900 //GG Enable rotation around screen Z axis when
127 // rotation begin far the center of the screen.
128 // Thanks to Patrick REGINSTER (SAMTECH)
129 // GG 21/12/00 Due to a regression on the previous specifications
130 // this new functionnality is right now deactivated
131 // by default (see StartRotation(...,zRotationThreshold)
134 #define BUC60952 //GG Enable to rotate around the view axis
135 // and the required view point
137 #define RIC120302 //GG Add a NEW SetWindow method which enable
138 // to connect a graphic widget and context to OGL.
140 #define IMP260302 //GG To avoid conflicting in Window destructor
141 // nullify this handle in Remove method
143 #define OCC280 //SAV fix for FitAll problem in the perspective view.
145 #define OCC1188 //SAV Added methods to set background image
147 /*----------------------------------------------------------------------*/
152 #include <Standard_TypeMismatch.hxx>
153 #include <Visual3d_ViewManager.hxx>
154 #include <Visual3d_Light.hxx>
155 #include <Visual3d_ClipPlane.hxx>
156 #include <Graphic3d_Structure.hxx>
157 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
158 #include <Graphic3d_MapOfStructure.hxx>
159 #include <Graphic3d_TextureEnv.hxx>
160 #include <Image_AlienPixMap.hxx>
162 #include <V3d_View.ixx>
163 #include <Viewer_BadValue.hxx>
164 #include <Standard_ShortReal.hxx>
165 #include <gp_Dir.hxx>
166 #include <TColStd_Array2OfReal.hxx>
167 #include <Visual3d_TransientManager.hxx>
168 #include <Precision.hxx>
171 #include <Graphic3d_AspectMarker3d.hxx>
174 #include <Aspect_GenericColorMap.hxx>
175 #include <Aspect_TypeMap.hxx>
176 #include <Aspect_WidthMap.hxx>
177 #include <Aspect_MarkMap.hxx>
178 #include <Aspect_FontMap.hxx>
179 #include <PlotMgt_ImageDriver.hxx>
180 #include <TColStd_HSequenceOfInteger.hxx>
182 # include <WNT_WDriver.hxx>
184 # include <Xw_Driver.hxx>
188 # define V3d_FLAG_ANIMATION 0x00000001
189 # define V3d_FLAG_DEGENERATION 0x00000002
190 # define V3d_FLAG_COMPUTATION 0x00000004
194 #include <OSD_Timer.hxx>
195 static OSD_Timer FullTimer;
198 #include <OSD_Environment.hxx>
200 /*----------------------------------------------------------------------*/
206 #define DEUXPI (2. * M_PI)
208 /*----------------------------------------------------------------------*/
210 * Local data definitions
214 static Standard_Real MyXwindowCenter ;
215 static Standard_Real MyYwindowCenter ;
216 static Standard_Real MyWindowWidth ;
217 static Standard_Real MyWindowHeight ;
221 static Graphic3d_Vector MyXscreenAxis ;
222 static Graphic3d_Vector MyYscreenAxis ;
223 static Graphic3d_Vector MyZscreenAxis ;
224 static Graphic3d_Vector MyViewReferencePlane ;
225 static Graphic3d_Vector MyViewReferenceUp ;
226 static Graphic3d_Vector MyViewAxis ;
227 static Graphic3d_Vertex MyViewReferencePoint ;
228 static Graphic3d_Vertex MyGravityReferencePoint ;
229 static Graphic3d_Vertex MyProjReferencePoint ;
231 static Graphic3d_Vector& _MyXscreenAxis() {
232 static Graphic3d_Vector MyXscreenAxis;
233 return MyXscreenAxis;
235 #define MyXscreenAxis _MyXscreenAxis()
237 static Graphic3d_Vector& _MyYscreenAxis() {
238 static Graphic3d_Vector MyYscreenAxis;
239 return MyYscreenAxis;
241 #define MyYscreenAxis _MyYscreenAxis()
243 static Graphic3d_Vector& _MyZscreenAxis() {
244 static Graphic3d_Vector MyZscreenAxis;
245 return MyZscreenAxis;
247 #define MyZscreenAxis _MyZscreenAxis()
249 static Graphic3d_Vector& _MyViewReferencePlane() {
250 static Graphic3d_Vector MyViewReferencePlane;
251 return MyViewReferencePlane;
253 #define MyViewReferencePlane _MyViewReferencePlane()
255 static Graphic3d_Vector& _MyViewReferenceUp() {
256 static Graphic3d_Vector MyViewReferenceUp;
257 return MyViewReferenceUp;
259 #define MyViewReferenceUp _MyViewReferenceUp()
261 static Graphic3d_Vector& _MyViewAxis() {
262 static Graphic3d_Vector MyViewAxis;
265 #define MyViewAxis _MyViewAxis()
267 static Graphic3d_Vertex& _MyViewReferencePoint() {
268 static Graphic3d_Vertex MyViewReferencePoint;
269 return MyViewReferencePoint;
271 #define MyViewReferencePoint _MyViewReferencePoint()
273 static Graphic3d_Vertex& _MyGravityReferencePoint() {
274 static Graphic3d_Vertex MyGravityReferencePoint;
275 return MyGravityReferencePoint;
277 #define MyGravityReferencePoint _MyGravityReferencePoint()
279 static Graphic3d_Vertex& _MyProjReferencePoint() {
280 static Graphic3d_Vertex MyProjReferencePoint;
281 return MyProjReferencePoint;
283 #define MyProjReferencePoint _MyProjReferencePoint()
286 /*----------------------------------------------------------------------*/
289 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
291 MyViewer(VM.operator->()),
295 myActiveLightsIterator(),
296 myActivePlanesIterator(),
297 SwitchSetFront(Standard_False),
298 MyTrsf (1, 4, 1, 4), // S3892
299 MyProjModel(V3d_TPM_SCREEN)
301 myImmediateUpdate = Standard_False;
302 MyView = new Visual3d_View(MyViewer->Viewer());
304 // { Begin to retrieve the definition from ViewContext.
305 // Step MyViewContext = MyView->Context() ;
306 // to permit MyView->SetContext to compare
307 // the old and the new context.
308 // No problem for MyViewMapping, MyViewOrientation
309 // as MyView->SetViewMapping and MyView->SetViewOrientation
310 // don't try to optimize the modifications introduced to
311 // viewmapping and vieworientation.
314 if ((MyView->Context ()).AliasingIsOn ())
315 MyViewContext.SetAliasingOn ();
317 MyViewContext.SetAliasingOff ();
320 MyViewContext.SetDepthCueingBackPlane
321 ((MyView->Context ()).DepthCueingBackPlane ());
322 MyViewContext.SetDepthCueingFrontPlane
323 ((MyView->Context ()).DepthCueingFrontPlane ());
325 if ((MyView->Context ()).DepthCueingIsOn ())
326 MyViewContext.SetDepthCueingOn ();
328 MyViewContext.SetDepthCueingOff ();
331 MyViewContext.SetZClippingBackPlane
332 ((MyView->Context ()).ZClippingBackPlane ());
333 MyViewContext.SetZClippingFrontPlane
334 ((MyView->Context ()).ZClippingFrontPlane ());
336 if ((MyView->Context ()).FrontZClippingIsOn ())
337 MyViewContext.SetFrontZClippingOn ();
339 MyViewContext.SetFrontZClippingOff ();
341 if ((MyView->Context ()).BackZClippingIsOn ())
342 MyViewContext.SetBackZClippingOn ();
344 MyViewContext.SetBackZClippingOff ();
346 // Visualisation and Shading Model
347 MyViewContext.SetModel ((MyView->Context ()).Model ());
348 MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
351 MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
352 MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
353 // } End of retrieval of the definition of ViewContext.
355 MyViewMapping = MyView->ViewMapping() ;
356 MyViewOrientation = MyView->ViewOrientation() ;
357 MyBackground = VM->GetBackgroundColor() ;
358 MyGradientBackground = VM->GetGradientBackground() ;
360 SetAxis(0.,0.,0.,1.,1.,1.) ;
361 SetVisualization(VM->DefaultVisualization()) ;
362 SetShadingModel(VM->DefaultShadingModel()) ;
363 SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
366 SetProj(VM->DefaultViewProj()) ;
367 SetSize(VM->DefaultViewSize()) ;
368 Standard_Real zsize = VM->DefaultViewSize();
369 SetZSize(2.*zsize+zsize*Zmargin) ;
370 SetZClippingDepth(0.);
371 SetZClippingWidth(zsize);
373 SetZCueingWidth(zsize);
374 SetDepth(VM->DefaultViewSize()/2.) ;
376 SetViewMappingDefault();
379 myImmediateUpdate = Standard_True;
386 MyAnimationFlags = 0;
390 MyTransparencyFlag = Standard_False;
394 /*----------------------------------------------------------------------*/
396 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
398 MyViewer(VM.operator->()),
402 myActiveLightsIterator(),
403 myActivePlanesIterator(),
404 SwitchSetFront(Standard_False),
405 MyTrsf (1, 4, 1, 4), // S3892
406 MyProjModel(V3d_TPM_SCREEN)
408 Handle(Visual3d_View) FromView = V->View() ;
410 myImmediateUpdate = Standard_False;
411 MyView = new Visual3d_View(MyViewer->Viewer());
413 for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){
414 MyActiveLights.Append(V->ActiveLight());}
415 for (V->InitActivePlanes();V->MoreActivePlanes();V->NextActivePlanes()){
416 MyActivePlanes.Append(V->ActivePlane());}
418 MyViewContext = FromView->Context() ;
420 MyViewMapping = FromView->ViewMapping() ;
421 MyViewOrientation = FromView->ViewOrientation() ;
422 MyBackground = FromView->Background() ;
423 MyGradientBackground = FromView->GradientBackground();
425 MyView->SetContext(MyViewContext) ;
427 SetAxis(0.,0.,0.,1.,1.,1.) ;
430 myImmediateUpdate = Standard_True;
433 MyAnimationFlags = 0;
437 /*----------------------------------------------------------------------*/
441 void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
442 const Handle(V3d_View)& aPreviousView,
443 const Standard_Integer x1,
444 const Standard_Integer y1,
445 const Standard_Integer x2,
446 const Standard_Integer y2)
448 if( !MyView->IsDefined() ) {
449 Standard_Real a,b,c,d;
450 aPreviousView->Convert(x1,y1,a,b);
451 aPreviousView->Convert(x2,y2,c,d);
452 MyView->SetWindow(TheWindow) ;
453 FitAll(TheWindow,a,b,c,d);
454 MyView->SetContext(MyViewContext) ;
455 MyView->SetViewOrientation(MyViewOrientation) ;
456 MyView->SetBackground(MyBackground) ;
457 MyViewer->SetViewOn(this) ;
458 MyWindow = TheWindow;
460 SetViewMappingDefault();
464 /*----------------------------------------------------------------------*/
466 void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
468 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
469 "V3d_View::SetWindow, window of view already defined");
471 MyView->SetWindow(TheWindow) ;
472 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
473 // calling Redraw(). Otherwise it is impossible to call certain methods of
474 // V3d_View like Convert() inside the context of Redraw(),
475 // particularly in class NIS_View.
476 MyWindow = TheWindow;
477 // SetWindow carries out SetRatio and modifies
478 // ViewMapping and ViewMappingDefault of MyView.
479 MyViewMapping = MyView->ViewMapping() ;
480 MyView->SetContext(MyViewContext) ;
481 MyView->SetViewMapping(MyViewMapping) ;
482 MyView->SetViewOrientation(MyViewOrientation) ;
483 MyView->SetBackground(MyBackground) ;
484 MyViewer->SetViewOn(this) ;
489 /*----------------------------------------------------------------------*/
491 void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
492 const Aspect_RenderingContext aContext,
493 const Aspect_GraphicCallbackProc& aDisplayCB,
494 const Standard_Address aClientData)
496 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
497 "V3d_View::SetWindow, "
498 "window of view already defined");
499 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
500 // calling Redraw(). Otherwise it is impossible to call certain methods of
501 // V3d_View like Convert() inside the context of Redraw(),
502 // particularly in class NIS_View.
504 MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
505 MyViewMapping = MyView->ViewMapping() ;
506 MyView->SetContext(MyViewContext) ;
507 MyView->SetViewMapping(MyViewMapping) ;
508 MyView->SetViewOrientation(MyViewOrientation) ;
509 MyView->SetBackground(MyBackground) ;
510 MyViewer->SetViewOn(this) ;
515 /*----------------------------------------------------------------------*/
517 void V3d_View::Remove() const
519 MyViewer->DelView (this);
521 Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
525 /*----------------------------------------------------------------------*/
527 void V3d_View::Update() const
529 if( MyView->IsDefined() ) MyView->Update() ;
532 /*----------------------------------------------------------------------*/
534 void V3d_View::Redraw() const
536 if( MyView->IsDefined() ) MyView->Redraw() ;
539 /*----------------------------------------------------------------------*/
541 void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
542 const Standard_Integer width,const Standard_Integer height) const
544 if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
547 /*----------------------------------------------------------------------*/
549 Standard_Boolean V3d_View::IsEmpty() const
551 Standard_Boolean TheStatus = Standard_True ;
552 if( MyView->IsDefined() ) {
553 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
554 if( Nstruct > 0 ) TheStatus = Standard_False ;
559 /*----------------------------------------------------------------------*/
561 void V3d_View::UpdateLights() const
563 MyView->SetContext(MyViewContext);
567 /*----------------------------------------------------------------------*/
569 void V3d_View::DoMapping()
571 if( MyView->IsDefined() ) {
572 (MyView->Window())->DoMapping() ;
576 /*----------------------------------------------------------------------*/
578 void V3d_View::MustBeResized()
580 if ( !MyLayerMgr.IsNull() )
581 MyLayerMgr->Resized();
583 if( MyView->IsDefined() ) {
585 MyViewMapping = MyView->ViewMapping();
590 /*----------------------------------------------------------------------*/
592 void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
594 Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
595 Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 );
596 Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 );
598 Quantity_Color C( V1, V2, V3, Type );
599 SetBackgroundColor( C );
602 /*----------------------------------------------------------------------*/
604 void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
606 MyBackground.SetColor( Color );
607 if ( MyView->IsDefined() )
608 MyView->SetBackground( MyBackground );
610 if ( !MyLayerMgr.IsNull() )
611 MyLayerMgr->Resized();
614 /*----------------------------------------------------------------------*/
616 void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
618 Quantity_Color C( Name );
619 SetBackgroundColor( C );
622 /*----------------------------------------------------------------------*/
624 void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
625 const Quantity_Color& Color2,
626 const Aspect_GradientFillMethod FillStyle,
627 const Standard_Boolean status)
629 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
630 if ( MyView->IsDefined() )
631 MyView->SetGradientBackground( MyGradientBackground, status );
634 /*----------------------------------------------------------------------*/
636 void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
637 const Quantity_NameOfColor Color2,
638 const Aspect_GradientFillMethod FillStyle,
639 const Standard_Boolean status )
641 Quantity_Color C1( Color1 );
642 Quantity_Color C2( Color2 );
643 MyGradientBackground.SetColors( C1, C2, FillStyle );
644 if ( MyView->IsDefined() )
645 MyView->SetGradientBackground( MyGradientBackground, status );
648 /*----------------------------------------------------------------------*/
650 void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
651 const Standard_Boolean update)
653 Quantity_Color Color1, Color2;
654 MyGradientBackground.Colors( Color1, Color2 );
655 MyGradientBackground.SetColors( Color1, Color2, FillStyle );
656 if( MyView->IsDefined() )
657 MyView->SetBgGradientStyle( FillStyle, update ) ;
660 /*----------------------------------------------------------------------*/
662 void V3d_View::SetBackgroundImage( const Standard_CString FileName,
663 const Aspect_FillMethod FillStyle,
664 const Standard_Boolean update )
667 if( MyView->IsDefined() )
668 MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
672 /*----------------------------------------------------------------------*/
674 void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
675 const Standard_Boolean update )
678 if( MyView->IsDefined() )
679 MyView->SetBgImageStyle( FillStyle, update ) ;
683 /*----------------------------------------------------------------------*/
685 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)
687 Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
689 D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ;
690 Viewer_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis");
691 Nx /= D ; Ny /= D ; Nz /= D ;
692 MyDefaultViewPoint.SetCoord(X,Y,Z) ;
693 MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
694 MyDefaultViewAxis.Normalize() ;
697 /*----------------------------------------------------------------------*/
699 void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model)
701 MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
702 MyView->SetContext(MyViewContext) ;
705 /*----------------------------------------------------------------------*/
707 void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model)
709 MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
710 MyView->SetContext(MyViewContext) ;
713 /*----------------------------------------------------------------------*/
715 void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
717 MyViewContext.SetTextureEnv(ATexture) ;
718 MyView->SetContext(MyViewContext) ;
721 /*----------------------------------------------------------------------*/
723 void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode)
725 MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
726 MyView->SetContext(MyViewContext) ;
729 /*----------------------------------------------------------------------*/
731 void V3d_View::SetFront()
733 gp_Ax3 a = MyViewer->PrivilegedPlane();
734 Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
736 a.Direction().Coord(vx,vy,vz);
737 a.YDirection().Coord(xu,yu,zu);
738 a.Location().Coord(xo,yo,zo);
741 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
743 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
745 SwitchSetFront = !SwitchSetFront;
747 MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
748 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
750 MyView->SetViewOrientation(MyViewOrientation) ;
755 /*----------------------------------------------------------------------*/
757 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
759 Standard_Real Ax = ax ;
760 Standard_Real Ay = ay ;
761 Standard_Real Az = az ;
762 Graphic3d_Vector Vpn,Vup ;
763 TColStd_Array2OfReal Matrix(0,3,0,3) ;
764 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
766 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
767 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
768 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
769 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
770 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
771 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
774 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
775 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
776 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
777 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
778 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
779 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
784 if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
786 RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
787 Multiply(Matrix, Rmatrix, Matrix);
790 RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
791 Multiply(Matrix, Rmatrix, Matrix);
793 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
794 MyViewOrientation.SetViewReferencePlane(Vpn) ;
795 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
796 MyViewOrientation.SetViewReferenceUp(Vup) ;
797 MyView->SetViewOrientation(MyViewOrientation) ;
804 /*----------------------------------------------------------------------*/
806 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
807 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
809 Standard_Real Ax = ax ;
810 Standard_Real Ay = ay ;
811 Standard_Real Az = az ;
812 Graphic3d_Vector Vpn,Vup ;
813 Graphic3d_Vertex Vrp ;
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 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
826 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
827 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
828 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
829 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
830 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
831 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
836 if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
838 RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
839 Multiply(Matrix, Rmatrix, Matrix);
842 RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
843 Multiply(Matrix, Rmatrix, Matrix);
845 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
846 MyViewOrientation.SetViewReferencePoint(Vrp) ;
847 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
848 MyViewOrientation.SetViewReferencePlane(Vpn) ;
849 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
850 MyViewOrientation.SetViewReferenceUp(Vup) ;
851 MyView->SetViewOrientation(MyViewOrientation) ;
858 /*----------------------------------------------------------------------*/
860 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
864 Rotate(angle,0.,0.,Start);
867 Rotate(0.,angle,0.,Start);
870 Rotate(0.,0.,angle,Start);
875 /*----------------------------------------------------------------------*/
877 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
878 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
880 Standard_Real Angle = angle ;
881 Graphic3d_Vector Vpn,Vup ;
882 Graphic3d_Vertex Vrp ;
883 TColStd_Array2OfReal Matrix(0,3,0,3) ;
885 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
886 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
889 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
890 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
891 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
892 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
895 MyViewAxis.SetCoord(1.,0.,0.) ;
898 MyViewAxis.SetCoord(0.,1.,0.) ;
901 MyViewAxis.SetCoord(0.,0.,1.) ;
906 RotAxis(MyGravityReferencePoint,MyViewAxis,Angle,Matrix) ;
907 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
908 MyViewOrientation.SetViewReferencePoint(Vrp) ;
909 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
910 MyViewOrientation.SetViewReferencePlane(Vpn) ;
911 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
912 MyViewOrientation.SetViewReferenceUp(Vup) ;
913 MyView->SetViewOrientation(MyViewOrientation) ;
920 /*----------------------------------------------------------------------*/
922 void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
924 Standard_Real Angle = angle ;
925 Graphic3d_Vector Vpn,Vup ;
926 TColStd_Array2OfReal Matrix(0,3,0,3) ;
928 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
929 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
932 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
933 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
934 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
937 RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
939 Graphic3d_Vertex Vrp ;
940 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
941 MyViewOrientation.SetViewReferencePoint(Vrp) ;
943 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
944 MyViewOrientation.SetViewReferencePlane(Vpn) ;
945 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
946 MyViewOrientation.SetViewReferenceUp(Vup) ;
947 MyView->SetViewOrientation(MyViewOrientation) ;
954 /*----------------------------------------------------------------------*/
956 void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
958 Standard_Real Ax = ax ;
959 Standard_Real Ay = ay ;
960 Standard_Real Az = az ;
961 Graphic3d_Vertex Vrp,Eye ;
962 Graphic3d_Vector Vpn,Vup ;
963 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
964 TColStd_Array2OfReal Matrix(0,3,0,3) ;
965 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
967 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
968 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
969 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
970 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
971 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
972 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
975 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
976 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
977 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
978 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
979 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
980 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
981 Viewer_BadValue::Raise ("V3d_View::Turn, alignment of Eye,At,Up");
985 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
986 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
987 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
988 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
989 Eye.SetCoord(Xeye,Yeye,Zeye) ;
990 if( Ax != 0. ) RotAxis(Eye,MyYscreenAxis,-Ax,Matrix) ;
992 RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
993 Multiply(Matrix, Rmatrix, Matrix);
996 RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
997 Multiply(Matrix, Rmatrix, Matrix);
999 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1000 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1001 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1002 MyViewOrientation.SetViewReferenceUp(Vpn) ;
1003 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1004 MyViewOrientation.SetViewReferenceUp(Vup) ;
1005 MyView->SetViewOrientation(MyViewOrientation) ;
1009 // Check ZClipping planes
1010 Standard_Real Zmax ;
1011 Vrp.Coord(Xat,Yat,Zat) ;
1012 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat) ;
1013 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1014 MyProjModel == V3d_TPM_SCREEN ) {
1015 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1021 /*----------------------------------------------------------------------*/
1023 void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1027 Turn(angle,0.,0.,Start);
1030 Turn(0.,angle,0.,Start);
1033 Turn(0.,0.,angle,Start);
1038 void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
1040 Standard_Real Angle = angle ;
1041 Graphic3d_Vertex Vrp,Eye ;
1042 Graphic3d_Vector Vpn,Vup ;
1043 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1044 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1046 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1047 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1050 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1051 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1052 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1053 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1055 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1056 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1057 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1058 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1059 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1060 RotAxis(Eye,MyDefaultViewAxis,Angle,Matrix) ;
1061 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1062 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1063 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1064 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1065 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1066 MyViewOrientation.SetViewReferenceUp(Vup) ;
1067 MyView->SetViewOrientation(MyViewOrientation) ;
1071 // Check ZClipping planes
1072 Standard_Real Zmax ;
1073 Vrp.Coord(Xat,Yat,Zat) ;
1074 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat ) ;
1075 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1076 MyProjModel == V3d_TPM_SCREEN ) {
1077 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1083 void V3d_View::SetTwist(const Standard_Real angle)
1085 Standard_Real Angle = angle ;
1086 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1087 Standard_Boolean TheStatus ;
1089 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1090 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1092 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1093 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1094 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1095 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1097 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1098 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1099 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1102 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1103 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1104 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1107 Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
1109 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1110 RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
1111 MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
1112 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1113 MyView->SetViewOrientation(MyViewOrientation) ;
1118 void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
1120 MyProjModel = aModel;
1123 V3d_TypeOfProjectionModel V3d_View::ProjModel() const
1129 void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1131 Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
1133 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1134 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1135 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1136 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1137 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1138 Xpn = X - Xat ; Ypn = Y - Yat ; Zpn = Z - Zat ;
1139 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1140 Viewer_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused");
1142 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1143 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1144 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1145 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1146 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1148 Standard_Boolean update = myImmediateUpdate;
1149 myImmediateUpdate = Standard_False;
1150 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1151 //FMN desactivation temp SetTwist(Angle) ;
1153 MyView->SetViewOrientation(MyViewOrientation) ;
1154 MyView->SetViewMapping(MyViewMapping) ;
1161 // Check ZClipping planes
1162 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1163 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1164 MyProjModel == V3d_TPM_SCREEN ) {
1165 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1167 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1168 MyView->SetViewMapping(MyViewMapping);
1171 myImmediateUpdate = update;
1175 void V3d_View::SetDepth(const Standard_Real Depth)
1177 Standard_Real Xrp,Yrp,Zrp ;
1179 Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
1181 Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
1184 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1185 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1186 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1187 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1193 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1194 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1197 // Check ZClipping planes
1198 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
1199 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1200 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1202 if( Depth < 0. ) { // Move the view ref point instead of the eye.
1203 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1205 Xat = Xeye - Xpn*Zrp ; Yat = Yeye - Ypn*Zrp ; Zat = Zeye - Zpn*Zrp;
1206 MyViewReferencePoint.SetCoord(Xat,Yat,Zat) ;
1207 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1208 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1209 MyView->SetViewOrientation(MyViewOrientation);
1213 MyView->SetViewMapping(MyViewMapping) ;
1216 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1217 Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1219 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1220 MyProjModel == V3d_TPM_SCREEN ) {
1221 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1223 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1227 MyView->SetViewMapping(MyViewMapping) ;
1235 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1237 Standard_Real Angle ;
1239 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1240 "V3d_View::SetProj, null projection vector");
1243 MyViewReferencePlane.SetCoord(Vx,Vy,Vz) ;
1244 MyViewReferencePlane.Normalize() ;
1245 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1246 Standard_Boolean update = myImmediateUpdate;
1247 myImmediateUpdate = Standard_False;
1248 if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ;
1252 myImmediateUpdate = update;
1256 void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation )
1258 MyViewReferencePlane = V3d::GetProjAxis(Orientation) ;
1259 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1260 // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955
1261 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex (0.0f, 0.0f, 0.0f));
1262 Standard_Real Xpn=0;
1263 Standard_Real Ypn=0;
1264 Standard_Real Zpn=0;
1266 switch (Orientation) {
1283 void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1285 Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
1286 Standard_Real Xeye,Yeye,Zeye ;
1289 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1290 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1291 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1292 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1293 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1294 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1295 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1296 Xpn = Xeye - X ; Ypn = Yeye - Y ; Zpn = Zeye - Z ;
1297 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1298 Viewer_BadValue_Raise_if( Zrp <= 0.,
1299 "V3d_View::SetAt, Eye,At are Confused");
1301 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1302 MyViewReferencePoint.SetCoord(X,Y,Z) ;
1303 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1304 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1305 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1306 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1307 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1308 Standard_Boolean update = myImmediateUpdate;
1309 myImmediateUpdate = Standard_False;
1310 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1311 //FMN desactivation temp SetTwist(Angle) ;
1313 MyView->SetViewOrientation(MyViewOrientation) ;
1314 MyView->SetViewMapping(MyViewMapping) ;
1319 MyView->SetViewMapping(MyViewMapping);
1323 // Check ZClipping planes
1324 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1325 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1326 MyProjModel == V3d_TPM_SCREEN ) {
1327 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1329 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1330 MyView->SetViewMapping(MyViewMapping);
1333 myImmediateUpdate = update;
1337 void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz)
1339 Standard_Boolean TheStatus ;
1340 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
1341 "V3d_View::SetUp, nullUp vector");
1343 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1344 MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
1345 MyViewReferenceUp.Normalize() ;
1346 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1347 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1349 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1350 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1351 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1354 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1355 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1356 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1359 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1360 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1361 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1363 Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
1365 MyViewReferenceUp = MyYscreenAxis ;
1366 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1367 MyView->SetViewOrientation(MyViewOrientation) ;
1371 void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
1373 Standard_Boolean TheStatus ;
1375 MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
1376 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1377 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1378 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1380 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1381 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1382 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1385 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1386 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1387 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1390 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1391 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1392 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1394 Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
1396 MyViewReferenceUp = MyYscreenAxis ;
1397 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1398 MyView->SetViewOrientation(MyViewOrientation) ;
1402 void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
1404 MyViewOrientation = VO;
1405 MyView->SetViewOrientation(MyViewOrientation) ;
1409 void V3d_View::SetViewOrientationDefault()
1411 MyView->SetViewOrientation(MyViewOrientation) ;
1412 MyView->SetViewOrientationDefault() ;
1416 void V3d_View::ResetViewOrientation()
1418 MyView->ViewOrientationReset() ;
1419 MyViewOrientation = MyView->ViewOrientation() ;
1423 void V3d_View::Reset( const Standard_Boolean update )
1425 MyView->ViewOrientationReset() ;
1426 MyViewOrientation = MyView->ViewOrientation() ;
1427 MyView->ViewMappingReset();
1428 MyViewMapping = MyView->ViewMapping() ;
1431 SwitchSetFront = Standard_False;
1433 if( !myImmediateUpdate && update ) Update();
1439 void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
1441 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ;
1442 Viewer_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
1445 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1446 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1447 MyXwindowCenter = (Umin + Umax)/2. ;
1448 MyYwindowCenter = (Vmin + Vmax)/2. ;
1449 MyWindowWidth = Abs(Umax - Umin) ;
1450 MyWindowHeight = Abs(Vmax - Vmin) ;
1451 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1452 "V3d_View::Panning, Window Size is NULL");
1454 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1455 Xrp = MyXwindowCenter - Dx ;
1456 Yrp = MyYwindowCenter - Dy ;
1457 Dxv = MyWindowWidth/aZoomFactor ; Dyv = MyWindowHeight/aZoomFactor ;
1458 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1459 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1460 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1461 if( MyType != V3d_PERSPECTIVE ) {
1462 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1463 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1465 MyView->SetViewMapping(MyViewMapping) ;
1469 void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y)
1476 void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc)
1478 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
1480 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1481 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1482 MyXwindowCenter = Xrp = Xc ; MyYwindowCenter = Yrp = Yc ;
1483 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1484 MyWindowWidth = Abs(Umax - Umin) ; MyWindowHeight = Abs(Vmax - Vmin) ;
1485 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1486 "V3d_View::SetCenter, Window Size is NULL");
1488 Umin = Xc - MyWindowWidth/2. ; Vmin = Yc - MyWindowHeight/2. ;
1489 Umax = Xc + MyWindowWidth/2. ; Vmax = Yc + MyWindowHeight/2. ;
1490 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1491 if( MyType != V3d_PERSPECTIVE ) {
1492 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1493 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1495 MyView->SetViewMapping(MyViewMapping) ;
1499 void V3d_View::SetSize(const Standard_Real Size)
1501 Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
1503 Viewer_BadValue_Raise_if( Size <= 0.,
1504 "V3d_View::SetSize, Window Size is NULL");
1507 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1508 MyWindowWidth = Abs(Umax - Umin) ;
1509 MyWindowHeight = Abs(Vmax - Vmin) ;
1510 MyXwindowCenter = (Umin + Umax)/2. ;
1511 MyYwindowCenter = (Vmin + Vmax)/2. ;
1512 Rap = MyWindowWidth/MyWindowHeight ;
1513 if( MyWindowWidth >= MyWindowHeight ) {
1514 MyWindowWidth = Size ; MyWindowHeight = Size/Rap ;
1516 MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
1518 Umin = MyXwindowCenter - MyWindowWidth/2. ;
1519 Vmin = MyYwindowCenter - MyWindowHeight/2. ;
1520 Umax = MyXwindowCenter + MyWindowWidth/2. ;
1521 Vmax = MyYwindowCenter + MyWindowHeight/2. ;
1522 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1523 MyView->SetViewMapping(MyViewMapping) ;
1527 void V3d_View::SetZSize(const Standard_Real Size)
1529 Standard_Real Zmax = Size/2.;
1533 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye;
1534 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1535 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1536 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1537 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat;
1538 Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1539 if( Zmax <= MyViewMapping.FrontPlaneDistance() ) return;
1542 Viewer_BadValue_Raise_if( Size <= 0.,
1543 "V3d_View::SetZSize, Window ZSize is NULL");
1546 Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
1547 Standard_Real Back = MyViewContext.ZClippingBackPlane() ;
1548 Standard_Real focale= Focale();
1550 MyViewMapping.SetFrontPlaneDistance(Zmax) ;
1551 MyViewMapping.SetBackPlaneDistance(-Zmax) ;
1554 if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
1555 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
1558 MyView->SetViewMapping(MyViewMapping) ;
1559 if( MyViewContext.FrontZClippingIsOn() ||
1560 MyViewContext.BackZClippingIsOn() )
1562 MyViewContext.SetZClippingFrontPlane(Front) ;
1563 MyViewContext.SetZClippingBackPlane(Back) ;
1564 MyView->SetContext(MyViewContext) ;
1568 void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
1570 Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
1571 Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
1574 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1575 MyXwindowCenter = (Umin + Umax)/2. ;
1576 MyYwindowCenter = (Vmin + Vmax)/2. ;
1577 MyWindowWidth = Abs(Umax - Umin) ;
1578 MyWindowHeight = Abs(Vmax - Vmin) ;
1581 // ensure that zoom will not be too small or too big
1582 Standard_Real coef = Coef;
1583 if ( MyWindowWidth < coef * Precision::Confusion() )
1584 coef = MyWindowWidth / Precision::Confusion();
1585 else if ( MyWindowWidth > coef * 1e12 )
1586 coef = MyWindowWidth / 1e12;
1587 if ( MyWindowHeight < coef * Precision::Confusion() )
1588 coef = MyWindowHeight / Precision::Confusion();
1589 else if ( MyWindowHeight > coef * 1e12 )
1590 coef = MyWindowHeight / 1e12;
1592 Dxv = MyWindowWidth/coef;
1593 Dyv = MyWindowHeight/coef;
1594 Umin = MyXwindowCenter - Dxv/2. ; Umax = MyXwindowCenter + Dxv/2. ;
1595 Vmin = MyYwindowCenter - Dyv/2. ; Vmax = MyYwindowCenter + Dyv/2. ;
1596 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1597 MyView->SetViewMapping(MyViewMapping) ;
1601 void V3d_View::SetScale( const Standard_Real Coef )
1603 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
1604 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
1606 Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1608 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1609 Dxv = Abs(Umax - Umin) ; Dyv = Abs(Vmax - Vmin) ;
1610 Dxv /= Coef ; Dyv /= Coef ;
1611 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1612 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
1613 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1614 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1615 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1616 MyView->SetViewMapping(MyViewMapping) ;
1620 void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
1622 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1623 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1624 Viewer_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
1626 MyViewOrientation.SetAxialScale( Sx, Sy, Sz );
1627 Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode();
1628 MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP);
1629 MyView->SetViewOrientation(MyViewOrientation);
1630 MyView->ViewManager()->SetUpdateMode(updateMode);
1632 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1634 Standard_Real LIM = ShortRealLast() -1.;
1635 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1636 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1640 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1641 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1642 Umax = Max(Umin,Umax) ; Vmax = Max(Vmin,Vmax) ;
1643 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1644 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1645 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1646 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1647 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1648 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1649 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1650 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1651 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1652 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1653 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1654 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1655 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1656 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1657 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1658 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1659 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1660 Umax = Max(Umax,Vmax) ;
1661 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1662 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1663 Wmax = Max(Abs(Umax),Abs(Wmax)) ;
1666 SetZSize(2.*Wmax + Wmax) ;
1670 void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
1671 const Standard_Boolean update)
1673 Standard_Real Umin, Umax, Vmin, Vmax, Xrp, Yrp, Zrp, U, V, W, U1, V1, W1;
1674 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
1675 Standard_Real DxvOld, DyvOld, DxvNew, DyvNew;
1676 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures();
1678 if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
1686 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1687 MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
1688 if (MyView->IsDefined())
1690 Standard_Integer Xpixel, Ypixel;
1691 MyWindow->Size (Xpixel, Ypixel);
1697 MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
1698 DxvOld = Abs (Umax - Umin);
1699 DyvOld = Abs (Vmax - Vmin);
1701 if ((DxvOld == 0.0) || (DyvOld == 0.0))
1706 Standard_Real aWinRatio = DxvOld / DyvOld;
1708 // retrieve min / max values for current displayed objects
1709 MyView->MinMaxValues (Xmin, Ymin, Zmin,
1712 Standard_Real LIM = ShortRealLast() - 1.0;
1713 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1714 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM)
1722 // eliminate fluctuations between sequential FitAll() calls
1723 MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0);
1724 if (MyType != V3d_PERSPECTIVE)
1726 MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
1727 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1729 MyView->SetViewMapping (MyViewMapping);
1731 // iterate 2 times to find optimal view plane size
1732 // (use view plane values computed on previous iteration)
1733 for (Standard_Integer aIteration = 2; aIteration > 0; --aIteration)
1735 MyView->Projects (Xmin, Ymin, Zmin, U, V, W);
1736 MyView->Projects (Xmax, Ymax, Zmax, U1, V1, W1);
1737 Umin = Min (U, U1); Umax = Max (U, U1);
1738 Vmin = Min (V, V1); Vmax = Max (V, V1);
1740 MyView->Projects (Xmin, Ymin, Zmax, U, V, W);
1741 Umin = Min (U, Umin); Umax = Max (U, Umax);
1742 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1744 MyView->Projects (Xmax, Ymin, Zmax, U, V, W);
1745 Umin = Min (U, Umin); Umax = Max (U, Umax);
1746 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1748 MyView->Projects (Xmax, Ymin, Zmin, U, V, W);
1749 Umin = Min (U, Umin); Umax = Max (U, Umax);
1750 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1752 MyView->Projects (Xmax, Ymax, Zmin, U, V, W);
1753 Umin = Min (U, Umin); Umax = Max (U, Umax);
1754 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1756 MyView->Projects (Xmin, Ymax, Zmax, U, V, W);
1757 Umin = Min (U, Umin); Umax = Max (U, Umax);
1758 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1760 MyView->Projects (Xmin, Ymax, Zmin, U, V, W);
1761 Umin = Min (U, Umin); Umax = Max (U, Umax);
1762 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1764 DxvNew = Abs (Umax - Umin);
1765 DyvNew = Abs (Vmax - Vmin);
1767 if (DyvNew < 10.0 * Precision::Confusion())
1769 if (DxvNew < 10.0 * Precision::Confusion())
1771 // whole scene projected to point
1772 DxvNew = Max (Abs (Zmax - Zmin), (Max (Abs (Xmax - Xmin), Abs (Ymax - Ymin))));
1773 if (DxvNew < 10.0 * Precision::Confusion())
1775 // this is really just one (!) point and zooming has no any effect
1776 // just center the view
1782 // we look along some line
1783 // fit view like that to see whole scene on rotation
1784 DxvNew += Coef * DxvNew;
1785 DyvNew = DxvNew / aWinRatio;
1790 // whole scene projected to horizontal line
1791 DxvNew += Coef * DxvNew;
1792 DyvNew = DxvNew / aWinRatio;
1797 // general case (or DxvNew == 0.0 - vertical line)
1798 // safe original ratio
1799 Standard_Real aFitRatio = DxvNew / DyvNew;
1800 if (aFitRatio >= aWinRatio)
1802 DxvNew += Coef * DxvNew;
1803 DyvNew = DxvNew / aWinRatio;
1807 DyvNew += Coef * DyvNew;
1808 DxvNew = DyvNew * aWinRatio;
1813 Xrp = 0.5 * (Umin + Umax);
1814 Yrp = 0.5 * (Vmin + Vmax);
1816 // new window limits
1817 Umin = Xrp - 0.5 * DxvNew;
1818 Umax = Xrp + 0.5 * DxvNew;
1819 Vmin = Yrp - 0.5 * DyvNew;
1820 Vmax = Yrp + 0.5 * DyvNew;
1821 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
1823 if (MyType != V3d_PERSPECTIVE)
1826 MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
1827 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1829 MyView->SetViewMapping (MyViewMapping);
1843 if (!myImmediateUpdate && update)
1850 void V3d_View::ZFitAll(const Standard_Real Coef)
1852 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1853 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1855 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1857 if( MyType == V3d_PERSPECTIVE ) {
1862 if( (Nstruct <= 0) || (Coef < 0.) ) {
1867 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1869 Standard_Real LIM = ShortRealLast() -1.;
1870 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1871 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1877 // Case when view contains only a point
1878 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
1882 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1883 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1884 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1885 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1886 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1887 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1888 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1889 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1890 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1891 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1892 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1893 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1894 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1895 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1896 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1898 SetZSize(2.*Wmax + Coef * Wmax) ;
1903 void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
1904 const Quantity_Coefficient Margin)
1906 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
1907 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1908 Standard_Real Xrp,Yrp,Zrp,Dx,Dy,Dz,Size;
1910 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1912 if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
1917 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1918 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1920 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1922 Standard_Real LIM = ShortRealLast() -1.;
1923 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1924 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1929 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
1933 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
1934 MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
1935 Umin = Min(U,U1) ; Umax = Max(U,U1) ;
1936 Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
1937 Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
1938 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1939 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1940 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1941 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1942 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1943 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1944 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1945 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1946 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1947 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1948 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1949 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1950 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1951 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1952 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1953 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1954 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1955 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1956 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1957 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1958 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1959 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1960 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1961 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1964 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1965 Dz = 2.*Wmax + Margin * Wmax;
1967 // Compute depth value
1968 Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
1969 Dx += Margin * Dx; Dy += Margin * Dy;
1970 Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
1973 SetDepth( Aspect * Size / 2.);
1979 void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax)
1981 FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
1987 void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax)
1989 WindowFit(Xmin,Ymin,Xmax,Ymax);
1992 void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax)
1994 Standard_Real x1,y1,x2,y2;
1995 Convert(Xmin,Ymin,x1,y1);
1996 Convert(Xmax,Ymax,x2,y2);
1997 FitAll(x1,y1,x2,y2);
2000 void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
2003 // ajust view type according to mapping projection
2004 // NOTE: Might be dangerous, potentially conflicts with the C++ view class
2005 // (orthographic or perspective)! Use with care!
2006 if ( VM.Projection() == Visual3d_TOP_PERSPECTIVE )
2007 MyType = V3d_PERSPECTIVE;
2008 else MyType = V3d_ORTHOGRAPHIC;
2010 MyView->SetViewMapping(MyViewMapping) ;
2014 void V3d_View::SetViewMappingDefault()
2016 MyView->SetViewMapping(MyViewMapping) ;
2017 MyView->SetViewMappingDefault();
2021 void V3d_View::ResetViewMapping()
2023 MyView->ViewMappingReset();
2024 MyViewMapping = MyView->ViewMapping() ;
2033 Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
2035 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
2036 Standard_Integer Dxw,Dyw ;
2038 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2040 MyWindow->Size(Dxw,Dyw);
2041 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2043 Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
2048 void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const
2050 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Dyv ;
2051 Standard_Integer Dxw,Dyw ;
2053 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2055 MyWindow->Size(Dxw,Dyw);
2056 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2057 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
2058 Xv = Umin + Dxv*(Standard_Real)Xp/(Standard_Real)Dxw ;
2059 Yv = Vmin + Dyv*(Standard_Real)(Dyw-Yp)/(Standard_Real)Dyw ;
2062 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
2064 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2066 Standard_Integer Dxw, Dyw;
2067 MyWindow->Size(Dxw,Dyw);
2069 Standard_Real Umin,Umax,Vmin,Vmax;
2070 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2071 Standard_Real Dxv = Umax - Umin;
2072 return RealToInt ( Dxw * Vv / Dxv );
2075 void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
2077 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2079 Standard_Integer Dxw, Dyw;
2080 MyWindow->Size(Dxw,Dyw);
2082 Standard_Real Umin,Umax,Vmin,Vmax;
2083 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2084 Standard_Real Dxv = Umax - Umin;
2085 Standard_Real Dyv = Vmax - Vmin;
2087 // CAL 15/12/93 warning: double assigned to int
2088 Xp = RealToInt (Dxw*(Xv - Umin)/Dxv);
2089 // CAL 15/12/93 warning: double assigned to int
2090 Yp = Dyw - RealToInt (Dyw*(Yv - Vmin)/Dyv);
2093 void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2095 Graphic3d_Vertex Vrp ;
2096 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2099 if( MyViewer->Grid()->IsActive() ) {
2100 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2101 NewVrp.Coord(X,Y,Z) ;
2106 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
2108 Graphic3d_Vertex Vrp ;
2109 Graphic3d_Vector Proj ;
2110 (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
2112 Proj.Coord(Dx,Dy,Dz) ;
2114 if( MyViewer->Grid()->IsActive() ) {
2115 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2116 NewVrp.Coord(X,Y,Z) ;
2122 void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const
2124 Graphic3d_Vertex Vrp ;
2125 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2126 if( MyViewer->Grid()->IsActive() ) {
2127 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2128 NewVrp.Coord(Xg,Yg,Zg) ;
2130 Vrp.Coord(Xg,Yg,Zg) ;
2133 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
2135 if( MyViewer->Grid()->IsActive() ) {
2136 Graphic3d_Vertex Vrp(X,Y,Z) ;
2137 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2138 NewVrp.Coord(Xg,Yg,Zg) ;
2140 Xg = X; Yg = Y; Zg = Z;
2146 void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2148 Graphic3d_Vertex Vrp ;
2149 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2151 if( MyViewer->Grid()->IsActive() ) {
2152 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2153 NewVrp.Coord(X,Y,Z) ;
2159 void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const
2161 void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const
2164 Graphic3d_Vertex Vrp(X,Y,Z) ;
2165 (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
2168 void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
2170 if ( MyType != V3d_PERSPECTIVE )
2172 // use old implementation
2174 MyView->Projects( X, Y, Z, Xp, Yp, Zp );
2178 // NKV - Using raster projection
2179 Standard_Integer Xpx, Ypx;
2180 Convert(X, Y, Z, Xpx, Ypx);
2181 Convert(Xpx, Ypx, Xp, Yp);
2185 void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const
2187 Quantity_Color C = BackgroundColor() ;
2188 C.Values(V1,V2,V3,Type) ;
2191 Quantity_Color V3d_View::BackgroundColor() const
2193 return MyBackground.Color() ;
2196 void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const
2198 MyGradientBackground.Colors(Color1, Color2);
2201 Aspect_GradientBackground V3d_View::GradientBackground() const
2203 return MyGradientBackground;
2206 Standard_Real V3d_View::Scale() const
2208 Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
2209 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
2210 Standard_Real S = 0. ;
2212 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2214 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2215 if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
2219 void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
2221 MyViewOrientation.AxialScale( Sx, Sy, Sz );
2224 void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const
2226 Standard_Real Umin,Vmin,Umax,Vmax ;
2228 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2229 Xc = (Umin + Umax)/2. ;
2230 Yc = (Vmin + Vmax)/2. ;
2233 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
2235 Standard_Real Umin,Vmin,Umax,Vmax ;
2237 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2238 Width = Umax - Umin ;
2239 Height = Vmax - Vmin ;
2242 Standard_Real V3d_View::ZSize() const
2244 Standard_Real Wmin,Wmax,Depth ;
2246 Wmax = MyViewMapping.FrontPlaneDistance() ;
2247 Wmin = MyViewMapping.BackPlaneDistance() ;
2248 Depth = 2. * Max(Wmin,Wmax) ;
2252 Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const
2254 Standard_Real Wmin,Wmax,U,V,W ;
2255 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2257 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2260 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2261 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
2262 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
2263 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2264 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2265 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2266 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2267 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2268 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2269 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2270 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2271 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2272 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2273 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2274 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2275 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2276 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2277 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2278 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2279 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2280 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2281 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2282 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2283 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2284 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2285 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2286 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2291 Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const
2294 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2295 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2298 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2303 Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2305 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
2306 Standard_Real Umin,Vmin,Umax,Vmax ;
2307 Standard_Integer Nstruct,Npoint ;
2308 Graphic3d_MapOfStructure MySetOfStructures;
2310 MyView->DisplayedStructures (MySetOfStructures);
2311 Nstruct = MySetOfStructures.Extent() ;
2313 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
2315 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2316 Npoint = 0 ; X = Y = Z = 0. ;
2317 for( ; MyIterator.More(); MyIterator.Next()) {
2318 if (!(MyIterator.Key())->IsEmpty()) {
2319 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
2322 Standard_Real LIM = ShortRealLast() -1.;
2323 if (! (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2324 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM )) {
2326 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2327 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2328 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmin ;
2330 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2331 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2332 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmin ;
2334 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2335 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2336 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmin ;
2338 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2339 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2340 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmin ;
2342 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2343 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2344 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmax ;
2346 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2347 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2348 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmax ;
2350 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2351 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2352 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmax ;
2354 MyView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
2355 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2356 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmax ;
2362 X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
2368 void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2370 Graphic3d_Vertex Prp ;
2371 Graphic3d_Vector Vpn ;
2372 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
2374 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
2375 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
2376 Prp = MyViewMapping.ProjectionReferencePoint() ;
2377 Prp.Coord(Xrp,Yrp,Zrp) ;
2378 Vpn = MyViewOrientation.ViewReferencePlane() ;
2379 Vpn.Coord(Xpn,Ypn,Zpn) ;
2380 X = Zrp*Xpn + Xat; Y = Zrp*Ypn + Yat; Z = Zrp*Zpn + Zat;
2383 void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const
2385 Graphic3d_Vertex PRP,VRPoint;
2386 Graphic3d_Vector VRPlane;
2387 Standard_Real FPD,Xprp,Yprp,Zprp;
2388 Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp;
2390 if ( MyType == V3d_PERSPECTIVE ) {
2391 PRP = MyViewMapping.ProjectionReferencePoint() ;
2392 FPD = MyViewMapping.FrontPlaneDistance();
2393 PRP.Coord(Xprp,Yprp,Zprp);
2394 VRPoint = MyViewOrientation.ViewReferencePoint();
2395 VRPoint.Coord(Xvrp,Yvrp,Zvrp);
2396 VRPlane = MyViewOrientation.ViewReferencePlane();
2397 VRPlane.Coord(DXvrp,DYvrp,DZvrp);
2398 X = (FPD + Zprp) * DXvrp + Xvrp;
2399 Y = (FPD + Zprp) * DYvrp + Yvrp;
2400 Z = (FPD + Zprp) * DZvrp + Zvrp;
2405 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
2407 Standard_Real Xo,Yo,Zo;
2409 Convert(Xpix,Ypix,XP,YP,ZP);
2410 if ( MyType == V3d_PERSPECTIVE ) {
2411 FocalReferencePoint(Xo,Yo,Zo);
2421 Standard_Real V3d_View::Depth() const
2423 Graphic3d_Vertex Prp ;
2424 Standard_Real Xrp,Yrp,Zrp ;
2426 Prp = MyViewMapping.ProjectionReferencePoint() ;
2427 Prp.Coord(Xrp,Yrp,Zrp) ;
2431 void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
2433 Graphic3d_Vector Vpn ;
2435 Vpn = MyViewOrientation.ViewReferencePlane() ;
2436 Vpn.Coord(Dx,Dy,Dz) ;
2439 void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2441 Graphic3d_Vertex Vrp ;
2443 Vrp = MyViewOrientation.ViewReferencePoint() ;
2447 void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
2449 Graphic3d_Vector Vup ;
2451 Vup = MyViewOrientation.ViewReferenceUp() ;
2452 Vup.Coord(Vx,Vy,Vz) ;
2455 Standard_Real V3d_View::Twist() const
2457 Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ;
2458 Standard_Real pvx,pvy,pvz,pvn,sca,angle ;
2459 Graphic3d_Vector Vpn,Vup,Xaxis,Yaxis,Zaxis ;
2460 Standard_Boolean TheStatus ;
2462 Vpn = MyViewOrientation.ViewReferencePlane() ;
2463 Vpn.Coord(Xpn,Ypn,Zpn) ;
2464 Vup.SetCoord(0.,0.,1.) ;
2465 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2467 Vup.SetCoord(0.,1.,0.) ;
2468 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2471 Vup.SetCoord(1.,0.,0.) ;
2472 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2474 Yaxis.Coord(X0,Y0,Z0) ;
2475 Vup = MyViewOrientation.ViewReferenceUp() ;
2476 Vup.Coord(Xup,Yup,Zup) ;
2477 /* Compute Cross Vector From Up & Origin */
2478 pvx = Y0*Zup - Z0*Yup ;
2479 pvy = Z0*Xup - X0*Zup ;
2480 pvz = X0*Yup - Y0*Xup ;
2481 pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
2482 sca = X0*Xup + Y0*Yup + Z0*Zup ;
2485 if( angle > 1. ) angle = 1. ;
2486 else if( angle < -1. ) angle = -1. ;
2487 angle = asin(angle) ;
2488 if( sca < 0. ) angle = M_PI - angle ;
2489 if( angle > 0. && angle < M_PI ) {
2490 sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
2491 if( sca < 0. ) angle = DEUXPI - angle ;
2496 V3d_TypeOfShadingModel V3d_View::ShadingModel() const
2498 V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
2502 V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const
2504 V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
2508 Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const
2510 Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
2514 V3d_TypeOfVisualization V3d_View::Visualization() const
2516 V3d_TypeOfVisualization V =
2517 (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
2521 Standard_Boolean V3d_View::Antialiasing() const
2523 Standard_Boolean A = MyViewContext.AliasingIsOn() ;
2527 Handle(V3d_Viewer) V3d_View::Viewer() const
2532 Standard_Boolean V3d_View::IfWindow() const
2534 Standard_Boolean TheStatus = MyView->IsDefined() ;
2538 Handle(Aspect_Window) V3d_View::Window() const
2543 V3d_TypeOfView V3d_View::Type() const
2548 void V3d_View::SetFocale( const Standard_Real focale )
2550 Standard_TypeMismatch_Raise_if (MyType != V3d_PERSPECTIVE,
2551 "the view is not a perspective view");
2552 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2553 Graphic3d_Vertex Prp ;
2554 Prp = MyViewMapping.ProjectionReferencePoint() ;
2555 Prp.Coord(Xrp,Yrp,Zrp) ;
2556 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2557 ViewPlane = Zrp - focale ;
2559 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2560 ViewPlane = FrontPlane + Zrp - focale ;
2562 MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
2563 MyView->SetViewMapping(MyViewMapping) ;
2568 Standard_Real V3d_View::Focale( ) const
2570 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2571 Standard_Real focale = 0.0 ;
2572 Graphic3d_Vertex Prp ;
2574 if( MyType == V3d_PERSPECTIVE ) {
2575 Prp = MyViewMapping.ProjectionReferencePoint() ;
2576 Prp.Coord(Xrp,Yrp,Zrp) ;
2577 ViewPlane = MyViewMapping.ViewPlaneDistance() ;
2578 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2579 focale = Zrp - ViewPlane ;
2581 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2582 focale = FrontPlane + Zrp - ViewPlane ;
2588 void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right,
2589 const Standard_Real Bottom, const Standard_Real Top,
2590 const Standard_Real ZNear, const Standard_Real ZFar)
2592 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
2594 Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
2596 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2597 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2600 Standard_Real size = (ZFar - ZNear) / 2.;
2602 MyViewMapping.SetFrontPlaneDistance(size);
2603 MyViewMapping.SetBackPlaneDistance(-size);
2605 // keep view plane at front plane distance
2606 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
2608 // set window limits
2609 Umin = Left; Umax = Right;
2610 Vmin = Bottom; Vmax = Top;
2611 MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
2613 // Update window center
2614 if ( MyType == V3d_PERSPECTIVE ) {
2618 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
2620 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
2621 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2623 MyView->SetViewMapping(MyViewMapping) ;
2628 Handle(Visual3d_View) V3d_View::View() const
2633 Visual3d_ViewMapping V3d_View::ViewMapping() const
2635 return MyViewMapping;
2638 Visual3d_ViewOrientation V3d_View::ViewOrientation() const
2640 return MyViewOrientation;
2643 Standard_Boolean V3d_View::ScreenAxis( const Graphic3d_Vector &Vpn, const Graphic3d_Vector &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe)
2645 Standard_Real Xpn,Ypn,Zpn,Xup,Yup,Zup ;
2646 Standard_Real dx1,dy1,dz1,dx2,dy2,dz2,xx,yy,zz ;
2648 Vpn.Coord(Xpn,Ypn,Zpn) ;
2649 Vup.Coord(Xup,Yup,Zup) ;
2650 xx = Yup*Zpn - Zup*Ypn ;
2651 yy = Zup*Xpn - Xup*Zpn ;
2652 zz = Xup*Ypn - Yup*Xpn ;
2653 Xaxe.SetCoord(xx,yy,zz) ;
2654 if( Xaxe.LengthZero() ) return Standard_False;
2655 Xaxe.Normalize() ; Xaxe.Coord(dx1,dy1,dz1) ;
2656 xx = Ypn*dz1 - Zpn*dy1 ;
2657 yy = Zpn*dx1 - Xpn*dz1 ;
2658 zz = Xpn*dy1 - Ypn*dx1 ;
2659 Yaxe.SetCoord(xx,yy,zz) ;
2660 if( Yaxe.LengthZero() ) return Standard_False;
2661 Yaxe.Normalize() ; Yaxe.Coord(dx2,dy2,dz2) ;
2662 xx = dy1*dz2 - dz1*dy2 ;
2663 yy = dz1*dx2 - dx1*dz2 ;
2664 zz = dx1*dy2 - dy1*dx2 ;
2665 Zaxe.SetCoord(xx,yy,zz) ;
2666 if( Zaxe.LengthZero() ) return Standard_False;
2668 return Standard_True ;
2671 void V3d_View::InitMatrix( TColStd_Array2OfReal& Matrix )
2673 Standard_Integer LR = Matrix.LowerRow() ;
2674 Standard_Integer UR = Matrix.UpperRow() ;
2675 Standard_Integer LC = Matrix.LowerCol() ;
2676 Standard_Integer UC = Matrix.UpperCol() ;
2677 Standard_Integer I,J ;
2679 for( I=LR ; I<=UR ; I++ ) {
2680 for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
2682 for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
2685 Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix)
2687 Standard_Integer llr = Left.LowerRow ();
2688 Standard_Integer llc = Left.LowerCol ();
2689 Standard_Integer luc = Left.UpperCol ();
2691 Standard_Integer rlr = Right.LowerRow ();
2692 Standard_Integer rur = Right.UpperRow ();
2693 Standard_Integer rlc = Right.LowerCol ();
2695 Standard_Integer mlr = Matrix.LowerRow ();
2696 Standard_Integer mur = Matrix.UpperRow ();
2697 Standard_Integer mlc = Matrix.LowerCol ();
2698 Standard_Integer muc = Matrix.UpperCol ();
2700 TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
2702 InitMatrix (Result);
2704 // Left et Right incompatibles
2705 if (luc - llc + 1 != rur - rlr + 1)
2706 return Standard_False;
2708 Standard_Integer i, j, k;
2711 Standard_Integer I1 = llr;
2713 for (i=mlr; i<=mur; i++) {
2714 Standard_Integer J2 = rlc;
2715 for (j=mlc; j<=muc; j++) {
2717 Standard_Integer J1 = llc;
2718 Standard_Integer I2 = rlr;
2719 for (k=llc; k<=luc; k++) {
2720 Som = Som + Left (I1, J1) * Right (I2, J2);
2724 Result (i, j) = Som;
2730 for (i=mlr; i<=mur; i++)
2731 for (j=mlc; j<=muc; j++)
2732 Matrix (i, j) = Result (i, j);
2734 return Standard_True;
2737 /*----------------------------------------------------------------------*/
2739 void V3d_View::RotAxis( const Graphic3d_Vertex &Vrp, const Graphic3d_Vector &Axe, const Standard_Real angle, TColStd_Array2OfReal& Matrix )
2741 Standard_Real Xrp,Yrp,Zrp,Xaxe,Yaxe,Zaxe ;
2742 Standard_Real sina,cosa,cos1m,terms1,terms2,terms3 ;
2743 Standard_Real termc12,termc13,termc23,vcal ;
2744 TColStd_Array2OfReal Tmatrix(0,3,0,3) ;
2745 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
2747 InitMatrix(Matrix) ;
2748 InitMatrix(Tmatrix) ;
2750 Vrp.Coord(Xrp,Yrp,Zrp) ;
2751 Axe.Coord(Xaxe,Yaxe,Zaxe) ;
2752 /* translation of x,y,z */
2753 Tmatrix(0,3) = Xrp ; Tmatrix(1,3) = Yrp ; Tmatrix(2,3) = Zrp ;
2754 /* rotation around an axis */
2755 cosa = cos(angle); sina = sin(angle); cos1m = 1. - cosa ;
2756 termc12 = Xaxe * Yaxe * cos1m ;
2757 termc13 = Xaxe * Zaxe * cos1m ;
2758 termc23 = Yaxe * Zaxe * cos1m ;
2759 terms1 = Xaxe * sina ;
2760 terms2 = Yaxe * sina ;
2761 terms3 = Zaxe * sina ;
2763 vcal = Xaxe * Xaxe ;
2764 Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
2765 Rmatrix(1,0) = termc12 + terms3 ;
2766 Rmatrix(2,0) = termc13 - terms2 ;
2768 Rmatrix(0,1) = termc12 - terms3 ;
2769 vcal = Yaxe * Yaxe ;
2770 Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
2771 Rmatrix(2,1) = termc23 + terms1 ;
2773 Rmatrix(0,2) = termc13 + terms2 ;
2774 Rmatrix(1,2) = termc23 - terms1 ;
2775 vcal = Zaxe * Zaxe ;
2776 Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
2782 /* produced by two matrices */
2783 Multiply(Tmatrix, Rmatrix, Matrix);
2784 /* translation invert */
2785 Tmatrix(0,3) = -Xrp;
2786 Tmatrix(1,3) = -Yrp;
2787 Tmatrix(2,3) = -Zrp;
2789 Multiply(Matrix, Tmatrix, Matrix);
2792 /*----------------------------------------------------------------------*/
2794 Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix )
2796 Graphic3d_Vertex PP ;
2797 Standard_Real X,Y,Z,XX,YY,ZZ ;
2800 Standard_Integer lr, ur, lc, uc;
2801 lr = Matrix.LowerRow ();
2802 ur = Matrix.UpperRow ();
2803 lc = Matrix.LowerCol ();
2804 uc = Matrix.UpperCol ();
2805 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2807 PP.SetCoord(X,Y,Z) ;
2811 XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+
2812 Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ;
2814 YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) +
2815 Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ;
2817 ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) +
2818 Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ;
2819 PP.SetCoord(XX,YY,ZZ) ;
2823 Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix )
2825 Graphic3d_Vector VV ;
2826 Standard_Real X,Y,Z,XX,YY,ZZ ;
2829 Standard_Integer lr, ur, lc, uc;
2830 lr = Matrix.LowerRow ();
2831 ur = Matrix.UpperRow ();
2832 lc = Matrix.LowerCol ();
2833 uc = Matrix.UpperCol ();
2834 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2836 VV.SetCoord(X,Y,Z) ;
2840 XX = X*Matrix(lr,lc)+Y*Matrix(lr,lc+1)+Z*Matrix(lr,lc+2) ;
2841 YY = X*Matrix(lr+1,lc)+Y*Matrix(lr+1,lc+1)+Z*Matrix(lr+1,lc+2) ;
2842 ZZ = X*Matrix(lr+2,lc)+Y*Matrix(lr+2,lc+1)+Z*Matrix(lr+2,lc+2) ;
2843 VV.SetCoord(XX,YY,ZZ) ; VV.Normalize() ;
2847 void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor)
2849 Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
2852 void V3d_View::Zoom (const Standard_Integer X1,
2853 const Standard_Integer Y1,
2854 const Standard_Integer X2,
2855 const Standard_Integer Y2)
2858 Standard_Real dx = Standard_Real (X2-X1);
2859 Standard_Real dy = Standard_Real (Y2-Y1);
2860 if ( dx != 0. || dy != 0. ) {
2861 Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1;
2862 dzoom = (dx > 0) ? dzoom : 1./dzoom;
2863 SetZoom(dzoom, Standard_True);
2867 void V3d_View::Zoom (const Standard_Integer X1,
2868 const Standard_Integer Y1)
2872 Standard_Integer ix,iy;
2877 // Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
2878 void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
2880 MyZoomAtPointX = xpix;
2881 MyZoomAtPointY = ypix;
2884 // Zooms the model at a pixel defined by the method StartZoomAtPoint().
2885 void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
2886 const Standard_Integer mouseStartY,
2887 const Standard_Integer mouseEndX,
2888 const Standard_Integer mouseEndY)
2890 Standard_Boolean update;
2891 V3d_Coordinate X0, Y0, XS, YS;
2893 // Forbid any update.
2894 update = SetImmediateUpdate(Standard_False);
2899 // Pan the point to the center of window.
2900 Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
2901 Panning(X0-XS, Y0-YS);
2904 Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
2906 Standard_Real dzoom = fabs(d) / 100.0 + 1.0;
2907 dzoom = (d > 0) ? dzoom : 1.0 / dzoom;
2908 Viewer_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
2910 Standard_Real Umin,Vmin,Umax,Vmax;
2911 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
2913 MyXwindowCenter = (Umin + Umax) / 2.0;
2914 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2915 MyWindowWidth = Abs(Umax - Umin);
2916 MyWindowHeight = Abs(Vmax - Vmin);
2918 // Ensure that zoom will not be too small or too big.
2919 Standard_Real coef = dzoom;
2920 if (MyWindowWidth < coef * Precision::Confusion())
2921 coef = MyWindowWidth / Precision::Confusion();
2922 else if (MyWindowWidth > coef * 1e12)
2923 coef = MyWindowWidth / 1e12;
2924 if (MyWindowHeight < coef * Precision::Confusion())
2925 coef = MyWindowHeight / Precision::Confusion();
2926 else if (MyWindowHeight > coef * 1e12)
2927 coef = MyWindowHeight / 1e12;
2929 Standard_Real Dxv = MyWindowWidth / coef;
2930 Standard_Real Dyv = MyWindowHeight / coef;
2932 Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
2933 Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
2935 // Pan the point backwards.
2936 Dxv = (XS - X0) / coef;
2937 Dyv = (YS - Y0) / coef;
2939 MyXwindowCenter = (Umin + Umax) / 2.0;
2940 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2941 MyWindowWidth = Abs(Umax - Umin);
2942 MyWindowHeight = Abs(Vmax - Vmin);
2944 Standard_Real Xrp,Yrp,Zrp;
2945 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
2946 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
2948 Xrp = MyXwindowCenter - Dxv;
2949 Yrp = MyYwindowCenter - Dyv;
2951 Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
2952 Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
2954 // Set new reference plane coordintes of the window.
2955 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
2956 if (MyType != V3d_PERSPECTIVE)
2958 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
2959 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2961 MyView->SetViewMapping(MyViewMapping);
2964 SetImmediateUpdate(update);
2968 void V3d_View::AxialScale (const Standard_Integer Dx,
2969 const Standard_Integer Dy,
2970 const V3d_TypeOfAxe Axis)
2972 if( Dx != 0. || Dy != 0. ) {
2973 Standard_Real Sx, Sy, Sz;
2974 AxialScale( Sx, Sy, Sz );
2975 Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
2976 dscale = (Dx > 0) ? dscale : 1./dscale;
2977 if( Axis == V3d_X ) Sx = dscale;
2978 if( Axis == V3d_Y ) Sy = dscale;
2979 if( Axis == V3d_Z ) Sz = dscale;
2980 SetAxialScale( Sx, Sy, Sz );
2984 void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
2985 const Standard_Real Xmin,
2986 const Standard_Real Ymin,
2987 const Standard_Real Xmax,
2988 const Standard_Real Ymax)
2991 Standard_Real Umin,Umax,Vmin,Vmax,Xrp,Yrp,Zrp ;
2992 Standard_Real DxvOld,DyvOld,DxvNew,DyvNew,RapOld,RapNew ;
2993 Standard_Integer Xpixel,Ypixel;
2994 //Standard_Integer Xleft,Yup,Xright,Ylow ;
2996 Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
2997 "V3d_View::FitAll, Window Size is NULL");
2999 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
3000 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
3001 aWindow->Size(Xpixel,Ypixel);
3002 DxvOld = Xpixel; DyvOld = Ypixel;
3004 if( (DxvOld == 0.) || (DyvOld == 0.) ) return ;
3005 RapOld = DxvOld/DyvOld ;
3006 DxvNew = Abs(Xmax - Xmin) ; DyvNew = Abs(Ymax - Ymin) ;
3007 RapNew = DxvNew/DyvNew ;
3008 if( RapNew >= RapOld ) {
3009 DyvNew = DxvNew/RapOld ;
3011 DxvNew = DyvNew*RapOld ;
3013 Xrp = (Xmin + Xmax)/2. ; Yrp = (Ymin + Ymax)/2. ;
3014 Umin = Xrp - DxvNew/2. ; Vmin = Yrp - DyvNew/2. ;
3015 Umax = Xrp + DxvNew/2. ; Vmax = Yrp + DyvNew/2. ;
3016 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
3017 if( MyType != V3d_PERSPECTIVE ) {
3018 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
3019 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3021 MyView->SetViewMapping(MyViewMapping) ;
3030 static Standard_Boolean zRotation = Standard_False;
3032 void V3d_View::StartRotation(const Standard_Integer X,
3033 const Standard_Integer Y,
3034 const Quantity_Ratio zRotationThreshold)
3040 rx = Standard_Real(Convert(x));
3041 ry = Standard_Real(Convert(y));
3043 Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
3045 zRotation = Standard_False;
3046 if( zRotationThreshold > 0. ) {
3047 Standard_Real dx = Abs(sx - rx/2.);
3048 Standard_Real dy = Abs(sy - ry/2.);
3049 // if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True;
3050 Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
3051 if( dx > dd || dy > dd ) zRotation = Standard_True;
3057 void V3d_View::Rotation(const Standard_Integer X,
3058 const Standard_Integer Y)
3062 if( rx == 0. || ry == 0. ) {
3068 Standard_Real dx=0.,dy=0.,dz=0.;
3070 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
3071 atan2(sx-rx/2.,ry/2.-sy);
3073 dx = (Standard_Real(X) - sx) * M_PI / rx;
3074 dy = (sy - Standard_Real(Y)) * M_PI / ry;
3076 Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
3078 Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
3079 Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
3080 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3083 if( !myImmediateUpdate ) Update();
3085 myImmediateUpdate = Standard_False;
3086 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3087 ZFitAll (Zmargin); //Don't do that, perf improvment
3088 myImmediateUpdate = Standard_True;
3093 void V3d_View::SetAnimationModeOn () {
3095 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3096 if( ComputedMode() ) { // Deactivates computed mode during animation
3097 MyAnimationFlags |= V3d_FLAG_COMPUTATION;
3098 Standard_Boolean immediatUpdate = myImmediateUpdate;
3099 myImmediateUpdate = Standard_False;
3100 SetComputedMode(Standard_False);
3101 myImmediateUpdate = immediatUpdate;
3103 MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
3106 MyView->SetAnimationModeOn();
3110 void V3d_View::SetAnimationModeOff () {
3112 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3113 MyView -> SetAnimationModeOff ();
3114 if ( MyAnimationFlags & V3d_FLAG_COMPUTATION ) {
3115 // Reactivates computed mode after animation
3116 MyAnimationFlags &= ~V3d_FLAG_COMPUTATION;
3117 SetComputedMode(Standard_True);
3118 } else if( MyAnimationFlags & V3d_FLAG_DEGENERATION ) {
3123 MyView->SetAnimationModeOff();
3127 Standard_Boolean V3d_View::AnimationModeIsOn () const
3129 return MyView->AnimationModeIsOn();
3133 void V3d_View :: SetAnimationMode
3135 const Standard_Boolean anAnimationFlag,
3136 const Standard_Boolean aDegenerationFlag
3139 if ( anAnimationFlag )
3140 MyAnimationFlags |= V3d_FLAG_ANIMATION;
3142 MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
3144 if ( aDegenerationFlag )
3145 MyAnimationFlags |= V3d_FLAG_DEGENERATION;
3147 MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
3149 } // end V3d_View :: SetAnimationMode
3151 Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
3153 isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
3154 return MyAnimationFlags & V3d_FLAG_ANIMATION;
3158 void V3d_View::SetDegenerateModeOn()
3161 SetComputedMode(Standard_False);
3163 MyView->SetDegenerateModeOn();
3168 void V3d_View::SetDegenerateModeOff()
3171 SetComputedMode(Standard_True);
3173 if(myComputedMode) {
3174 MyView->SetDegenerateModeOff();
3180 Standard_Boolean V3d_View::DegenerateModeIsOn() const
3183 return !ComputedMode();
3185 return MyView->DegenerateModeIsOn();
3190 void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3193 if( myComputedMode ) {
3194 MyView -> SetComputedMode ( Standard_True );
3198 MyView -> SetComputedMode ( Standard_False );
3203 Standard_Boolean V3d_View :: ComputedMode () const
3205 return MyView -> ComputedMode ();
3208 void V3d_View :: SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel)
3210 MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
3214 V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const
3216 return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
3220 Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const
3222 return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
3225 void V3d_View::TransientManagerClearDraw() const
3227 Visual3d_TransientManager::ClearDraw(MyView);
3230 Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const
3232 return Visual3d_TransientManager::BeginAddDraw(MyView);
3235 void V3d_View::Init()
3237 myComputedMode = MyViewer->ComputedMode();
3239 if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
3240 SetComputedMode(Standard_False);
3244 MyView->SetDegenerateModeOn();
3246 if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
3250 OSD_Environment env_walkthrow("CSF_WALKTHROUGH");
3251 env_walkthrow.SetName( "CSF_WALKTHROUGH" );
3252 if ( env_walkthrow.Value () != "" ) MyProjModel = V3d_TPM_WALKTHROUGH;
3253 else MyProjModel = V3d_TPM_SCREEN;
3257 void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter)
3259 MyPlotter = aPlotter;
3262 void V3d_View::Plot()
3264 Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
3265 MyView->Plot(MyPlotter);
3268 Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
3273 if (AnimationMode) MyView->SetAnimationModeOn();
3275 Standard_Real delta = 0.01;
3276 Standard_Real xangle, yangle;
3277 xangle = yangle = delta*int(NbImages/3);
3279 Rotate (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_True);
3280 for (i=1; i<=int(NbImages/3); i++)
3281 Rotate (delta*i, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_False);
3282 for (i=1; i<=int(NbImages/3); i++)
3283 Rotate (xangle, delta*i, 0.0, 0.0, 0.0, 0.0, Standard_False);
3284 for (i=1; i<=int(NbImages/3); i++)
3285 Rotate (xangle, yangle, delta*i, 0.0, 0.0, 0.0, Standard_False);
3286 if (AnimationMode) MyView->SetAnimationModeOff();
3289 cout << "For " << NbImages << " Images : " << endl;
3290 FullTimer.Show (cout);
3293 Standard_Real Seconds, CPUtime;
3294 Standard_Integer Minutes, Hours;
3296 FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
3297 cout << "Result " << (AnimationMode ? "with " : "without ")
3298 << "display list : " << NbImages/CPUtime << " images/Second."
3301 return NbImages/CPUtime;
3304 #define SCREENCOPY_FILENAME "screencopy3d.gif"
3305 void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
3306 const Standard_Boolean fWhiteBackground,
3307 const Quantity_Factor aPlotScale)
3309 TCollection_AsciiString aFileToDump;
3310 Handle(Aspect_WindowDriver) aWindowDriver =
3312 new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
3314 new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
3316 Quantity_Factor aScale;
3317 Quantity_Length thePixel;
3318 Quantity_Parameter theWWidth, theWHeight;
3319 Quantity_Parameter thePWidth, thePHeight;
3320 aPlotterDriver -> WorkSpace (thePWidth, thePHeight);
3321 aWindowDriver -> WorkSpace (theWWidth, theWHeight);
3322 thePixel = aWindowDriver -> Convert (1);
3324 if (theWWidth * theWHeight != 0.) {
3325 if (aPlotScale == 0.) {
3326 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3328 // To be changed !!!!!!!!!!!!!!!
3329 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3332 // Set default maps (color, type, etc) for plotter driver
3333 aPlotterDriver -> SetColorMap ( new Aspect_GenericColorMap () );
3334 aPlotterDriver -> SetTypeMap ( new Aspect_TypeMap () );
3335 aPlotterDriver -> SetWidthMap ( new Aspect_WidthMap () );
3336 aPlotterDriver -> SetFontMap ( new Aspect_FontMap () );
3337 aPlotterDriver -> SetMarkMap ( new Aspect_MarkMap () );
3339 // Set backgroung to white, unihiglight if any
3340 Quantity_Parameter theRed, theGreen, theBlue;
3341 Handle(TColStd_HSequenceOfInteger) theFlags;
3342 Graphic3d_MapOfStructure theStructures;
3343 BackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3344 if (fWhiteBackground)
3345 SetBackgroundColor (Quantity_NOC_WHITE);
3346 MyView -> DisplayedStructures (theStructures);
3347 theFlags = new TColStd_HSequenceOfInteger ();
3348 Graphic3d_MapIteratorOfMapOfStructure Iterator (theStructures);
3349 while (Iterator.More ()) {
3350 Handle(Graphic3d_Structure) aStructure = Iterator.Key();
3351 if (aStructure -> IsHighlighted()) {
3352 theFlags -> Append (1);
3353 aStructure -> UnHighlight ();
3355 theFlags -> Append (0);
3362 if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
3363 aFileToDump = aPlotterDriver->PlotFileName();
3365 aFileToDump = aPlotterDriver->SpoolDirectory();
3366 aFileToDump += SCREENCOPY_FILENAME;
3368 MyWindow -> Dump (aFileToDump.ToCString());
3370 Standard_Integer theCurStruct = 1;
3371 Iterator = Graphic3d_MapIteratorOfMapOfStructure (theStructures);
3372 while (Iterator.More ()) {
3373 if (theFlags -> Value(theCurStruct))
3374 Iterator.Key() -> Highlight (Aspect_TOHM_COLOR);
3378 if (fWhiteBackground)
3379 SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3382 // Draw imagefile by plotter driver
3383 aPlotterDriver -> SetPixelSize (thePixel);
3384 aPlotterDriver -> BeginDraw ();
3385 aPlotterDriver -> DrawImageFile (
3386 aFileToDump.ToCString(), (float)(thePWidth / 2.), (float)(thePHeight / 2.), aScale);
3387 aPlotterDriver -> EndDraw ();
3390 #undef SCREENCOPY_FILENAME
3392 #include <Aspect.hxx>
3393 #include <Visual3d_Layer.hxx>
3395 ////////////////////////////////////////////////////////////////
3396 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3397 const Graphic3d_BufferType& theBufferType)
3399 Standard_Integer aWinWidth, aWinHeight;
3400 MyWindow->Size (aWinWidth, aWinHeight);
3401 Image_AlienPixMap anImage;
3402 return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
3405 ////////////////////////////////////////////////////////////////
3406 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3407 const Aspect_FormatOfSheetPaper theFormat,
3408 const Graphic3d_BufferType& theBufferType)
3410 // convert Aspect_FormatOfSheetPaper size to pixel ...
3411 Quantity_Length anSPWidth, anSPHeight;
3412 Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
3414 // adjusting to the ratio width/height ...
3415 Quantity_Length aWinWidth, aWinHeight;
3416 MyWindow->MMSize (aWinWidth, aWinHeight);
3417 Standard_Integer aPixelWidth, aPixelHeight;
3418 MyWindow->Size (aPixelWidth, aPixelHeight);
3420 Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
3421 aPixelWidth = Standard_Integer (aPixelWidth * aScale);
3422 aPixelHeight = Standard_Integer (aPixelHeight * aScale);
3424 Image_AlienPixMap anImage;
3425 ToPixMap (anImage, aPixelWidth, aPixelHeight, theBufferType);
3426 OSD_Environment anEnvGamma ("CSF_GAMMA_CORRECTION");
3427 TCollection_AsciiString strGamma (anEnvGamma.Value());
3428 if (!anImage.IsEmpty() && !strGamma.IsEmpty())
3430 Standard_Real aGammaValue = strGamma.RealValue();
3431 anImage.AdjustGamma (aGammaValue);
3433 return anImage.Save (theFile);
3436 ////////////////////////////////////////////////////////////////
3437 Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage,
3438 const Standard_Integer theWidth,
3439 const Standard_Integer theHeight,
3440 const Graphic3d_BufferType& theBufferType,
3441 const Standard_Boolean theIsForceCentred)
3443 // always prefer hardware accelerated offscreen buffer
3444 Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
3445 Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
3446 Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
3447 Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0);
3448 Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
3449 if (aPrevFBOPtr != NULL)
3451 MyView->FBOGetDimensions (aPrevFBOPtr,
3452 aPrevFBOVPSizeX, aPrevFBOVPSizeY,
3453 aPrevFBOSizeXMax, aPrevFBOSizeYMax);
3454 if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax)
3456 MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
3457 aFBOPtr = aPrevFBOPtr;
3461 if (aFBOPtr == NULL)
3463 // Try to create hardware accelerated buffer
3464 aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY);
3465 if (aFBOPtr != NULL)
3467 MyView->FBOGetDimensions (aFBOPtr,
3468 aFBOVPSizeX, aFBOVPSizeY,
3469 aFBOSizeXMax, aFBOSizeYMax);
3470 // reduce viewport in case of hardware limits
3471 if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax;
3472 if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax;
3473 MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
3476 cView->ptrFBO = aFBOPtr;
3478 // If hardware accelerated buffer - try to use onscreen buffer
3479 // Results may be bad!
3480 if (aFBOPtr == NULL)
3482 // retrieve window sizes
3483 Standard_Integer aWinWidth, aWinHeight;
3484 MyWindow->Size (aWinWidth, aWinHeight);
3486 // technically we can reduce existing viewport...
3487 // but currently allow only dumping the window itself
3488 if (aFBOVPSizeX != aWinWidth || aFBOVPSizeY != aWinHeight)
3490 return Standard_False;
3495 Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
3496 Standard_Real Umin, Vmin, Umax, Vmax;
3498 if (theIsForceCentred)
3500 //szv: get mapping frame
3501 Standard_Real PUmin, PVmin, PUmax, PVmax;
3502 prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
3504 //szv: calculate expansion
3505 Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
3506 Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
3507 Standard_Real newWidth = (oldHeight * aFBOVPSizeX) / aFBOVPSizeY;
3508 if (newWidth < oldWidth)
3510 Standard_Real newHeight = (oldWidth * aFBOVPSizeY) / aFBOVPSizeX;
3512 Standard_Real delta = 0.5 * (newHeight - oldHeight);
3513 Vmin = PVmin - delta;
3514 Vmax = PVmax + delta;
3519 Standard_Real delta = 0.5 * (newWidth - oldWidth);
3520 Umin = PUmin - delta;
3521 Umax = PUmax + delta;
3524 //szv: apply expanded mapping
3525 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
3526 MyView->SetViewMapping (MyViewMapping);
3529 //workround for rendering list of Over and Under Layers
3530 if (!MyLayerMgr.IsNull())
3532 MyLayerMgr->Compute();
3536 //szv: restore mapping
3537 MyViewMapping = prevMapping;
3538 MyView->SetViewMapping (prevMapping);
3540 Standard_Boolean isSuccess = Standard_True;
3542 // allocate image buffer for dumping
3543 if (theImage.IsEmpty()
3544 || (Standard_Size )aFBOVPSizeX != theImage.SizeX()
3545 || (Standard_Size )aFBOVPSizeY != theImage.SizeY())
3547 bool isBigEndian = Image_PixMap::IsBigEndianHost();
3548 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
3549 switch (theBufferType)
3551 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
3552 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
3553 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
3556 isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY);
3558 isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType);
3560 // FBO now useless, free resources
3561 if (aFBOPtr != aPrevFBOPtr)
3563 MyView->FBORelease (aFBOPtr);
3565 else if (aPrevFBOPtr != NULL)
3567 MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
3569 cView->ptrFBO = aPrevFBOPtr;