0023272: Image comparison algorithm
[occt.git] / src / V3d / V3d_View.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 18/***********************************************************************
19
20FONCTION :
21----------
22Classe V3d_View :
23
24HISTORIQUE DES MODIFICATIONS :
25--------------------------------
2600-09-92 : GG ; Creation.
2702-10-96 : FMN ; Suppression appel Redraw sans MustBeResized()
2805-06-97 : FMN ; Correction FitAll()
2930-06-97 : GG ; Correction + Optimisation de Panning(...)
30On fait la translation + le zoom en une seule
31operation au lieu de 2 precedemment qui etait buggee.
3209-07-97 : FMN ; Correction FitAll() sur le Ratio
3316-07-97 : FMN ; Correction FitAll() sur le calcul de la Box
3422-07-97 : FMN ; Ajout mode RetainMode pour le Transient
3515-12-97 : FMN ; Ajout texture mapping
3617-12-97 : FMN ; CTS19129 Correction FitAll() multiple
3718-12-97 : FMN ; Ajout mode Ajout
3824-12-97 : FMN ; Remplacement de math par MathGra
3924-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window
4031-12-97 : CAL ; Remplacement de MathGra par Array2OfReal
4107-01-98 : CAL ; Ajout de la methode DoMapping.
4207-01-98 : CAL ; Retrait de tous les "this->" inutiles
4321-01-98 : CAL ; Remplacement des Window->Position () par Window->Size ()
4427-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
4512-02-98 : GG ; Reactivation du Redraw dans MustBeResized()
4623-02-98 : FMN ; Remplacement PI par Standard_PI
4725-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view
4811-03-98 : STT ; S3558
4919-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
50ne marche pas.
5108-04-98 : STT ; suppr. S3558
5210-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef
5313-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
54ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
5516-08-98 : CAL ; S3892. Ajout grilles 3d.
5609-09-98 : CAL ; S3892. Generalisation de TrsPoint.
5724-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
5806-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
5916-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
6006-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
6113-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
6229-OCT-98 : DCB : Adding ScreenCopy () method.
6322-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
6410-11-99 : GG ; PRO19603 Add Redraw( area ) method
65IMP130100 : GG
66-> Don't increase too much the ZSize.
67-> Initialize correctly the Z clipping and D cueing
68planes.
69IMP100701 : SZV ; Add ToPixMap() method
70
71REMARQUES :
72-----------
73About FitAll() multiple. This probleme is caused by missing
74precision of transformation matrices. If it is supposed that
75projection is made in the plane (U,V), there is a difference
76after several Zoom - compared to the exact value (cf ZoomX).
77Don't forget that the matrices work in float and not in double.
78To solve the problem (for lack of a better solution) I make 2 passes.
79
80************************************************************************/
81
82#define GER61351 //GG_15/12/99 Add SetBackgroundColor()
83// and BackgroundColor() methods
84
85
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.
99
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
107
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.
112
113#define IMP210200 //GG Add Transparency() method
114
115#define IMP250200 //GG With SetDepth() method, when the requested
116// depth is < 0.,
117// move the view ref point and the eye,instead
118// only the eye.
119
120#define IMP020300 //GG Don't use ZFitAll in during Rotation
121// for perf improvment
122
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.
126
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)
133// method.
134
135#define BUC60952 //GG Enable to rotate around the view axis
136// and the required view point
137
138#define RIC120302 //GG Add a NEW SetWindow method which enable
139// to connect a graphic widget and context to OGL.
140
141#define IMP260302 //GG To avoid conflicting in Window destructor
142// nullify this handle in Remove method
143
144#define OCC280 //SAV fix for FitAll problem in the perspective view.
145
146#define OCC1188 //SAV Added methods to set background image
147
148/*----------------------------------------------------------------------*/
149/*
150* Includes
151*/
152
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>
692613e5 161#include <Image_AlienPixMap.hxx>
7fd59977 162#include <V3d.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>
170
171// S3892
172#include <Graphic3d_AspectMarker3d.hxx>
173
174// S3603
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>
182#ifdef WNT
183# include <WNT_WDriver.hxx>
184#else
185# include <Xw_Driver.hxx>
186#endif
187
188#ifdef G003
189# define V3d_FLAG_ANIMATION 0x00000001
190# define V3d_FLAG_DEGENERATION 0x00000002
191# define V3d_FLAG_COMPUTATION 0x00000004
192#endif // G003
193
194// Tumble
195#include <OSD_Timer.hxx>
196static OSD_Timer FullTimer;
197
198// Perspective
199#include <OSD_Environment.hxx>
200
201/*----------------------------------------------------------------------*/
202/*
203* Constant
204*/
205
206#define Zmargin 1.
c6541a0c 207#define DEUXPI (2. * M_PI)
7fd59977 208
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
213
214/*----------------------------------------------------------------------*/
215/*
216* Local data definitions
217*/
218
219
220static Standard_Real MyXwindowCenter ;
221static Standard_Real MyYwindowCenter ;
222static Standard_Real MyWindowWidth ;
223static Standard_Real MyWindowHeight ;
224
225#define LOPTIM
226#ifndef LOPTIM
227static Graphic3d_Vector MyXscreenAxis ;
228static Graphic3d_Vector MyYscreenAxis ;
229static Graphic3d_Vector MyZscreenAxis ;
230static Graphic3d_Vector MyViewReferencePlane ;
231static Graphic3d_Vector MyViewReferenceUp ;
232static Graphic3d_Vector MyViewAxis ;
233static Graphic3d_Vertex MyViewReferencePoint ;
234static Graphic3d_Vertex MyGravityReferencePoint ;
235static Graphic3d_Vertex MyProjReferencePoint ;
236#else
237static Graphic3d_Vector& _MyXscreenAxis() {
238 static Graphic3d_Vector MyXscreenAxis;
239 return MyXscreenAxis;
240}
241#define MyXscreenAxis _MyXscreenAxis()
242
243static Graphic3d_Vector& _MyYscreenAxis() {
244 static Graphic3d_Vector MyYscreenAxis;
245 return MyYscreenAxis;
246}
247#define MyYscreenAxis _MyYscreenAxis()
248
249static Graphic3d_Vector& _MyZscreenAxis() {
250 static Graphic3d_Vector MyZscreenAxis;
251 return MyZscreenAxis;
252}
253#define MyZscreenAxis _MyZscreenAxis()
254
255static Graphic3d_Vector& _MyViewReferencePlane() {
256 static Graphic3d_Vector MyViewReferencePlane;
257 return MyViewReferencePlane;
258}
259#define MyViewReferencePlane _MyViewReferencePlane()
260
261static Graphic3d_Vector& _MyViewReferenceUp() {
262 static Graphic3d_Vector MyViewReferenceUp;
263 return MyViewReferenceUp;
264}
265#define MyViewReferenceUp _MyViewReferenceUp()
266
267static Graphic3d_Vector& _MyViewAxis() {
268 static Graphic3d_Vector MyViewAxis;
269 return MyViewAxis;
270}
271#define MyViewAxis _MyViewAxis()
272
273static Graphic3d_Vertex& _MyViewReferencePoint() {
274 static Graphic3d_Vertex MyViewReferencePoint;
275 return MyViewReferencePoint;
276}
277#define MyViewReferencePoint _MyViewReferencePoint()
278
279static Graphic3d_Vertex& _MyGravityReferencePoint() {
280 static Graphic3d_Vertex MyGravityReferencePoint;
281 return MyGravityReferencePoint;
282}
283#define MyGravityReferencePoint _MyGravityReferencePoint()
284
285static Graphic3d_Vertex& _MyProjReferencePoint() {
286 static Graphic3d_Vertex MyProjReferencePoint;
287 return MyProjReferencePoint;
288}
289#define MyProjReferencePoint _MyProjReferencePoint()
290#endif // LOPTIM
291
292/*----------------------------------------------------------------------*/
293//-Constructors
294
295V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
296MyType ( Type ),
297MyViewer(VM.operator->()),
298MyActiveLights(),
299MyActivePlanes(),
300MyViewContext (),
301myActiveLightsIterator(),
302myActivePlanesIterator(),
303SwitchSetFront(Standard_False),
304MyTrsf (1, 4, 1, 4), // S3892
305MyProjModel(V3d_TPM_SCREEN)
306#if defined(TRACE_POINTS)
307,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
308MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
309#endif
310{
311
312 myImmediateUpdate = Standard_False;
313 MyView = new Visual3d_View(MyViewer->Viewer());
314
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.
323
324 // Aliasing
325 if ((MyView->Context ()).AliasingIsOn ())
326 MyViewContext.SetAliasingOn ();
327 else
328 MyViewContext.SetAliasingOff ();
329
330 // DepthCueing
331 MyViewContext.SetDepthCueingBackPlane
332 ((MyView->Context ()).DepthCueingBackPlane ());
333 MyViewContext.SetDepthCueingFrontPlane
334 ((MyView->Context ()).DepthCueingFrontPlane ());
335
336 if ((MyView->Context ()).DepthCueingIsOn ())
337 MyViewContext.SetDepthCueingOn ();
338 else
339 MyViewContext.SetDepthCueingOff ();
340
341 // ZClipping
342 MyViewContext.SetZClippingBackPlane
343 ((MyView->Context ()).ZClippingBackPlane ());
344 MyViewContext.SetZClippingFrontPlane
345 ((MyView->Context ()).ZClippingFrontPlane ());
346
347 if ((MyView->Context ()).FrontZClippingIsOn ())
348 MyViewContext.SetFrontZClippingOn ();
349 else
350 MyViewContext.SetFrontZClippingOff ();
351
352 if ((MyView->Context ()).BackZClippingIsOn ())
353 MyViewContext.SetBackZClippingOn ();
354 else
355 MyViewContext.SetBackZClippingOff ();
356
357 // Visualisation and Shading Model
358 MyViewContext.SetModel ((MyView->Context ()).Model ());
359 MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
360
361 // Texture Mapping
362 MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
363 MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
364 // } End of retrieval of the definition of ViewContext.
365
366 MyViewMapping = MyView->ViewMapping() ;
367 MyViewOrientation = MyView->ViewOrientation() ;
368 MyBackground = VM->GetBackgroundColor() ;
369 MyGradientBackground = VM->GetGradientBackground() ;
370
371 SetAxis(0.,0.,0.,1.,1.,1.) ;
372 SetVisualization(VM->DefaultVisualization()) ;
373 SetShadingModel(VM->DefaultShadingModel()) ;
374 SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
375 SetTwist(0.) ;
376 SetAt(0.,0.,0.) ;
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);
383 SetZCueingDepth(0.);
384 SetZCueingWidth(zsize);
385 SetDepth(VM->DefaultViewSize()/2.) ;
386 SetCenter(0.,0.) ;
387 SetViewMappingDefault();
388 VM->AddView(this) ;
389 Init();
390 myImmediateUpdate = Standard_True;
391
392 // S3892
393#ifndef IMP240100
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);
400#endif
401#endif //IMP240100
402
403#ifdef G003
404 MyAnimationFlags = 0;
405#endif // G003
406
407#ifdef IMP210200
408 MyTransparencyFlag = Standard_False;
409#endif
410
411}
412
413/*----------------------------------------------------------------------*/
414
415V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
416MyType ( Type ),
417MyViewer(VM.operator->()),
418MyActiveLights(),
419MyActivePlanes(),
420MyViewContext (),
421myActiveLightsIterator(),
422myActivePlanesIterator(),
423SwitchSetFront(Standard_False),
424MyTrsf (1, 4, 1, 4), // S3892
425MyProjModel(V3d_TPM_SCREEN)
426#if defined(TRACE_POINTS)
427,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
428MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
429#endif
430{
431
432 Handle(Visual3d_View) FromView = V->View() ;
433
434 myImmediateUpdate = Standard_False;
435 MyView = new Visual3d_View(MyViewer->Viewer());
436
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());}
441
442 MyViewContext = FromView->Context() ;
443
444 MyViewMapping = FromView->ViewMapping() ;
445 MyViewOrientation = FromView->ViewOrientation() ;
446 MyBackground = FromView->Background() ;
447 MyGradientBackground = FromView->GradientBackground();
448
449 MyView->SetContext(MyViewContext) ;
450
451 SetAxis(0.,0.,0.,1.,1.,1.) ;
452 VM->AddView(this) ;
453 Init();
454 myImmediateUpdate = Standard_True;
455
456 // S3892
457#ifndef IMP240100
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);
464#endif
465#endif //IMP240100
466
467#ifdef G003
468 MyAnimationFlags = 0;
469#endif
470
471}
472
473/*----------------------------------------------------------------------*/
474
475//-Methods, in order
476
477void 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)
483{
484
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;
496 MyView->Redraw() ;
497 SetViewMappingDefault();
498 }
499
500}
501
502/*----------------------------------------------------------------------*/
503
504void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
505{
506
507 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
508 "V3d_View::SetWindow, window of view already defined");
509
510 MyView->SetWindow(TheWindow) ;
cdc2203b
M
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;
7fd59977 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) ;
524#ifdef TRACE_POINTS
525 MyGridEchoStructure->SetInfiniteState (Standard_True); // S3892
526 MyGridEchoStructure->Display (); // S3892
527#endif
528 MyView->Redraw() ;
7fd59977 529
530}
531
532// RIC120302
533/*----------------------------------------------------------------------*/
534
535void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
536 const Aspect_RenderingContext aContext,
537 const Aspect_GraphicCallbackProc& aDisplayCB,
538 const Standard_Address aClientData)
539{
540
541 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
542 "V3d_View::SetWindow, "
543 "window of view already defined");
cdc2203b
M
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.
548 MyWindow = aWindow;
7fd59977 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) ;
556 MyView->Redraw() ;
7fd59977 557
558}
559// RIC120302
560
561/*----------------------------------------------------------------------*/
562
5e27df78 563void V3d_View::Remove() const
564{
565 MyViewer->DelView (this);
566 MyView->Remove();
567 Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
568 aWin.Nullify();
7fd59977 569}
570
571/*----------------------------------------------------------------------*/
572
573void V3d_View::Update() const {
574 if( MyView->IsDefined() ) MyView->Update() ;
575}
576
577/*----------------------------------------------------------------------*/
578
579void V3d_View::Redraw() const {
580 if( MyView->IsDefined() ) MyView->Redraw() ;
581}
582/*----------------------------------------------------------------------*/
583
584void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
585 const Standard_Integer width,const Standard_Integer height) const
586{
587 if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
588}
589
590/*----------------------------------------------------------------------*/
591
592Standard_Boolean V3d_View::IsEmpty() const {
593
594 Standard_Boolean TheStatus = Standard_True ;
595 if( MyView->IsDefined() ) {
596 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
597 if( Nstruct > 0 ) TheStatus = Standard_False ;
598 }
599 return (TheStatus) ;
600
601}
602
603/*----------------------------------------------------------------------*/
604
605void V3d_View::UpdateLights() const {
606 MyView->SetContext(MyViewContext);
607 Update();
608}
609
610/*----------------------------------------------------------------------*/
611
612void V3d_View::DoMapping() {
613 if( MyView->IsDefined() ) {
614 (MyView->Window())->DoMapping() ;
615 }
616}
617
618/*----------------------------------------------------------------------*/
619
620void V3d_View::MustBeResized() {
621
622 if ( !MyLayerMgr.IsNull() )
623 MyLayerMgr->Resized();
624
625 if( MyView->IsDefined() ) {
626 MyView->Resized() ;
627 MyViewMapping = MyView->ViewMapping();
628 MyView->Redraw();
629 }
630
631}
632
633/*----------------------------------------------------------------------*/
634
635void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
636{
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 );
640
641 Quantity_Color C( V1, V2, V3, Type );
642#ifdef GER61351
643 SetBackgroundColor( C );
644#else
645 MyBackground.SetColor( C );
646 if ( MyView->IsDefined() )
647 MyView->SetBackground( MyBackground );
648 if ( !MyLayerMgr.IsNull() )
649 MyLayerMgr->Resized();
650#endif
651}
652
653#ifdef GER61351
654/*----------------------------------------------------------------------*/
655
656void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
657{
658 MyBackground.SetColor( Color );
659 if ( MyView->IsDefined() )
660 MyView->SetBackground( MyBackground );
661 //szv: Why?
662 if ( !MyLayerMgr.IsNull() )
663 MyLayerMgr->Resized();
664}
665#endif
666
667/*----------------------------------------------------------------------*/
668
669void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
670{
671 Quantity_Color C( Name );
672#ifdef GER61351
673 SetBackgroundColor( C );
674#else
675 MyBackground.SetColor( C );
676 if ( MyView->IsDefined() )
677 MyView->SetBackground( MyBackground );
678 if ( !MyColorScale.IsNull() )
679 MyColorScale->Resized();
680#endif
681}
682
683/*----------------------------------------------------------------------*/
684
685void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
686 const Quantity_Color& Color2,
687 const Aspect_GradientFillMethod FillStyle,
688 const Standard_Boolean status)
689{
690
691 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
692 if ( MyView->IsDefined() )
693 MyView->SetGradientBackground( MyGradientBackground, status );
694
695}
696
697/*----------------------------------------------------------------------*/
698
699void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
700 const Quantity_NameOfColor Color2,
701 const Aspect_GradientFillMethod FillStyle,
702 const Standard_Boolean status )
703{
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 );
709}
710
711/*----------------------------------------------------------------------*/
712
713void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
f8b2ed36 714 const Standard_Boolean update)
7fd59977 715{
f8b2ed36 716 Quantity_Color Color1, Color2;
717 MyGradientBackground.Colors( Color1, Color2 );
718 MyGradientBackground.SetColors( Color1, Color2, FillStyle );
7fd59977 719 if( MyView->IsDefined() )
f8b2ed36 720 MyView->SetBgGradientStyle( FillStyle, update ) ;
7fd59977 721}
722
723/*----------------------------------------------------------------------*/
724
725void V3d_View::SetBackgroundImage( const Standard_CString FileName,
726 const Aspect_FillMethod FillStyle,
727 const Standard_Boolean update )
728{
729#ifdef OCC1188
730 if( MyView->IsDefined() )
731 MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
732#endif
733}
734
735/*----------------------------------------------------------------------*/
736
737void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
738 const Standard_Boolean update )
739{
740#ifdef OCC1188
741 if( MyView->IsDefined() )
742 MyView->SetBgImageStyle( FillStyle, update ) ;
743#endif
744}
745
746/*----------------------------------------------------------------------*/
747
748void 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) {
749
750 Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
751
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() ;
758
759}
760
761/*----------------------------------------------------------------------*/
762
763void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) {
764
765 MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
766 MyView->SetContext(MyViewContext) ;
767
768}
769
770/*----------------------------------------------------------------------*/
771
772void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) {
773
774 MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
775 MyView->SetContext(MyViewContext) ;
776
777}
778
779/*----------------------------------------------------------------------*/
780
781void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) {
782
783 MyViewContext.SetTextureEnv(ATexture) ;
784 MyView->SetContext(MyViewContext) ;
785
786}
787
788/*----------------------------------------------------------------------*/
789
790void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) {
791
792 MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
793 MyView->SetContext(MyViewContext) ;
794
795}
796
797/*----------------------------------------------------------------------*/
798
799void V3d_View::SetFront() {
800
801 gp_Ax3 a = MyViewer->PrivilegedPlane();
802 Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
803
804 a.Direction().Coord(vx,vy,vz);
805 a.YDirection().Coord(xu,yu,zu);
806 a.Location().Coord(xo,yo,zo);
807
808 if(SwitchSetFront)
809 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
810 else
811 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
812
813 SwitchSetFront = !SwitchSetFront;
814
815 MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
816 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
817
818 MyView->SetViewOrientation(MyViewOrientation) ;
819
820 ImmediateUpdate();
821
822}
823
824/*----------------------------------------------------------------------*/
825
826void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) {
827
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) ;
834
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 ;
841
842 if( Start ) {
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");
849 }
850
851 InitMatrix(Matrix) ;
852
853 if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
854 if( Ay != 0. ) {
855 RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
856 Multiply(Matrix, Rmatrix, Matrix);
857 }
858 if( Az != 0. ) {
859 RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
860 Multiply(Matrix, Rmatrix, Matrix);
861 }
862 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
863 MyViewOrientation.SetViewReferencePlane(Vpn) ;
864 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
865 MyViewOrientation.SetViewReferenceUp(Vup) ;
866 MyView->SetViewOrientation(MyViewOrientation) ;
867#ifdef IMP020300
868 SetZSize(0.) ;
869#endif
870 ImmediateUpdate();
871
872}
873
874/*----------------------------------------------------------------------*/
875
876void 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)
878{
879
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) ;
887
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 ;
894
895 if( Start ) {
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");
903 }
904
905 InitMatrix(Matrix) ;
906
907 if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
908 if( Ay != 0. ) {
909 RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
910 Multiply(Matrix, Rmatrix, Matrix);
911 }
912 if( Az != 0. ) {
913 RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
914 Multiply(Matrix, Rmatrix, Matrix);
915 }
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) ;
923#ifdef IMP020300
924 SetZSize(0.) ;
925#endif
926 ImmediateUpdate();
927
928}
929
930/*----------------------------------------------------------------------*/
931
932void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) {
933
934 switch (Axe) {
935 case V3d_X :
936 Rotate(angle,0.,0.,Start);
937 break ;
938 case V3d_Y :
939 Rotate(0.,angle,0.,Start);
940 break ;
941 case V3d_Z :
942 Rotate(0.,0.,angle,Start);
943 break ;
944 }
945
946}
947
948/*----------------------------------------------------------------------*/
949
950void 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)
952{
953
954 Standard_Real Angle = angle ;
955 Graphic3d_Vector Vpn,Vup ;
956 Graphic3d_Vertex Vrp ;
957 TColStd_Array2OfReal Matrix(0,3,0,3) ;
958
959 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
960 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
961
962 if( Start ) {
963 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
964 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
965 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
966 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
967 switch (Axe) {
968 case V3d_X :
969 MyViewAxis.SetCoord(1.,0.,0.) ;
970 break ;
971 case V3d_Y :
972 MyViewAxis.SetCoord(0.,1.,0.) ;
973 break ;
974 case V3d_Z :
975 MyViewAxis.SetCoord(0.,0.,1.) ;
976 break ;
977 }
978 }
979
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) ;
988#ifdef IMP020300
989 SetZSize(0.) ;
990#endif
991 ImmediateUpdate();
992
993}
994
995/*----------------------------------------------------------------------*/
996
997void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) {
998
999 Standard_Real Angle = angle ;
1000 Graphic3d_Vector Vpn,Vup ;
1001 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1002
1003 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1004 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1005
1006 if( Start ) {
1007 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1008 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1009 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1010 }
1011
1012 RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
1013#ifdef BUC60952
1014 Graphic3d_Vertex Vrp ;
1015 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1016 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1017#endif
1018 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1019 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1020 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1021 MyViewOrientation.SetViewReferenceUp(Vup) ;
1022 MyView->SetViewOrientation(MyViewOrientation) ;
1023#ifdef IMP020300
1024 SetZSize(0.) ;
1025#endif
1026 ImmediateUpdate();
1027
1028}
1029
1030/*----------------------------------------------------------------------*/
1031
1032void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
1033{
1034
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) ;
1043
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 ;
1050
1051 if( Start ) {
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");
1059 }
1060
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) ;
1068 if( Ay != 0. ) {
1069 RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
1070 Multiply(Matrix, Rmatrix, Matrix);
1071 }
1072 if( Az != 0. ) {
1073 RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
1074 Multiply(Matrix, Rmatrix, Matrix);
1075 }
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) ;
1083#ifdef IMP020300
1084 SetZSize(0.) ;
1085#else
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) ;
1093 }
1094#endif
1095 ImmediateUpdate();
1096
1097}
1098
1099/*----------------------------------------------------------------------*/
1100
1101void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1102{
1103
1104 switch (Axe) {
1105 case V3d_X :
1106 Turn(angle,0.,0.,Start);
1107 break ;
1108 case V3d_Y :
1109 Turn(0.,angle,0.,Start);
1110 break ;
1111 case V3d_Z :
1112 Turn(0.,0.,angle,Start);
1113 break ;
1114 }
1115}
1116
1117void 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) ;
1123
1124 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1125 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1126
1127 if( Start ) {
1128 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1129 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1130 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1131 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1132 }
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) ;
1146#ifdef IMP020300
1147 SetZSize(0.) ;
1148#else
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) ;
1156 }
1157#endif
1158 ImmediateUpdate();
1159
1160}
1161
1162void V3d_View::SetTwist(const Standard_Real angle) {
1163
1164 Standard_Real Angle = angle ;
1165 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1166 Standard_Boolean TheStatus ;
1167
1168 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1169 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1170
1171 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1172 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1173 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1174 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1175 if( !TheStatus ) {
1176 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1177 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1178 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1179 }
1180 if( !TheStatus ) {
1181 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1182 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1183 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1184 }
1185
1186 Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
1187
1188 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1189 RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
1190 MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
1191 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1192 MyView->SetViewOrientation(MyViewOrientation) ;
1193 ImmediateUpdate();
1194
1195}
1196
1197#ifdef IMP240100
1198void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
1199{
1200
1201 MyProjModel = aModel;
1202
1203}
1204
1205V3d_TypeOfProjectionModel V3d_View::ProjModel() const {
1206
1207 return MyProjModel;
1208
1209}
1210#endif
1211
1212void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1213
1214 Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
1215 Angle = Twist() ;
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");
1224
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);
1230
1231 Standard_Boolean update = myImmediateUpdate;
1232 myImmediateUpdate = Standard_False;
1233 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1234 //FMN desactivation temp SetTwist(Angle) ;
1235 // Set infos.
1236 MyView->SetViewOrientation(MyViewOrientation) ;
1237 MyView->SetViewMapping(MyViewMapping) ;
1238 } else {
1239 SetTwist(Angle) ;
1240 }
1241#ifdef IMP020300
1242 SetZSize(0.) ;
1243#else
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) ;
1249 } else {
1250 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1251 MyView->SetViewMapping(MyViewMapping);
1252 }
1253#endif
1254 myImmediateUpdate = update;
1255 ImmediateUpdate();
1256
1257}
1258
1259void V3d_View::SetDepth(const Standard_Real Depth) {
1260
1261 Standard_Real Xrp,Yrp,Zrp ;
1262#ifdef IMP250200
1263 Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
1264#else
1265 Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
1266#endif
1267
1268#ifdef DEB
1269 Standard_Real twist =
1270#endif
1271 Twist();
1272 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1273 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1274 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1275 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1276#ifdef IMP250200
1277 if( Depth > 0. )
1278#endif
1279 {
1280 Zrp = Depth;
1281 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1282 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1283 }
1284
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) ;
1289#ifdef IMP250200
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 ;
1292 Zrp = Abs(Depth) ;
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);
1298 }
1299#endif
1300#ifdef IMP020300
1301 MyView->SetViewMapping(MyViewMapping) ;
1302 SetZSize(0.) ;
1303#else
1304 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1305 Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1306
1307 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1308 MyProjModel == V3d_TPM_SCREEN ) {
1309 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1310 } else {
1311 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1312#ifdef IMP250200
1313 if( Depth > 0. )
1314#endif
1315 MyView->SetViewMapping(MyViewMapping) ;
1316 }
1317#endif
1318
1319 ImmediateUpdate();
1320
1321}
1322
1323
1324void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1325{
1326
1327 Standard_Real Angle ;
1328
1329 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1330 "V3d_View::SetProj, null projection vector");
1331
1332 Angle = Twist() ;
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) ;
1339#ifdef IMP020300
1340 SetZSize(0.) ;
1341#endif
1342 myImmediateUpdate = update;
1343 ImmediateUpdate();
1344
1345}
1346
1347void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) {
1348
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;
1356
1357 switch (Orientation) {
1358 case V3d_Zpos :
1359 Ypn = 1. ;
1360 break ;
1361 case V3d_Zneg :
1362 Ypn = -1. ;
1363 break ;
1364 default:
1365 Zpn = 1.;
1366 }
1367 SetUp(Xpn,Ypn,Zpn);
1368#ifdef IMP020300
1369 SetZSize(0.) ;
1370#endif
1371 ImmediateUpdate();
1372
1373}
1374
1375void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1376
1377 Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
1378 Standard_Real Xeye,Yeye,Zeye ;
1379
1380 Angle = Twist() ;
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");
1392
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) ;
1404 // Set infos.
1405 MyView->SetViewOrientation(MyViewOrientation) ;
1406 MyView->SetViewMapping(MyViewMapping) ;
1407 } else {
1408 SetTwist(Angle) ;
1409 }
1410#ifdef IMP020300
1411 MyView->SetViewMapping(MyViewMapping);
1412 SetZSize(0.) ;
1413#else
1414 ImmediateUpdate();
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) ;
1420 } else {
1421 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1422 MyView->SetViewMapping(MyViewMapping);
1423 }
1424#endif
1425 myImmediateUpdate = update;
1426 ImmediateUpdate();
1427
1428}
1429
1430void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) {
1431
1432 Standard_Boolean TheStatus ;
1433 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
1434 "V3d_View::SetUp, nullUp vector");
1435
1436 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1437 MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
1438 MyViewReferenceUp.Normalize() ;
1439 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1440 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1441 if( !TheStatus ) {
1442 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1443 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1444 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1445 }
1446 if( !TheStatus ) {
1447 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1448 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1449 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1450 }
1451 if( !TheStatus ) {
1452 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1453 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1454 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1455 }
1456 Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
1457
1458 MyViewReferenceUp = MyYscreenAxis ;
1459 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1460 MyView->SetViewOrientation(MyViewOrientation) ;
1461 ImmediateUpdate();
1462
1463}
1464
1465void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) {
1466
1467 Standard_Boolean TheStatus ;
1468
1469 MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
1470 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1471 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1472 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1473 if( !TheStatus ) {
1474 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1475 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1476 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1477 }
1478 if( !TheStatus ) {
1479 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1480 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1481 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1482 }
1483 if( !TheStatus ) {
1484 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1485 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1486 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1487 }
1488 Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
1489
1490 MyViewReferenceUp = MyYscreenAxis ;
1491 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1492 MyView->SetViewOrientation(MyViewOrientation) ;
1493 ImmediateUpdate();
1494
1495}
1496
1497void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
1498{
1499 MyViewOrientation = VO;
1500 MyView->SetViewOrientation(MyViewOrientation) ;
1501 ImmediateUpdate();
1502}
1503
1504void V3d_View::SetViewOrientationDefault() {
1505
1506 MyView->SetViewOrientation(MyViewOrientation) ;
1507 MyView->SetViewOrientationDefault() ;
1508 ImmediateUpdate();
1509}
1510
1511void V3d_View::ResetViewOrientation() {
1512
1513 MyView->ViewOrientationReset() ;
1514 MyViewOrientation = MyView->ViewOrientation() ;
1515 ImmediateUpdate();
1516}
1517
1518void V3d_View::Reset( const Standard_Boolean update ) {
1519
1520 MyView->ViewOrientationReset() ;
1521 MyViewOrientation = MyView->ViewOrientation() ;
1522 MyView->ViewMappingReset();
1523 MyViewMapping = MyView->ViewMapping() ;
1524
1525 ZFitAll (Zmargin);
1526 SwitchSetFront = Standard_False;
1527#ifdef IMP020300
1528 if( !myImmediateUpdate && update ) Update();
1529#else
1530 ImmediateUpdate();
1531#endif
1532
1533}
1534
1535void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
1536{
1537
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");
1540
1541 if( Start ) {
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");
1550 }
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) ;
1561 }
1562 MyView->SetViewMapping(MyViewMapping) ;
1563 ImmediateUpdate();
1564
1565}
1566void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) {
1567 Standard_Real x,y;
1568 Convert(X,Y,x,y);
1569 SetCenter(x,y);
1570}
1571
1572void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc){
1573
1574 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
1575
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");
1583
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) ;
1590 }
1591 MyView->SetViewMapping(MyViewMapping) ;
1592 ImmediateUpdate();
1593
1594}
1595
1596void V3d_View::SetSize(const Standard_Real Size)
1597{
1598
1599 Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
1600
1601 Viewer_BadValue_Raise_if( Size <= 0.,
1602 "V3d_View::SetSize, Window Size is NULL");
1603
1604
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 ;
1613 } else {
1614 MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
1615 }
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) ;
1622 ImmediateUpdate();
1623
1624}
1625
1626void V3d_View::SetZSize(const Standard_Real Size)
1627{
1628
1629 Standard_Real Zmax = Size/2.;
1630
1631#ifdef IMP020300
1632 if( Size <= 0. ) {
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;
1640 }
1641#else
1642 Viewer_BadValue_Raise_if( Size <= 0.,
1643 "V3d_View::SetZSize, Window ZSize is NULL");
1644#endif
1645
1646 Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
1647 Standard_Real Back = MyViewContext.ZClippingBackPlane() ;
1648 Standard_Real focale= Focale();
1649
1650 MyViewMapping.SetFrontPlaneDistance(Zmax) ;
1651 MyViewMapping.SetBackPlaneDistance(-Zmax) ;
1652
1653 // OCC18942
1654 if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
1655 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
1656 }
1657
1658 MyView->SetViewMapping(MyViewMapping) ;
1659 if( MyViewContext.FrontZClippingIsOn() ||
1660 MyViewContext.BackZClippingIsOn() ) {
1661 MyViewContext.SetZClippingFrontPlane(Front) ;
1662 MyViewContext.SetZClippingBackPlane(Back) ;
1663 MyView->SetContext(MyViewContext) ;
1664 }
1665
1666}
1667
1668void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
1669{
1670
1671 Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
1672 Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
1673
1674 if( Start ) {
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) ;
1680 }
1681
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;
1692
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) ;
1699 ImmediateUpdate();
1700}
1701
1702void V3d_View::SetScale( const Standard_Real Coef ) {
1703 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
1704 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
1705
1706 Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1707
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) ;
1717 ImmediateUpdate();
1718
1719}
1720
1721void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) {
1722
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");
1726
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);
1732
1733 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1734
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 ) {
1738 return;
1739 }
1740
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)) ;
1765
1766 if( Wmax > 0. ) {
1767 SetZSize(2.*Wmax + Wmax) ;
1768 }
1769
1770}
1771
1772void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
1773 const Standard_Boolean update)
1774{
35617823
K
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();
7fd59977 1779
35617823
K
1780 if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
1781 {
7fd59977 1782#ifndef IMP020300
1783 ImmediateUpdate();
1784#endif
35617823 1785 return;
7fd59977 1786 }
7fd59977 1787
35617823
K
1788 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1789 MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
1790 if (MyView->IsDefined())
1791 {
1792 Standard_Integer Xpixel, Ypixel;
1793 MyWindow->Size (Xpixel, Ypixel);
1794 DxvOld = Xpixel;
1795 DyvOld = Ypixel;
7fd59977 1796 }
35617823
K
1797 else
1798 {
1799 MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
1800 DxvOld = Abs (Umax - Umin);
1801 DyvOld = Abs (Vmax - Vmin);
7fd59977 1802 }
35617823
K
1803 if ((DxvOld == 0.0) || (DyvOld == 0.0))
1804 {
1805 return;
7fd59977 1806 }
1807
35617823
K
1808 Standard_Real aWinRatio = DxvOld / DyvOld;
1809
1810 // retrieve min / max values for current displayed objects
1811 MyView->MinMaxValues (Xmin, Ymin, Zmin,
1812 Xmax, Ymax, Zmax);
1813
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)
1817 {
7fd59977 1818#ifndef IMP020300
35617823 1819 ImmediateUpdate();
7fd59977 1820#endif
35617823
K
1821 return;
1822 }
7fd59977 1823
35617823
K
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)
1827 {
1828 MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
1829 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1830 }
1831 MyView->SetViewMapping (MyViewMapping);
1832
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)
1836 {
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);
1841
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);
1845
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);
1849
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);
1853
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);
7fd59977 1857
35617823
K
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);
7fd59977 1861
35617823
K
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);
1865
1866 DxvNew = Abs (Umax - Umin);
1867 DyvNew = Abs (Vmax - Vmin);
1868
1869 if (DyvNew < 10.0 * Precision::Confusion())
1870 {
1871 if (DxvNew < 10.0 * Precision::Confusion())
1872 {
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())
1876 {
1877 // this is really just one (!) point and zooming has no any effect
1878 // just center the view
1879 DyvNew = DyvOld;
1880 DxvNew = DxvOld;
7fd59977 1881 }
35617823
K
1882 else
1883 {
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;
1888 }
1889 }
1890 else
1891 {
1892 // whole scene projected to horizontal line
1893 DxvNew += Coef * DxvNew;
1894 DyvNew = DxvNew / aWinRatio;
7fd59977 1895 }
35617823
K
1896 }
1897 else
1898 {
1899 // general case (or DxvNew == 0.0 - vertical line)
1900 // safe original ratio
1901 Standard_Real aFitRatio = DxvNew / DyvNew;
1902 if (aFitRatio >= aWinRatio)
1903 {
1904 DxvNew += Coef * DxvNew;
1905 DyvNew = DxvNew / aWinRatio;
1906 }
1907 else
1908 {
1909 DyvNew += Coef * DyvNew;
1910 DxvNew = DyvNew * aWinRatio;
1911 }
1912 }
7fd59977 1913
35617823
K
1914 // new scene center
1915 Xrp = 0.5 * (Umin + Umax);
1916 Yrp = 0.5 * (Vmin + Vmax);
7fd59977 1917
35617823
K
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);
1924
1925 if (MyType != V3d_PERSPECTIVE)
1926 {
1927 // center the view
1928 MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
1929 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1930 }
1931 MyView->SetViewMapping (MyViewMapping);
1932 }
1933
1934 if (FitZ)
1935 {
1936 ZFitAll (Zmargin);
7fd59977 1937#ifdef IMP020300
35617823
K
1938 }
1939 else
1940 {
1941 ImmediateUpdate();
7fd59977 1942#endif
35617823 1943 }
7fd59977 1944#ifdef IMP020300
35617823
K
1945 if (!myImmediateUpdate && update)
1946 {
1947 Update();
1948 }
7fd59977 1949#endif
1950}
1951
1952void V3d_View::ZFitAll(const Standard_Real Coef) {
1953
1954 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1955 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1956 // CAL 6/11/98
1957 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1958
1959 if( MyType == V3d_PERSPECTIVE ) {
1960 ImmediateUpdate();
1961 return ;
1962 }
1963
1964 if( (Nstruct <= 0) || (Coef < 0.) ) {
1965 ImmediateUpdate();
1966 return ;
1967 }
1968
1969 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1970
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 ) {
1974 ImmediateUpdate();
1975 return ;
1976 }
1977
7fd59977 1978 // CAL 6/11/98
1979 // Case when view contains only a point
1980 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
1981 ImmediateUpdate();
1982 return ;
1983 }
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)) ;
1999 if( Wmax > 0. ) {
2000 SetZSize(2.*Wmax + Coef * Wmax) ;
2001 }
2002 ImmediateUpdate();
2003}
2004
2005void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
2006 const Quantity_Coefficient Margin)
2007{
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;
2011
2012 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2013
2014 if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
2015 ImmediateUpdate();
2016 return ;
2017 }
2018
2019 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2020 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2021
2022 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2023
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 ) {
2027 ImmediateUpdate();
2028 return ;
2029 }
2030
7fd59977 2031 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
2032 ImmediateUpdate();
2033 return ;
2034 }
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) ;
2064
2065 // Adjust Z size
2066 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
2067 Dz = 2.*Wmax + Margin * Wmax;
2068
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);
2073 if( Size > 0. ) {
2074 SetZSize(Size) ;
2075 SetDepth( Aspect * Size / 2.);
2076 }
2077
2078 ImmediateUpdate();
2079}
2080
2081void 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);
2083#ifndef IMP020300
2084 ImmediateUpdate();
2085#endif
2086}
2087
2088void 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);
2090
2091}
2092void 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);
2097}
2098
2099void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
2100{
2101 MyViewMapping = 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;
2108
2109 MyView->SetViewMapping(MyViewMapping) ;
2110 ImmediateUpdate();
2111}
2112
2113void V3d_View::SetViewMappingDefault() {
2114 MyView->SetViewMapping(MyViewMapping) ;
2115 MyView->SetViewMappingDefault();
2116 ImmediateUpdate();
2117}
2118
2119void V3d_View::ResetViewMapping() {
2120
2121 MyView->ViewMappingReset();
2122 MyViewMapping = MyView->ViewMapping() ;
2123#ifdef IMP020300
2124 ZFitAll (Zmargin);
2125 Update();
2126#else
2127 ImmediateUpdate();
2128#endif
2129}
2130
2131Standard_Real V3d_View::Convert(const Standard_Integer Vp) const {
2132 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
2133 Standard_Integer Dxw,Dyw ;
2134
2135 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2136
2137 MyWindow->Size(Dxw,Dyw);
2138 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2139 Dxv = Umax - Umin ;
2140 Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
2141
2142 return Vv ;
2143}
2144
2145void 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 ;
2148
2149 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2150
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 ;
2156}
2157
2158Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
2159{
2160 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2161
2162 Standard_Integer Dxw, Dyw;
2163 MyWindow->Size(Dxw,Dyw);
2164
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 );
2169}
2170
2171void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
2172{
2173 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2174
2175 Standard_Integer Dxw, Dyw;
2176 MyWindow->Size(Dxw,Dyw);
2177
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;
2182
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);
2187}
2188
2189void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2190
2191 Graphic3d_Vertex Vrp ;
2192 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2193 Vrp.Coord(X,Y,Z) ;
2194#ifndef IMP240100
2195 if( MyViewer->Grid()->IsActive() ) {
2196 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2197 NewVrp.Coord(X,Y,Z) ;
2198 }
2199#endif
2200}
2201
2202void 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
2203{
2204 Graphic3d_Vertex Vrp ;
2205 Graphic3d_Vector Proj ;
2206 (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
2207 Vrp.Coord(X,Y,Z) ;
2208 Proj.Coord(Dx,Dy,Dz) ;
2209#ifndef IMP240100
2210 if( MyViewer->Grid()->IsActive() ) {
2211 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2212 NewVrp.Coord(X,Y,Z) ;
2213 }
2214#endif
2215}
2216
2217#ifdef IMP240100
2218void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
2219
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) ;
2225 } else
2226 Vrp.Coord(Xg,Yg,Zg) ;
2227}
2228
2229void 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 {
2230
2231 if( MyViewer->Grid()->IsActive() ) {
2232 Graphic3d_Vertex Vrp(X,Y,Z) ;
2233 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2234 NewVrp.Coord(Xg,Yg,Zg) ;
2235 } else {
2236 Xg = X; Yg = Y; Zg = Z;
2237 }
2238}
2239#endif
2240
2241#ifndef IMP240100
2242void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2243
2244 Graphic3d_Vertex Vrp ;
2245 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2246 Vrp.Coord(X,Y,Z) ;
2247 if( MyViewer->Grid()->IsActive() ) {
2248 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2249 NewVrp.Coord(X,Y,Z) ;
2250 }
2251}
2252#endif
2253
2254#ifdef IMP240100
2255void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2256#else
2257void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2258#endif
2259
2260 Graphic3d_Vertex Vrp(X,Y,Z) ;
2261 (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
2262}
2263
2264void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
2265{
2266 if ( MyType != V3d_PERSPECTIVE )
2267 {
2268 // use old implementation
2269 Standard_Real Zp;
2270 MyView->Projects( X, Y, Z, Xp, Yp, Zp );
2271 }
2272 else
2273 {
2274 // NKV - Using raster projection
2275 Standard_Integer Xpx, Ypx;
2276 Convert(X, Y, Z, Xpx, Ypx);
2277 Convert(Xpx, Ypx, Xp, Yp);
2278 }
2279}
2280
2281void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3)const {
2282
2283#ifdef GER61351
2284 Quantity_Color C = BackgroundColor() ;
2285#else
2286 Quantity_Color C ;
2287 C = MyBackground.Color() ;
2288#endif
2289 C.Values(V1,V2,V3,Type) ;
2290}
2291
2292#ifdef GER61351
2293Quantity_Color V3d_View::BackgroundColor() const {
2294
2295 return MyBackground.Color() ;
2296}
2297#endif
2298
2299void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
2300 MyGradientBackground.Colors(Color1, Color2);
2301}
2302
2303Aspect_GradientBackground V3d_View::GradientBackground() const {
2304 return MyGradientBackground;
2305}
2306
2307Standard_Real V3d_View::Scale()const {
2308 Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
2309 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
2310 Standard_Real S = 0. ;
2311
2312 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2313 Dxv = Umax - Umin ;
2314 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2315 if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
2316 return S ;
2317}
2318
2319void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const {
2320 MyViewOrientation.AxialScale( Sx, Sy, Sz );
2321}
2322
2323void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const {
2324
2325 Standard_Real Umin,Vmin,Umax,Vmax ;
2326
2327 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2328 Xc = (Umin + Umax)/2. ;
2329 Yc = (Vmin + Vmax)/2. ;
2330}
2331
2332void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const {
2333
2334 Standard_Real Umin,Vmin,Umax,Vmax ;
2335
2336 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2337 Width = Umax - Umin ;
2338 Height = Vmax - Vmin ;
2339}
2340
2341Standard_Real V3d_View::ZSize() const {
2342
2343 Standard_Real Wmin,Wmax,Depth ;
2344
2345 Wmax = MyViewMapping.FrontPlaneDistance() ;
2346 Wmin = MyViewMapping.BackPlaneDistance() ;
2347 Depth = 2. * Max(Wmin,Wmax) ;
2348 return (Depth) ;
2349}
2350
2351Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
2352
2353 Standard_Real Wmin,Wmax,U,V,W ;
2354 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2355 // CAL 6/11/98
2356 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2357
2358 if( Nstruct ) {
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) ;
2386 }
2387 return Nstruct ;
2388}
2389
2390Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const {
2391 // CAL 6/11/98
2392 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2393 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2394
2395 if( Nstruct ) {
2396 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2397 }
2398 return Nstruct ;
2399}
2400
2401Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2402
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;
2407
2408 MyView->DisplayedStructures (MySetOfStructures);
2409 Nstruct = MySetOfStructures.Extent() ;
2410
2411 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
2412
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,
2418 Xmax,Ymax,Zmax) ;
2419
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 )) {
2423
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 ;
2427 }
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 ;
2431 }
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 ;
2435 }
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 ;
2439 }
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 ;
2443 }
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 ;
2447 }
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 ;
2451 }
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 ;
2455 }
2456 }
2457 }
2458 }
2459 if( Npoint > 0 ) {
2460 X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
2461 }
2462
2463 return Nstruct ;
2464}
2465
2466void 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 ;
2470
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;
2478}
2479
2480void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const {
2481
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;
2486
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;
2498 }
2499 else Eye(X,Y,Z);
2500}
2501
2502void 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 {
2503
2504 Standard_Real Xo,Yo,Zo;
2505
2506 Convert(Xpix,Ypix,XP,YP,ZP);
2507 if ( MyType == V3d_PERSPECTIVE ) {
2508 FocalReferencePoint(Xo,Yo,Zo);
2509 VX = Xo - XP;
2510 VY = Yo - YP;
2511 VZ = Zo - ZP;
2512 }
2513 else {
2514 Proj(VX,VY,VZ);
2515 }
2516}
2517
2518
2519Standard_Real V3d_View::Depth() const {
2520 Graphic3d_Vertex Prp ;
2521 Standard_Real Xrp,Yrp,Zrp ;
2522
2523 Prp = MyViewMapping.ProjectionReferencePoint() ;
2524 Prp.Coord(Xrp,Yrp,Zrp) ;
2525 return Zrp ;
2526}
2527
2528void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const {
2529 Graphic3d_Vector Vpn ;
2530
2531 Vpn = MyViewOrientation.ViewReferencePlane() ;
2532 Vpn.Coord(Dx,Dy,Dz) ;
2533}
2534
2535void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2536 Graphic3d_Vertex Vrp ;
2537
2538 Vrp = MyViewOrientation.ViewReferencePoint() ;
2539 Vrp.Coord(X,Y,Z) ;
2540}
2541
2542void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const {
2543 Graphic3d_Vector Vup ;
2544
2545 Vup = MyViewOrientation.ViewReferenceUp() ;
2546 Vup.Coord(Vx,Vy,Vz) ;
2547}
2548
2549Standard_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 ;
2554
2555 Vpn = MyViewOrientation.ViewReferencePlane() ;
2556 Vpn.Coord(Xpn,Ypn,Zpn) ;
2557 Vup.SetCoord(0.,0.,1.) ;
2558 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2559 if( !TheStatus ) {
2560 Vup.SetCoord(0.,1.,0.) ;
2561 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2562 }
2563 if( !TheStatus ) {
2564 Vup.SetCoord(1.,0.,0.) ;
2565 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2566 }
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 ;
2576 /* Compute Angle */
2577 angle = Sqrt(pvn) ;
2578 if( angle > 1. ) angle = 1. ;
2579 else if( angle < -1. ) angle = -1. ;
2580 angle = asin(angle) ;
c6541a0c
D
2581 if( sca < 0. ) angle = M_PI - angle ;
2582 if( angle > 0. && angle < M_PI ) {
7fd59977 2583 sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
2584 if( sca < 0. ) angle = DEUXPI - angle ;
2585 }
2586 return angle ;
2587}
2588
2589V3d_TypeOfShadingModel V3d_View::ShadingModel()const {
2590 V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
2591 return SM ;
2592}
2593
2594V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail()const {
2595 V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
2596 return SM ;
2597}
2598
2599
2600Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const {
2601 Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
2602 return SM ;
2603}
2604
2605V3d_TypeOfVisualization V3d_View::Visualization()const {
2606 V3d_TypeOfVisualization V =
2607 (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
2608 return V ;
2609}
2610
2611Standard_Boolean V3d_View::Antialiasing()const {
2612 Standard_Boolean A = MyViewContext.AliasingIsOn() ;
2613 return A ;
2614}
2615
2616Handle(V3d_Viewer) V3d_View::Viewer() const {
2617 return MyViewer ;
2618}
2619
2620Standard_Boolean V3d_View::IfWindow() const {
2621 Standard_Boolean TheStatus = MyView->IsDefined() ;
2622 return TheStatus ;
2623}
2624
2625Handle(Aspect_Window) V3d_View::Window() const {
2626 return MyWindow;
2627}
2628
2629V3d_TypeOfView V3d_View::Type() const {
2630
2631 return (MyType) ;
2632}
2633
2634void V3d_View::SetFocale( const Standard_Real focale ) {
2635
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 ;
2644 } else {
2645 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2646 ViewPlane = FrontPlane + Zrp - focale ;
2647 }
2648 MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
2649 MyView->SetViewMapping(MyViewMapping) ;
2650
2651 ImmediateUpdate();
2652}
2653
2654Standard_Real V3d_View::Focale( ) const {
2655 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2656 Standard_Real focale = 0.0 ;
2657 Graphic3d_Vertex Prp ;
2658
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 ;
2665 } else {
2666 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2667 focale = FrontPlane + Zrp - ViewPlane ;
2668 }
2669 }
2670 return (focale) ;
2671}
2672
2673void 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)
2676{
2677 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
2678
2679 Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
2680
2681 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2682 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2683 Zrp = ZNear;
2684
2685 Standard_Real size = (ZFar - ZNear) / 2.;
2686
2687 MyViewMapping.SetFrontPlaneDistance(size);
2688 MyViewMapping.SetBackPlaneDistance(-size);
2689
2690 // keep view plane at front plane distance
2691 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
2692
2693 // set window limits
2694 Umin = Left; Umax = Right;
2695 Vmin = Bottom; Vmax = Top;
2696 MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
2697
2698 // Update window center
2699 if ( MyType == V3d_PERSPECTIVE ) {
2700 Xrp = Yrp = 0.0;
2701 }
2702 else {
2703 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
2704 }
2705 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
2706 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2707
2708 MyView->SetViewMapping(MyViewMapping) ;
2709 // SetZSize(0.);
2710 ImmediateUpdate();
2711}
2712
2713Handle(Visual3d_View) V3d_View::View() const
2714{
2715 return MyView ;
2716}
2717
2718Visual3d_ViewMapping V3d_View::ViewMapping() const
2719{
2720 return MyViewMapping;
2721}
2722
2723Visual3d_ViewOrientation V3d_View::ViewOrientation() const
2724{
2725 return MyViewOrientation;
2726}
2727
2728Standard_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 ;
2731
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;
2751 Zaxe.Normalize() ;
2752 return Standard_True ;
2753}
2754
2755void 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 ;
2761
2762 for( I=LR ; I<=UR ; I++ ) {
2763 for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
2764 }
2765 for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
2766}
2767
2768Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) {
2769
2770 Standard_Integer llr = Left.LowerRow ();
2771 Standard_Integer llc = Left.LowerCol ();
2772 Standard_Integer luc = Left.UpperCol ();
2773
2774 Standard_Integer rlr = Right.LowerRow ();
2775 Standard_Integer rur = Right.UpperRow ();
2776 Standard_Integer rlc = Right.LowerCol ();
2777
2778 Standard_Integer mlr = Matrix.LowerRow ();
2779 Standard_Integer mur = Matrix.UpperRow ();
2780 Standard_Integer mlc = Matrix.LowerCol ();
2781 Standard_Integer muc = Matrix.UpperCol ();
2782
2783 TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
2784
2785 InitMatrix (Result);
2786
2787 // Left et Right incompatibles
2788 if (luc - llc + 1 != rur - rlr + 1)
2789 return Standard_False;
2790
2791 Standard_Integer i, j, k;
2792
2793 Standard_Real Som;
2794 Standard_Integer I1 = llr;
2795
2796 for (i=mlr; i<=mur; i++) {
2797 Standard_Integer J2 = rlc;
2798 for (j=mlc; j<=muc; j++) {
2799 Som = 0.0;
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);
2804 J1++;
2805 I2++;
2806 }
2807 Result (i, j) = Som;
2808 J2++;
2809 }
2810 I1++;
2811 }
2812
2813 for (i=mlr; i<=mur; i++)
2814 for (j=mlc; j<=muc; j++)
2815 Matrix (i, j) = Result (i, j);
2816
2817 return Standard_True;
2818}
2819
2820/*----------------------------------------------------------------------*/
2821
2822void 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) ;
2828
2829 InitMatrix(Matrix) ;
2830 InitMatrix(Tmatrix) ;
2831
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 ;
2844
2845 vcal = Xaxe * Xaxe ;
2846 Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
2847 Rmatrix(1,0) = termc12 + terms3 ;
2848 Rmatrix(2,0) = termc13 - terms2 ;
2849 Rmatrix(3,0) = 0. ;
2850 Rmatrix(0,1) = termc12 - terms3 ;
2851 vcal = Yaxe * Yaxe ;
2852 Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
2853 Rmatrix(2,1) = termc23 + terms1 ;
2854 Rmatrix(3,1) = 0. ;
2855 Rmatrix(0,2) = termc13 + terms2 ;
2856 Rmatrix(1,2) = termc23 - terms1 ;
2857 vcal = Zaxe * Zaxe ;
2858 Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
2859 Rmatrix(3,2) = 0. ;
2860 Rmatrix(0,3) = 0. ;
2861 Rmatrix(1,3) = 0. ;
2862 Rmatrix(2,3) = 0. ;
2863 Rmatrix(3,3) = 1. ;
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;
2870 /* product final */
2871 Multiply(Matrix, Tmatrix, Matrix);
2872}
2873
2874/*----------------------------------------------------------------------*/
2875
2876Graphic3d_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 ;
2879
2880 // CAL. S3892
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) ) {
2887 P.Coord(X,Y,Z) ;
2888 PP.SetCoord(X,Y,Z) ;
2889 return PP ;
2890 }
2891 P.Coord(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) ;
2894
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) ;
2897
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) ;
2901 return PP ;
2902}
2903
2904Graphic3d_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 ;
2907
2908 // CAL. S3892
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) ) {
2915 V.Coord(X,Y,Z) ;
2916 VV.SetCoord(X,Y,Z) ;
2917 return VV ;
2918 }
2919 V.Coord(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() ;
2924 return VV ;
2925}
2926
2927
2928void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) {
2929
2930 Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
2931
2932}
2933
2934void V3d_View::Zoom (const Standard_Integer X1,
2935 const Standard_Integer Y1,
2936 const Standard_Integer X2,
2937 const Standard_Integer Y2)
2938{
2939
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);
2946 }
2947}
2948
2949void V3d_View::Zoom (const Standard_Integer X1,
2950 const Standard_Integer Y1)
2951{
2952 Standard_Real x,y;
2953 Center(x,y);
2954 Standard_Integer ix,iy;
2955 Convert(x,y,ix,iy);
2956 Zoom(ix,iy,X1,Y1);
2957}
2958
2959// Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
2960void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
2961{
2962 MyZoomAtPointX = xpix;
2963 MyZoomAtPointY = ypix;
2964}
2965
2966// Zooms the model at a pixel defined by the method StartZoomAtPoint().
2967void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
2968 const Standard_Integer mouseStartY,
2969 const Standard_Integer mouseEndX,
2970 const Standard_Integer mouseEndY)
2971{
2972 Standard_Boolean update;
2973 V3d_Coordinate X0, Y0, XS, YS;
2974
2975 // Forbid any update.
2976 update = SetImmediateUpdate(Standard_False);
2977
2978 // Get center point
2979 Center(X0, Y0);
2980
2981 // Pan the point to the center of window.
2982 Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
2983 Panning(X0-XS, Y0-YS);
2984
2985 // Zoom
2986 Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
2987
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");
2991
2992 Standard_Real Umin,Vmin,Umax,Vmax;
2993 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
2994
2995 MyXwindowCenter = (Umin + Umax) / 2.0;
2996 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2997 MyWindowWidth = Abs(Umax - Umin);
2998 MyWindowHeight = Abs(Vmax - Vmin);
2999
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;
3010
3011 Standard_Real Dxv = MyWindowWidth / coef;
3012 Standard_Real Dyv = MyWindowHeight / coef;
3013
3014 Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
3015 Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
3016
3017 // Pan the point backwards.
3018 Dxv = (XS - X0) / coef;
3019 Dyv = (YS - Y0) / coef;
3020
3021 MyXwindowCenter = (Umin + Umax) / 2.0;
3022 MyYwindowCenter = (Vmin + Vmax) / 2.0;
3023 MyWindowWidth = Abs(Umax - Umin);
3024 MyWindowHeight = Abs(Vmax - Vmin);
3025
3026 Standard_Real Xrp,Yrp,Zrp;
3027 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
3028 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
3029
3030 Xrp = MyXwindowCenter - Dxv;
3031 Yrp = MyYwindowCenter - Dyv;
3032
3033 Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
3034 Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
3035
3036 // Set new reference plane coordintes of the window.
3037 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
3038 if (MyType != V3d_PERSPECTIVE)
3039 {
3040 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
3041 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3042 }
3043 MyView->SetViewMapping(MyViewMapping);
3044
3045 // Update the view.
3046 SetImmediateUpdate(update);
3047 ImmediateUpdate();
3048}
3049
3050void V3d_View::AxialScale (const Standard_Integer Dx,
3051 const Standard_Integer Dy,
3052 const V3d_TypeOfAxe Axis)
3053{
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 );
3063 }
3064}
3065
3066void 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)
3071{
3072
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 ;
3077
3078 Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
3079 "V3d_View::FitAll, Window Size is NULL");
3080
3081 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
3082 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
3083 aWindow->Size(Xpixel,Ypixel);
3084 DxvOld = Xpixel; DyvOld = Ypixel;
3085
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 ;
3092 } else {
3093 DxvNew = DyvNew*RapOld ;
3094 }
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);
3102 }
3103 MyView->SetViewMapping(MyViewMapping) ;
3104#ifdef IMP020300
3105 Update();
3106#else
3107 ImmediateUpdate();
3108#endif
3109}
3110
3111#ifdef IMP250900
3112static Standard_Boolean zRotation = Standard_False;
3113#endif
3114void V3d_View::StartRotation(const Standard_Integer X,
3115 const Standard_Integer Y,
3116 const Quantity_Ratio zRotationThreshold)
3117{
3118
3119 sx = X; sy = Y;
3120 Standard_Real x,y;
3121 Size(x,y);
3122 rx = Standard_Real(Convert(x));
3123 ry = Standard_Real(Convert(y));
3124 Gravity(gx,gy,gz);
3125 Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
3126#ifdef IMP250900
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;
3134 }
3135#endif
3136
3137}
3138
3139void V3d_View::Rotation(const Standard_Integer X,
3140 const Standard_Integer Y)
3141{
3142
3143#ifdef IMP210600
3144 if( rx == 0. || ry == 0. ) {
3145 StartRotation(X,Y);
3146 return;
3147 }
3148#endif
3149#ifdef IMP250900
3150 Standard_Real dx=0.,dy=0.,dz=0.;
3151 if( zRotation ) {
3152 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
3153 atan2(sx-rx/2.,ry/2.-sy);
3154 } else {
c6541a0c
D
3155 dx = (Standard_Real(X) - sx) * M_PI / rx;
3156 dy = (sy - Standard_Real(Y)) * M_PI / ry;
7fd59977 3157 }
3158 Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
3159#else
c6541a0c
D
3160 Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
3161 Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
7fd59977 3162 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3163#endif
3164#ifdef IMP020300
3165 if( !myImmediateUpdate ) Update();
3166#else
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;
3171 ImmediateUpdate();
3172#endif
3173}
3174
3175void V3d_View::SetAnimationModeOn () {
3176#ifdef G003
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;
3184 }
3185 MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
3186 }
3187#else
3188 MyView->SetAnimationModeOn();
3189#endif
3190}
3191
3192void V3d_View::SetAnimationModeOff () {
3193#ifdef G003
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 ) {
3201 Update();
3202 }
3203 }
3204#else
3205 MyView->SetAnimationModeOff();
3206#endif
3207}
3208
3209Standard_Boolean V3d_View::AnimationModeIsOn () const {
3210 return MyView->AnimationModeIsOn();
3211}
3212
3213#ifdef G003
3214void V3d_View :: SetAnimationMode
3215(
3216 const Standard_Boolean anAnimationFlag,
3217 const Standard_Boolean aDegenerationFlag
3218 )
3219{
3220
3221 if ( anAnimationFlag )
3222 MyAnimationFlags |= V3d_FLAG_ANIMATION;
3223 else
3224 MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
3225
3226 if ( aDegenerationFlag )
3227 MyAnimationFlags |= V3d_FLAG_DEGENERATION;
3228 else
3229 MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
3230
3231} // end V3d_View :: SetAnimationMode
3232
3233Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
3234{
3235
3236 isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
3237 return MyAnimationFlags & V3d_FLAG_ANIMATION;
3238}
3239#endif
3240
3241void V3d_View::SetDegenerateModeOn() {
3242#ifdef G003
3243 SetComputedMode(Standard_False);
3244#else
3245 MyView->SetDegenerateModeOn();
3246 ImmediateUpdate();
3247#endif
3248}
3249
3250void V3d_View::SetDegenerateModeOff()
3251{
3252#ifdef G003
3253 SetComputedMode(Standard_True);
3254#else
3255 if(myComputedMode) {
3256 MyView->SetDegenerateModeOff();
3257 ImmediateUpdate();
3258 }
3259#endif
3260}
3261
3262Standard_Boolean V3d_View::DegenerateModeIsOn() const
3263{
3264#ifdef G003
3265 return !ComputedMode();
3266#else
3267 return MyView->DegenerateModeIsOn();
3268#endif
3269}
3270
3271#ifdef G003
3272void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3273{
3274
3275 if( aMode ) {
3276 if( myComputedMode ) {
3277 MyView -> SetComputedMode ( Standard_True );
3278 Update ();
3279 }
3280 } else {
3281 MyView -> SetComputedMode ( Standard_False );
3282 Update ();
3283 }
3284
3285} // end V3d_View :: SetComputedMode
3286
3287Standard_Boolean V3d_View :: ComputedMode () const
3288{
3289
3290 return MyView -> ComputedMode ();
3291
3292} // end V3d_View :: ComputedMode
3293
3294void V3d_View :: SetBackFacingModel (
3295 const V3d_TypeOfBackfacingModel aModel)
3296{
3297
3298 MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
3299 Redraw();
3300} // end V3d_View :: SetBackFacingModel
3301
3302V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const {
3303
3304 return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
3305
3306} // end V3d_View :: BackFacingModel
3307#endif
3308
3309Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const {
3310 return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
3311}
3312
3313void V3d_View::TransientManagerClearDraw() const {
3314 Visual3d_TransientManager::ClearDraw(MyView);
3315}
3316
3317Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const {
3318 return Visual3d_TransientManager::BeginAddDraw(MyView);
3319}
3320
3321void V3d_View::Init() {
3322 myComputedMode = MyViewer->ComputedMode();
3323#ifdef G003
3324 if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
3325 SetComputedMode(Standard_False);
3326 }
3327#else
3328 if(!myComputedMode)
3329 MyView->SetDegenerateModeOn();
3330 else
3331 if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
3332#endif
3333
3334#ifdef IMP240100
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;
3339#endif
3340
3341}
3342
3343void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) {
3344 MyPlotter = aPlotter;
3345}
3346
3347void V3d_View::Plot()
3348{
3349
3350 Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
3351
3352 MyView->Plot(MyPlotter);
3353}
3354
3355Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
3356{
3357
3358 FullTimer.Reset ();
3359 FullTimer.Start ();
3360
3361 if (AnimationMode) MyView->SetAnimationModeOn();
3362 Standard_Integer i;
3363 Standard_Real delta = 0.01;
3364 Standard_Real xangle, yangle;
3365 xangle = yangle = delta*int(NbImages/3);
3366
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();
3375
3376 FullTimer.Stop ();
3377 cout << "For " << NbImages << " Images : " << endl;
3378 FullTimer.Show (cout);
3379 cout << flush;
3380
3381 Standard_Real Seconds, CPUtime;
3382 Standard_Integer Minutes, Hours;
3383
3384 FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
3385 cout << "Result " << (AnimationMode ? "with " : "without ")
3386 << "display list : " << NbImages/CPUtime << " images/Second."
3387 << endl;
3388
3389 return NbImages/CPUtime;
3390
3391}
3392
3393#define SCREENCOPY_FILENAME "screencopy3d.gif"
3394void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
3395 const Standard_Boolean fWhiteBackground,
3396 const Quantity_Factor aPlotScale)
3397{
3398 TCollection_AsciiString aFileToDump;
3399 Handle(Aspect_WindowDriver) aWindowDriver =
3400#ifdef WNT
3401 new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
3402#else
3403 new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
3404#endif // WNT
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);
3412
3413 if (theWWidth * theWHeight != 0.) {
3414 if (aPlotScale == 0.) {
3415 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3416 } else {
3417 // To be changed !!!!!!!!!!!!!!!
3418 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3419 }
3420
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 () );
3427
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 ();
3443 } else {
3444 theFlags -> Append (0);
3445 }
3446 Iterator.Next ();
3447 }
3448 Redraw ();
3449
3450 // Dump the view
3451 if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
3452 aFileToDump = aPlotterDriver->PlotFileName();
3453 } else {
3454 aFileToDump = aPlotterDriver->SpoolDirectory();
3455 aFileToDump += SCREENCOPY_FILENAME;
3456 }
3457 MyWindow -> Dump (aFileToDump.ToCString());
3458
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);
3464 Iterator.Next ();
3465 theCurStruct++;
3466 }
3467 if (fWhiteBackground)
3468 SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3469 Redraw ();
3470
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 ();
3477 }
3478}
3479#undef SCREENCOPY_FILENAME
3480
3481#include <Aspect.hxx>
3482#include <Visual3d_Layer.hxx>
3483
3484////////////////////////////////////////////////////////////////
692613e5 3485Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3486 const Graphic3d_BufferType& theBufferType)
7fd59977 3487{
3488 Standard_Integer aWinWidth, aWinHeight;
3489 MyWindow->Size (aWinWidth, aWinHeight);
692613e5 3490 Image_AlienPixMap anImage;
3491 return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
7fd59977 3492}
3493
3494////////////////////////////////////////////////////////////////
692613e5 3495Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
7fd59977 3496 const Aspect_FormatOfSheetPaper theFormat,
692613e5 3497 const Graphic3d_BufferType& theBufferType)
7fd59977 3498{
7fd59977 3499 // convert Aspect_FormatOfSheetPaper size to pixel ...
3500 Quantity_Length anSPWidth, anSPHeight;
3501 Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
3502
3503 // adjusting to the ratio width/height ...
3504 Quantity_Length aWinWidth, aWinHeight;
3505 MyWindow->MMSize (aWinWidth, aWinHeight);
3506 Standard_Integer aPixelWidth, aPixelHeight;
3507 MyWindow->Size (aPixelWidth, aPixelHeight);
3508
3509 Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
3510 aPixelWidth = Standard_Integer (aPixelWidth * aScale);
3511 aPixelHeight = Standard_Integer (aPixelHeight * aScale);
692613e5 3512
3513 Image_AlienPixMap anImage;
3514 ToPixMap (anImage, aPixelWidth, aPixelHeight, theBufferType);
3515 OSD_Environment anEnvGamma ("CSF_GAMMA_CORRECTION");
3516 TCollection_AsciiString strGamma (anEnvGamma.Value());
3517 if (!anImage.IsEmpty() && !strGamma.IsEmpty())
7fd59977 3518 {
692613e5 3519 Standard_Real aGammaValue = strGamma.RealValue();
3520 anImage.AdjustGamma (aGammaValue);
7fd59977 3521 }
692613e5 3522 return anImage.Save (theFile);
7fd59977 3523}
3524
3525////////////////////////////////////////////////////////////////
692613e5 3526Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage,
3527 const Standard_Integer theWidth,
3528 const Standard_Integer theHeight,
3529 const Graphic3d_BufferType& theBufferType,
3530 const Standard_Boolean theIsForceCentred)
7fd59977 3531{
3532 // always prefer hardware accelerated offscreen buffer
3533 Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
3534 Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
3535 Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
85e096c3 3536 Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0);
7fd59977 3537 Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
3538 if (aPrevFBOPtr != NULL)
3539 {
3540 MyView->FBOGetDimensions (aPrevFBOPtr,
3541 aPrevFBOVPSizeX, aPrevFBOVPSizeY,
3542 aPrevFBOSizeXMax, aPrevFBOSizeYMax);
85e096c3 3543 if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax)
7fd59977 3544 {
85e096c3 3545 MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
7fd59977 3546 aFBOPtr = aPrevFBOPtr;
3547 }
3548 }
3549
3550 if (aFBOPtr == NULL)
3551 {
3552 // Try to create hardware accelerated buffer
85e096c3 3553 aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY);
3554 if (aFBOPtr != NULL)
3555 {
3556 MyView->FBOGetDimensions (aFBOPtr,
3557 aFBOVPSizeX, aFBOVPSizeY,
3558 aFBOSizeXMax, aFBOSizeYMax);
3559 // reduce viewport in case of hardware limits
3560 if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax;
3561 if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax;
3562 MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
3563 }
7fd59977 3564 }
3565 cView->ptrFBO = aFBOPtr;
3566
3567 // If hardware accelerated buffer - try to use onscreen buffer
3568 // Results may be bad!
3569 if (aFBOPtr == NULL)
3570 {
3571 // retrieve window sizes
3572 Standard_Integer aWinWidth, aWinHeight;
3573 MyWindow->Size (aWinWidth, aWinHeight);
3574
3575 // technically we can reduce existing viewport...
3576 // but currently allow only dumping the window itself
85e096c3 3577 if (aFBOVPSizeX != aWinWidth || aFBOVPSizeY != aWinHeight)
7fd59977 3578 {
692613e5 3579 return Standard_False;
7fd59977 3580 }
3581 }
3582
3583 //szv: save mapping
3584 Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
3585 Standard_Real Umin, Vmin, Umax, Vmax;
3586
3587 if (theIsForceCentred)
3588 {
3589 //szv: get mapping frame
3590 Standard_Real PUmin, PVmin, PUmax, PVmax;
3591 prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
3592
3593 //szv: calculate expansion
3594 Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
3595 Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
85e096c3 3596 Standard_Real newWidth = (oldHeight * aFBOVPSizeX) / aFBOVPSizeY;
7fd59977 3597 if (newWidth < oldWidth)
3598 {
85e096c3 3599 Standard_Real newHeight = (oldWidth * aFBOVPSizeY) / aFBOVPSizeX;
7fd59977 3600 // Expand height
3601 Standard_Real delta = 0.5 * (newHeight - oldHeight);
3602 Vmin = PVmin - delta;
3603 Vmax = PVmax + delta;
3604 }
3605 else
3606 {
3607 // Expand width
3608 Standard_Real delta = 0.5 * (newWidth - oldWidth);
3609 Umin = PUmin - delta;
3610 Umax = PUmax + delta;
3611 }
3612
3613 //szv: apply expanded mapping
3614 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
3615 MyView->SetViewMapping (MyViewMapping);
3616 }
3617
3618 //workround for rendering list of Over and Under Layers
3619 if (!MyLayerMgr.IsNull())
3620 {
3621 MyLayerMgr->Compute();
3622 }
3623 Redraw();
3624
3625 //szv: restore mapping
3626 MyViewMapping = prevMapping;
3627 MyView->SetViewMapping (prevMapping);
3628
692613e5 3629 Standard_Boolean isSuccess = Standard_True;
3630
7fd59977 3631 // allocate image buffer for dumping
692613e5 3632 if (theImage.IsEmpty()
3633 || (Standard_Size )aFBOVPSizeX != theImage.SizeX()
3634 || (Standard_Size )aFBOVPSizeY != theImage.SizeY())
7fd59977 3635 {
692613e5 3636 bool isBigEndian = Image_PixMap::IsBigEndianHost();
3637 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
3638 switch (theBufferType)
3639 {
3640 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
3641 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
3642 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
3643 }
3644
3645 isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY);
7fd59977 3646 }
692613e5 3647 isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType);
7fd59977 3648
3649 // FBO now useless, free resources
3650 if (aFBOPtr != aPrevFBOPtr)
3651 {
3652 MyView->FBORelease (aFBOPtr);
3653 }
3654 else if (aPrevFBOPtr != NULL)
3655 {
3656 MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
3657 }
3658 cView->ptrFBO = aPrevFBOPtr;
692613e5 3659 return isSuccess;
7fd59977 3660}