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 #define GER61351 //GG_15/12/99 Add SetBackgroundColor()
83 // and BackgroundColor() methods
86 #define IMP240100 //GG
87 // -> Remove PixToRef() method ,use
88 // instead the equivalent Convert() method.
89 // -> Rename RefToPix() to Convert() method.
90 // -> Remove the grid computation in Convert()
91 // method. Use instead the NEW ConvertToGrid() methods.
92 // Reason is the Convert() method is call by
93 // StdSelect_ViewSelector3d_Pick() from
94 // AIS_InteractiveContext() and it's not possible
95 // to select an object vertex when the grid is active!
96 // -> Remove grid echo marker definition
97 // (reported in the viewer)
98 // -> Add SetProjModel() methods.
100 #define G003 //EUG 04-10-99
101 // -> computed mode management
102 // Add SetComputedMode(..) method
103 // -> animation mode management
104 // Add SetAnimationMode()
105 // -> backfacing management
106 // Add SetBackFacingModel() method
108 #define G004 //VKH 15-11-99
109 // -> Add Dump() methods
110 // -> GG 07/03/00 Use the new MMSize()
111 // method from Aspect_Window class.
113 #define IMP210200 //GG Add Transparency() method
115 #define IMP250200 //GG With SetDepth() method, when the requested
117 // move the view ref point and the eye,instead
120 #define IMP020300 //GG Don't use ZFitAll in during Rotation
121 // for perf improvment
123 #define IMP210600 //GG Avoid to have infinite loop when call Rotation() method
124 // without call before StartRotation().
125 // This problem occurs when CTRL MB3 is maintain press betwwen 2 views.
127 #define IMP250900 //GG Enable rotation around screen Z axis when
128 // rotation begin far the center of the screen.
129 // Thanks to Patrick REGINSTER (SAMTECH)
130 // GG 21/12/00 Due to a regression on the previous specifications
131 // this new functionnality is right now deactivated
132 // by default (see StartRotation(...,zRotationThreshold)
135 #define BUC60952 //GG Enable to rotate around the view axis
136 // and the required view point
138 #define RIC120302 //GG Add a NEW SetWindow method which enable
139 // to connect a graphic widget and context to OGL.
141 #define IMP260302 //GG To avoid conflicting in Window destructor
142 // nullify this handle in Remove method
144 #define OCC280 //SAV fix for FitAll problem in the perspective view.
146 #define OCC1188 //SAV Added methods to set background image
148 /*----------------------------------------------------------------------*/
153 #include <Standard_TypeMismatch.hxx>
154 #include <Visual3d_ViewManager.hxx>
155 #include <Visual3d_Light.hxx>
156 #include <Visual3d_ClipPlane.hxx>
157 #include <Graphic3d_Structure.hxx>
158 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
159 #include <Graphic3d_MapOfStructure.hxx>
160 #include <Graphic3d_TextureEnv.hxx>
161 #include <Image_PixMap.hxx>
163 #include <V3d_View.ixx>
164 #include <Viewer_BadValue.hxx>
165 #include <Standard_ShortReal.hxx>
166 #include <gp_Dir.hxx>
167 #include <TColStd_Array2OfReal.hxx>
168 #include <Visual3d_TransientManager.hxx>
169 #include <Precision.hxx>
172 #include <Graphic3d_AspectMarker3d.hxx>
175 #include <Aspect_GenericColorMap.hxx>
176 #include <Aspect_TypeMap.hxx>
177 #include <Aspect_WidthMap.hxx>
178 #include <Aspect_MarkMap.hxx>
179 #include <Aspect_FontMap.hxx>
180 #include <PlotMgt_ImageDriver.hxx>
181 #include <TColStd_HSequenceOfInteger.hxx>
183 # include <WNT_WDriver.hxx>
185 # include <Xw_Driver.hxx>
189 # define V3d_FLAG_ANIMATION 0x00000001
190 # define V3d_FLAG_DEGENERATION 0x00000002
191 # define V3d_FLAG_COMPUTATION 0x00000004
195 #include <OSD_Timer.hxx>
196 static OSD_Timer FullTimer;
199 #include <OSD_Environment.hxx>
201 /*----------------------------------------------------------------------*/
207 #define DEUXPI (2. * M_PI)
209 // in case of NO_TRACE_ECHO and NO_TRACE_POINTS, in V3d_View_4.cxx and in
210 // V3d_View.cxx, change MyGridEchoStructure and MyGridEchoGroup in cdl
211 #define NO_TRACE_ECHO
212 #define NO_TRACE_POINTS
214 /*----------------------------------------------------------------------*/
216 * Local data definitions
220 static Standard_Real MyXwindowCenter ;
221 static Standard_Real MyYwindowCenter ;
222 static Standard_Real MyWindowWidth ;
223 static Standard_Real MyWindowHeight ;
227 static Graphic3d_Vector MyXscreenAxis ;
228 static Graphic3d_Vector MyYscreenAxis ;
229 static Graphic3d_Vector MyZscreenAxis ;
230 static Graphic3d_Vector MyViewReferencePlane ;
231 static Graphic3d_Vector MyViewReferenceUp ;
232 static Graphic3d_Vector MyViewAxis ;
233 static Graphic3d_Vertex MyViewReferencePoint ;
234 static Graphic3d_Vertex MyGravityReferencePoint ;
235 static Graphic3d_Vertex MyProjReferencePoint ;
237 static Graphic3d_Vector& _MyXscreenAxis() {
238 static Graphic3d_Vector MyXscreenAxis;
239 return MyXscreenAxis;
241 #define MyXscreenAxis _MyXscreenAxis()
243 static Graphic3d_Vector& _MyYscreenAxis() {
244 static Graphic3d_Vector MyYscreenAxis;
245 return MyYscreenAxis;
247 #define MyYscreenAxis _MyYscreenAxis()
249 static Graphic3d_Vector& _MyZscreenAxis() {
250 static Graphic3d_Vector MyZscreenAxis;
251 return MyZscreenAxis;
253 #define MyZscreenAxis _MyZscreenAxis()
255 static Graphic3d_Vector& _MyViewReferencePlane() {
256 static Graphic3d_Vector MyViewReferencePlane;
257 return MyViewReferencePlane;
259 #define MyViewReferencePlane _MyViewReferencePlane()
261 static Graphic3d_Vector& _MyViewReferenceUp() {
262 static Graphic3d_Vector MyViewReferenceUp;
263 return MyViewReferenceUp;
265 #define MyViewReferenceUp _MyViewReferenceUp()
267 static Graphic3d_Vector& _MyViewAxis() {
268 static Graphic3d_Vector MyViewAxis;
271 #define MyViewAxis _MyViewAxis()
273 static Graphic3d_Vertex& _MyViewReferencePoint() {
274 static Graphic3d_Vertex MyViewReferencePoint;
275 return MyViewReferencePoint;
277 #define MyViewReferencePoint _MyViewReferencePoint()
279 static Graphic3d_Vertex& _MyGravityReferencePoint() {
280 static Graphic3d_Vertex MyGravityReferencePoint;
281 return MyGravityReferencePoint;
283 #define MyGravityReferencePoint _MyGravityReferencePoint()
285 static Graphic3d_Vertex& _MyProjReferencePoint() {
286 static Graphic3d_Vertex MyProjReferencePoint;
287 return MyProjReferencePoint;
289 #define MyProjReferencePoint _MyProjReferencePoint()
292 /*----------------------------------------------------------------------*/
295 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
297 MyViewer(VM.operator->()),
301 myActiveLightsIterator(),
302 myActivePlanesIterator(),
303 SwitchSetFront(Standard_False),
304 MyTrsf (1, 4, 1, 4), // S3892
305 MyProjModel(V3d_TPM_SCREEN)
306 #if defined(TRACE_POINTS)
307 ,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
308 MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
312 myImmediateUpdate = Standard_False;
313 MyView = new Visual3d_View(MyViewer->Viewer());
315 // { Begin to retrieve the definition from ViewContext.
316 // Step MyViewContext = MyView->Context() ;
317 // to permit MyView->SetContext to compare
318 // the old and the new context.
319 // No problem for MyViewMapping, MyViewOrientation
320 // as MyView->SetViewMapping and MyView->SetViewOrientation
321 // don't try to optimize the modifications introduced to
322 // viewmapping and vieworientation.
325 if ((MyView->Context ()).AliasingIsOn ())
326 MyViewContext.SetAliasingOn ();
328 MyViewContext.SetAliasingOff ();
331 MyViewContext.SetDepthCueingBackPlane
332 ((MyView->Context ()).DepthCueingBackPlane ());
333 MyViewContext.SetDepthCueingFrontPlane
334 ((MyView->Context ()).DepthCueingFrontPlane ());
336 if ((MyView->Context ()).DepthCueingIsOn ())
337 MyViewContext.SetDepthCueingOn ();
339 MyViewContext.SetDepthCueingOff ();
342 MyViewContext.SetZClippingBackPlane
343 ((MyView->Context ()).ZClippingBackPlane ());
344 MyViewContext.SetZClippingFrontPlane
345 ((MyView->Context ()).ZClippingFrontPlane ());
347 if ((MyView->Context ()).FrontZClippingIsOn ())
348 MyViewContext.SetFrontZClippingOn ();
350 MyViewContext.SetFrontZClippingOff ();
352 if ((MyView->Context ()).BackZClippingIsOn ())
353 MyViewContext.SetBackZClippingOn ();
355 MyViewContext.SetBackZClippingOff ();
357 // Visualisation and Shading Model
358 MyViewContext.SetModel ((MyView->Context ()).Model ());
359 MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
362 MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
363 MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
364 // } End of retrieval of the definition of ViewContext.
366 MyViewMapping = MyView->ViewMapping() ;
367 MyViewOrientation = MyView->ViewOrientation() ;
368 MyBackground = VM->GetBackgroundColor() ;
369 MyGradientBackground = VM->GetGradientBackground() ;
371 SetAxis(0.,0.,0.,1.,1.,1.) ;
372 SetVisualization(VM->DefaultVisualization()) ;
373 SetShadingModel(VM->DefaultShadingModel()) ;
374 SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
377 SetProj(VM->DefaultViewProj()) ;
378 SetSize(VM->DefaultViewSize()) ;
379 Standard_Real zsize = VM->DefaultViewSize();
380 SetZSize(2.*zsize+zsize*Zmargin) ;
381 SetZClippingDepth(0.);
382 SetZClippingWidth(zsize);
384 SetZCueingWidth(zsize);
385 SetDepth(VM->DefaultViewSize()/2.) ;
387 SetViewMappingDefault();
390 myImmediateUpdate = Standard_True;
394 #if defined(TRACE_POINTS)
395 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
396 MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
397 MarkerAttrib->SetScale (3.0);
398 MarkerAttrib->SetType (Aspect_TOM_STAR);
399 MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
404 MyAnimationFlags = 0;
408 MyTransparencyFlag = Standard_False;
413 /*----------------------------------------------------------------------*/
415 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
417 MyViewer(VM.operator->()),
421 myActiveLightsIterator(),
422 myActivePlanesIterator(),
423 SwitchSetFront(Standard_False),
424 MyTrsf (1, 4, 1, 4), // S3892
425 MyProjModel(V3d_TPM_SCREEN)
426 #if defined(TRACE_POINTS)
427 ,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
428 MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
432 Handle(Visual3d_View) FromView = V->View() ;
434 myImmediateUpdate = Standard_False;
435 MyView = new Visual3d_View(MyViewer->Viewer());
437 for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){
438 MyActiveLights.Append(V->ActiveLight());}
439 for (V->InitActivePlanes();V->MoreActivePlanes();V->NextActivePlanes()){
440 MyActivePlanes.Append(V->ActivePlane());}
442 MyViewContext = FromView->Context() ;
444 MyViewMapping = FromView->ViewMapping() ;
445 MyViewOrientation = FromView->ViewOrientation() ;
446 MyBackground = FromView->Background() ;
447 MyGradientBackground = FromView->GradientBackground();
449 MyView->SetContext(MyViewContext) ;
451 SetAxis(0.,0.,0.,1.,1.,1.) ;
454 myImmediateUpdate = Standard_True;
458 #if defined(TRACE_ECHO)
459 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
460 MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
461 MarkerAttrib->SetScale (3.0);
462 MarkerAttrib->SetType (Aspect_TOM_STAR);
463 MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
468 MyAnimationFlags = 0;
473 /*----------------------------------------------------------------------*/
477 void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
478 const Handle(V3d_View)& aPreviousView,
479 const Standard_Integer x1,
480 const Standard_Integer y1,
481 const Standard_Integer x2,
482 const Standard_Integer y2)
485 if( !MyView->IsDefined() ) {
486 Standard_Real a,b,c,d;
487 aPreviousView->Convert(x1,y1,a,b);
488 aPreviousView->Convert(x2,y2,c,d);
489 MyView->SetWindow(TheWindow) ;
490 FitAll(TheWindow,a,b,c,d);
491 MyView->SetContext(MyViewContext) ;
492 MyView->SetViewOrientation(MyViewOrientation) ;
493 MyView->SetBackground(MyBackground) ;
494 MyViewer->SetViewOn(this) ;
495 MyWindow = TheWindow;
497 SetViewMappingDefault();
502 /*----------------------------------------------------------------------*/
504 void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
507 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
508 "V3d_View::SetWindow, window of view already defined");
510 MyView->SetWindow(TheWindow) ;
511 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
512 // calling Redraw(). Otherwise it is impossible to call certain methods of
513 // V3d_View like Convert() inside the context of Redraw(),
514 // particularly in class NIS_View.
515 MyWindow = TheWindow;
516 // SetWindow carries out SetRatio and modifies
517 // ViewMapping and ViewMappingDefault of MyView.
518 MyViewMapping = MyView->ViewMapping() ;
519 MyView->SetContext(MyViewContext) ;
520 MyView->SetViewMapping(MyViewMapping) ;
521 MyView->SetViewOrientation(MyViewOrientation) ;
522 MyView->SetBackground(MyBackground) ;
523 MyViewer->SetViewOn(this) ;
525 MyGridEchoStructure->SetInfiniteState (Standard_True); // S3892
526 MyGridEchoStructure->Display (); // S3892
533 /*----------------------------------------------------------------------*/
535 void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
536 const Aspect_RenderingContext aContext,
537 const Aspect_GraphicCallbackProc& aDisplayCB,
538 const Standard_Address aClientData)
541 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
542 "V3d_View::SetWindow, "
543 "window of view already defined");
544 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
545 // calling Redraw(). Otherwise it is impossible to call certain methods of
546 // V3d_View like Convert() inside the context of Redraw(),
547 // particularly in class NIS_View.
549 MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
550 MyViewMapping = MyView->ViewMapping() ;
551 MyView->SetContext(MyViewContext) ;
552 MyView->SetViewMapping(MyViewMapping) ;
553 MyView->SetViewOrientation(MyViewOrientation) ;
554 MyView->SetBackground(MyBackground) ;
555 MyViewer->SetViewOn(this) ;
561 /*----------------------------------------------------------------------*/
563 void V3d_View::Remove() const
565 MyViewer->DelView (this);
567 Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
571 /*----------------------------------------------------------------------*/
573 void V3d_View::Update() const {
574 if( MyView->IsDefined() ) MyView->Update() ;
577 /*----------------------------------------------------------------------*/
579 void V3d_View::Redraw() const {
580 if( MyView->IsDefined() ) MyView->Redraw() ;
582 /*----------------------------------------------------------------------*/
584 void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
585 const Standard_Integer width,const Standard_Integer height) const
587 if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
590 /*----------------------------------------------------------------------*/
592 Standard_Boolean V3d_View::IsEmpty() const {
594 Standard_Boolean TheStatus = Standard_True ;
595 if( MyView->IsDefined() ) {
596 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
597 if( Nstruct > 0 ) TheStatus = Standard_False ;
603 /*----------------------------------------------------------------------*/
605 void V3d_View::UpdateLights() const {
606 MyView->SetContext(MyViewContext);
610 /*----------------------------------------------------------------------*/
612 void V3d_View::DoMapping() {
613 if( MyView->IsDefined() ) {
614 (MyView->Window())->DoMapping() ;
618 /*----------------------------------------------------------------------*/
620 void V3d_View::MustBeResized() {
622 if ( !MyLayerMgr.IsNull() )
623 MyLayerMgr->Resized();
625 if( MyView->IsDefined() ) {
627 MyViewMapping = MyView->ViewMapping();
633 /*----------------------------------------------------------------------*/
635 void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
637 Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
638 Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 );
639 Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 );
641 Quantity_Color C( V1, V2, V3, Type );
643 SetBackgroundColor( C );
645 MyBackground.SetColor( C );
646 if ( MyView->IsDefined() )
647 MyView->SetBackground( MyBackground );
648 if ( !MyLayerMgr.IsNull() )
649 MyLayerMgr->Resized();
654 /*----------------------------------------------------------------------*/
656 void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
658 MyBackground.SetColor( Color );
659 if ( MyView->IsDefined() )
660 MyView->SetBackground( MyBackground );
662 if ( !MyLayerMgr.IsNull() )
663 MyLayerMgr->Resized();
667 /*----------------------------------------------------------------------*/
669 void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
671 Quantity_Color C( Name );
673 SetBackgroundColor( C );
675 MyBackground.SetColor( C );
676 if ( MyView->IsDefined() )
677 MyView->SetBackground( MyBackground );
678 if ( !MyColorScale.IsNull() )
679 MyColorScale->Resized();
683 /*----------------------------------------------------------------------*/
685 void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
686 const Quantity_Color& Color2,
687 const Aspect_GradientFillMethod FillStyle,
688 const Standard_Boolean status)
691 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
692 if ( MyView->IsDefined() )
693 MyView->SetGradientBackground( MyGradientBackground, status );
697 /*----------------------------------------------------------------------*/
699 void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
700 const Quantity_NameOfColor Color2,
701 const Aspect_GradientFillMethod FillStyle,
702 const Standard_Boolean status )
704 Quantity_Color C1( Color1 );
705 Quantity_Color C2( Color2 );
706 MyGradientBackground.SetColors( C1, C2, FillStyle );
707 if ( MyView->IsDefined() )
708 MyView->SetGradientBackground( MyGradientBackground, status );
711 /*----------------------------------------------------------------------*/
713 void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
714 const Standard_Boolean update)
716 Quantity_Color Color1, Color2;
717 MyGradientBackground.Colors( Color1, Color2 );
718 MyGradientBackground.SetColors( Color1, Color2, FillStyle );
719 if( MyView->IsDefined() )
720 MyView->SetBgGradientStyle( FillStyle, update ) ;
723 /*----------------------------------------------------------------------*/
725 void V3d_View::SetBackgroundImage( const Standard_CString FileName,
726 const Aspect_FillMethod FillStyle,
727 const Standard_Boolean update )
730 if( MyView->IsDefined() )
731 MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
735 /*----------------------------------------------------------------------*/
737 void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
738 const Standard_Boolean update )
741 if( MyView->IsDefined() )
742 MyView->SetBgImageStyle( FillStyle, update ) ;
746 /*----------------------------------------------------------------------*/
748 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) {
750 Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
752 D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ;
753 Viewer_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis");
754 Nx /= D ; Ny /= D ; Nz /= D ;
755 MyDefaultViewPoint.SetCoord(X,Y,Z) ;
756 MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
757 MyDefaultViewAxis.Normalize() ;
761 /*----------------------------------------------------------------------*/
763 void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) {
765 MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
766 MyView->SetContext(MyViewContext) ;
770 /*----------------------------------------------------------------------*/
772 void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) {
774 MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
775 MyView->SetContext(MyViewContext) ;
779 /*----------------------------------------------------------------------*/
781 void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) {
783 MyViewContext.SetTextureEnv(ATexture) ;
784 MyView->SetContext(MyViewContext) ;
788 /*----------------------------------------------------------------------*/
790 void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) {
792 MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
793 MyView->SetContext(MyViewContext) ;
797 /*----------------------------------------------------------------------*/
799 void V3d_View::SetFront() {
801 gp_Ax3 a = MyViewer->PrivilegedPlane();
802 Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
804 a.Direction().Coord(vx,vy,vz);
805 a.YDirection().Coord(xu,yu,zu);
806 a.Location().Coord(xo,yo,zo);
809 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
811 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
813 SwitchSetFront = !SwitchSetFront;
815 MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
816 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
818 MyView->SetViewOrientation(MyViewOrientation) ;
824 /*----------------------------------------------------------------------*/
826 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) {
828 Standard_Real Ax = ax ;
829 Standard_Real Ay = ay ;
830 Standard_Real Az = az ;
831 Graphic3d_Vector Vpn,Vup ;
832 TColStd_Array2OfReal Matrix(0,3,0,3) ;
833 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
835 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
836 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
837 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
838 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
839 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
840 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
843 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
844 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
845 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
846 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
847 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
848 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
853 if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
855 RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
856 Multiply(Matrix, Rmatrix, Matrix);
859 RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
860 Multiply(Matrix, Rmatrix, Matrix);
862 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
863 MyViewOrientation.SetViewReferencePlane(Vpn) ;
864 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
865 MyViewOrientation.SetViewReferenceUp(Vup) ;
866 MyView->SetViewOrientation(MyViewOrientation) ;
874 /*----------------------------------------------------------------------*/
876 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
877 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
880 Standard_Real Ax = ax ;
881 Standard_Real Ay = ay ;
882 Standard_Real Az = az ;
883 Graphic3d_Vector Vpn,Vup ;
884 Graphic3d_Vertex Vrp ;
885 TColStd_Array2OfReal Matrix(0,3,0,3) ;
886 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
888 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
889 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
890 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
891 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
892 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
893 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
896 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
897 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
898 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
899 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
900 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
901 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
902 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
907 if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
909 RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
910 Multiply(Matrix, Rmatrix, Matrix);
913 RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
914 Multiply(Matrix, Rmatrix, Matrix);
916 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
917 MyViewOrientation.SetViewReferencePoint(Vrp) ;
918 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
919 MyViewOrientation.SetViewReferencePlane(Vpn) ;
920 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
921 MyViewOrientation.SetViewReferenceUp(Vup) ;
922 MyView->SetViewOrientation(MyViewOrientation) ;
930 /*----------------------------------------------------------------------*/
932 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) {
936 Rotate(angle,0.,0.,Start);
939 Rotate(0.,angle,0.,Start);
942 Rotate(0.,0.,angle,Start);
948 /*----------------------------------------------------------------------*/
950 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
951 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
954 Standard_Real Angle = angle ;
955 Graphic3d_Vector Vpn,Vup ;
956 Graphic3d_Vertex Vrp ;
957 TColStd_Array2OfReal Matrix(0,3,0,3) ;
959 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
960 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
963 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
964 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
965 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
966 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
969 MyViewAxis.SetCoord(1.,0.,0.) ;
972 MyViewAxis.SetCoord(0.,1.,0.) ;
975 MyViewAxis.SetCoord(0.,0.,1.) ;
980 RotAxis(MyGravityReferencePoint,MyViewAxis,Angle,Matrix) ;
981 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
982 MyViewOrientation.SetViewReferencePoint(Vrp) ;
983 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
984 MyViewOrientation.SetViewReferencePlane(Vpn) ;
985 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
986 MyViewOrientation.SetViewReferenceUp(Vup) ;
987 MyView->SetViewOrientation(MyViewOrientation) ;
995 /*----------------------------------------------------------------------*/
997 void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) {
999 Standard_Real Angle = angle ;
1000 Graphic3d_Vector Vpn,Vup ;
1001 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1003 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1004 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1007 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1008 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1009 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1012 RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
1014 Graphic3d_Vertex Vrp ;
1015 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1016 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1018 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1019 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1020 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1021 MyViewOrientation.SetViewReferenceUp(Vup) ;
1022 MyView->SetViewOrientation(MyViewOrientation) ;
1030 /*----------------------------------------------------------------------*/
1032 void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
1035 Standard_Real Ax = ax ;
1036 Standard_Real Ay = ay ;
1037 Standard_Real Az = az ;
1038 Graphic3d_Vertex Vrp,Eye ;
1039 Graphic3d_Vector Vpn,Vup ;
1040 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1041 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1042 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
1044 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
1045 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
1046 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
1047 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
1048 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
1049 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
1052 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1053 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1054 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1055 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1056 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1057 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
1058 Viewer_BadValue::Raise ("V3d_View::Turn, alignment of Eye,At,Up");
1061 InitMatrix(Matrix) ;
1062 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1063 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1064 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1065 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1066 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1067 if( Ax != 0. ) RotAxis(Eye,MyYscreenAxis,-Ax,Matrix) ;
1069 RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
1070 Multiply(Matrix, Rmatrix, Matrix);
1073 RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
1074 Multiply(Matrix, Rmatrix, Matrix);
1076 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1077 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1078 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1079 MyViewOrientation.SetViewReferenceUp(Vpn) ;
1080 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1081 MyViewOrientation.SetViewReferenceUp(Vup) ;
1082 MyView->SetViewOrientation(MyViewOrientation) ;
1086 // Check ZClipping planes
1087 Standard_Real Zmax ;
1088 Vrp.Coord(Xat,Yat,Zat) ;
1089 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat) ;
1090 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1091 MyProjModel == V3d_TPM_SCREEN ) {
1092 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1099 /*----------------------------------------------------------------------*/
1101 void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1106 Turn(angle,0.,0.,Start);
1109 Turn(0.,angle,0.,Start);
1112 Turn(0.,0.,angle,Start);
1117 void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) {
1118 Standard_Real Angle = angle ;
1119 Graphic3d_Vertex Vrp,Eye ;
1120 Graphic3d_Vector Vpn,Vup ;
1121 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1122 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1124 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1125 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1128 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1129 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1130 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1131 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1133 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1134 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1135 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1136 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1137 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1138 RotAxis(Eye,MyDefaultViewAxis,Angle,Matrix) ;
1139 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1140 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1141 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1142 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1143 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1144 MyViewOrientation.SetViewReferenceUp(Vup) ;
1145 MyView->SetViewOrientation(MyViewOrientation) ;
1149 // Check ZClipping planes
1150 Standard_Real Zmax ;
1151 Vrp.Coord(Xat,Yat,Zat) ;
1152 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat ) ;
1153 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1154 MyProjModel == V3d_TPM_SCREEN ) {
1155 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1162 void V3d_View::SetTwist(const Standard_Real angle) {
1164 Standard_Real Angle = angle ;
1165 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1166 Standard_Boolean TheStatus ;
1168 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1169 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1171 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1172 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1173 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1174 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1176 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1177 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1178 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1181 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1182 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1183 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1186 Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
1188 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1189 RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
1190 MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
1191 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1192 MyView->SetViewOrientation(MyViewOrientation) ;
1198 void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
1201 MyProjModel = aModel;
1205 V3d_TypeOfProjectionModel V3d_View::ProjModel() const {
1212 void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1214 Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
1216 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1217 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1218 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1219 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1220 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1221 Xpn = X - Xat ; Ypn = Y - Yat ; Zpn = Z - Zat ;
1222 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1223 Viewer_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused");
1225 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1226 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1227 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1228 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1229 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1231 Standard_Boolean update = myImmediateUpdate;
1232 myImmediateUpdate = Standard_False;
1233 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1234 //FMN desactivation temp SetTwist(Angle) ;
1236 MyView->SetViewOrientation(MyViewOrientation) ;
1237 MyView->SetViewMapping(MyViewMapping) ;
1244 // Check ZClipping planes
1245 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1246 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1247 MyProjModel == V3d_TPM_SCREEN ) {
1248 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1250 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1251 MyView->SetViewMapping(MyViewMapping);
1254 myImmediateUpdate = update;
1259 void V3d_View::SetDepth(const Standard_Real Depth) {
1261 Standard_Real Xrp,Yrp,Zrp ;
1263 Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
1265 Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
1269 Standard_Real twist =
1272 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1273 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1274 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1275 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1281 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1282 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1285 // Check ZClipping planes
1286 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
1287 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1288 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1290 if( Depth < 0. ) { // Move the view ref point instead of the eye.
1291 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1293 Xat = Xeye - Xpn*Zrp ; Yat = Yeye - Ypn*Zrp ; Zat = Zeye - Zpn*Zrp;
1294 MyViewReferencePoint.SetCoord(Xat,Yat,Zat) ;
1295 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1296 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1297 MyView->SetViewOrientation(MyViewOrientation);
1301 MyView->SetViewMapping(MyViewMapping) ;
1304 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1305 Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1307 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1308 MyProjModel == V3d_TPM_SCREEN ) {
1309 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1311 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1315 MyView->SetViewMapping(MyViewMapping) ;
1324 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1327 Standard_Real Angle ;
1329 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1330 "V3d_View::SetProj, null projection vector");
1333 MyViewReferencePlane.SetCoord(Vx,Vy,Vz) ;
1334 MyViewReferencePlane.Normalize() ;
1335 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1336 Standard_Boolean update = myImmediateUpdate;
1337 myImmediateUpdate = Standard_False;
1338 if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ;
1342 myImmediateUpdate = update;
1347 void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) {
1349 MyViewReferencePlane = V3d::GetProjAxis(Orientation) ;
1350 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1351 // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955
1352 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(0,0,0));
1353 Standard_Real Xpn=0;
1354 Standard_Real Ypn=0;
1355 Standard_Real Zpn=0;
1357 switch (Orientation) {
1375 void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1377 Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
1378 Standard_Real Xeye,Yeye,Zeye ;
1381 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1382 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1383 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1384 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1385 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1386 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1387 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1388 Xpn = Xeye - X ; Ypn = Yeye - Y ; Zpn = Zeye - Z ;
1389 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1390 Viewer_BadValue_Raise_if( Zrp <= 0.,
1391 "V3d_View::SetAt, Eye,At are Confused");
1393 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1394 MyViewReferencePoint.SetCoord(X,Y,Z) ;
1395 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1396 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1397 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1398 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1399 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1400 Standard_Boolean update = myImmediateUpdate;
1401 myImmediateUpdate = Standard_False;
1402 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1403 //FMN desactivation temp SetTwist(Angle) ;
1405 MyView->SetViewOrientation(MyViewOrientation) ;
1406 MyView->SetViewMapping(MyViewMapping) ;
1411 MyView->SetViewMapping(MyViewMapping);
1415 // Check ZClipping planes
1416 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1417 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1418 MyProjModel == V3d_TPM_SCREEN ) {
1419 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1421 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1422 MyView->SetViewMapping(MyViewMapping);
1425 myImmediateUpdate = update;
1430 void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) {
1432 Standard_Boolean TheStatus ;
1433 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
1434 "V3d_View::SetUp, nullUp vector");
1436 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1437 MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
1438 MyViewReferenceUp.Normalize() ;
1439 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1440 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1442 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1443 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1444 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1447 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1448 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1449 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1452 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1453 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1454 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1456 Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
1458 MyViewReferenceUp = MyYscreenAxis ;
1459 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1460 MyView->SetViewOrientation(MyViewOrientation) ;
1465 void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) {
1467 Standard_Boolean TheStatus ;
1469 MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
1470 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1471 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1472 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1474 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1475 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1476 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1479 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1480 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1481 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1484 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1485 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1486 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1488 Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
1490 MyViewReferenceUp = MyYscreenAxis ;
1491 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1492 MyView->SetViewOrientation(MyViewOrientation) ;
1497 void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
1499 MyViewOrientation = VO;
1500 MyView->SetViewOrientation(MyViewOrientation) ;
1504 void V3d_View::SetViewOrientationDefault() {
1506 MyView->SetViewOrientation(MyViewOrientation) ;
1507 MyView->SetViewOrientationDefault() ;
1511 void V3d_View::ResetViewOrientation() {
1513 MyView->ViewOrientationReset() ;
1514 MyViewOrientation = MyView->ViewOrientation() ;
1518 void V3d_View::Reset( const Standard_Boolean update ) {
1520 MyView->ViewOrientationReset() ;
1521 MyViewOrientation = MyView->ViewOrientation() ;
1522 MyView->ViewMappingReset();
1523 MyViewMapping = MyView->ViewMapping() ;
1526 SwitchSetFront = Standard_False;
1528 if( !myImmediateUpdate && update ) Update();
1535 void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
1538 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ;
1539 Viewer_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
1542 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1543 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1544 MyXwindowCenter = (Umin + Umax)/2. ;
1545 MyYwindowCenter = (Vmin + Vmax)/2. ;
1546 MyWindowWidth = Abs(Umax - Umin) ;
1547 MyWindowHeight = Abs(Vmax - Vmin) ;
1548 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1549 "V3d_View::Panning, Window Size is NULL");
1551 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1552 Xrp = MyXwindowCenter - Dx ;
1553 Yrp = MyYwindowCenter - Dy ;
1554 Dxv = MyWindowWidth/aZoomFactor ; Dyv = MyWindowHeight/aZoomFactor ;
1555 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1556 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1557 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1558 if( MyType != V3d_PERSPECTIVE ) {
1559 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1560 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1562 MyView->SetViewMapping(MyViewMapping) ;
1566 void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) {
1572 void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc){
1574 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
1576 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1577 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1578 MyXwindowCenter = Xrp = Xc ; MyYwindowCenter = Yrp = Yc ;
1579 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1580 MyWindowWidth = Abs(Umax - Umin) ; MyWindowHeight = Abs(Vmax - Vmin) ;
1581 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1582 "V3d_View::SetCenter, Window Size is NULL");
1584 Umin = Xc - MyWindowWidth/2. ; Vmin = Yc - MyWindowHeight/2. ;
1585 Umax = Xc + MyWindowWidth/2. ; Vmax = Yc + MyWindowHeight/2. ;
1586 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1587 if( MyType != V3d_PERSPECTIVE ) {
1588 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1589 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1591 MyView->SetViewMapping(MyViewMapping) ;
1596 void V3d_View::SetSize(const Standard_Real Size)
1599 Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
1601 Viewer_BadValue_Raise_if( Size <= 0.,
1602 "V3d_View::SetSize, Window Size is NULL");
1605 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1606 MyWindowWidth = Abs(Umax - Umin) ;
1607 MyWindowHeight = Abs(Vmax - Vmin) ;
1608 MyXwindowCenter = (Umin + Umax)/2. ;
1609 MyYwindowCenter = (Vmin + Vmax)/2. ;
1610 Rap = MyWindowWidth/MyWindowHeight ;
1611 if( MyWindowWidth >= MyWindowHeight ) {
1612 MyWindowWidth = Size ; MyWindowHeight = Size/Rap ;
1614 MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
1616 Umin = MyXwindowCenter - MyWindowWidth/2. ;
1617 Vmin = MyYwindowCenter - MyWindowHeight/2. ;
1618 Umax = MyXwindowCenter + MyWindowWidth/2. ;
1619 Vmax = MyYwindowCenter + MyWindowHeight/2. ;
1620 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1621 MyView->SetViewMapping(MyViewMapping) ;
1626 void V3d_View::SetZSize(const Standard_Real Size)
1629 Standard_Real Zmax = Size/2.;
1633 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye;
1634 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1635 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1636 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1637 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat;
1638 Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1639 if( Zmax <= MyViewMapping.FrontPlaneDistance() ) return;
1642 Viewer_BadValue_Raise_if( Size <= 0.,
1643 "V3d_View::SetZSize, Window ZSize is NULL");
1646 Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
1647 Standard_Real Back = MyViewContext.ZClippingBackPlane() ;
1648 Standard_Real focale= Focale();
1650 MyViewMapping.SetFrontPlaneDistance(Zmax) ;
1651 MyViewMapping.SetBackPlaneDistance(-Zmax) ;
1654 if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
1655 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
1658 MyView->SetViewMapping(MyViewMapping) ;
1659 if( MyViewContext.FrontZClippingIsOn() ||
1660 MyViewContext.BackZClippingIsOn() ) {
1661 MyViewContext.SetZClippingFrontPlane(Front) ;
1662 MyViewContext.SetZClippingBackPlane(Back) ;
1663 MyView->SetContext(MyViewContext) ;
1668 void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
1671 Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
1672 Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
1675 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1676 MyXwindowCenter = (Umin + Umax)/2. ;
1677 MyYwindowCenter = (Vmin + Vmax)/2. ;
1678 MyWindowWidth = Abs(Umax - Umin) ;
1679 MyWindowHeight = Abs(Vmax - Vmin) ;
1682 // ensure that zoom will not be too small or too big
1683 Standard_Real coef = Coef;
1684 if ( MyWindowWidth < coef * Precision::Confusion() )
1685 coef = MyWindowWidth / Precision::Confusion();
1686 else if ( MyWindowWidth > coef * 1e12 )
1687 coef = MyWindowWidth / 1e12;
1688 if ( MyWindowHeight < coef * Precision::Confusion() )
1689 coef = MyWindowHeight / Precision::Confusion();
1690 else if ( MyWindowHeight > coef * 1e12 )
1691 coef = MyWindowHeight / 1e12;
1693 Dxv = MyWindowWidth/coef;
1694 Dyv = MyWindowHeight/coef;
1695 Umin = MyXwindowCenter - Dxv/2. ; Umax = MyXwindowCenter + Dxv/2. ;
1696 Vmin = MyYwindowCenter - Dyv/2. ; Vmax = MyYwindowCenter + Dyv/2. ;
1697 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1698 MyView->SetViewMapping(MyViewMapping) ;
1702 void V3d_View::SetScale( const Standard_Real Coef ) {
1703 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
1704 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
1706 Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1708 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1709 Dxv = Abs(Umax - Umin) ; Dyv = Abs(Vmax - Vmin) ;
1710 Dxv /= Coef ; Dyv /= Coef ;
1711 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1712 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
1713 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1714 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1715 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1716 MyView->SetViewMapping(MyViewMapping) ;
1721 void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) {
1723 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1724 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1725 Viewer_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
1727 MyViewOrientation.SetAxialScale( Sx, Sy, Sz );
1728 Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode();
1729 MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP);
1730 MyView->SetViewOrientation(MyViewOrientation);
1731 MyView->ViewManager()->SetUpdateMode(updateMode);
1733 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1735 Standard_Real LIM = ShortRealLast() -1.;
1736 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1737 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1741 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1742 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1743 Umax = Max(Umin,Umax) ; Vmax = Max(Vmin,Vmax) ;
1744 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1745 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1746 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1747 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1748 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1749 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1750 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1751 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1752 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1753 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1754 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1755 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1756 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1757 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1758 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1759 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1760 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1761 Umax = Max(Umax,Vmax) ;
1762 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1763 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1764 Wmax = Max(Abs(Umax),Abs(Wmax)) ;
1767 SetZSize(2.*Wmax + Wmax) ;
1772 void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
1773 const Standard_Boolean update)
1775 Standard_Real Umin, Umax, Vmin, Vmax, Xrp, Yrp, Zrp, U, V, W, U1, V1, W1;
1776 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
1777 Standard_Real DxvOld, DyvOld, DxvNew, DyvNew;
1778 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures();
1780 if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
1788 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1789 MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
1790 if (MyView->IsDefined())
1792 Standard_Integer Xpixel, Ypixel;
1793 MyWindow->Size (Xpixel, Ypixel);
1799 MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
1800 DxvOld = Abs (Umax - Umin);
1801 DyvOld = Abs (Vmax - Vmin);
1803 if ((DxvOld == 0.0) || (DyvOld == 0.0))
1808 Standard_Real aWinRatio = DxvOld / DyvOld;
1810 // retrieve min / max values for current displayed objects
1811 MyView->MinMaxValues (Xmin, Ymin, Zmin,
1814 Standard_Real LIM = ShortRealLast() - 1.0;
1815 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1816 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM)
1824 // eliminate fluctuations between sequential FitAll() calls
1825 MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0);
1826 if (MyType != V3d_PERSPECTIVE)
1828 MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
1829 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1831 MyView->SetViewMapping (MyViewMapping);
1833 // iterate 2 times to find optimal view plane size
1834 // (use view plane values computed on previous iteration)
1835 for (Standard_Integer aIteration = 2; aIteration > 0; --aIteration)
1837 MyView->Projects (Xmin, Ymin, Zmin, U, V, W);
1838 MyView->Projects (Xmax, Ymax, Zmax, U1, V1, W1);
1839 Umin = Min (U, U1); Umax = Max (U, U1);
1840 Vmin = Min (V, V1); Vmax = Max (V, V1);
1842 MyView->Projects (Xmin, Ymin, Zmax, U, V, W);
1843 Umin = Min (U, Umin); Umax = Max (U, Umax);
1844 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1846 MyView->Projects (Xmax, Ymin, Zmax, U, V, W);
1847 Umin = Min (U, Umin); Umax = Max (U, Umax);
1848 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1850 MyView->Projects (Xmax, Ymin, Zmin, U, V, W);
1851 Umin = Min (U, Umin); Umax = Max (U, Umax);
1852 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1854 MyView->Projects (Xmax, Ymax, Zmin, U, V, W);
1855 Umin = Min (U, Umin); Umax = Max (U, Umax);
1856 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1858 MyView->Projects (Xmin, Ymax, Zmax, U, V, W);
1859 Umin = Min (U, Umin); Umax = Max (U, Umax);
1860 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1862 MyView->Projects (Xmin, Ymax, Zmin, U, V, W);
1863 Umin = Min (U, Umin); Umax = Max (U, Umax);
1864 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1866 DxvNew = Abs (Umax - Umin);
1867 DyvNew = Abs (Vmax - Vmin);
1869 if (DyvNew < 10.0 * Precision::Confusion())
1871 if (DxvNew < 10.0 * Precision::Confusion())
1873 // whole scene projected to point
1874 DxvNew = Max (Abs (Zmax - Zmin), (Max (Abs (Xmax - Xmin), Abs (Ymax - Ymin))));
1875 if (DxvNew < 10.0 * Precision::Confusion())
1877 // this is really just one (!) point and zooming has no any effect
1878 // just center the view
1884 // we look along some line
1885 // fit view like that to see whole scene on rotation
1886 DxvNew += Coef * DxvNew;
1887 DyvNew = DxvNew / aWinRatio;
1892 // whole scene projected to horizontal line
1893 DxvNew += Coef * DxvNew;
1894 DyvNew = DxvNew / aWinRatio;
1899 // general case (or DxvNew == 0.0 - vertical line)
1900 // safe original ratio
1901 Standard_Real aFitRatio = DxvNew / DyvNew;
1902 if (aFitRatio >= aWinRatio)
1904 DxvNew += Coef * DxvNew;
1905 DyvNew = DxvNew / aWinRatio;
1909 DyvNew += Coef * DyvNew;
1910 DxvNew = DyvNew * aWinRatio;
1915 Xrp = 0.5 * (Umin + Umax);
1916 Yrp = 0.5 * (Vmin + Vmax);
1918 // new window limits
1919 Umin = Xrp - 0.5 * DxvNew;
1920 Umax = Xrp + 0.5 * DxvNew;
1921 Vmin = Yrp - 0.5 * DyvNew;
1922 Vmax = Yrp + 0.5 * DyvNew;
1923 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
1925 if (MyType != V3d_PERSPECTIVE)
1928 MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
1929 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1931 MyView->SetViewMapping (MyViewMapping);
1945 if (!myImmediateUpdate && update)
1952 void V3d_View::ZFitAll(const Standard_Real Coef) {
1954 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1955 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1957 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1959 if( MyType == V3d_PERSPECTIVE ) {
1964 if( (Nstruct <= 0) || (Coef < 0.) ) {
1969 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1971 Standard_Real LIM = ShortRealLast() -1.;
1972 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1973 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1979 // Case when view contains only a point
1980 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
1984 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1985 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1986 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1987 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1988 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1989 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1990 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1991 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1992 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1993 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1994 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1995 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1996 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1997 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1998 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
2000 SetZSize(2.*Wmax + Coef * Wmax) ;
2005 void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
2006 const Quantity_Coefficient Margin)
2008 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
2009 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
2010 Standard_Real Xrp,Yrp,Zrp,Dx,Dy,Dz,Size;
2012 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2014 if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
2019 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2020 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2022 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2024 Standard_Real LIM = ShortRealLast() -1.;
2025 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2026 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
2031 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
2035 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2036 MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
2037 Umin = Min(U,U1) ; Umax = Max(U,U1) ;
2038 Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
2039 Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
2040 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2041 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2042 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2043 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2044 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2045 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2046 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2047 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2048 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2049 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2050 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2051 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2052 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2053 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2054 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2055 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2056 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2057 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2058 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2059 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2060 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2061 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2062 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2063 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2066 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
2067 Dz = 2.*Wmax + Margin * Wmax;
2069 // Compute depth value
2070 Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
2071 Dx += Margin * Dx; Dy += Margin * Dy;
2072 Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
2075 SetDepth( Aspect * Size / 2.);
2081 void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax) {
2082 FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
2088 void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
2089 WindowFit(Xmin,Ymin,Xmax,Ymax);
2092 void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
2093 Standard_Real x1,y1,x2,y2;
2094 Convert(Xmin,Ymin,x1,y1);
2095 Convert(Xmax,Ymax,x2,y2);
2096 FitAll(x1,y1,x2,y2);
2099 void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
2102 // ajust view type according to mapping projection
2103 // NOTE: Might be dangerous, potentially conflicts with the C++ view class
2104 // (orthographic or perspective)! Use with care!
2105 if ( VM.Projection() == Visual3d_TOP_PERSPECTIVE )
2106 MyType = V3d_PERSPECTIVE;
2107 else MyType = V3d_ORTHOGRAPHIC;
2109 MyView->SetViewMapping(MyViewMapping) ;
2113 void V3d_View::SetViewMappingDefault() {
2114 MyView->SetViewMapping(MyViewMapping) ;
2115 MyView->SetViewMappingDefault();
2119 void V3d_View::ResetViewMapping() {
2121 MyView->ViewMappingReset();
2122 MyViewMapping = MyView->ViewMapping() ;
2131 Standard_Real V3d_View::Convert(const Standard_Integer Vp) const {
2132 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
2133 Standard_Integer Dxw,Dyw ;
2135 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2137 MyWindow->Size(Dxw,Dyw);
2138 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2140 Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
2145 void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const {
2146 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Dyv ;
2147 Standard_Integer Dxw,Dyw ;
2149 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2151 MyWindow->Size(Dxw,Dyw);
2152 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2153 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
2154 Xv = Umin + Dxv*(Standard_Real)Xp/(Standard_Real)Dxw ;
2155 Yv = Vmin + Dyv*(Standard_Real)(Dyw-Yp)/(Standard_Real)Dyw ;
2158 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
2160 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2162 Standard_Integer Dxw, Dyw;
2163 MyWindow->Size(Dxw,Dyw);
2165 Standard_Real Umin,Umax,Vmin,Vmax;
2166 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2167 Standard_Real Dxv = Umax - Umin;
2168 return RealToInt ( Dxw * Vv / Dxv );
2171 void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
2173 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2175 Standard_Integer Dxw, Dyw;
2176 MyWindow->Size(Dxw,Dyw);
2178 Standard_Real Umin,Umax,Vmin,Vmax;
2179 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2180 Standard_Real Dxv = Umax - Umin;
2181 Standard_Real Dyv = Vmax - Vmin;
2183 // CAL 15/12/93 warning: double assigned to int
2184 Xp = RealToInt (Dxw*(Xv - Umin)/Dxv);
2185 // CAL 15/12/93 warning: double assigned to int
2186 Yp = Dyw - RealToInt (Dyw*(Yv - Vmin)/Dyv);
2189 void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2191 Graphic3d_Vertex Vrp ;
2192 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2195 if( MyViewer->Grid()->IsActive() ) {
2196 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2197 NewVrp.Coord(X,Y,Z) ;
2202 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
2204 Graphic3d_Vertex Vrp ;
2205 Graphic3d_Vector Proj ;
2206 (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
2208 Proj.Coord(Dx,Dy,Dz) ;
2210 if( MyViewer->Grid()->IsActive() ) {
2211 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2212 NewVrp.Coord(X,Y,Z) ;
2218 void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
2220 Graphic3d_Vertex Vrp ;
2221 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2222 if( MyViewer->Grid()->IsActive() ) {
2223 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2224 NewVrp.Coord(Xg,Yg,Zg) ;
2226 Vrp.Coord(Xg,Yg,Zg) ;
2229 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 {
2231 if( MyViewer->Grid()->IsActive() ) {
2232 Graphic3d_Vertex Vrp(X,Y,Z) ;
2233 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2234 NewVrp.Coord(Xg,Yg,Zg) ;
2236 Xg = X; Yg = Y; Zg = Z;
2242 void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2244 Graphic3d_Vertex Vrp ;
2245 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2247 if( MyViewer->Grid()->IsActive() ) {
2248 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2249 NewVrp.Coord(X,Y,Z) ;
2255 void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2257 void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2260 Graphic3d_Vertex Vrp(X,Y,Z) ;
2261 (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
2264 void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
2266 if ( MyType != V3d_PERSPECTIVE )
2268 // use old implementation
2270 MyView->Projects( X, Y, Z, Xp, Yp, Zp );
2274 // NKV - Using raster projection
2275 Standard_Integer Xpx, Ypx;
2276 Convert(X, Y, Z, Xpx, Ypx);
2277 Convert(Xpx, Ypx, Xp, Yp);
2281 void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3)const {
2284 Quantity_Color C = BackgroundColor() ;
2287 C = MyBackground.Color() ;
2289 C.Values(V1,V2,V3,Type) ;
2293 Quantity_Color V3d_View::BackgroundColor() const {
2295 return MyBackground.Color() ;
2299 void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
2300 MyGradientBackground.Colors(Color1, Color2);
2303 Aspect_GradientBackground V3d_View::GradientBackground() const {
2304 return MyGradientBackground;
2307 Standard_Real V3d_View::Scale()const {
2308 Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
2309 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
2310 Standard_Real S = 0. ;
2312 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2314 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2315 if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
2319 void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const {
2320 MyViewOrientation.AxialScale( Sx, Sy, Sz );
2323 void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const {
2325 Standard_Real Umin,Vmin,Umax,Vmax ;
2327 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2328 Xc = (Umin + Umax)/2. ;
2329 Yc = (Vmin + Vmax)/2. ;
2332 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const {
2334 Standard_Real Umin,Vmin,Umax,Vmax ;
2336 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2337 Width = Umax - Umin ;
2338 Height = Vmax - Vmin ;
2341 Standard_Real V3d_View::ZSize() const {
2343 Standard_Real Wmin,Wmax,Depth ;
2345 Wmax = MyViewMapping.FrontPlaneDistance() ;
2346 Wmin = MyViewMapping.BackPlaneDistance() ;
2347 Depth = 2. * Max(Wmin,Wmax) ;
2351 Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
2353 Standard_Real Wmin,Wmax,U,V,W ;
2354 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2356 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2359 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2360 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
2361 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
2362 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2363 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2364 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2365 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2366 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2367 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2368 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2369 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2370 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2371 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2372 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2373 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2374 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2375 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2376 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2377 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2378 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2379 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2380 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2381 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2382 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2383 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2384 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2385 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2390 Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const {
2392 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2393 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2396 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2401 Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2403 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
2404 Standard_Real Umin,Vmin,Umax,Vmax ;
2405 Standard_Integer Nstruct,Npoint ;
2406 Graphic3d_MapOfStructure MySetOfStructures;
2408 MyView->DisplayedStructures (MySetOfStructures);
2409 Nstruct = MySetOfStructures.Extent() ;
2411 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
2413 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2414 Npoint = 0 ; X = Y = Z = 0. ;
2415 for( ; MyIterator.More(); MyIterator.Next()) {
2416 if (!(MyIterator.Key())->IsEmpty()) {
2417 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
2420 Standard_Real LIM = ShortRealLast() -1.;
2421 if (! (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2422 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM )) {
2424 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2425 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2426 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmin ;
2428 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2429 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2430 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmin ;
2432 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2433 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2434 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmin ;
2436 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2437 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2438 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmin ;
2440 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2441 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2442 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmax ;
2444 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2445 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2446 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmax ;
2448 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2449 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2450 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmax ;
2452 MyView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
2453 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2454 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmax ;
2460 X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
2466 void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2467 Graphic3d_Vertex Prp ;
2468 Graphic3d_Vector Vpn ;
2469 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
2471 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
2472 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
2473 Prp = MyViewMapping.ProjectionReferencePoint() ;
2474 Prp.Coord(Xrp,Yrp,Zrp) ;
2475 Vpn = MyViewOrientation.ViewReferencePlane() ;
2476 Vpn.Coord(Xpn,Ypn,Zpn) ;
2477 X = Zrp*Xpn + Xat; Y = Zrp*Ypn + Yat; Z = Zrp*Zpn + Zat;
2480 void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const {
2482 Graphic3d_Vertex PRP,VRPoint;
2483 Graphic3d_Vector VRPlane;
2484 Standard_Real FPD,Xprp,Yprp,Zprp;
2485 Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp;
2487 if ( MyType == V3d_PERSPECTIVE ) {
2488 PRP = MyViewMapping.ProjectionReferencePoint() ;
2489 FPD = MyViewMapping.FrontPlaneDistance();
2490 PRP.Coord(Xprp,Yprp,Zprp);
2491 VRPoint = MyViewOrientation.ViewReferencePoint();
2492 VRPoint.Coord(Xvrp,Yvrp,Zvrp);
2493 VRPlane = MyViewOrientation.ViewReferencePlane();
2494 VRPlane.Coord(DXvrp,DYvrp,DZvrp);
2495 X = (FPD + Zprp) * DXvrp + Xvrp;
2496 Y = (FPD + Zprp) * DYvrp + Yvrp;
2497 Z = (FPD + Zprp) * DZvrp + Zvrp;
2502 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 {
2504 Standard_Real Xo,Yo,Zo;
2506 Convert(Xpix,Ypix,XP,YP,ZP);
2507 if ( MyType == V3d_PERSPECTIVE ) {
2508 FocalReferencePoint(Xo,Yo,Zo);
2519 Standard_Real V3d_View::Depth() const {
2520 Graphic3d_Vertex Prp ;
2521 Standard_Real Xrp,Yrp,Zrp ;
2523 Prp = MyViewMapping.ProjectionReferencePoint() ;
2524 Prp.Coord(Xrp,Yrp,Zrp) ;
2528 void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const {
2529 Graphic3d_Vector Vpn ;
2531 Vpn = MyViewOrientation.ViewReferencePlane() ;
2532 Vpn.Coord(Dx,Dy,Dz) ;
2535 void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2536 Graphic3d_Vertex Vrp ;
2538 Vrp = MyViewOrientation.ViewReferencePoint() ;
2542 void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const {
2543 Graphic3d_Vector Vup ;
2545 Vup = MyViewOrientation.ViewReferenceUp() ;
2546 Vup.Coord(Vx,Vy,Vz) ;
2549 Standard_Real V3d_View::Twist()const {
2550 Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ;
2551 Standard_Real pvx,pvy,pvz,pvn,sca,angle ;
2552 Graphic3d_Vector Vpn,Vup,Xaxis,Yaxis,Zaxis ;
2553 Standard_Boolean TheStatus ;
2555 Vpn = MyViewOrientation.ViewReferencePlane() ;
2556 Vpn.Coord(Xpn,Ypn,Zpn) ;
2557 Vup.SetCoord(0.,0.,1.) ;
2558 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2560 Vup.SetCoord(0.,1.,0.) ;
2561 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2564 Vup.SetCoord(1.,0.,0.) ;
2565 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2567 Yaxis.Coord(X0,Y0,Z0) ;
2568 Vup = MyViewOrientation.ViewReferenceUp() ;
2569 Vup.Coord(Xup,Yup,Zup) ;
2570 /* Compute Cross Vector From Up & Origin */
2571 pvx = Y0*Zup - Z0*Yup ;
2572 pvy = Z0*Xup - X0*Zup ;
2573 pvz = X0*Yup - Y0*Xup ;
2574 pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
2575 sca = X0*Xup + Y0*Yup + Z0*Zup ;
2578 if( angle > 1. ) angle = 1. ;
2579 else if( angle < -1. ) angle = -1. ;
2580 angle = asin(angle) ;
2581 if( sca < 0. ) angle = M_PI - angle ;
2582 if( angle > 0. && angle < M_PI ) {
2583 sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
2584 if( sca < 0. ) angle = DEUXPI - angle ;
2589 V3d_TypeOfShadingModel V3d_View::ShadingModel()const {
2590 V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
2594 V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail()const {
2595 V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
2600 Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const {
2601 Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
2605 V3d_TypeOfVisualization V3d_View::Visualization()const {
2606 V3d_TypeOfVisualization V =
2607 (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
2611 Standard_Boolean V3d_View::Antialiasing()const {
2612 Standard_Boolean A = MyViewContext.AliasingIsOn() ;
2616 Handle(V3d_Viewer) V3d_View::Viewer() const {
2620 Standard_Boolean V3d_View::IfWindow() const {
2621 Standard_Boolean TheStatus = MyView->IsDefined() ;
2625 Handle(Aspect_Window) V3d_View::Window() const {
2629 V3d_TypeOfView V3d_View::Type() const {
2634 void V3d_View::SetFocale( const Standard_Real focale ) {
2636 Standard_TypeMismatch_Raise_if (MyType != V3d_PERSPECTIVE,
2637 "the view is not a perspective view");
2638 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2639 Graphic3d_Vertex Prp ;
2640 Prp = MyViewMapping.ProjectionReferencePoint() ;
2641 Prp.Coord(Xrp,Yrp,Zrp) ;
2642 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2643 ViewPlane = Zrp - focale ;
2645 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2646 ViewPlane = FrontPlane + Zrp - focale ;
2648 MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
2649 MyView->SetViewMapping(MyViewMapping) ;
2654 Standard_Real V3d_View::Focale( ) const {
2655 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2656 Standard_Real focale = 0.0 ;
2657 Graphic3d_Vertex Prp ;
2659 if( MyType == V3d_PERSPECTIVE ) {
2660 Prp = MyViewMapping.ProjectionReferencePoint() ;
2661 Prp.Coord(Xrp,Yrp,Zrp) ;
2662 ViewPlane = MyViewMapping.ViewPlaneDistance() ;
2663 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2664 focale = Zrp - ViewPlane ;
2666 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2667 focale = FrontPlane + Zrp - ViewPlane ;
2673 void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right,
2674 const Standard_Real Bottom, const Standard_Real Top,
2675 const Standard_Real ZNear, const Standard_Real ZFar)
2677 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
2679 Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
2681 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2682 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2685 Standard_Real size = (ZFar - ZNear) / 2.;
2687 MyViewMapping.SetFrontPlaneDistance(size);
2688 MyViewMapping.SetBackPlaneDistance(-size);
2690 // keep view plane at front plane distance
2691 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
2693 // set window limits
2694 Umin = Left; Umax = Right;
2695 Vmin = Bottom; Vmax = Top;
2696 MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
2698 // Update window center
2699 if ( MyType == V3d_PERSPECTIVE ) {
2703 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
2705 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
2706 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2708 MyView->SetViewMapping(MyViewMapping) ;
2713 Handle(Visual3d_View) V3d_View::View() const
2718 Visual3d_ViewMapping V3d_View::ViewMapping() const
2720 return MyViewMapping;
2723 Visual3d_ViewOrientation V3d_View::ViewOrientation() const
2725 return MyViewOrientation;
2728 Standard_Boolean V3d_View::ScreenAxis( const Graphic3d_Vector &Vpn, const Graphic3d_Vector &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe) {
2729 Standard_Real Xpn,Ypn,Zpn,Xup,Yup,Zup ;
2730 Standard_Real dx1,dy1,dz1,dx2,dy2,dz2,xx,yy,zz ;
2732 Vpn.Coord(Xpn,Ypn,Zpn) ;
2733 Vup.Coord(Xup,Yup,Zup) ;
2734 xx = Yup*Zpn - Zup*Ypn ;
2735 yy = Zup*Xpn - Xup*Zpn ;
2736 zz = Xup*Ypn - Yup*Xpn ;
2737 Xaxe.SetCoord(xx,yy,zz) ;
2738 if( Xaxe.LengthZero() ) return Standard_False;
2739 Xaxe.Normalize() ; Xaxe.Coord(dx1,dy1,dz1) ;
2740 xx = Ypn*dz1 - Zpn*dy1 ;
2741 yy = Zpn*dx1 - Xpn*dz1 ;
2742 zz = Xpn*dy1 - Ypn*dx1 ;
2743 Yaxe.SetCoord(xx,yy,zz) ;
2744 if( Yaxe.LengthZero() ) return Standard_False;
2745 Yaxe.Normalize() ; Yaxe.Coord(dx2,dy2,dz2) ;
2746 xx = dy1*dz2 - dz1*dy2 ;
2747 yy = dz1*dx2 - dx1*dz2 ;
2748 zz = dx1*dy2 - dy1*dx2 ;
2749 Zaxe.SetCoord(xx,yy,zz) ;
2750 if( Zaxe.LengthZero() ) return Standard_False;
2752 return Standard_True ;
2755 void V3d_View::InitMatrix( TColStd_Array2OfReal& Matrix ) {
2756 Standard_Integer LR = Matrix.LowerRow() ;
2757 Standard_Integer UR = Matrix.UpperRow() ;
2758 Standard_Integer LC = Matrix.LowerCol() ;
2759 Standard_Integer UC = Matrix.UpperCol() ;
2760 Standard_Integer I,J ;
2762 for( I=LR ; I<=UR ; I++ ) {
2763 for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
2765 for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
2768 Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) {
2770 Standard_Integer llr = Left.LowerRow ();
2771 Standard_Integer llc = Left.LowerCol ();
2772 Standard_Integer luc = Left.UpperCol ();
2774 Standard_Integer rlr = Right.LowerRow ();
2775 Standard_Integer rur = Right.UpperRow ();
2776 Standard_Integer rlc = Right.LowerCol ();
2778 Standard_Integer mlr = Matrix.LowerRow ();
2779 Standard_Integer mur = Matrix.UpperRow ();
2780 Standard_Integer mlc = Matrix.LowerCol ();
2781 Standard_Integer muc = Matrix.UpperCol ();
2783 TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
2785 InitMatrix (Result);
2787 // Left et Right incompatibles
2788 if (luc - llc + 1 != rur - rlr + 1)
2789 return Standard_False;
2791 Standard_Integer i, j, k;
2794 Standard_Integer I1 = llr;
2796 for (i=mlr; i<=mur; i++) {
2797 Standard_Integer J2 = rlc;
2798 for (j=mlc; j<=muc; j++) {
2800 Standard_Integer J1 = llc;
2801 Standard_Integer I2 = rlr;
2802 for (k=llc; k<=luc; k++) {
2803 Som = Som + Left (I1, J1) * Right (I2, J2);
2807 Result (i, j) = Som;
2813 for (i=mlr; i<=mur; i++)
2814 for (j=mlc; j<=muc; j++)
2815 Matrix (i, j) = Result (i, j);
2817 return Standard_True;
2820 /*----------------------------------------------------------------------*/
2822 void V3d_View::RotAxis( const Graphic3d_Vertex &Vrp, const Graphic3d_Vector &Axe, const Standard_Real angle, TColStd_Array2OfReal& Matrix ) {
2823 Standard_Real Xrp,Yrp,Zrp,Xaxe,Yaxe,Zaxe ;
2824 Standard_Real sina,cosa,cos1m,terms1,terms2,terms3 ;
2825 Standard_Real termc12,termc13,termc23,vcal ;
2826 TColStd_Array2OfReal Tmatrix(0,3,0,3) ;
2827 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
2829 InitMatrix(Matrix) ;
2830 InitMatrix(Tmatrix) ;
2832 Vrp.Coord(Xrp,Yrp,Zrp) ;
2833 Axe.Coord(Xaxe,Yaxe,Zaxe) ;
2834 /* translation of x,y,z */
2835 Tmatrix(0,3) = Xrp ; Tmatrix(1,3) = Yrp ; Tmatrix(2,3) = Zrp ;
2836 /* rotation around an axis */
2837 cosa = cos(angle); sina = sin(angle); cos1m = 1. - cosa ;
2838 termc12 = Xaxe * Yaxe * cos1m ;
2839 termc13 = Xaxe * Zaxe * cos1m ;
2840 termc23 = Yaxe * Zaxe * cos1m ;
2841 terms1 = Xaxe * sina ;
2842 terms2 = Yaxe * sina ;
2843 terms3 = Zaxe * sina ;
2845 vcal = Xaxe * Xaxe ;
2846 Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
2847 Rmatrix(1,0) = termc12 + terms3 ;
2848 Rmatrix(2,0) = termc13 - terms2 ;
2850 Rmatrix(0,1) = termc12 - terms3 ;
2851 vcal = Yaxe * Yaxe ;
2852 Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
2853 Rmatrix(2,1) = termc23 + terms1 ;
2855 Rmatrix(0,2) = termc13 + terms2 ;
2856 Rmatrix(1,2) = termc23 - terms1 ;
2857 vcal = Zaxe * Zaxe ;
2858 Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
2864 /* produced by two matrices */
2865 Multiply(Tmatrix, Rmatrix, Matrix);
2866 /* translation invert */
2867 Tmatrix(0,3) = -Xrp;
2868 Tmatrix(1,3) = -Yrp;
2869 Tmatrix(2,3) = -Zrp;
2871 Multiply(Matrix, Tmatrix, Matrix);
2874 /*----------------------------------------------------------------------*/
2876 Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix ) {
2877 Graphic3d_Vertex PP ;
2878 Standard_Real X,Y,Z,XX,YY,ZZ ;
2881 Standard_Integer lr, ur, lc, uc;
2882 lr = Matrix.LowerRow ();
2883 ur = Matrix.UpperRow ();
2884 lc = Matrix.LowerCol ();
2885 uc = Matrix.UpperCol ();
2886 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2888 PP.SetCoord(X,Y,Z) ;
2892 XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+
2893 Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ;
2895 YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) +
2896 Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ;
2898 ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) +
2899 Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ;
2900 PP.SetCoord(XX,YY,ZZ) ;
2904 Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix ) {
2905 Graphic3d_Vector VV ;
2906 Standard_Real X,Y,Z,XX,YY,ZZ ;
2909 Standard_Integer lr, ur, lc, uc;
2910 lr = Matrix.LowerRow ();
2911 ur = Matrix.UpperRow ();
2912 lc = Matrix.LowerCol ();
2913 uc = Matrix.UpperCol ();
2914 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2916 VV.SetCoord(X,Y,Z) ;
2920 XX = X*Matrix(lr,lc)+Y*Matrix(lr,lc+1)+Z*Matrix(lr,lc+2) ;
2921 YY = X*Matrix(lr+1,lc)+Y*Matrix(lr+1,lc+1)+Z*Matrix(lr+1,lc+2) ;
2922 ZZ = X*Matrix(lr+2,lc)+Y*Matrix(lr+2,lc+1)+Z*Matrix(lr+2,lc+2) ;
2923 VV.SetCoord(XX,YY,ZZ) ; VV.Normalize() ;
2928 void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) {
2930 Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
2934 void V3d_View::Zoom (const Standard_Integer X1,
2935 const Standard_Integer Y1,
2936 const Standard_Integer X2,
2937 const Standard_Integer Y2)
2940 Standard_Real dx = Standard_Real (X2-X1);
2941 Standard_Real dy = Standard_Real (Y2-Y1);
2942 if ( dx != 0. || dy != 0. ) {
2943 Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1;
2944 dzoom = (dx > 0) ? dzoom : 1./dzoom;
2945 SetZoom(dzoom, Standard_True);
2949 void V3d_View::Zoom (const Standard_Integer X1,
2950 const Standard_Integer Y1)
2954 Standard_Integer ix,iy;
2959 // Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
2960 void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
2962 MyZoomAtPointX = xpix;
2963 MyZoomAtPointY = ypix;
2966 // Zooms the model at a pixel defined by the method StartZoomAtPoint().
2967 void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
2968 const Standard_Integer mouseStartY,
2969 const Standard_Integer mouseEndX,
2970 const Standard_Integer mouseEndY)
2972 Standard_Boolean update;
2973 V3d_Coordinate X0, Y0, XS, YS;
2975 // Forbid any update.
2976 update = SetImmediateUpdate(Standard_False);
2981 // Pan the point to the center of window.
2982 Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
2983 Panning(X0-XS, Y0-YS);
2986 Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
2988 Standard_Real dzoom = fabs(d) / 100.0 + 1.0;
2989 dzoom = (d > 0) ? dzoom : 1.0 / dzoom;
2990 Viewer_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
2992 Standard_Real Umin,Vmin,Umax,Vmax;
2993 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
2995 MyXwindowCenter = (Umin + Umax) / 2.0;
2996 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2997 MyWindowWidth = Abs(Umax - Umin);
2998 MyWindowHeight = Abs(Vmax - Vmin);
3000 // Ensure that zoom will not be too small or too big.
3001 Standard_Real coef = dzoom;
3002 if (MyWindowWidth < coef * Precision::Confusion())
3003 coef = MyWindowWidth / Precision::Confusion();
3004 else if (MyWindowWidth > coef * 1e12)
3005 coef = MyWindowWidth / 1e12;
3006 if (MyWindowHeight < coef * Precision::Confusion())
3007 coef = MyWindowHeight / Precision::Confusion();
3008 else if (MyWindowHeight > coef * 1e12)
3009 coef = MyWindowHeight / 1e12;
3011 Standard_Real Dxv = MyWindowWidth / coef;
3012 Standard_Real Dyv = MyWindowHeight / coef;
3014 Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
3015 Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
3017 // Pan the point backwards.
3018 Dxv = (XS - X0) / coef;
3019 Dyv = (YS - Y0) / coef;
3021 MyXwindowCenter = (Umin + Umax) / 2.0;
3022 MyYwindowCenter = (Vmin + Vmax) / 2.0;
3023 MyWindowWidth = Abs(Umax - Umin);
3024 MyWindowHeight = Abs(Vmax - Vmin);
3026 Standard_Real Xrp,Yrp,Zrp;
3027 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
3028 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
3030 Xrp = MyXwindowCenter - Dxv;
3031 Yrp = MyYwindowCenter - Dyv;
3033 Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
3034 Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
3036 // Set new reference plane coordintes of the window.
3037 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
3038 if (MyType != V3d_PERSPECTIVE)
3040 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
3041 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3043 MyView->SetViewMapping(MyViewMapping);
3046 SetImmediateUpdate(update);
3050 void V3d_View::AxialScale (const Standard_Integer Dx,
3051 const Standard_Integer Dy,
3052 const V3d_TypeOfAxe Axis)
3054 if( Dx != 0. || Dy != 0. ) {
3055 Standard_Real Sx, Sy, Sz;
3056 AxialScale( Sx, Sy, Sz );
3057 Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
3058 dscale = (Dx > 0) ? dscale : 1./dscale;
3059 if( Axis == V3d_X ) Sx = dscale;
3060 if( Axis == V3d_Y ) Sy = dscale;
3061 if( Axis == V3d_Z ) Sz = dscale;
3062 SetAxialScale( Sx, Sy, Sz );
3066 void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
3067 const Standard_Real Xmin,
3068 const Standard_Real Ymin,
3069 const Standard_Real Xmax,
3070 const Standard_Real Ymax)
3073 Standard_Real Umin,Umax,Vmin,Vmax,Xrp,Yrp,Zrp ;
3074 Standard_Real DxvOld,DyvOld,DxvNew,DyvNew,RapOld,RapNew ;
3075 Standard_Integer Xpixel,Ypixel;
3076 //Standard_Integer Xleft,Yup,Xright,Ylow ;
3078 Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
3079 "V3d_View::FitAll, Window Size is NULL");
3081 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
3082 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
3083 aWindow->Size(Xpixel,Ypixel);
3084 DxvOld = Xpixel; DyvOld = Ypixel;
3086 if( (DxvOld == 0.) || (DyvOld == 0.) ) return ;
3087 RapOld = DxvOld/DyvOld ;
3088 DxvNew = Abs(Xmax - Xmin) ; DyvNew = Abs(Ymax - Ymin) ;
3089 RapNew = DxvNew/DyvNew ;
3090 if( RapNew >= RapOld ) {
3091 DyvNew = DxvNew/RapOld ;
3093 DxvNew = DyvNew*RapOld ;
3095 Xrp = (Xmin + Xmax)/2. ; Yrp = (Ymin + Ymax)/2. ;
3096 Umin = Xrp - DxvNew/2. ; Vmin = Yrp - DyvNew/2. ;
3097 Umax = Xrp + DxvNew/2. ; Vmax = Yrp + DyvNew/2. ;
3098 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
3099 if( MyType != V3d_PERSPECTIVE ) {
3100 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
3101 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3103 MyView->SetViewMapping(MyViewMapping) ;
3112 static Standard_Boolean zRotation = Standard_False;
3114 void V3d_View::StartRotation(const Standard_Integer X,
3115 const Standard_Integer Y,
3116 const Quantity_Ratio zRotationThreshold)
3122 rx = Standard_Real(Convert(x));
3123 ry = Standard_Real(Convert(y));
3125 Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
3127 zRotation = Standard_False;
3128 if( zRotationThreshold > 0. ) {
3129 Standard_Real dx = Abs(sx - rx/2.);
3130 Standard_Real dy = Abs(sy - ry/2.);
3131 // if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True;
3132 Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
3133 if( dx > dd || dy > dd ) zRotation = Standard_True;
3139 void V3d_View::Rotation(const Standard_Integer X,
3140 const Standard_Integer Y)
3144 if( rx == 0. || ry == 0. ) {
3150 Standard_Real dx=0.,dy=0.,dz=0.;
3152 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
3153 atan2(sx-rx/2.,ry/2.-sy);
3155 dx = (Standard_Real(X) - sx) * M_PI / rx;
3156 dy = (sy - Standard_Real(Y)) * M_PI / ry;
3158 Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
3160 Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
3161 Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
3162 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3165 if( !myImmediateUpdate ) Update();
3167 myImmediateUpdate = Standard_False;
3168 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3169 ZFitAll (Zmargin); //Don't do that, perf improvment
3170 myImmediateUpdate = Standard_True;
3175 void V3d_View::SetAnimationModeOn () {
3177 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3178 if( ComputedMode() ) { // Deactivates computed mode during animation
3179 MyAnimationFlags |= V3d_FLAG_COMPUTATION;
3180 Standard_Boolean immediatUpdate = myImmediateUpdate;
3181 myImmediateUpdate = Standard_False;
3182 SetComputedMode(Standard_False);
3183 myImmediateUpdate = immediatUpdate;
3185 MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
3188 MyView->SetAnimationModeOn();
3192 void V3d_View::SetAnimationModeOff () {
3194 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3195 MyView -> SetAnimationModeOff ();
3196 if ( MyAnimationFlags & V3d_FLAG_COMPUTATION ) {
3197 // Reactivates computed mode after animation
3198 MyAnimationFlags &= ~V3d_FLAG_COMPUTATION;
3199 SetComputedMode(Standard_True);
3200 } else if( MyAnimationFlags & V3d_FLAG_DEGENERATION ) {
3205 MyView->SetAnimationModeOff();
3209 Standard_Boolean V3d_View::AnimationModeIsOn () const {
3210 return MyView->AnimationModeIsOn();
3214 void V3d_View :: SetAnimationMode
3216 const Standard_Boolean anAnimationFlag,
3217 const Standard_Boolean aDegenerationFlag
3221 if ( anAnimationFlag )
3222 MyAnimationFlags |= V3d_FLAG_ANIMATION;
3224 MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
3226 if ( aDegenerationFlag )
3227 MyAnimationFlags |= V3d_FLAG_DEGENERATION;
3229 MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
3231 } // end V3d_View :: SetAnimationMode
3233 Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
3236 isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
3237 return MyAnimationFlags & V3d_FLAG_ANIMATION;
3241 void V3d_View::SetDegenerateModeOn() {
3243 SetComputedMode(Standard_False);
3245 MyView->SetDegenerateModeOn();
3250 void V3d_View::SetDegenerateModeOff()
3253 SetComputedMode(Standard_True);
3255 if(myComputedMode) {
3256 MyView->SetDegenerateModeOff();
3262 Standard_Boolean V3d_View::DegenerateModeIsOn() const
3265 return !ComputedMode();
3267 return MyView->DegenerateModeIsOn();
3272 void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3276 if( myComputedMode ) {
3277 MyView -> SetComputedMode ( Standard_True );
3281 MyView -> SetComputedMode ( Standard_False );
3285 } // end V3d_View :: SetComputedMode
3287 Standard_Boolean V3d_View :: ComputedMode () const
3290 return MyView -> ComputedMode ();
3292 } // end V3d_View :: ComputedMode
3294 void V3d_View :: SetBackFacingModel (
3295 const V3d_TypeOfBackfacingModel aModel)
3298 MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
3300 } // end V3d_View :: SetBackFacingModel
3302 V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const {
3304 return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
3306 } // end V3d_View :: BackFacingModel
3309 Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const {
3310 return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
3313 void V3d_View::TransientManagerClearDraw() const {
3314 Visual3d_TransientManager::ClearDraw(MyView);
3317 Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const {
3318 return Visual3d_TransientManager::BeginAddDraw(MyView);
3321 void V3d_View::Init() {
3322 myComputedMode = MyViewer->ComputedMode();
3324 if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
3325 SetComputedMode(Standard_False);
3329 MyView->SetDegenerateModeOn();
3331 if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
3335 OSD_Environment env_walkthrow("CSF_WALKTHROUGH");
3336 env_walkthrow.SetName( "CSF_WALKTHROUGH" );
3337 if ( env_walkthrow.Value () != "" ) MyProjModel = V3d_TPM_WALKTHROUGH;
3338 else MyProjModel = V3d_TPM_SCREEN;
3343 void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) {
3344 MyPlotter = aPlotter;
3347 void V3d_View::Plot()
3350 Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
3352 MyView->Plot(MyPlotter);
3355 Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
3361 if (AnimationMode) MyView->SetAnimationModeOn();
3363 Standard_Real delta = 0.01;
3364 Standard_Real xangle, yangle;
3365 xangle = yangle = delta*int(NbImages/3);
3367 Rotate (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_True);
3368 for (i=1; i<=int(NbImages/3); i++)
3369 Rotate (delta*i, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_False);
3370 for (i=1; i<=int(NbImages/3); i++)
3371 Rotate (xangle, delta*i, 0.0, 0.0, 0.0, 0.0, Standard_False);
3372 for (i=1; i<=int(NbImages/3); i++)
3373 Rotate (xangle, yangle, delta*i, 0.0, 0.0, 0.0, Standard_False);
3374 if (AnimationMode) MyView->SetAnimationModeOff();
3377 cout << "For " << NbImages << " Images : " << endl;
3378 FullTimer.Show (cout);
3381 Standard_Real Seconds, CPUtime;
3382 Standard_Integer Minutes, Hours;
3384 FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
3385 cout << "Result " << (AnimationMode ? "with " : "without ")
3386 << "display list : " << NbImages/CPUtime << " images/Second."
3389 return NbImages/CPUtime;
3393 #define SCREENCOPY_FILENAME "screencopy3d.gif"
3394 void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
3395 const Standard_Boolean fWhiteBackground,
3396 const Quantity_Factor aPlotScale)
3398 TCollection_AsciiString aFileToDump;
3399 Handle(Aspect_WindowDriver) aWindowDriver =
3401 new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
3403 new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
3405 Quantity_Factor aScale;
3406 Quantity_Length thePixel;
3407 Quantity_Parameter theWWidth, theWHeight;
3408 Quantity_Parameter thePWidth, thePHeight;
3409 aPlotterDriver -> WorkSpace (thePWidth, thePHeight);
3410 aWindowDriver -> WorkSpace (theWWidth, theWHeight);
3411 thePixel = aWindowDriver -> Convert (1);
3413 if (theWWidth * theWHeight != 0.) {
3414 if (aPlotScale == 0.) {
3415 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3417 // To be changed !!!!!!!!!!!!!!!
3418 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3421 // Set default maps (color, type, etc) for plotter driver
3422 aPlotterDriver -> SetColorMap ( new Aspect_GenericColorMap () );
3423 aPlotterDriver -> SetTypeMap ( new Aspect_TypeMap () );
3424 aPlotterDriver -> SetWidthMap ( new Aspect_WidthMap () );
3425 aPlotterDriver -> SetFontMap ( new Aspect_FontMap () );
3426 aPlotterDriver -> SetMarkMap ( new Aspect_MarkMap () );
3428 // Set backgroung to white, unihiglight if any
3429 Quantity_Parameter theRed, theGreen, theBlue;
3430 Handle(TColStd_HSequenceOfInteger) theFlags;
3431 Graphic3d_MapOfStructure theStructures;
3432 BackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3433 if (fWhiteBackground)
3434 SetBackgroundColor (Quantity_NOC_WHITE);
3435 MyView -> DisplayedStructures (theStructures);
3436 theFlags = new TColStd_HSequenceOfInteger ();
3437 Graphic3d_MapIteratorOfMapOfStructure Iterator (theStructures);
3438 while (Iterator.More ()) {
3439 Handle(Graphic3d_Structure) aStructure = Iterator.Key();
3440 if (aStructure -> IsHighlighted()) {
3441 theFlags -> Append (1);
3442 aStructure -> UnHighlight ();
3444 theFlags -> Append (0);
3451 if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
3452 aFileToDump = aPlotterDriver->PlotFileName();
3454 aFileToDump = aPlotterDriver->SpoolDirectory();
3455 aFileToDump += SCREENCOPY_FILENAME;
3457 MyWindow -> Dump (aFileToDump.ToCString());
3459 Standard_Integer theCurStruct = 1;
3460 Iterator = Graphic3d_MapIteratorOfMapOfStructure (theStructures);
3461 while (Iterator.More ()) {
3462 if (theFlags -> Value(theCurStruct))
3463 Iterator.Key() -> Highlight (Aspect_TOHM_COLOR);
3467 if (fWhiteBackground)
3468 SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3471 // Draw imagefile by plotter driver
3472 aPlotterDriver -> SetPixelSize (thePixel);
3473 aPlotterDriver -> BeginDraw ();
3474 aPlotterDriver -> DrawImageFile (
3475 aFileToDump.ToCString(), (float)(thePWidth / 2.), (float)(thePHeight / 2.), aScale);
3476 aPlotterDriver -> EndDraw ();
3479 #undef SCREENCOPY_FILENAME
3481 #include <Aspect.hxx>
3482 #include <Visual3d_Layer.hxx>
3484 ////////////////////////////////////////////////////////////////
3485 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3486 const Image_TypeOfImage theBufferType)
3488 Standard_Integer aWinWidth, aWinHeight;
3489 MyWindow->Size (aWinWidth, aWinHeight);
3491 Handle(Aspect_PixMap) aPixMap = ToPixMap (aWinWidth, aWinHeight, theBufferType);
3492 return !aPixMap.IsNull() && aPixMap->Dump (theFile);
3495 ////////////////////////////////////////////////////////////////
3496 Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3497 const Aspect_FormatOfSheetPaper theFormat,
3498 const Image_TypeOfImage theBufferType)
3500 Standard_Boolean isDone = Standard_False;
3501 // convert Aspect_FormatOfSheetPaper size to pixel ...
3502 Quantity_Length anSPWidth, anSPHeight;
3503 Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
3505 // adjusting to the ratio width/height ...
3506 Quantity_Length aWinWidth, aWinHeight;
3507 MyWindow->MMSize (aWinWidth, aWinHeight);
3508 Standard_Integer aPixelWidth, aPixelHeight;
3509 MyWindow->Size (aPixelWidth, aPixelHeight);
3511 Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
3512 aPixelWidth = Standard_Integer (aPixelWidth * aScale);
3513 aPixelHeight = Standard_Integer (aPixelHeight * aScale);
3515 Handle(Aspect_PixMap) aBitmap = ToPixMap (aPixelWidth, aPixelHeight, theBufferType);
3516 Standard_Real aGammaValue = 1.0;
3517 OSD_Environment anEnvGamma ("CSF_GAMMA_CORRECTION");
3518 TCollection_AsciiString strGamma (anEnvGamma.Value());
3519 if (!strGamma.IsEmpty()) aGammaValue = strGamma.RealValue();
3520 isDone = !aBitmap.IsNull() && aBitmap->Dump (theFile, aGammaValue);
3525 ////////////////////////////////////////////////////////////////
3526 Handle(Image_PixMap) V3d_View::ToPixMap (const Standard_Integer theWidth,
3527 const Standard_Integer theHeight,
3528 const Image_TypeOfImage theBufferType,
3529 const Standard_Boolean theIsForceCentred)
3531 // always prefer hardware accelerated offscreen buffer
3532 Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
3533 Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
3534 Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
3535 Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0);
3536 Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
3537 if (aPrevFBOPtr != NULL)
3539 MyView->FBOGetDimensions (aPrevFBOPtr,
3540 aPrevFBOVPSizeX, aPrevFBOVPSizeY,
3541 aPrevFBOSizeXMax, aPrevFBOSizeYMax);
3542 if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax)
3544 MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
3545 aFBOPtr = aPrevFBOPtr;
3549 if (aFBOPtr == NULL)
3551 // Try to create hardware accelerated buffer
3552 aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY);
3553 if (aFBOPtr != NULL)
3555 MyView->FBOGetDimensions (aFBOPtr,
3556 aFBOVPSizeX, aFBOVPSizeY,
3557 aFBOSizeXMax, aFBOSizeYMax);
3558 // reduce viewport in case of hardware limits
3559 if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax;
3560 if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax;
3561 MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
3564 cView->ptrFBO = aFBOPtr;
3566 // If hardware accelerated buffer - try to use onscreen buffer
3567 // Results may be bad!
3568 if (aFBOPtr == NULL)
3570 // retrieve window sizes
3571 Standard_Integer aWinWidth, aWinHeight;
3572 MyWindow->Size (aWinWidth, aWinHeight);
3574 // technically we can reduce existing viewport...
3575 // but currently allow only dumping the window itself
3576 if (aFBOVPSizeX != aWinWidth || aFBOVPSizeY != aWinHeight)
3578 return Handle(Image_PixMap)();
3583 Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
3584 Standard_Real Umin, Vmin, Umax, Vmax;
3586 if (theIsForceCentred)
3588 //szv: get mapping frame
3589 Standard_Real PUmin, PVmin, PUmax, PVmax;
3590 prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
3592 //szv: calculate expansion
3593 Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
3594 Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
3595 Standard_Real newWidth = (oldHeight * aFBOVPSizeX) / aFBOVPSizeY;
3596 if (newWidth < oldWidth)
3598 Standard_Real newHeight = (oldWidth * aFBOVPSizeY) / aFBOVPSizeX;
3600 Standard_Real delta = 0.5 * (newHeight - oldHeight);
3601 Vmin = PVmin - delta;
3602 Vmax = PVmax + delta;
3607 Standard_Real delta = 0.5 * (newWidth - oldWidth);
3608 Umin = PUmin - delta;
3609 Umax = PUmax + delta;
3612 //szv: apply expanded mapping
3613 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
3614 MyView->SetViewMapping (MyViewMapping);
3617 //workround for rendering list of Over and Under Layers
3618 if (!MyLayerMgr.IsNull())
3620 MyLayerMgr->Compute();
3624 //szv: restore mapping
3625 MyViewMapping = prevMapping;
3626 MyView->SetViewMapping (prevMapping);
3628 // allocate image buffer for dumping
3629 Image_CRawBufferData aRawBuffer;
3630 Handle(Image_PixMap) anImageBitmap = new Image_PixMap (aFBOVPSizeX, aFBOVPSizeY, theBufferType);
3631 anImageBitmap->AccessBuffer (aRawBuffer);
3632 if (!MyView->BufferDump (aRawBuffer))
3635 anImageBitmap = Handle(Image_PixMap)();
3638 // FBO now useless, free resources
3639 if (aFBOPtr != aPrevFBOPtr)
3641 MyView->FBORelease (aFBOPtr);
3643 else if (aPrevFBOPtr != NULL)
3645 MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
3647 cView->ptrFBO = aPrevFBOPtr;
3648 return anImageBitmap;