0032473: Visualization, WNT_Window::ProcessMessage() - handle WM_TOUCH
[occt.git] / src / V3d / V3d_View.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
3bffef55 14#include <V3d_View.hxx>
7fd59977 15
478862fc 16#include <Aspect_CircularGrid.hxx>
42cf5bc1 17#include <Aspect_GradientBackground.hxx>
18#include <Aspect_Grid.hxx>
478862fc 19#include <Aspect_RectangularGrid.hxx>
42cf5bc1 20#include <Aspect_Window.hxx>
21#include <Bnd_Box.hxx>
22#include <gp_Ax3.hxx>
7fd59977 23#include <gp_Dir.hxx>
b5ac8292 24#include <gp_Pln.hxx>
42cf5bc1 25#include <Graphic3d_AspectMarker3d.hxx>
26#include <Graphic3d_GraphicDriver.hxx>
27#include <Graphic3d_Group.hxx>
b5ac8292 28#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
29#include <Graphic3d_MapOfStructure.hxx>
42cf5bc1 30#include <Graphic3d_Structure.hxx>
b5ac8292 31#include <Graphic3d_TextureEnv.hxx>
42cf5bc1 32#include <Image_AlienPixMap.hxx>
3bffef55 33#include <Message.hxx>
34#include <Message_Messenger.hxx>
42cf5bc1 35#include <NCollection_Array1.hxx>
36#include <Precision.hxx>
37#include <Quantity_Color.hxx>
38#include <Standard_Assert.hxx>
39#include <Standard_DivideByZero.hxx>
40#include <Standard_ErrorHandler.hxx>
41#include <Standard_MultiplyDefined.hxx>
42#include <Standard_ShortReal.hxx>
43#include <Standard_Type.hxx>
44#include <Standard_TypeMismatch.hxx>
c357e426 45#include <TColgp_Array1OfPnt.hxx>
42cf5bc1 46#include <TColStd_Array2OfReal.hxx>
47#include <TColStd_HSequenceOfInteger.hxx>
48#include <V3d.hxx>
49#include <V3d_BadValue.hxx>
42cf5bc1 50#include <V3d_Light.hxx>
51#include <V3d_StereoDumpOptions.hxx>
52#include <V3d_UnMapped.hxx>
42cf5bc1 53#include <V3d_Viewer.hxx>
7fd59977 54
25e59720 55IMPLEMENT_STANDARD_RTTIEXT(V3d_View,Standard_Transient)
92efcf78 56
c6541a0c 57#define DEUXPI (2. * M_PI)
7fd59977 58
4af098ba 59namespace
60{
61 static const Standard_Integer THE_NB_BOUND_POINTS = 8;
62}
63
197ac94e 64//=============================================================================
65//function : Constructor
66//purpose :
67//=============================================================================
c357e426 68V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType)
49582f9d 69: myIsInvalidatedImmediate (Standard_True),
70 MyViewer (theViewer.operator->()),
c357e426 71 SwitchSetFront (Standard_False),
016e5959 72 myZRotation (Standard_False),
6bc6a6fc 73 MyTrsf (1, 4, 1, 4)
7fd59977 74{
c357e426 75 myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
7fd59977 76
c357e426 77 myView->SetBackground (theViewer->GetBackgroundColor());
78 myView->SetGradientBackground (theViewer->GetGradientBackground());
7fd59977 79
832ae82d 80 ChangeRenderingParams() = theViewer->DefaultRenderingParams();
81
b5ac8292 82 // camera init
83 Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
84 aCamera->SetFOVy (45.0);
85 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05);
86 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0);
c357e426 87 aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC)
88 ? Graphic3d_Camera::Projection_Orthographic
89 : Graphic3d_Camera::Projection_Perspective);
b5ac8292 90
c357e426 91 myDefaultCamera = new Graphic3d_Camera();
92
93 myImmediateUpdate = Standard_False;
c357e426 94 SetAutoZFitMode (Standard_True, 1.0);
95 SetBackFacingModel (V3d_TOBM_AUTOMATIC);
96 SetCamera (aCamera);
b5ac8292 97 SetAxis (0.,0.,0.,1.,1.,1.);
c357e426 98 SetVisualization (theViewer->DefaultVisualization());
b5ac8292 99 SetTwist (0.);
100 SetAt (0.,0.,0.);
c357e426 101 SetProj (theViewer->DefaultViewProj());
102 SetSize (theViewer->DefaultViewSize());
103 Standard_Real zsize = theViewer->DefaultViewSize();
b5ac8292 104 SetZSize (2.*zsize);
c357e426 105 SetDepth (theViewer->DefaultViewSize() / 2.0);
7fd59977 106 SetViewMappingDefault();
fc8eab5e 107 SetViewOrientationDefault();
c357e426 108 theViewer->AddView (this);
7fd59977 109 Init();
110 myImmediateUpdate = Standard_True;
7fd59977 111}
112
197ac94e 113//=============================================================================
114//function : Constructor
115//purpose :
116//=============================================================================
c357e426 117V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
49582f9d 118: myIsInvalidatedImmediate (Standard_True),
119 MyViewer (theViewer.operator->()),
197ac94e 120 SwitchSetFront(Standard_False),
016e5959 121 myZRotation (Standard_False),
197ac94e 122 MyTrsf (1, 4, 1, 4)
7fd59977 123{
c357e426 124 myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
7fd59977 125
c357e426 126 myView->CopySettings (theView->View());
9e04ccdc 127 myDefaultViewPoint = theView->myDefaultViewPoint;
128 myDefaultViewAxis = theView->myDefaultViewAxis;
7fd59977 129
9e04ccdc 130 myDefaultCamera = new Graphic3d_Camera (theView->DefaultCamera());
b5ac8292 131
c357e426 132 myImmediateUpdate = Standard_False;
133 SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor());
c357e426 134 theViewer->AddView (this);
7fd59977 135 Init();
136 myImmediateUpdate = Standard_True;
7fd59977 137}
138
197ac94e 139//=============================================================================
c357e426 140//function : Destructor
197ac94e 141//purpose :
142//=============================================================================
c357e426 143V3d_View::~V3d_View()
144{
145 if (!myView->IsRemoved())
146 {
147 myView->Remove();
7fd59977 148 }
7fd59977 149}
150
197ac94e 151//=============================================================================
c357e426 152//function : SetMagnify
197ac94e 153//purpose :
154//=============================================================================
c357e426 155void V3d_View::SetMagnify (const Handle(Aspect_Window)& theWindow,
156 const Handle(V3d_View)& thePreviousView,
157 const Standard_Integer theX1,
158 const Standard_Integer theY1,
159 const Standard_Integer theX2,
160 const Standard_Integer theY2)
7fd59977 161{
c357e426 162 if (!myView->IsRemoved() && !myView->IsDefined())
163 {
164 Standard_Real aU1, aV1, aU2, aV2;
165 thePreviousView->Convert (theX1, theY1, aU1, aV1);
166 thePreviousView->Convert (theX2, theY2, aU2, aV2);
167 myView->SetWindow (theWindow);
434ffc09 168 FitAll (aU1, aV1, aU2, aV2);
c357e426 169 MyViewer->SetViewOn (this);
170 MyWindow = theWindow;
171 SetRatio();
172 Redraw();
173 SetViewMappingDefault();
174 }
7fd59977 175}
176
197ac94e 177//=============================================================================
178//function : SetWindow
179//purpose :
180//=============================================================================
a521d90d 181void V3d_View::SetWindow (const Handle(Aspect_Window)& theWindow,
182 const Aspect_RenderingContext theContext)
7fd59977 183{
c357e426 184 if (myView->IsRemoved())
185 {
186 return;
187 }
188
05e2200b 189 // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
c357e426 190 MyWindow = theWindow;
a521d90d 191 myView->SetWindow (theWindow, theContext);
c357e426 192 MyViewer->SetViewOn (this);
193 SetRatio();
39235bed 194 if (myImmediateUpdate)
195 {
196 Redraw();
197 }
7fd59977 198}
7fd59977 199
197ac94e 200//=============================================================================
201//function : Remove
202//purpose :
203//=============================================================================
5634c81a 204void V3d_View::Remove()
5e27df78 205{
475c2302 206 if (!MyGrid.IsNull())
207 {
208 MyGrid->Erase();
209 }
210 if (!myTrihedron.IsNull())
211 {
212 myTrihedron->Erase();
213 }
214
5e27df78 215 MyViewer->DelView (this);
c357e426 216 myView->Remove();
5e27df78 217 Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
218 aWin.Nullify();
7fd59977 219}
220
197ac94e 221//=============================================================================
222//function : Update
223//purpose :
224//=============================================================================
b8ddfc2f 225void V3d_View::Update() const
226{
c357e426 227 if (!myView->IsDefined()
228 || !myView->IsActive())
229 {
230 return;
231 }
232
49582f9d 233 myIsInvalidatedImmediate = Standard_False;
cfece3ef 234 myView->Update();
235 myView->Compute();
b40cdc2b 236 AutoZFit();
cfece3ef 237 myView->Redraw();
7fd59977 238}
239
197ac94e 240//=============================================================================
241//function : Redraw
242//purpose :
243//=============================================================================
b8ddfc2f 244void V3d_View::Redraw() const
245{
c357e426 246 if (!myView->IsDefined()
247 || !myView->IsActive())
248 {
249 return;
250 }
251
49582f9d 252 myIsInvalidatedImmediate = Standard_False;
c357e426 253 Handle(Graphic3d_StructureManager) aStructureMgr = MyViewer->StructureManager();
254 for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
255 {
851dacdb 256 if (aStructureMgr->IsDeviceLost())
c357e426 257 {
258 aStructureMgr->RecomputeStructures();
c357e426 259 }
260
261 AutoZFit();
262
263 myView->Redraw();
264
851dacdb 265 if (!aStructureMgr->IsDeviceLost())
c357e426 266 {
267 return;
268 }
269 }
7fd59977 270}
b8ddfc2f 271
679ecdee 272//=============================================================================
273//function : RedrawImmediate
274//purpose :
275//=============================================================================
276void V3d_View::RedrawImmediate() const
277{
c357e426 278 if (!myView->IsDefined()
279 || !myView->IsActive())
679ecdee 280 {
c357e426 281 return;
679ecdee 282 }
c357e426 283
49582f9d 284 myIsInvalidatedImmediate = Standard_False;
c357e426 285 myView->RedrawImmediate();
679ecdee 286}
287
288//=============================================================================
289//function : Invalidate
290//purpose :
291//=============================================================================
292void V3d_View::Invalidate() const
293{
c357e426 294 if (!myView->IsDefined())
679ecdee 295 {
c357e426 296 return;
679ecdee 297 }
c357e426 298
299 myView->Invalidate();
679ecdee 300}
301
6bc6a6fc 302//=============================================================================
62e1beed 303//function : IsInvalidated
304//purpose :
305//=============================================================================
306Standard_Boolean V3d_View::IsInvalidated() const
307{
c357e426 308 return !myView->IsDefined()
309 || myView->IsInvalidated();
62e1beed 310}
311
c357e426 312// ========================================================================
313// function : SetAutoZFitMode
314// purpose :
315// ========================================================================
316void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
317 const Standard_Real theScaleFactor)
318{
319 Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
320 myAutoZFitScaleFactor = theScaleFactor;
321 myAutoZFitIsOn = theIsOn;
322}
323
6bc6a6fc 324//=============================================================================
c357e426 325//function : AutoZFit
6bc6a6fc 326//purpose :
327//=============================================================================
c357e426 328void V3d_View::AutoZFit() const
6bc6a6fc 329{
c357e426 330 if (!AutoZFitMode())
331 {
332 return;
333 }
334
335 ZFitAll (myAutoZFitScaleFactor);
6bc6a6fc 336}
337
197ac94e 338//=============================================================================
c357e426 339//function : ZFitAll
197ac94e 340//purpose :
341//=============================================================================
c357e426 342void V3d_View::ZFitAll (const Standard_Real theScaleFactor) const
7fd59977 343{
c357e426 344 Bnd_Box aMinMaxBox = myView->MinMaxValues (Standard_False); // applicative min max boundaries
345 Bnd_Box aGraphicBox = myView->MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag).
346
347 myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
7fd59977 348}
349
197ac94e 350//=============================================================================
351//function : IsEmpty
352//purpose :
353//=============================================================================
b8ddfc2f 354Standard_Boolean V3d_View::IsEmpty() const
355{
7fd59977 356 Standard_Boolean TheStatus = Standard_True ;
c357e426 357 if( myView->IsDefined() ) {
358 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
7fd59977 359 if( Nstruct > 0 ) TheStatus = Standard_False ;
360 }
361 return (TheStatus) ;
7fd59977 362}
363
197ac94e 364//=============================================================================
365//function : UpdateLights
366//purpose :
367//=============================================================================
b8ddfc2f 368void V3d_View::UpdateLights() const
369{
992ed6b3 370 Handle(Graphic3d_LightSet) aLights = new Graphic3d_LightSet();
6a24c6de 371 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
c357e426 372 {
992ed6b3 373 aLights->Add (anActiveLightIter.Value());
c357e426 374 }
c357e426 375 myView->SetLights (aLights);
7fd59977 376}
377
197ac94e 378//=============================================================================
379//function : DoMapping
380//purpose :
381//=============================================================================
b8ddfc2f 382void V3d_View::DoMapping()
383{
c357e426 384 if (!myView->IsDefined())
385 {
386 return;
7fd59977 387 }
c357e426 388
389 myView->Window()->DoMapping();
7fd59977 390}
391
197ac94e 392//=============================================================================
393//function : MustBeResized
394//purpose :
395//=============================================================================
b8ddfc2f 396void V3d_View::MustBeResized()
397{
c357e426 398 if (!myView->IsDefined())
399 {
400 return;
7fd59977 401 }
c357e426 402
403 myView->Resized();
404
405 SetRatio();
39235bed 406 if (myImmediateUpdate)
407 {
408 Redraw();
409 }
7fd59977 410}
411
197ac94e 412//=============================================================================
413//function : SetBackgroundColor
414//purpose :
415//=============================================================================
c357e426 416void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType,
417 const Standard_Real theV1,
418 const Standard_Real theV2,
419 const Standard_Real theV3)
7fd59977 420{
c357e426 421 Standard_Real aV1 = Max (Min (theV1, 1.0), 0.0);
422 Standard_Real aV2 = Max (Min (theV2, 1.0), 0.0);
423 Standard_Real aV3 = Max (Min (theV3, 1.0), 0.0);
7fd59977 424
c357e426 425 SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
7fd59977 426}
427
197ac94e 428//=============================================================================
429//function : SetBackgroundColor
430//purpose :
431//=============================================================================
c357e426 432void V3d_View::SetBackgroundColor (const Quantity_Color& theColor)
7fd59977 433{
c357e426 434 myView->SetBackground (Aspect_Background (theColor));
435
436 if (myImmediateUpdate)
437 {
438 Redraw();
439 }
7fd59977 440}
7fd59977 441
197ac94e 442//=============================================================================
443//function : SetBgGradientColors
444//purpose :
445//=============================================================================
c357e426 446void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
447 const Quantity_Color& theColor2,
448 const Aspect_GradientFillMethod theFillStyle,
449 const Standard_Boolean theToUpdate)
7fd59977 450{
c357e426 451 Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle);
452
453 myView->SetGradientBackground (aGradientBg);
454
455 if (myImmediateUpdate || theToUpdate)
456 {
457 Redraw();
458 }
7fd59977 459}
460
197ac94e 461//=============================================================================
462//function : SetBgGradientStyle
463//purpose :
464//=============================================================================
c357e426 465void V3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate)
7fd59977 466{
c357e426 467 Quantity_Color aColor1;
468 Quantity_Color aColor2;
469 GradientBackground().Colors (aColor1, aColor2);
470
471 SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
7fd59977 472}
473
197ac94e 474//=============================================================================
475//function : SetBackgroundImage
476//purpose :
477//=============================================================================
c357e426 478void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
479 const Aspect_FillMethod theFillStyle,
480 const Standard_Boolean theToUpdate)
7fd59977 481{
99289bed 482 Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2Dmanual (theFileName);
483 aTextureMap->DisableModulate();
484 SetBackgroundImage (aTextureMap, theFillStyle, theToUpdate);
485}
c357e426 486
99289bed 487//=============================================================================
488//function : SetBackgroundImage
489//purpose :
490//=============================================================================
491void V3d_View::SetBackgroundImage (const Handle(Graphic3d_Texture2D)& theTexture,
492 const Aspect_FillMethod theFillStyle,
493 const Standard_Boolean theToUpdate)
494{
495 myView->SetBackgroundImage (theTexture);
496 myView->SetBackgroundImageStyle (theFillStyle);
c357e426 497 if (myImmediateUpdate || theToUpdate)
498 {
499 Redraw();
500 }
7fd59977 501}
502
197ac94e 503//=============================================================================
504//function : SetBgImageStyle
505//purpose :
506//=============================================================================
c357e426 507void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate)
7fd59977 508{
c357e426 509 myView->SetBackgroundImageStyle (theFillStyle);
510
511 if (myImmediateUpdate || theToUpdate)
512 {
513 Redraw();
514 }
7fd59977 515}
516
197ac94e 517//=============================================================================
077a220c 518//function : SetBackgroundCubeMap
519//purpose :
520//=============================================================================
521void V3d_View::SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
67312b79 522 Standard_Boolean theToUpdatePBREnv,
077a220c 523 Standard_Boolean theToUpdate)
524{
99289bed 525 myView->SetBackgroundImage (theCubeMap, theToUpdatePBREnv);
67312b79 526 if (myImmediateUpdate || theToUpdate)
527 {
528 Redraw();
529 }
530}
077a220c 531
67312b79 532//=============================================================================
533//function : GeneratePBREnvironment
534//purpose :
535//=============================================================================
536void V3d_View::GeneratePBREnvironment (Standard_Boolean theToUpdate)
537{
538 myView->GeneratePBREnvironment();
539 if (myImmediateUpdate || theToUpdate)
540 {
541 Redraw();
542 }
543}
544
545//=============================================================================
546//function : ClearPBREnvironment
547//purpose :
548//=============================================================================
549void V3d_View::ClearPBREnvironment (Standard_Boolean theToUpdate)
550{
551 myView->ClearPBREnvironment();
077a220c 552 if (myImmediateUpdate || theToUpdate)
553 {
554 Redraw();
555 }
556}
557
558//=============================================================================
197ac94e 559//function : SetAxis
560//purpose :
561//=============================================================================
21b2385f 562void V3d_View::SetAxis (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
563 const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
b8ddfc2f 564{
21b2385f 565 myDefaultViewPoint.SetCoord (theX, theY, theZ);
566 myDefaultViewAxis.SetCoord (theVx, theVy, theVz);
7fd59977 567}
568
197ac94e 569//=============================================================================
570//function : SetShadingModel
571//purpose :
572//=============================================================================
dc89236f 573void V3d_View::SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel)
b8ddfc2f 574{
dc89236f 575 myView->SetShadingModel (theShadingModel);
7fd59977 576}
577
197ac94e 578//=============================================================================
579//function : SetTextureEnv
580//purpose :
581//=============================================================================
c357e426 582void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture)
b8ddfc2f 583{
c357e426 584 myView->SetTextureEnv (theTexture);
585
586 if (myImmediateUpdate)
587 {
588 Redraw();
589 }
7fd59977 590}
591
197ac94e 592//=============================================================================
593//function : SetVisualization
594//purpose :
595//=============================================================================
c357e426 596void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType)
b8ddfc2f 597{
c357e426 598 myView->SetVisualizationType (static_cast <Graphic3d_TypeOfVisualization> (theType));
599
600 if (myImmediateUpdate)
601 {
602 Redraw();
603 }
7fd59977 604}
605
197ac94e 606//=============================================================================
607//function : SetFront
608//purpose :
609//=============================================================================
b8ddfc2f 610void V3d_View::SetFront()
611{
7fd59977 612 gp_Ax3 a = MyViewer->PrivilegedPlane();
b5ac8292 613 Standard_Real xo, yo, zo, vx, vy, vz, xu, yu, zu;
7fd59977 614
615 a.Direction().Coord(vx,vy,vz);
616 a.YDirection().Coord(xu,yu,zu);
617 a.Location().Coord(xo,yo,zo);
618
c357e426 619 Handle(Graphic3d_Camera) aCamera = Camera();
620
621 aCamera->SetCenter (gp_Pnt (xo, yo, zo));
622
7fd59977 623 if(SwitchSetFront)
c357e426 624 {
625 aCamera->SetDirection (gp_Dir (vx, vy, vz));
626 }
7fd59977 627 else
c357e426 628 {
629 aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
630 }
631
632 aCamera->SetUp (gp_Dir (xu, yu, zu));
7fd59977 633
b5ac8292 634 SwitchSetFront = !SwitchSetFront;
7fd59977 635
636 ImmediateUpdate();
7fd59977 637}
638
197ac94e 639//=============================================================================
640//function : Rotate
641//purpose :
642//=============================================================================
b5ac8292 643void V3d_View::Rotate (const Standard_Real ax,
644 const Standard_Real ay,
645 const Standard_Real az,
646 const Standard_Boolean Start)
b8ddfc2f 647{
b5ac8292 648 Standard_Real Ax = ax;
649 Standard_Real Ay = ay;
650 Standard_Real Az = az;
7fd59977 651
b5ac8292 652 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI;
653 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI;
654 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI;
655 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI;
656 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI;
657 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI;
658
c357e426 659 Handle(Graphic3d_Camera) aCamera = Camera();
660
b5ac8292 661 if (Start)
662 {
c357e426 663 myCamStartOpUp = aCamera->Up();
607e5e62 664 myCamStartOpDir = aCamera->Direction();
c357e426 665 myCamStartOpEye = aCamera->Eye();
666 myCamStartOpCenter = aCamera->Center();
b5ac8292 667 }
668
607e5e62 669 aCamera->SetUp (myCamStartOpUp);
670 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
671 aCamera->SetDirectionFromEye (myCamStartOpDir);
b5ac8292 672
673 // rotate camera around 3 initial axes
607e5e62 674 gp_Dir aBackDir = -myCamStartOpDir;
b5ac8292 675 gp_Dir aXAxis (myCamStartOpUp.Crossed (aBackDir));
676 gp_Dir aYAxis (aBackDir.Crossed (aXAxis));
677 gp_Dir aZAxis (aXAxis.Crossed (aYAxis));
678
679 gp_Trsf aRot[3], aTrsf;
680 aRot[0].SetRotation (gp_Ax1 (myCamStartOpCenter, aYAxis), -Ax);
681 aRot[1].SetRotation (gp_Ax1 (myCamStartOpCenter, aXAxis), Ay);
682 aRot[2].SetRotation (gp_Ax1 (myCamStartOpCenter, aZAxis), Az);
683 aTrsf.Multiply (aRot[0]);
684 aTrsf.Multiply (aRot[1]);
685 aTrsf.Multiply (aRot[2]);
686
c357e426 687 aCamera->Transform (aTrsf);
b5ac8292 688
7fd59977 689 ImmediateUpdate();
7fd59977 690}
691
197ac94e 692//=============================================================================
693//function : Rotate
694//purpose :
695//=============================================================================
7fd59977 696void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
697 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
698{
b5ac8292 699
7fd59977 700 Standard_Real Ax = ax ;
701 Standard_Real Ay = ay ;
702 Standard_Real Az = az ;
7fd59977 703
704 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
705 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
706 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
707 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
708 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
709 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
710
c357e426 711 Handle(Graphic3d_Camera) aCamera = Camera();
712
b5ac8292 713 if (Start)
714 {
715 myGravityReferencePoint.SetCoord (X, Y, Z);
c357e426 716 myCamStartOpUp = aCamera->Up();
607e5e62 717 myCamStartOpDir = aCamera->Direction();
c357e426 718 myCamStartOpEye = aCamera->Eye();
719 myCamStartOpCenter = aCamera->Center();
b5ac8292 720 }
721
722 const Graphic3d_Vertex& aVref = myGravityReferencePoint;
723
607e5e62 724 aCamera->SetUp (myCamStartOpUp);
725 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
726 aCamera->SetDirectionFromEye (myCamStartOpDir);
b5ac8292 727
728 // rotate camera around 3 initial axes
729 gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
730
c357e426 731 gp_Dir aZAxis (aCamera->Direction().Reversed());
732 gp_Dir aYAxis (aCamera->Up());
b5ac8292 733 gp_Dir aXAxis (aYAxis.Crossed (aZAxis));
734
735 gp_Trsf aRot[3], aTrsf;
736 aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
737 aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
738 aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
739 aTrsf.Multiply (aRot[0]);
740 aTrsf.Multiply (aRot[1]);
741 aTrsf.Multiply (aRot[2]);
742
c357e426 743 aCamera->Transform (aTrsf);
b5ac8292 744
7fd59977 745 ImmediateUpdate();
7fd59977 746}
747
197ac94e 748//=============================================================================
749//function : Rotate
750//purpose :
751//=============================================================================
b8ddfc2f 752void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
753{
7fd59977 754 switch (Axe) {
755 case V3d_X :
756 Rotate(angle,0.,0.,Start);
757 break ;
758 case V3d_Y :
759 Rotate(0.,angle,0.,Start);
760 break ;
761 case V3d_Z :
762 Rotate(0.,0.,angle,Start);
763 break ;
764 }
7fd59977 765}
766
197ac94e 767//=============================================================================
768//function : Rotate
769//purpose :
770//=============================================================================
21b2385f 771void V3d_View::Rotate (const V3d_TypeOfAxe theAxe, const Standard_Real theAngle,
772 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, const Standard_Boolean theStart)
7fd59977 773{
21b2385f 774 Standard_Real anAngle = theAngle;
7fd59977 775
21b2385f 776 if (anAngle > 0.0) while (anAngle > DEUXPI) anAngle -= DEUXPI;
777 else if (anAngle < 0.0) while (anAngle < -DEUXPI) anAngle += DEUXPI;
7fd59977 778
c357e426 779 Handle(Graphic3d_Camera) aCamera = Camera();
780
21b2385f 781 if (theStart)
b5ac8292 782 {
21b2385f 783 myGravityReferencePoint.SetCoord (theX, theY, theZ);
c357e426 784 myCamStartOpUp = aCamera->Up();
607e5e62 785 myCamStartOpDir = aCamera->Direction();
c357e426 786 myCamStartOpEye = aCamera->Eye();
787 myCamStartOpCenter = aCamera->Center();
21b2385f 788 switch (theAxe)
789 {
790 case V3d_X: myViewAxis = gp::DX(); break;
791 case V3d_Y: myViewAxis = gp::DY(); break;
792 case V3d_Z: myViewAxis = gp::DZ(); break;
7fd59977 793 }
794 }
795
b5ac8292 796 const Graphic3d_Vertex& aVref = myGravityReferencePoint;
797
607e5e62 798 aCamera->SetUp (myCamStartOpUp);
799 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
800 aCamera->SetDirectionFromEye (myCamStartOpDir);
b5ac8292 801
802 // rotate camera around passed axis
803 gp_Trsf aRotation;
804 gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
21b2385f 805 gp_Dir aRAxis ((theAxe == V3d_X) ? 1.0 : 0.0,
806 (theAxe == V3d_Y) ? 1.0 : 0.0,
807 (theAxe == V3d_Z) ? 1.0 : 0.0);
b5ac8292 808
21b2385f 809 aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), anAngle);
b5ac8292 810
c357e426 811 aCamera->Transform (aRotation);
812
7fd59977 813 ImmediateUpdate();
7fd59977 814}
815
197ac94e 816//=============================================================================
817//function : Rotate
818//purpose :
819//=============================================================================
b8ddfc2f 820void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
821{
b5ac8292 822 Standard_Real Angle = angle;
7fd59977 823
824 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
825 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
826
c357e426 827 Handle(Graphic3d_Camera) aCamera = Camera();
828
607e5e62 829 if (Start)
830 {
c357e426 831 myCamStartOpUp = aCamera->Up();
607e5e62 832 myCamStartOpDir = aCamera->Direction();
c357e426 833 myCamStartOpEye = aCamera->Eye();
834 myCamStartOpCenter = aCamera->Center();
7fd59977 835 }
836
607e5e62 837 aCamera->SetUp (myCamStartOpUp);
838 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
839 aCamera->SetDirectionFromEye (myCamStartOpDir);
b5ac8292 840
841 gp_Trsf aRotation;
21b2385f 842 gp_Pnt aRCenter (myDefaultViewPoint);
843 gp_Dir aRAxis (myDefaultViewAxis);
b5ac8292 844 aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
b5ac8292 845
c357e426 846 aCamera->Transform (aRotation);
847
7fd59977 848 ImmediateUpdate();
7fd59977 849}
850
197ac94e 851//=============================================================================
852//function : Turn
853//purpose :
854//=============================================================================
7fd59977 855void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
856{
b5ac8292 857 Standard_Real Ax = ax;
858 Standard_Real Ay = ay;
859 Standard_Real Az = az;
7fd59977 860
861 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
862 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
863 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
864 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
865 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
866 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
867
c357e426 868 Handle(Graphic3d_Camera) aCamera = Camera();
869
607e5e62 870 if (Start)
871 {
c357e426 872 myCamStartOpUp = aCamera->Up();
607e5e62 873 myCamStartOpDir = aCamera->Direction();
c357e426 874 myCamStartOpEye = aCamera->Eye();
875 myCamStartOpCenter = aCamera->Center();
b5ac8292 876 }
877
607e5e62 878 aCamera->SetUp (myCamStartOpUp);
879 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
880 aCamera->SetDirectionFromEye (myCamStartOpDir);
b5ac8292 881
882 // rotate camera around 3 initial axes
c357e426 883 gp_Pnt aRCenter = aCamera->Eye();
884 gp_Dir aZAxis (aCamera->Direction().Reversed());
885 gp_Dir aYAxis (aCamera->Up());
b5ac8292 886 gp_Dir aXAxis (aYAxis.Crossed (aZAxis));
887
888 gp_Trsf aRot[3], aTrsf;
889 aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
890 aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
891 aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
892 aTrsf.Multiply (aRot[0]);
893 aTrsf.Multiply (aRot[1]);
894 aTrsf.Multiply (aRot[2]);
895
c357e426 896 aCamera->Transform (aTrsf);
b5ac8292 897
b5ac8292 898 ImmediateUpdate();
7fd59977 899}
900
197ac94e 901//=============================================================================
902//function : Turn
903//purpose :
904//=============================================================================
7fd59977 905void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
906{
7fd59977 907 switch (Axe) {
908 case V3d_X :
909 Turn(angle,0.,0.,Start);
910 break ;
911 case V3d_Y :
912 Turn(0.,angle,0.,Start);
913 break ;
914 case V3d_Z :
915 Turn(0.,0.,angle,Start);
916 break ;
917 }
918}
919
197ac94e 920//=============================================================================
921//function : Turn
922//purpose :
923//=============================================================================
b8ddfc2f 924void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
925{
7fd59977 926 Standard_Real Angle = angle ;
7fd59977 927
928 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
929 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
930
c357e426 931 Handle(Graphic3d_Camera) aCamera = Camera();
932
607e5e62 933 if (Start)
934 {
c357e426 935 myCamStartOpUp = aCamera->Up();
607e5e62 936 myCamStartOpDir = aCamera->Direction();
c357e426 937 myCamStartOpEye = aCamera->Eye();
938 myCamStartOpCenter = aCamera->Center();
b5ac8292 939 }
940
607e5e62 941 aCamera->SetUp (myCamStartOpUp);
942 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
943 aCamera->SetDirectionFromEye (myCamStartOpDir);
b5ac8292 944
b5ac8292 945 gp_Trsf aRotation;
c357e426 946 gp_Pnt aRCenter = aCamera->Eye();
21b2385f 947 gp_Dir aRAxis (myDefaultViewAxis);
b5ac8292 948 aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
b5ac8292 949
c357e426 950 aCamera->Transform (aRotation);
951
b5ac8292 952 ImmediateUpdate();
7fd59977 953}
954
197ac94e 955//=============================================================================
956//function : SetTwist
957//purpose :
958//=============================================================================
b8ddfc2f 959void V3d_View::SetTwist(const Standard_Real angle)
960{
7fd59977 961 Standard_Real Angle = angle ;
7fd59977 962
963 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
964 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
965
c357e426 966 Handle(Graphic3d_Camera) aCamera = Camera();
967
21b2385f 968 const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
969 if (!screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
970 && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1507ccda 971 && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
21b2385f 972 {
973 throw V3d_BadValue ("V3d_ViewSetTwist, alignment of Eye,At,Up,");
7fd59977 974 }
b5ac8292 975
c357e426 976 gp_Pnt aRCenter = aCamera->Center();
977 gp_Dir aZAxis (aCamera->Direction().Reversed());
b5ac8292 978
979 gp_Trsf aTrsf;
980 aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
981
21b2385f 982 aCamera->SetUp (gp_Dir (myYscreenAxis));
c357e426 983 aCamera->Transform (aTrsf);
b5ac8292 984
7fd59977 985 ImmediateUpdate();
7fd59977 986}
987
197ac94e 988//=============================================================================
989//function : SetEye
990//purpose :
991//=============================================================================
992void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
993{
994 Standard_Real aTwistBefore = Twist();
7fd59977 995
197ac94e 996 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
b5ac8292 997
c357e426 998 Handle(Graphic3d_Camera) aCamera = Camera();
999
1000 aCamera->SetEye (gp_Pnt (X, Y, Z));
1001
197ac94e 1002 SetTwist (aTwistBefore);
b5ac8292 1003
197ac94e 1004 SetImmediateUpdate (wasUpdateEnabled);
1005
b5ac8292 1006 ImmediateUpdate();
7fd59977 1007}
1008
197ac94e 1009//=============================================================================
1010//function : SetDepth
1011//purpose :
1012//=============================================================================
b8ddfc2f 1013void V3d_View::SetDepth(const Standard_Real Depth)
1014{
b5ac8292 1015 V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
7fd59977 1016
c357e426 1017 Handle(Graphic3d_Camera) aCamera = Camera();
1018
7fd59977 1019 if( Depth > 0. )
7fd59977 1020 {
b5ac8292 1021 // Move eye using center (target) as anchor.
c357e426 1022 aCamera->SetDistance (Depth);
b5ac8292 1023 }
1024 else
197ac94e 1025 {
b5ac8292 1026 // Move the view ref point instead of the eye.
c357e426 1027 gp_Vec aDir (aCamera->Direction());
1028 gp_Pnt aCameraEye = aCamera->Eye();
197ac94e 1029 gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
1030
c357e426 1031 aCamera->SetCenter (aCameraCenter);
7fd59977 1032 }
7fd59977 1033
b5ac8292 1034 ImmediateUpdate();
7fd59977 1035}
1036
197ac94e 1037//=============================================================================
1038//function : SetProj
1039//purpose :
1040//=============================================================================
7fd59977 1041void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1042{
6942f04a 1043 V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
7fd59977 1044 "V3d_View::SetProj, null projection vector");
1045
197ac94e 1046 Standard_Real aTwistBefore = Twist();
b5ac8292 1047
197ac94e 1048 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
b5ac8292 1049
c357e426 1050 Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
b5ac8292 1051
1521659a 1052 SetTwist(aTwistBefore);
b5ac8292 1053
197ac94e 1054 SetImmediateUpdate (wasUpdateEnabled);
1055
7fd59977 1056 ImmediateUpdate();
7fd59977 1057}
1058
197ac94e 1059//=============================================================================
1060//function : SetProj
1061//purpose :
1062//=============================================================================
fc552d84 1063void V3d_View::SetProj (const V3d_TypeOfOrientation theOrientation,
1064 const Standard_Boolean theIsYup)
b8ddfc2f 1065{
fc552d84 1066 Graphic3d_Vec3d anUp = theIsYup ? Graphic3d_Vec3d (0.0, 1.0, 0.0) : Graphic3d_Vec3d (0.0, 0.0, 1.0);
1067 if (theIsYup)
1068 {
1069 if (theOrientation == V3d_Ypos
1070 || theOrientation == V3d_Yneg)
1071 {
1072 anUp.SetValues (0.0, 0.0, -1.0);
1073 }
1074 }
1075 else
1076 {
1077 if (theOrientation == V3d_Zpos)
1078 {
1079 anUp.SetValues (0.0, 1.0, 0.0);
1080 }
1081 else if (theOrientation == V3d_Zneg)
1082 {
1083 anUp.SetValues (0.0, -1.0, 0.0);
1084 }
7fd59977 1085 }
b5ac8292 1086
fc552d84 1087 const gp_Dir aBck = V3d::GetProjAxis (theOrientation);
197ac94e 1088
1089 // retain camera panning from origin when switching projection
fc552d84 1090 const Handle(Graphic3d_Camera)& aCamera = Camera();
1091 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
197ac94e 1092
607e5e62 1093 const Standard_Real aNewDist = aCamera->Eye().Distance (gp_Pnt (0, 0, 0));
1094 aCamera->SetEyeAndCenter (gp_XYZ (0, 0, 0) + aBck.XYZ() * aNewDist,
1095 gp_XYZ (0, 0, 0));
1096 aCamera->SetDirectionFromEye (-aBck);
fc552d84 1097 aCamera->SetUp (gp_Dir (anUp.x(), anUp.y(), anUp.z()));
c357e426 1098 aCamera->OrthogonalizeUp();
197ac94e 1099
fc552d84 1100 Panning (anOriginVCS.X(), anOriginVCS.Y());
b5ac8292 1101
7fd59977 1102 ImmediateUpdate();
7fd59977 1103}
1104
197ac94e 1105//=============================================================================
1106//function : SetAt
1107//purpose :
1108//=============================================================================
b8ddfc2f 1109void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1110{
197ac94e 1111 Standard_Real aTwistBefore = Twist();
b5ac8292 1112
197ac94e 1113 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
b5ac8292 1114
c357e426 1115 Camera()->SetCenter (gp_Pnt (X, Y, Z));
b5ac8292 1116
197ac94e 1117 SetTwist (aTwistBefore);
b5ac8292 1118
197ac94e 1119 SetImmediateUpdate (wasUpdateEnabled);
1120
7fd59977 1121 ImmediateUpdate();
7fd59977 1122}
1123
197ac94e 1124//=============================================================================
1125//function : SetUp
1126//purpose :
1127//=============================================================================
21b2385f 1128void V3d_View::SetUp (const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
b8ddfc2f 1129{
c357e426 1130 Handle(Graphic3d_Camera) aCamera = Camera();
1131
21b2385f 1132 const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1133 const gp_Dir anUp (theVx, theVy, theVz);
1134 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis)
1135 && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1136 && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1137 && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1138 {
1139 throw V3d_BadValue ("V3d_View::Setup, alignment of Eye,At,Up");
7fd59977 1140 }
b5ac8292 1141
21b2385f 1142 aCamera->SetUp (gp_Dir (myYscreenAxis));
197ac94e 1143
7fd59977 1144 ImmediateUpdate();
7fd59977 1145}
1146
197ac94e 1147//=============================================================================
1148//function : SetUp
1149//purpose :
1150//=============================================================================
21b2385f 1151void V3d_View::SetUp (const V3d_TypeOfOrientation theOrientation)
b8ddfc2f 1152{
c357e426 1153 Handle(Graphic3d_Camera) aCamera = Camera();
1154
21b2385f 1155 const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1156 const gp_Dir anUp = V3d::GetProjAxis (theOrientation);
1157 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis)
1158 && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1159 && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1160 && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1161 {
1162 throw V3d_BadValue ("V3d_View::SetUp, alignment of Eye,At,Up");
7fd59977 1163 }
b5ac8292 1164
21b2385f 1165 aCamera->SetUp (gp_Dir (myYscreenAxis));
197ac94e 1166
7fd59977 1167 ImmediateUpdate();
1168}
1169
197ac94e 1170//=============================================================================
1171//function : SetViewOrientationDefault
1172//purpose :
1173//=============================================================================
b8ddfc2f 1174void V3d_View::SetViewOrientationDefault()
1175{
c357e426 1176 myDefaultCamera->CopyOrientationData (Camera());
1177}
b5ac8292 1178
c357e426 1179//=======================================================================
1180//function : SetViewMappingDefault
1181//purpose :
1182//=======================================================================
1183void V3d_View::SetViewMappingDefault()
1184{
1185 myDefaultCamera->CopyMappingData (Camera());
7fd59977 1186}
1187
197ac94e 1188//=============================================================================
1189//function : ResetViewOrientation
1190//purpose :
1191//=============================================================================
b8ddfc2f 1192void V3d_View::ResetViewOrientation()
1193{
c357e426 1194 Camera()->CopyOrientationData (myDefaultCamera);
c357e426 1195 ImmediateUpdate();
1196}
1197
1198//=======================================================================
1199//function : ResetViewMapping
1200//purpose :
1201//=======================================================================
1202void V3d_View::ResetViewMapping()
1203{
1204 Camera()->CopyMappingData (myDefaultCamera);
7fd59977 1205 ImmediateUpdate();
1206}
1207
197ac94e 1208//=============================================================================
1209//function : Reset
1210//purpose :
1211//=============================================================================
c357e426 1212void V3d_View::Reset (const Standard_Boolean theToUpdate)
b8ddfc2f 1213{
c357e426 1214 Camera()->Copy (myDefaultCamera);
197ac94e 1215
7fd59977 1216 SwitchSetFront = Standard_False;
b5ac8292 1217
c357e426 1218 if (myImmediateUpdate || theToUpdate)
1219 {
1220 Update();
1221 }
7fd59977 1222}
1223
197ac94e 1224//=======================================================================
1225//function : SetCenter
1226//purpose :
1227//=======================================================================
1228void V3d_View::SetCenter (const Standard_Integer theXp,
1229 const Standard_Integer theYp)
b8ddfc2f 1230{
197ac94e 1231 Standard_Real aXv, aYv;
1232 Convert (theXp, theYp, aXv, aYv);
c357e426 1233 Translate (Camera(), aXv, aYv);
7fd59977 1234
7fd59977 1235 ImmediateUpdate();
7fd59977 1236}
1237
197ac94e 1238//=============================================================================
1239//function : SetSize
1240//purpose :
1241//=============================================================================
3dfe95cd 1242void V3d_View::SetSize (const Standard_Real theSize)
7fd59977 1243{
3dfe95cd 1244 V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
7fd59977 1245
c357e426 1246 Handle(Graphic3d_Camera) aCamera = Camera();
1247
1248 aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize);
197ac94e 1249
7fd59977 1250 ImmediateUpdate();
7fd59977 1251}
1252
197ac94e 1253//=============================================================================
1254//function : SetZSize
1255//purpose :
1256//=============================================================================
c357e426 1257void V3d_View::SetZSize (const Standard_Real theSize)
7fd59977 1258{
c357e426 1259 Handle(Graphic3d_Camera) aCamera = Camera();
7fd59977 1260
c357e426 1261 Standard_Real Zmax = theSize / 2.;
b5ac8292 1262
c357e426 1263 Standard_Real aDistance = aCamera->Distance();
1264
1265 if (theSize <= 0.)
1266 {
b5ac8292 1267 Zmax = aDistance;
7fd59977 1268 }
7fd59977 1269
197ac94e 1270 // ShortReal precision factor used to add meaningful tolerance to
1271 // ZNear, ZFar values in order to avoid equality after type conversion
1272 // to ShortReal matrices type.
1273 const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
1274
1275 Standard_Real aZFar = Zmax + aDistance * 2.0;
1276 Standard_Real aZNear = -Zmax + aDistance;
1277 aZNear -= Abs (aZNear) * aPrecision;
1278 aZFar += Abs (aZFar) * aPrecision;
1279
c357e426 1280 if (!aCamera->IsOrthographic())
197ac94e 1281 {
1282 if (aZFar < aPrecision)
1283 {
1284 // Invalid case when both values are negative
1285 aZNear = aPrecision;
1286 aZFar = aPrecision * 2.0;
1287 }
1288 else if (aZNear < Abs (aZFar) * aPrecision)
1289 {
1290 // Z is less than 0.0, try to fix it using any appropriate z-scale
1291 aZNear = Abs (aZFar) * aPrecision;
1292 }
1293 }
1294
1295 // If range is too small
1296 if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
1297 {
1298 aZFar = aZNear + Abs (aZFar) * aPrecision;
1299 }
1300
c357e426 1301 aCamera->SetZRange (aZNear, aZFar);
7fd59977 1302
c357e426 1303 if (myImmediateUpdate)
b8ddfc2f 1304 {
c357e426 1305 Redraw();
b8ddfc2f 1306 }
7fd59977 1307}
1308
197ac94e 1309//=============================================================================
1310//function : SetZoom
1311//purpose :
1312//=============================================================================
e44b0af4 1313void V3d_View::SetZoom (const Standard_Real theCoef,const Standard_Boolean theToStart)
7fd59977 1314{
e44b0af4 1315 V3d_BadValue_Raise_if (theCoef <= 0., "V3d_View::SetZoom, bad coefficient");
7fd59977 1316
c357e426 1317 Handle(Graphic3d_Camera) aCamera = Camera();
1318
e44b0af4 1319 if (theToStart)
b5ac8292 1320 {
c357e426 1321 myCamStartOpEye = aCamera->Eye();
1322 myCamStartOpCenter = aCamera->Center();
7fd59977 1323 }
1324
c357e426 1325 Standard_Real aViewWidth = aCamera->ViewDimensions().X();
1326 Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
b5ac8292 1327
7fd59977 1328 // ensure that zoom will not be too small or too big
e44b0af4 1329 Standard_Real aCoef = theCoef;
1330 if (aViewWidth < aCoef * Precision::Confusion())
b5ac8292 1331 {
e44b0af4 1332 aCoef = aViewWidth / Precision::Confusion();
b5ac8292 1333 }
e44b0af4 1334 else if (aViewWidth > aCoef * 1e12)
b5ac8292 1335 {
e44b0af4 1336 aCoef = aViewWidth / 1e12;
b5ac8292 1337 }
e44b0af4 1338 if (aViewHeight < aCoef * Precision::Confusion())
b5ac8292 1339 {
e44b0af4 1340 aCoef = aViewHeight / Precision::Confusion();
b5ac8292 1341 }
e44b0af4 1342 else if (aViewHeight > aCoef * 1e12)
b5ac8292 1343 {
e44b0af4 1344 aCoef = aViewHeight / 1e12;
b5ac8292 1345 }
1346
c357e426 1347 aCamera->SetEye (myCamStartOpEye);
1348 aCamera->SetCenter (myCamStartOpCenter);
e44b0af4 1349 aCamera->SetScale (aCamera->Scale() / aCoef);
c357e426 1350
7fd59977 1351 ImmediateUpdate();
1352}
1353
197ac94e 1354//=============================================================================
1355//function : SetScale
1356//purpose :
1357//=============================================================================
b8ddfc2f 1358void V3d_View::SetScale( const Standard_Real Coef )
1359{
6942f04a 1360 V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
7fd59977 1361
c357e426 1362 Handle(Graphic3d_Camera) aCamera = Camera();
b5ac8292 1363
c357e426 1364 Standard_Real aDefaultScale = myDefaultCamera->Scale();
1365 aCamera->SetAspect (myDefaultCamera->Aspect());
1366 aCamera->SetScale (aDefaultScale / Coef);
b5ac8292 1367
7fd59977 1368 ImmediateUpdate();
7fd59977 1369}
1370
197ac94e 1371//=============================================================================
1372//function : SetAxialScale
1373//purpose :
1374//=============================================================================
b8ddfc2f 1375void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
1376{
6942f04a 1377 V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
7fd59977 1378
c357e426 1379 Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
c357e426 1380}
1381
1382//=============================================================================
1383//function : SetRatio
1384//purpose :
1385//=============================================================================
1386void V3d_View::SetRatio()
1387{
1388 if (MyWindow.IsNull())
1389 {
1390 return;
1391 }
1392
1393 Standard_Integer aWidth = 0;
1394 Standard_Integer aHeight = 0;
1395 MyWindow->Size (aWidth, aHeight);
1396 if (aWidth > 0 && aHeight > 0)
1397 {
1398 Standard_Real aRatio = static_cast<Standard_Real> (aWidth) /
1399 static_cast<Standard_Real> (aHeight);
1400
1401 Camera() ->SetAspect (aRatio);
1402 myDefaultCamera->SetAspect (aRatio);
1403 }
7fd59977 1404}
1405
197ac94e 1406//=============================================================================
1407//function : FitAll
1408//purpose :
1409//=============================================================================
ee2be2a8 1410void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean theToUpdate)
7fd59977 1411{
c357e426 1412 FitAll (myView->MinMaxValues(), theMargin, theToUpdate);
b586500b 1413}
1414
1415//=============================================================================
1416//function : FitAll
1417//purpose :
1418//=============================================================================
ee2be2a8 1419void V3d_View::FitAll (const Bnd_Box& theBox, const Standard_Real theMargin, const Standard_Boolean theToUpdate)
b586500b 1420{
1421 Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
197ac94e 1422
c357e426 1423 if (myView->NumberOfDisplayedStructures() == 0)
197ac94e 1424 {
1425 return;
1426 }
35617823 1427
c357e426 1428 if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion()))
35617823 1429 {
35617823
K
1430 return;
1431 }
7fd59977 1432
197ac94e 1433 if (myImmediateUpdate || theToUpdate)
35617823 1434 {
b5ac8292 1435 Update();
35617823 1436 }
b5ac8292 1437}
35617823 1438
197ac94e 1439//=============================================================================
1440//function : DepthFitAll
1441//purpose :
1442//=============================================================================
ee2be2a8 1443void V3d_View::DepthFitAll(const Standard_Real Aspect,
1444 const Standard_Real Margin)
7fd59977 1445{
1446 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
1447 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
b5ac8292 1448 Standard_Real Dx,Dy,Dz,Size;
7fd59977 1449
c357e426 1450 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
7fd59977 1451
b5ac8292 1452 if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
7fd59977 1453 ImmediateUpdate();
1454 return ;
1455 }
1456
c357e426 1457 Bnd_Box aBox = myView->MinMaxValues();
ed063270 1458 if (aBox.IsVoid())
1459 {
1460 ImmediateUpdate();
1461 return ;
1462 }
1463 aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
c357e426 1464 Project (Xmin,Ymin,Zmin,U,V,W) ;
1465 Project (Xmax,Ymax,Zmax,U1,V1,W1) ;
7fd59977 1466 Umin = Min(U,U1) ; Umax = Max(U,U1) ;
1467 Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
1468 Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
c357e426 1469 Project (Xmin,Ymin,Zmax,U,V,W) ;
7fd59977 1470 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1471 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1472 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1473 Project (Xmax,Ymin,Zmax,U,V,W) ;
7fd59977 1474 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1475 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1476 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1477 Project (Xmax,Ymin,Zmin,U,V,W) ;
7fd59977 1478 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1479 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1480 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1481 Project (Xmax,Ymax,Zmin,U,V,W) ;
7fd59977 1482 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1483 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1484 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1485 Project (Xmin,Ymax,Zmax,U,V,W) ;
7fd59977 1486 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1487 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1488 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1489 Project (Xmin,Ymax,Zmin,U,V,W) ;
7fd59977 1490 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1491 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1492 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1493
1494 // Adjust Z size
1495 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1496 Dz = 2.*Wmax + Margin * Wmax;
1497
1498 // Compute depth value
1499 Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
1500 Dx += Margin * Dx; Dy += Margin * Dy;
1501 Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
1502 if( Size > 0. ) {
1503 SetZSize(Size) ;
1504 SetDepth( Aspect * Size / 2.);
1505 }
1506
1507 ImmediateUpdate();
1508}
1509
197ac94e 1510//=======================================================================
1511//function : WindowFit
1512//purpose :
1513//=======================================================================
1514void V3d_View::WindowFit (const Standard_Integer theMinXp,
1515 const Standard_Integer theMinYp,
1516 const Standard_Integer theMaxXp,
1517 const Standard_Integer theMaxYp)
b8ddfc2f 1518{
197ac94e 1519 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1520
c357e426 1521 Handle(Graphic3d_Camera) aCamera = Camera();
1522
1523 if (!aCamera->IsOrthographic())
b5ac8292 1524 {
ab1c121b 1525 // normalize view coordinates
b5ac8292 1526 Standard_Integer aWinWidth, aWinHeight;
1527 MyWindow->Size (aWinWidth, aWinHeight);
7fd59977 1528
b5ac8292 1529 // z coordinate of camera center
c357e426 1530 Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z();
b5ac8292 1531
1532 // camera projection coordinate are in NDC which are normalized [-1, 1]
197ac94e 1533 Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp - 1.0;
1534 Standard_Real aUMax = (2.0 / aWinWidth) * theMaxXp - 1.0;
1535 Standard_Real aVMin = (2.0 / aWinHeight) * theMinYp - 1.0;
1536 Standard_Real aVMax = (2.0 / aWinHeight) * theMaxYp - 1.0;
b5ac8292 1537
1538 // compute camera panning
1539 gp_Pnt aScreenCenter (0.0, 0.0, aDepth);
1540 gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth);
c357e426 1541 gp_Pnt aPanTo = aCamera->ConvertProj2View (aFitCenter);
1542 gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter);
b5ac8292 1543 gp_Vec aPanVec (aPanFrom, aPanTo);
1544
b5ac8292 1545 // compute section size
1546 gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
1547 gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
c357e426 1548 gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft);
1549 gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight);
b5ac8292 1550
1551 Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
1552 Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
1553
c357e426 1554 Translate (aCamera, aPanVec.X(), -aPanVec.Y());
1555 Scale (aCamera, aUSize, aVSize);
b5ac8292 1556 }
1557 else
1558 {
197ac94e 1559 Standard_Real aX1, aY1, aX2, aY2;
1560 Convert (theMinXp, theMinYp, aX1, aY1);
1561 Convert (theMaxXp, theMaxYp, aX2, aY2);
1562 FitAll (aX1, aY1, aX2, aY2);
b5ac8292 1563 }
197ac94e 1564
1565 SetImmediateUpdate (wasUpdateEnabled);
1566
1567 ImmediateUpdate();
7fd59977 1568}
1569
197ac94e 1570//=======================================================================
1571//function : ConvertToGrid
1572//purpose :
1573//=======================================================================
5634c81a 1574void V3d_View::ConvertToGrid(const Standard_Integer theXp,
1575 const Standard_Integer theYp,
1576 Standard_Real& theXg,
1577 Standard_Real& theYg,
1578 Standard_Real& theZg) const
b5ac8292 1579{
5634c81a 1580 Graphic3d_Vec3d anXYZ;
1581 Convert (theXp, theYp, anXYZ.x(), anXYZ.y(), anXYZ.z());
b5ac8292 1582
5634c81a 1583 Graphic3d_Vertex aVrp;
1584 aVrp.SetCoord (anXYZ.x(), anXYZ.y(), anXYZ.z());
1585 if (MyViewer->IsGridActive())
1586 {
1587 Graphic3d_Vertex aNewVrp = Compute (aVrp);
1588 aNewVrp.Coord (theXg, theYg, theZg);
1589 }
1590 else
1591 {
1592 aVrp.Coord (theXg, theYg, theZg);
1593 }
b5ac8292 1594}
1595
197ac94e 1596//=======================================================================
1597//function : ConvertToGrid
1598//purpose :
1599//=======================================================================
5634c81a 1600void V3d_View::ConvertToGrid(const Standard_Real theX,
1601 const Standard_Real theY,
1602 const Standard_Real theZ,
1603 Standard_Real& theXg,
1604 Standard_Real& theYg,
1605 Standard_Real& theZg) const
1606{
1607 if (MyViewer->IsGridActive())
1608 {
1609 Graphic3d_Vertex aVrp (theX, theY, theZ);
1610 Graphic3d_Vertex aNewVrp = Compute (aVrp);
1611 aNewVrp.Coord (theXg, theYg, theZg);
1612 }
1613 else
1614 {
1615 theXg = theX; theYg = theY; theZg = theZ;
b5ac8292 1616 }
1617}
1618
197ac94e 1619//=======================================================================
1620//function : Convert
1621//purpose :
1622//=======================================================================
b8ddfc2f 1623Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
1624{
b5ac8292 1625 Standard_Integer aDxw, aDyw ;
7fd59977 1626
c357e426 1627 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
7fd59977 1628
b5ac8292 1629 MyWindow->Size (aDxw, aDyw);
1630 Standard_Real aValue;
197ac94e 1631
c357e426 1632 gp_Pnt aViewDims = Camera()->ViewDimensions();
b5ac8292 1633 aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
7fd59977 1634
b5ac8292 1635 return aValue;
7fd59977 1636}
1637
197ac94e 1638//=======================================================================
1639//function : Convert
1640//purpose :
1641//=======================================================================
1642void V3d_View::Convert(const Standard_Integer Xp,
1643 const Standard_Integer Yp,
1644 Standard_Real& Xv,
1645 Standard_Real& Yv) const
b8ddfc2f 1646{
b5ac8292 1647 Standard_Integer aDxw, aDyw;
7fd59977 1648
c357e426 1649 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
b5ac8292 1650
1651 MyWindow->Size (aDxw, aDyw);
1652
1653 gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
c357e426 1654 aPoint = Camera()->ConvertProj2View (aPoint);
7fd59977 1655
b5ac8292 1656 Xv = aPoint.X();
1657 Yv = aPoint.Y();
7fd59977 1658}
1659
197ac94e 1660//=======================================================================
1661//function : Convert
1662//purpose :
1663//=======================================================================
7fd59977 1664Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
1665{
c357e426 1666 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
b5ac8292 1667
1668 Standard_Integer aDxw, aDyw;
1669 MyWindow->Size (aDxw, aDyw);
7fd59977 1670
c357e426 1671 gp_Pnt aViewDims = Camera()->ViewDimensions();
b5ac8292 1672 Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
7fd59977 1673
b5ac8292 1674 return aValue;
7fd59977 1675}
1676
197ac94e 1677//=======================================================================
1678//function : Convert
1679//purpose :
1680//=======================================================================
1681void V3d_View::Convert(const Standard_Real Xv,
1682 const Standard_Real Yv,
1683 Standard_Integer& Xp,
1684 Standard_Integer& Yp) const
7fd59977 1685{
c357e426 1686 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
7fd59977 1687
b5ac8292 1688 Standard_Integer aDxw, aDyw;
1689 MyWindow->Size (aDxw, aDyw);
7fd59977 1690
b5ac8292 1691 gp_Pnt aPoint (Xv, Yv, 0.0);
c357e426 1692 aPoint = Camera()->ConvertView2Proj (aPoint);
b5ac8292 1693 aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0);
7fd59977 1694
b5ac8292 1695 Xp = RealToInt (aPoint.X());
1696 Yp = RealToInt (aPoint.Y());
7fd59977 1697}
1698
197ac94e 1699//=======================================================================
1700//function : Convert
1701//purpose :
1702//=======================================================================
e70625d6 1703void V3d_View::Convert(const Standard_Integer theXp,
1704 const Standard_Integer theYp,
1705 Standard_Real& theX,
1706 Standard_Real& theY,
1707 Standard_Real& theZ) const
b8ddfc2f 1708{
c357e426 1709 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
e70625d6 1710 Standard_Integer aHeight = 0, aWidth = 0;
b5ac8292 1711 MyWindow->Size (aWidth, aHeight);
1712
e70625d6 1713 const gp_Pnt anXYZ (2.0 * theXp / aWidth - 1.0,
1714 2.0 * (aHeight - 1 - theYp) / aHeight - 1.0,
1715 Camera()->IsZeroToOneDepth() ? 0.0 : -1.0);
1716 const gp_Pnt aResult = Camera()->UnProject (anXYZ);
1717 theX = aResult.X();
1718 theY = aResult.Y();
1719 theZ = aResult.Z();
7fd59977 1720}
1721
197ac94e 1722//=======================================================================
1723//function : ConvertWithProj
1724//purpose :
1725//=======================================================================
3ed88fac 1726void V3d_View::ConvertWithProj(const Standard_Integer theXp,
1727 const Standard_Integer theYp,
1728 Standard_Real& theX,
1729 Standard_Real& theY,
1730 Standard_Real& theZ,
1731 Standard_Real& theDx,
1732 Standard_Real& theDy,
1733 Standard_Real& theDz) const
7fd59977 1734{
c357e426 1735 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
3ed88fac 1736 Standard_Integer aHeight = 0, aWidth = 0;
b5ac8292 1737 MyWindow->Size (aWidth, aHeight);
7fd59977 1738
3ed88fac 1739 const Standard_Real anX = 2.0 * theXp / aWidth - 1.0;
1740 const Standard_Real anY = 2.0 * (aHeight - 1 - theYp) / aHeight - 1.0;
1741 const Standard_Real aZ = 2.0 * 0.0 - 1.0;
b5ac8292 1742
3ed88fac 1743 const Handle(Graphic3d_Camera)& aCamera = Camera();
1744 const gp_Pnt aResult1 = aCamera->UnProject (gp_Pnt (anX, anY, aZ));
1745 const gp_Pnt aResult2 = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
b5ac8292 1746
3ed88fac 1747 theX = aResult1.X();
1748 theY = aResult1.Y();
1749 theZ = aResult1.Z();
1750 Graphic3d_Vec3d aNormDir (theX - aResult2.X(),
1751 theY - aResult2.Y(),
1752 theZ - aResult2.Z());
3910bc65 1753 aNormDir.Normalize();
1754
3ed88fac 1755 theDx = aNormDir.x();
1756 theDy = aNormDir.y();
1757 theDz = aNormDir.z();
7fd59977 1758}
7fd59977 1759
197ac94e 1760//=======================================================================
1761//function : Convert
1762//purpose :
1763//=======================================================================
1764void V3d_View::Convert(const Standard_Real X,
1765 const Standard_Real Y,
1766 const Standard_Real Z,
1767 Standard_Integer& Xp,
1768 Standard_Integer& Yp) const
b8ddfc2f 1769{
c357e426 1770 V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
b5ac8292 1771 Standard_Integer aHeight, aWidth;
1772 MyWindow->Size (aWidth, aHeight);
1773
c357e426 1774 gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z));
b5ac8292 1775
1776 Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
72b11796 1777 Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
7fd59977 1778}
1779
197ac94e 1780//=======================================================================
1781//function : Project
1782//purpose :
1783//=======================================================================
c357e426 1784void V3d_View::Project (const Standard_Real theX,
1785 const Standard_Real theY,
1786 const Standard_Real theZ,
1787 Standard_Real& theXp,
1788 Standard_Real& theYp) const
7fd59977 1789{
c357e426 1790 Standard_Real aZp;
1791 Project (theX, theY, theZ, theXp, theYp, aZp);
1792}
1793
1794//=======================================================================
1795//function : Project
1796//purpose :
1797//=======================================================================
1798void V3d_View::Project (const Standard_Real theX,
1799 const Standard_Real theY,
1800 const Standard_Real theZ,
1801 Standard_Real& theXp,
1802 Standard_Real& theYp,
1803 Standard_Real& theZp) const
1804{
1805 Handle(Graphic3d_Camera) aCamera = Camera();
1806
1807 gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1808 Standard_Real aXSize = aViewSpaceDimensions.X();
1809 Standard_Real aYSize = aViewSpaceDimensions.Y();
1810 Standard_Real aZSize = aViewSpaceDimensions.Z();
1811
1812 gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1813
1814 // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1815 theXp = aPoint.X() * aXSize * 0.5;
1816 theYp = aPoint.Y() * aYSize * 0.5;
e70625d6 1817 theZp = Camera()->IsZeroToOneDepth()
1818 ? aPoint.Z() * aZSize
1819 : aPoint.Z() * aZSize * 0.5;
7fd59977 1820}
1821
197ac94e 1822//=======================================================================
1823//function : BackgroundColor
1824//purpose :
1825//=======================================================================
1826void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,
1827 Standard_Real& V1,
1828 Standard_Real& V2,
1829 Standard_Real& V3) const
b8ddfc2f 1830{
7fd59977 1831 Quantity_Color C = BackgroundColor() ;
7fd59977 1832 C.Values(V1,V2,V3,Type) ;
1833}
1834
197ac94e 1835//=======================================================================
1836//function : BackgroundColor
1837//purpose :
1838//=======================================================================
b8ddfc2f 1839Quantity_Color V3d_View::BackgroundColor() const
1840{
c357e426 1841 return myView->Background().Color() ;
7fd59977 1842}
7fd59977 1843
197ac94e 1844//=======================================================================
1845//function : GradientBackgroundColors
1846//purpose :
1847//=======================================================================
c357e426 1848void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const
b8ddfc2f 1849{
c357e426 1850 myView->GradientBackground().Colors (theColor1, theColor2);
7fd59977 1851}
1852
197ac94e 1853//=======================================================================
1854//function : GradientBackground
1855//purpose :
1856//=======================================================================
b8ddfc2f 1857Aspect_GradientBackground V3d_View::GradientBackground() const
1858{
c357e426 1859 return myView->GradientBackground();
7fd59977 1860}
1861
197ac94e 1862//=======================================================================
1863//function : Scale
1864//purpose :
1865//=======================================================================
b8ddfc2f 1866Standard_Real V3d_View::Scale() const
1867{
c357e426 1868 return myDefaultCamera->Scale() / Camera()->Scale();
7fd59977 1869}
1870
197ac94e 1871//=======================================================================
1872//function : AxialScale
1873//purpose :
1874//=======================================================================
b8ddfc2f 1875void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
1876{
c357e426 1877 gp_Pnt anAxialScale = Camera()->AxialScale();
b5ac8292 1878 Sx = anAxialScale.X();
1879 Sy = anAxialScale.Y();
1880 Sz = anAxialScale.Z();
7fd59977 1881}
1882
197ac94e 1883//=======================================================================
1884//function : Size
1885//purpose :
1886//=======================================================================
b8ddfc2f 1887void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
1888{
c357e426 1889 gp_Pnt aViewDims = Camera()->ViewDimensions();
7fd59977 1890
b5ac8292 1891 Width = aViewDims.X();
1892 Height = aViewDims.Y();
7fd59977 1893}
1894
197ac94e 1895//=======================================================================
1896//function : ZSize
1897//purpose :
1898//=======================================================================
b8ddfc2f 1899Standard_Real V3d_View::ZSize() const
1900{
c357e426 1901 gp_Pnt aViewDims = Camera()->ViewDimensions();
7fd59977 1902
b5ac8292 1903 return aViewDims.Z();
7fd59977 1904}
1905
197ac94e 1906//=======================================================================
1907//function : MinMax
1908//purpose :
1909//=======================================================================
1910Standard_Integer V3d_View::MinMax(Standard_Real& Umin,
1911 Standard_Real& Vmin,
1912 Standard_Real& Umax,
1913 Standard_Real& Vmax) const
b8ddfc2f 1914{
7fd59977 1915 Standard_Real Wmin,Wmax,U,V,W ;
1916 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
1917 // CAL 6/11/98
c357e426 1918 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
7fd59977 1919
1920 if( Nstruct ) {
c357e426 1921 Bnd_Box aBox = myView->MinMaxValues();
ed063270 1922 aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
c357e426 1923 Project (Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1924 Project (Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1925 Project (Xmin,Ymin,Zmax,U,V,W) ;
7fd59977 1926 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1927 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1928 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1929 Project (Xmax,Ymin,Zmax,U,V,W) ;
7fd59977 1930 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1931 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1932 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1933 Project (Xmax,Ymin,Zmin,U,V,W) ;
7fd59977 1934 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1935 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1936 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1937 Project (Xmax,Ymax,Zmin,U,V,W) ;
7fd59977 1938 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1939 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1940 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1941 Project (Xmin,Ymax,Zmax,U,V,W) ;
7fd59977 1942 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1943 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1944 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
c357e426 1945 Project (Xmin,Ymax,Zmin,U,V,W) ;
7fd59977 1946 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1947 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1948 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1949 }
1950 return Nstruct ;
1951}
1952
197ac94e 1953//=======================================================================
1954//function : MinMax
1955//purpose :
1956//=======================================================================
1957Standard_Integer V3d_View::MinMax(Standard_Real& Xmin,
1958 Standard_Real& Ymin,
1959 Standard_Real& Zmin,
1960 Standard_Real& Xmax,
1961 Standard_Real& Ymax,
1962 Standard_Real& Zmax) const
b8ddfc2f 1963{
7fd59977 1964 // CAL 6/11/98
1965 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
c357e426 1966 Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
7fd59977 1967
1968 if( Nstruct ) {
c357e426 1969 Bnd_Box aBox = myView->MinMaxValues();
ed063270 1970 aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
7fd59977 1971 }
1972 return Nstruct ;
1973}
1974
197ac94e 1975//=======================================================================
49582f9d 1976//function : GravityPoint
197ac94e 1977//purpose :
1978//=======================================================================
49582f9d 1979gp_Pnt V3d_View::GravityPoint() const
b8ddfc2f 1980{
4af098ba 1981 Graphic3d_MapOfStructure aSetOfStructures;
c357e426 1982 myView->DisplayedStructures (aSetOfStructures);
4af098ba 1983
1984 Standard_Boolean hasSelection = Standard_False;
1985 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
1986 aStructIter.More(); aStructIter.Next())
1987 {
1988 if (aStructIter.Key()->IsHighlighted()
1989 && aStructIter.Key()->IsVisible())
1990 {
1991 hasSelection = Standard_True;
1992 break;
1993 }
1994 }
7fd59977 1995
4af098ba 1996 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
1997 Standard_Integer aNbPoints = 0;
1998 gp_XYZ aResult (0.0, 0.0, 0.0);
1999 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
2000 aStructIter.More(); aStructIter.Next())
2001 {
2002 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2003 if (!aStruct->IsVisible()
770fa4d4 2004 || aStruct->IsInfinite()
2005 || (hasSelection && !aStruct->IsHighlighted()))
4af098ba 2006 {
2007 continue;
2008 }
2009
7c3ef2f7 2010 const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
770fa4d4 2011 if (!aBox.IsValid())
2012 {
2013 continue;
2014 }
2015
2016 // skip transformation-persistent objects
778cd667 2017 if (!aStruct->TransformPersistence().IsNull())
4af098ba 2018 {
2019 continue;
2020 }
2021
2022 // use camera projection to find gravity point
7c3ef2f7 2023 Xmin = aBox.CornerMin().x();
2024 Ymin = aBox.CornerMin().y();
2025 Zmin = aBox.CornerMin().z();
2026 Xmax = aBox.CornerMax().x();
2027 Ymax = aBox.CornerMax().y();
2028 Zmax = aBox.CornerMax().z();
4af098ba 2029 gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
2030 {
2031 gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
2032 gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
2033 gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
2034 gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
2035 };
7fd59977 2036
4af098ba 2037 for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
2038 {
2039 const gp_Pnt& aBndPnt = aPnts[aPntIt];
c357e426 2040 const gp_Pnt aProjected = Camera()->Project (aBndPnt);
4af098ba 2041 if (Abs (aProjected.X()) <= 1.0
2042 && Abs (aProjected.Y()) <= 1.0)
2043 {
2044 aResult += aBndPnt.XYZ();
2045 ++aNbPoints;
2046 }
2047 }
2048 }
7fd59977 2049
4af098ba 2050 if (aNbPoints == 0)
b5ac8292 2051 {
770fa4d4 2052 // fallback - just use bounding box of entire scene
3fe9ce0e 2053 Bnd_Box aBox = myView->MinMaxValues();
770fa4d4 2054 if (!aBox.IsVoid())
b5ac8292 2055 {
4af098ba 2056 aBox.Get (Xmin, Ymin, Zmin,
2057 Xmax, Ymax, Zmax);
2058 gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
2059 {
b5ac8292 2060 gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
2061 gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
2062 gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
4af098ba 2063 gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
2064 };
b5ac8292 2065
4af098ba 2066 for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
b5ac8292 2067 {
2068 const gp_Pnt& aBndPnt = aPnts[aPntIt];
4af098ba 2069 aResult += aBndPnt.XYZ();
2070 ++aNbPoints;
b5ac8292 2071 }
7fd59977 2072 }
2073 }
7fd59977 2074
4af098ba 2075 if (aNbPoints > 0)
2076 {
2077 aResult /= aNbPoints;
2078 }
49582f9d 2079
2080 return aResult;
7fd59977 2081}
2082
197ac94e 2083//=======================================================================
2084//function : Eye
2085//purpose :
2086//=======================================================================
b8ddfc2f 2087void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2088{
c357e426 2089 gp_Pnt aCameraEye = Camera()->Eye();
b5ac8292 2090 X = aCameraEye.X();
2091 Y = aCameraEye.Y();
2092 Z = aCameraEye.Z();
7fd59977 2093}
2094
197ac94e 2095//=============================================================================
2096//function : ProjReferenceAxe
2097//purpose :
2098//=============================================================================
2099void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix,
2100 const Standard_Integer Ypix,
2101 Standard_Real& XP,
2102 Standard_Real& YP,
2103 Standard_Real& ZP,
2104 Standard_Real& VX,
2105 Standard_Real& VY,
2106 Standard_Real& VZ) const
b8ddfc2f 2107{
7fd59977 2108 Standard_Real Xo,Yo,Zo;
2109
b5ac8292 2110 Convert (Xpix, Ypix, XP, YP, ZP);
2111 if ( Type() == V3d_PERSPECTIVE )
2112 {
2113 FocalReferencePoint (Xo,Yo,Zo);
7fd59977 2114 VX = Xo - XP;
2115 VY = Yo - YP;
2116 VZ = Zo - ZP;
2117 }
b5ac8292 2118 else
2119 {
2120 Proj (VX,VY,VZ);
7fd59977 2121 }
2122}
2123
197ac94e 2124//=============================================================================
2125//function : Depth
2126//purpose :
2127//=============================================================================
b8ddfc2f 2128Standard_Real V3d_View::Depth() const
2129{
c357e426 2130 return Camera()->Distance();
7fd59977 2131}
2132
197ac94e 2133//=============================================================================
2134//function : Proj
2135//purpose :
2136//=============================================================================
b8ddfc2f 2137void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
2138{
c357e426 2139 gp_Dir aCameraDir = Camera()->Direction().Reversed();
b5ac8292 2140 Dx = aCameraDir.X();
2141 Dy = aCameraDir.Y();
2142 Dz = aCameraDir.Z();
7fd59977 2143}
2144
197ac94e 2145//=============================================================================
2146//function : At
2147//purpose :
2148//=============================================================================
b8ddfc2f 2149void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2150{
c357e426 2151 gp_Pnt aCameraCenter = Camera()->Center();
b5ac8292 2152 X = aCameraCenter.X();
2153 Y = aCameraCenter.Y();
2154 Z = aCameraCenter.Z();
7fd59977 2155}
2156
197ac94e 2157//=============================================================================
2158//function : Up
2159//purpose :
2160//=============================================================================
b8ddfc2f 2161void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
2162{
c357e426 2163 gp_Dir aCameraUp = Camera()->Up();
b5ac8292 2164 Vx = aCameraUp.X();
2165 Vy = aCameraUp.Y();
2166 Vz = aCameraUp.Z();
7fd59977 2167}
2168
197ac94e 2169//=============================================================================
2170//function : Twist
2171//purpose :
2172//=============================================================================
b8ddfc2f 2173Standard_Real V3d_View::Twist() const
2174{
21b2385f 2175 gp_Vec Xaxis, Yaxis, Zaxis;
2176 const gp_Dir aReferencePlane (Camera()->Direction().Reversed());
2177 if (!screenAxis (aReferencePlane, gp::DZ(), Xaxis, Yaxis, Zaxis)
2178 && !screenAxis (aReferencePlane, gp::DY(), Xaxis, Yaxis, Zaxis)
2179 && !screenAxis (aReferencePlane, gp::DX(), Xaxis, Yaxis, Zaxis))
2180 {
2181 //
2182 }
7fd59977 2183
21b2385f 2184 // Compute Cross Vector From Up & Origin
2185 const gp_Dir aCameraUp = Camera()->Up();
2186 const gp_XYZ aP = Yaxis.XYZ().Crossed (aCameraUp.XYZ());
b5ac8292 2187
21b2385f 2188 // compute Angle
2189 Standard_Real anAngle = ASin (Max (Min (aP.Modulus(), 1.0), -1.0));
2190 if (Yaxis.Dot (aCameraUp.XYZ()) < 0.0)
2191 {
2192 anAngle = M_PI - anAngle;
7fd59977 2193 }
21b2385f 2194 if (anAngle > 0.0
2195 && anAngle < M_PI)
2196 {
2197 const gp_Dir aProjDir = Camera()->Direction().Reversed();
2198 if (aP.Dot (aProjDir.XYZ()) < 0.0)
2199 {
2200 anAngle = DEUXPI - anAngle;
2201 }
7fd59977 2202 }
21b2385f 2203 return anAngle;
7fd59977 2204}
2205
197ac94e 2206//=============================================================================
2207//function : ShadingModel
2208//purpose :
2209//=============================================================================
dc89236f 2210Graphic3d_TypeOfShadingModel V3d_View::ShadingModel() const
b8ddfc2f 2211{
dc89236f 2212 return myView->ShadingModel();
7fd59977 2213}
2214
197ac94e 2215//=============================================================================
2216//function : TextureEnv
2217//purpose :
2218//=============================================================================
857ffd5e 2219Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
b8ddfc2f 2220{
c357e426 2221 return myView->TextureEnv();
7fd59977 2222}
2223
197ac94e 2224//=============================================================================
2225//function : Visualization
2226//purpose :
2227//=============================================================================
b8ddfc2f 2228V3d_TypeOfVisualization V3d_View::Visualization() const
2229{
c357e426 2230 return static_cast<V3d_TypeOfVisualization> (myView->VisualizationType());
7fd59977 2231}
2232
197ac94e 2233//=============================================================================
2234//function : IfWindow
2235//purpose :
2236//=============================================================================
b8ddfc2f 2237Standard_Boolean V3d_View::IfWindow() const
2238{
c357e426 2239 return myView->IsDefined();
7fd59977 2240}
2241
197ac94e 2242//=============================================================================
2243//function : Type
2244//purpose :
2245//=============================================================================
b8ddfc2f 2246V3d_TypeOfView V3d_View::Type() const
2247{
c357e426 2248 return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
7fd59977 2249}
2250
197ac94e 2251//=============================================================================
2252//function : SetFocale
2253//purpose :
2254//=============================================================================
b8ddfc2f 2255void V3d_View::SetFocale( const Standard_Real focale )
2256{
c357e426 2257 Handle(Graphic3d_Camera) aCamera = Camera();
2258
2259 if (aCamera->IsOrthographic())
b5ac8292 2260 {
2261 return;
7fd59977 2262 }
b5ac8292 2263
c357e426 2264 Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0));
b5ac8292 2265
c357e426 2266 aCamera->SetFOVy (aFOVyRad * (360 / M_PI));
7fd59977 2267
2268 ImmediateUpdate();
2269}
2270
197ac94e 2271//=============================================================================
2272//function : Focale
2273//purpose :
2274//=============================================================================
b5ac8292 2275Standard_Real V3d_View::Focale() const
b8ddfc2f 2276{
c357e426 2277 Handle(Graphic3d_Camera) aCamera = Camera();
2278
2279 if (aCamera->IsOrthographic())
b5ac8292 2280 {
2281 return 0.0;
7fd59977 2282 }
b5ac8292 2283
c357e426 2284 return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0);
7fd59977 2285}
2286
197ac94e 2287//=============================================================================
21b2385f 2288//function : screenAxis
197ac94e 2289//purpose :
2290//=============================================================================
21b2385f 2291Standard_Boolean V3d_View::screenAxis (const gp_Dir& theVpn, const gp_Dir& theVup,
2292 gp_Vec& theXaxe, gp_Vec& theYaxe, gp_Vec& theZaxe)
b5ac8292 2293{
21b2385f 2294 theXaxe = theVup.XYZ().Crossed (theVpn.XYZ());
2295 if (theXaxe.Magnitude() <= gp::Resolution())
2296 {
2297 return Standard_False;
2298 }
2299 theXaxe.Normalize();
b5ac8292 2300
21b2385f 2301 theYaxe = theVpn.XYZ().Crossed (theXaxe.XYZ());
2302 if (theYaxe.Magnitude() <= gp::Resolution())
2303 {
2304 return Standard_False;
2305 }
2306 theYaxe.Normalize();
b5ac8292 2307
21b2385f 2308 theZaxe = theVpn.XYZ();
2309 theZaxe.Normalize();
7fd59977 2310 return Standard_True;
2311}
2312
197ac94e 2313//=============================================================================
2314//function : TrsPoint
2315//purpose :
2316//=============================================================================
475c2302 2317gp_XYZ V3d_View::TrsPoint (const Graphic3d_Vertex& thePnt, const TColStd_Array2OfReal& theMat)
b8ddfc2f 2318{
7fd59977 2319 // CAL. S3892
475c2302 2320 const Standard_Integer lr = theMat.LowerRow();
2321 const Standard_Integer ur = theMat.UpperRow();
2322 const Standard_Integer lc = theMat.LowerCol();
2323 const Standard_Integer uc = theMat.UpperCol();
2324 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
2325 {
2326 return gp_XYZ (thePnt.X(), thePnt.Y(), thePnt.Z());
2327 }
2328
2329 Standard_Real X, Y, Z;
2330 thePnt.Coord (X,Y,Z);
2331 const Standard_Real XX = (theMat(lr,lc+3) + X*theMat(lr,lc) + Y*theMat(lr,lc+1) + Z*theMat(lr,lc+2)) / theMat(lr+3,lc+3);
2332 const Standard_Real YY = (theMat(lr+1,lc+3) + X*theMat(lr+1,lc) + Y*theMat(lr+1,lc+1) + Z*theMat(lr+1,lc+2))/theMat(lr+3,lc+3);
2333 const Standard_Real ZZ = (theMat(lr+2,lc+3) + X*theMat(lr+2,lc) + Y*theMat(lr+2,lc+1) + Z*theMat(lr+2,lc+2))/theMat(lr+3,lc+3);
2334 return gp_XYZ (XX, YY, ZZ);
7fd59977 2335}
2336
197ac94e 2337//=======================================================================
2338//function : Pan
2339//purpose :
2340//=======================================================================
2341void V3d_View::Pan (const Standard_Integer theDXp,
2342 const Standard_Integer theDYp,
ee2be2a8 2343 const Standard_Real theZoomFactor,
197ac94e 2344 const Standard_Boolean theToStart)
b8ddfc2f 2345{
197ac94e 2346 Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart);
7fd59977 2347}
2348
197ac94e 2349//=======================================================================
2350//function : Panning
2351//purpose :
2352//=======================================================================
2353void V3d_View::Panning (const Standard_Real theDXv,
2354 const Standard_Real theDYv,
ee2be2a8 2355 const Standard_Real theZoomFactor,
197ac94e 2356 const Standard_Boolean theToStart)
7fd59977 2357{
197ac94e 2358 Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
7fd59977 2359
c357e426 2360 Handle(Graphic3d_Camera) aCamera = Camera();
2361
197ac94e 2362 if (theToStart)
2363 {
607e5e62 2364 myCamStartOpDir = aCamera->Direction();
c357e426 2365 myCamStartOpEye = aCamera->Eye();
2366 myCamStartOpCenter = aCamera->Center();
7fd59977 2367 }
197ac94e 2368
2369 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
2370
c357e426 2371 gp_Pnt aViewDims = aCamera->ViewDimensions();
197ac94e 2372
607e5e62 2373 aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
2374 aCamera->SetDirectionFromEye (myCamStartOpDir);
c357e426 2375 Translate (aCamera, -theDXv, -theDYv);
2376 Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
197ac94e 2377
2378 SetImmediateUpdate (wasUpdateEnabled);
2379
2380 ImmediateUpdate();
7fd59977 2381}
2382
197ac94e 2383//=======================================================================
2384//function : Zoom
2385//purpose :
2386//=======================================================================
2387void V3d_View::Zoom (const Standard_Integer theXp1,
2388 const Standard_Integer theYp1,
2389 const Standard_Integer theXp2,
2390 const Standard_Integer theYp2)
2391{
2392 Standard_Integer aDx = theXp2 - theXp1;
2393 Standard_Integer aDy = theYp2 - theYp1;
2394 if (aDx != 0 || aDy != 0)
2395 {
2396 Standard_Real aCoeff = Sqrt( (Standard_Real)(aDx * aDx + aDy * aDy) ) / 100.0 + 1.0;
2397 aCoeff = (aDx > 0) ? aCoeff : 1.0 / aCoeff;
2398 SetZoom (aCoeff, Standard_True);
2399 }
7fd59977 2400}
2401
197ac94e 2402//=======================================================================
2403//function : StartZoomAtPoint
2404//purpose :
2405//=======================================================================
2406void V3d_View::StartZoomAtPoint (const Standard_Integer theXp,
2407 const Standard_Integer theYp)
7fd59977 2408{
197ac94e 2409 MyZoomAtPointX = theXp;
2410 MyZoomAtPointY = theYp;
7fd59977 2411}
2412
197ac94e 2413//=======================================================================
2414//function : ZoomAtPoint
2415//purpose :
2416//=======================================================================
2417void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
2418 const Standard_Integer theMouseStartY,
2419 const Standard_Integer theMouseEndX,
2420 const Standard_Integer theMouseEndY)
7fd59977 2421{
197ac94e 2422 Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
7fd59977 2423
197ac94e 2424 // zoom
2425 Standard_Real aDxy = Standard_Real ((theMouseEndX + theMouseEndY) - (theMouseStartX + theMouseStartY));
2426 Standard_Real aDZoom = Abs (aDxy) / 100.0 + 1.0;
2427 aDZoom = (aDxy > 0.0) ? aDZoom : 1.0 / aDZoom;
7fd59977 2428
197ac94e 2429 V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
7fd59977 2430
c357e426 2431 Handle(Graphic3d_Camera) aCamera = Camera();
2432
2433 Standard_Real aViewWidth = aCamera->ViewDimensions().X();
2434 Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
7fd59977 2435
197ac94e 2436 // ensure that zoom will not be too small or too big.
2437 Standard_Real aCoef = aDZoom;
2438 if (aViewWidth < aCoef * Precision::Confusion())
2439 {
2440 aCoef = aViewWidth / Precision::Confusion();
2441 }
2442 else if (aViewWidth > aCoef * 1e12)
2443 {
2444 aCoef = aViewWidth / 1e12;
2445 }
2446 if (aViewHeight < aCoef * Precision::Confusion())
2447 {
2448 aCoef = aViewHeight / Precision::Confusion();
2449 }
2450 else if (aViewHeight > aCoef * 1e12)
2451 {
2452 aCoef = aViewHeight / 1e12;
2453 }
7fd59977 2454
197ac94e 2455 Standard_Real aZoomAtPointXv = 0.0;
2456 Standard_Real aZoomAtPointYv = 0.0;
2457 Convert (MyZoomAtPointX, MyZoomAtPointY, aZoomAtPointXv, aZoomAtPointYv);
7fd59977 2458
ee2be2a8 2459 Standard_Real aDxv = aZoomAtPointXv / aCoef;
2460 Standard_Real aDyv = aZoomAtPointYv / aCoef;
7fd59977 2461
c357e426 2462 aCamera->SetScale (aCamera->Scale() / aCoef);
2463 Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
b5ac8292 2464
197ac94e 2465 SetImmediateUpdate (wasUpdateEnabled);
7fd59977 2466
197ac94e 2467 ImmediateUpdate();
7fd59977 2468}
2469
197ac94e 2470//=============================================================================
2471//function : AxialScale
2472//purpose :
2473//=============================================================================
7fd59977 2474void V3d_View::AxialScale (const Standard_Integer Dx,
2475 const Standard_Integer Dy,
2476 const V3d_TypeOfAxe Axis)
2477{
2478 if( Dx != 0. || Dy != 0. ) {
2479 Standard_Real Sx, Sy, Sz;
2480 AxialScale( Sx, Sy, Sz );
2481 Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
2482 dscale = (Dx > 0) ? dscale : 1./dscale;
2483 if( Axis == V3d_X ) Sx = dscale;
2484 if( Axis == V3d_Y ) Sy = dscale;
2485 if( Axis == V3d_Z ) Sz = dscale;
2486 SetAxialScale( Sx, Sy, Sz );
2487 }
2488}
2489
197ac94e 2490//=============================================================================
2491//function : FitAll
2492//purpose :
2493//=============================================================================
434ffc09 2494void V3d_View::FitAll(const Standard_Real theXmin,
2495 const Standard_Real theYmin,
2496 const Standard_Real theXmax,
2497 const Standard_Real theYmax)
7fd59977 2498{
434ffc09 2499 Handle(Graphic3d_Camera) aCamera = Camera();
2500 Standard_Real anAspect = aCamera->Aspect();
7fd59977 2501
434ffc09 2502 Standard_Real aFitSizeU = Abs (theXmax - theXmin);
2503 Standard_Real aFitSizeV = Abs (theYmax - theYmin);
197ac94e 2504 Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
434ffc09 2505 if (aFitAspect >= anAspect)
197ac94e 2506 {
434ffc09 2507 aFitSizeV = aFitSizeU / anAspect;
197ac94e 2508 }
2509 else
2510 {
434ffc09 2511 aFitSizeU = aFitSizeV * anAspect;
197ac94e 2512 }
b5ac8292 2513
434ffc09 2514 Translate (aCamera, (theXmin + theXmax) * 0.5, (theYmin + theYmax) * 0.5);
c357e426 2515 Scale (aCamera, aFitSizeU, aFitSizeV);
2516
197ac94e 2517 ImmediateUpdate();
7fd59977 2518}
2519
197ac94e 2520//=============================================================================
2521//function : StartRotation
2522//purpose :
2523//=============================================================================
7fd59977 2524void V3d_View::StartRotation(const Standard_Integer X,
2525 const Standard_Integer Y,
ee2be2a8 2526 const Standard_Real zRotationThreshold)
7fd59977 2527{
7fd59977 2528 sx = X; sy = Y;
2529 Standard_Real x,y;
2530 Size(x,y);
2531 rx = Standard_Real(Convert(x));
2532 ry = Standard_Real(Convert(y));
49582f9d 2533 myRotateGravity = GravityPoint();
2534 Rotate (0.0, 0.0, 0.0,
2535 myRotateGravity.X(), myRotateGravity.Y(), myRotateGravity.Z(),
2536 Standard_True);
016e5959 2537 myZRotation = Standard_False;
7fd59977 2538 if( zRotationThreshold > 0. ) {
2539 Standard_Real dx = Abs(sx - rx/2.);
2540 Standard_Real dy = Abs(sy - ry/2.);
016e5959 2541 // if( dx > rx/3. || dy > ry/3. ) myZRotation = Standard_True;
7fd59977 2542 Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
016e5959 2543 if( dx > dd || dy > dd ) myZRotation = Standard_True;
7fd59977 2544 }
7fd59977 2545
2546}
2547
197ac94e 2548//=============================================================================
2549//function : Rotation
2550//purpose :
2551//=============================================================================
7fd59977 2552void V3d_View::Rotation(const Standard_Integer X,
2553 const Standard_Integer Y)
2554{
7fd59977 2555 if( rx == 0. || ry == 0. ) {
2556 StartRotation(X,Y);
2557 return;
2558 }
7fd59977 2559 Standard_Real dx=0.,dy=0.,dz=0.;
016e5959 2560 if( myZRotation ) {
7fd59977 2561 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
2562 atan2(sx-rx/2.,ry/2.-sy);
2563 } else {
c6541a0c
D
2564 dx = (Standard_Real(X) - sx) * M_PI / rx;
2565 dy = (sy - Standard_Real(Y)) * M_PI / ry;
7fd59977 2566 }
b12a3e54 2567
49582f9d 2568 Rotate (dx, dy, dz,
2569 myRotateGravity.X(), myRotateGravity.Y(), myRotateGravity.Z(),
2570 Standard_False);
7fd59977 2571}
2572
197ac94e 2573//=============================================================================
2574//function : SetComputedMode
2575//purpose :
2576//=============================================================================
c357e426 2577void V3d_View::SetComputedMode (const Standard_Boolean theMode)
7fd59977 2578{
c357e426 2579 if (theMode)
197ac94e 2580 {
2581 if (myComputedMode)
2582 {
c357e426 2583 myView->SetComputedMode (Standard_True);
7fd59977 2584 }
c357e426 2585 }
2586 else
197ac94e 2587 {
c357e426 2588 myView->SetComputedMode (Standard_False);
7fd59977 2589 }
b8ddfc2f 2590}
7fd59977 2591
197ac94e 2592//=============================================================================
2593//function : ComputedMode
2594//purpose :
2595//=============================================================================
2596Standard_Boolean V3d_View::ComputedMode() const
7fd59977 2597{
c357e426 2598 return myView->ComputedMode();
b8ddfc2f 2599}
7fd59977 2600
197ac94e 2601//=============================================================================
2602//function : SetBackFacingModel
2603//purpose :
2604//=============================================================================
7fd4958d 2605void V3d_View::SetBackFacingModel (const Graphic3d_TypeOfBackfacingModel theModel)
7fd59977 2606{
7fd4958d 2607 myView->SetBackfacingModel (theModel);
7fd59977 2608 Redraw();
b8ddfc2f 2609}
7fd59977 2610
197ac94e 2611//=============================================================================
2612//function : BackFacingModel
2613//purpose :
2614//=============================================================================
7fd4958d 2615Graphic3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
b8ddfc2f 2616{
7fd4958d 2617 return myView->BackfacingModel();
b8ddfc2f 2618}
7fd59977 2619
c357e426 2620//=============================================================================
2621//function : Init
2622//purpose :
2623//=============================================================================
b8ddfc2f 2624void V3d_View::Init()
2625{
7fd59977 2626 myComputedMode = MyViewer->ComputedMode();
c357e426 2627 if (!myComputedMode || !MyViewer->DefaultComputedMode())
2628 {
2629 SetComputedMode (Standard_False);
7fd59977 2630 }
7fd59977 2631}
2632
197ac94e 2633//=============================================================================
2634//function : Dump
2635//purpose :
2636//=============================================================================
692613e5 2637Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
2638 const Graphic3d_BufferType& theBufferType)
7fd59977 2639{
2640 Standard_Integer aWinWidth, aWinHeight;
2641 MyWindow->Size (aWinWidth, aWinHeight);
692613e5 2642 Image_AlienPixMap anImage;
b5ac8292 2643
692613e5 2644 return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
7fd59977 2645}
2646
197ac94e 2647//=============================================================================
2648//function : ToPixMap
2649//purpose :
2650//=============================================================================
692613e5 2651Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage,
3bffef55 2652 const V3d_ImageDumpOptions& theParams)
7fd59977 2653{
3bffef55 2654 Graphic3d_Vec2i aTargetSize (theParams.Width, theParams.Height);
2655 if (aTargetSize.x() != 0
2656 && aTargetSize.y() != 0)
2657 {
2658 // allocate image buffer for dumping
2659 if (theImage.IsEmpty()
2660 || theImage.SizeX() != Standard_Size(aTargetSize.x())
2661 || theImage.SizeY() != Standard_Size(aTargetSize.y()))
2662 {
dc858f4c 2663 Image_Format aFormat = Image_Format_UNKNOWN;
3bffef55 2664 switch (theParams.BufferType)
2665 {
38d90bb3 2666 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
2667 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
2668 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
2669 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
4eff0c04 2670 case Graphic3d_BT_Red: aFormat = Image_Format_Gray; break;
3bffef55 2671 }
2672
2673 if (!theImage.InitZero (aFormat, Standard_Size(aTargetSize.x()), Standard_Size(aTargetSize.y())))
2674 {
a87b1b37 2675 Message::SendFail (TCollection_AsciiString ("Fail to allocate an image ") + aTargetSize.x() + "x" + aTargetSize.y() + " for view dump");
3bffef55 2676 return Standard_False;
2677 }
2678 }
2679 }
2680 if (theImage.IsEmpty())
2681 {
a87b1b37 2682 Message::SendFail ("V3d_View::ToPixMap() has been called without image dimensions");
3bffef55 2683 return Standard_False;
2684 }
2685 aTargetSize.x() = (Standard_Integer )theImage.SizeX();
2686 aTargetSize.y() = (Standard_Integer )theImage.SizeY();
2687
b128c892 2688 Handle(Standard_Transient) aFBOPtr;
2689 Handle(Standard_Transient) aPrevFBOPtr = myView->FBO();
3bffef55 2690 Graphic3d_Vec2i aFBOVPSize = aTargetSize;
2691
2692 bool isTiling = false;
2693 if (theParams.TileSize > 0)
2694 {
2695 if (aFBOVPSize.x() > theParams.TileSize
2696 || aFBOVPSize.y() > theParams.TileSize)
2697 {
2698 aFBOVPSize.x() = Min (aFBOVPSize.x(), theParams.TileSize);
2699 aFBOVPSize.y() = Min (aFBOVPSize.y(), theParams.TileSize);
2700 isTiling = true;
2701 }
2702 }
2703
2704 Graphic3d_Vec2i aPrevFBOVPSize;
b128c892 2705 if (!aPrevFBOPtr.IsNull())
7fd59977 2706 {
3bffef55 2707 Graphic3d_Vec2i aPrevFBOSizeMax;
c357e426 2708 myView->FBOGetDimensions (aPrevFBOPtr,
3bffef55 2709 aPrevFBOVPSize.x(), aPrevFBOVPSize.y(),
2710 aPrevFBOSizeMax.x(), aPrevFBOSizeMax.y());
2711 if (aFBOVPSize.x() <= aPrevFBOSizeMax.x()
2712 && aFBOVPSize.y() <= aPrevFBOSizeMax.y())
7fd59977 2713 {
7fd59977 2714 aFBOPtr = aPrevFBOPtr;
2715 }
2716 }
2717
b128c892 2718 if (aFBOPtr.IsNull())
7fd59977 2719 {
6997ff1c 2720 Standard_Integer aMaxTexSizeX = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeX);
2721 Standard_Integer aMaxTexSizeY = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeY);
2722 if (theParams.TileSize > aMaxTexSizeX
2723 || theParams.TileSize > aMaxTexSizeY)
85e096c3 2724 {
a87b1b37 2725 Message::SendFail (TCollection_AsciiString ("Image dump can not be performed - specified tile size (")
2726 + theParams.TileSize + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")");
3bffef55 2727 return Standard_False;
85e096c3 2728 }
3bffef55 2729
6997ff1c 2730 if (aFBOVPSize.x() > aMaxTexSizeX
2731 || aFBOVPSize.y() > aMaxTexSizeY)
3bffef55 2732 {
6997ff1c 2733 if (MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_IsWorkaroundFBO))
2734 {
a87b1b37 2735 Message::SendWarning ("Warning, workaround for Intel driver problem with empty FBO for images with big width is applied");
6997ff1c 2736 }
a87b1b37 2737 Message::SendInfo (TCollection_AsciiString ("Info, tiling image dump is used, image size (")
2738 + aFBOVPSize.x() + "x" + aFBOVPSize.y() + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")");
6997ff1c 2739 aFBOVPSize.x() = Min (aFBOVPSize.x(), aMaxTexSizeX);
2740 aFBOVPSize.y() = Min (aFBOVPSize.y(), aMaxTexSizeY);
3bffef55 2741 isTiling = true;
2742 }
2743
2744 // Try to create hardware accelerated buffer
2745 aFBOPtr = myView->FBOCreate (aFBOVPSize.x(), aFBOVPSize.y());
7fd59977 2746 }
c357e426 2747 myView->SetFBO (aFBOPtr);
7fd59977 2748
b128c892 2749 if (aFBOPtr.IsNull())
7fd59977 2750 {
3bffef55 2751 // try to use on-screen buffer
2752 Graphic3d_Vec2i aWinSize;
2753 MyWindow->Size (aWinSize.x(), aWinSize.y());
2754 if (aFBOVPSize.x() != aWinSize.x()
2755 || aFBOVPSize.y() != aWinSize.y())
7fd59977 2756 {
3bffef55 2757 isTiling = true;
7fd59977 2758 }
3bffef55 2759 aFBOVPSize = aWinSize;
2760
a87b1b37 2761 Message::SendWarning ("Warning, on screen buffer is used for image dump - content might be invalid");
7fd59977 2762 }
2763
3bffef55 2764 // backup camera parameters
b5ac8292 2765 Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
c357e426 2766 Handle(Graphic3d_Camera) aCamera = Camera();
c357e426 2767 aStoreMapping->Copy (aCamera);
c357e426 2768 if (aCamera->IsStereo())
b5ac8292 2769 {
3bffef55 2770 switch (theParams.StereoOptions)
b5ac8292 2771 {
f978241f 2772 case V3d_SDO_MONO:
2773 {
c357e426 2774 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
b5ac8292 2775 break;
f978241f 2776 }
2777 case V3d_SDO_LEFT_EYE:
2778 {
c357e426 2779 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
b5ac8292 2780 break;
f978241f 2781 }
2782 case V3d_SDO_RIGHT_EYE:
2783 {
c357e426 2784 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
b5ac8292 2785 break;
f978241f 2786 }
2787 case V3d_SDO_BLENDED:
2788 {
2789 break; // dump as is
2790 }
b5ac8292 2791 }
2792 }
3bffef55 2793 if (theParams.ToAdjustAspect)
197ac94e 2794 {
3bffef55 2795 aCamera->SetAspect (Standard_Real(aTargetSize.x()) / Standard_Real(aTargetSize.y()));
7fd59977 2796 }
2797
3bffef55 2798 // render immediate structures into back buffer rather than front
2799 const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False);
7fd59977 2800
692613e5 2801 Standard_Boolean isSuccess = Standard_True;
3bffef55 2802 if (!isTiling)
7fd59977 2803 {
3bffef55 2804 if (!aFBOPtr.IsNull())
692613e5 2805 {
3bffef55 2806 myView->FBOChangeViewport (aFBOPtr, aTargetSize.x(), aTargetSize.y());
692613e5 2807 }
3bffef55 2808 Redraw();
2809 isSuccess = isSuccess && myView->BufferDump (theImage, theParams.BufferType);
2810 }
2811 else
2812 {
2813 Image_PixMap aTilePixMap;
2814 aTilePixMap.SetTopDown (theImage.IsTopDown());
692613e5 2815
3bffef55 2816 Graphic3d_Vec2i anOffset (0, 0);
2817 for (; anOffset.y() < aTargetSize.y(); anOffset.y() += aFBOVPSize.y())
2818 {
2819 anOffset.x() = 0;
2820 for (; anOffset.x() < aTargetSize.x(); anOffset.x() += aFBOVPSize.x())
2821 {
c8fe0e2d 2822 Graphic3d_CameraTile aTileUncropped;
2823 aTileUncropped.Offset = anOffset;
2824 aTileUncropped.TotalSize = aTargetSize;
2825 aTileUncropped.TileSize = aFBOVPSize;
2826 const Graphic3d_CameraTile aTile = aTileUncropped.Cropped();
3bffef55 2827 if (aTile.TileSize.x() < 1
2828 || aTile.TileSize.y() < 1)
2829 {
2830 continue;
2831 }
2832
2833 const Standard_Integer aLeft = aTile.Offset.x();
2834 Standard_Integer aBottom = aTile.Offset.y();
2835 if (theImage.IsTopDown())
2836 {
2837 const Standard_Integer aTop = aTile.Offset.y() + aTile.TileSize.y();
2838 aBottom = aTargetSize.y() - aTop;
2839 }
2840 aTilePixMap.InitWrapper (theImage.Format(), theImage.ChangeData()
2841 + theImage.SizeRowBytes() * aBottom + theImage.SizePixelBytes() * aLeft,
2842 aTile.TileSize.x(), aTile.TileSize.y(),
2843 theImage.SizeRowBytes());
2844
3bffef55 2845 if (!aFBOPtr.IsNull())
2846 {
c8fe0e2d 2847 aCamera->SetTile (aTile);
3bffef55 2848 myView->FBOChangeViewport (aFBOPtr, aTile.TileSize.x(), aTile.TileSize.y());
2849 }
c8fe0e2d 2850 else
2851 {
2852 // no API to resize viewport of on-screen buffer - render uncropped
2853 aCamera->SetTile (aTileUncropped);
2854 }
3bffef55 2855 Redraw();
2856 isSuccess = isSuccess && myView->BufferDump (aTilePixMap, theParams.BufferType);
2857 if (!isSuccess)
2858 {
2859 break;
2860 }
2861 }
2862 if (!isSuccess)
2863 {
2864 break;
2865 }
2866 }
7fd59977 2867 }
2868
3bffef55 2869 // restore state
2870 myView->SetImmediateModeDrawToFront (aPrevImmediateMode);
2871 aCamera->Copy (aStoreMapping);
7fd59977 2872 if (aFBOPtr != aPrevFBOPtr)
2873 {
c357e426 2874 myView->FBORelease (aFBOPtr);
7fd59977 2875 }
b128c892 2876 else if (!aPrevFBOPtr.IsNull())
7fd59977 2877 {
3bffef55 2878 myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSize.x(), aPrevFBOVPSize.y());
7fd59977 2879 }
c357e426 2880 myView->SetFBO (aPrevFBOPtr);
692613e5 2881 return isSuccess;
7fd59977 2882}
6942f04a 2883
c357e426 2884//=============================================================================
2885//function : ImmediateUpdate
2886//purpose :
2887//=============================================================================
6942f04a 2888void V3d_View::ImmediateUpdate() const
2889{
c357e426 2890 if (myImmediateUpdate)
2891 {
2892 Update();
2893 }
6942f04a 2894}
2895
c357e426 2896//=============================================================================
2897//function : SetImmediateUpdate
2898//purpose :
2899//=============================================================================
6942f04a 2900Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate)
2901{
2902 Standard_Boolean aPreviousMode = myImmediateUpdate;
2903 myImmediateUpdate = theImmediateUpdate;
2904 return aPreviousMode;
2905}
b5ac8292 2906
2907// =======================================================================
2908// function : SetCamera
2909// purpose :
2910// =======================================================================
2911void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
2912{
c357e426 2913 myView->SetCamera (theCamera);
197ac94e 2914
c357e426 2915 ImmediateUpdate();
b5ac8292 2916}
2917
2918// =======================================================================
2919// function : GetCamera
2920// purpose :
2921// =======================================================================
197ac94e 2922const Handle(Graphic3d_Camera)& V3d_View::Camera() const
b5ac8292 2923{
c357e426 2924 return myView->Camera();
b5ac8292 2925}
2926
2927// =======================================================================
197ac94e 2928// function : FitMinMax
2929// purpose : Internal
b5ac8292 2930// =======================================================================
197ac94e 2931Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
ed063270 2932 const Bnd_Box& theBox,
197ac94e 2933 const Standard_Real theMargin,
2934 const Standard_Real theResolution,
2935 const Standard_Boolean theToEnlargeIfLine) const
2936{
f3a53980 2937 if (!theCamera->FitMinMax (theBox, theResolution, theToEnlargeIfLine))
b5ac8292 2938 {
197ac94e 2939 return Standard_False; // bounding box is out of bounds...
2940 }
2941
50d06d8f 2942 const Standard_Real aZoomCoef = myView->ConsiderZoomPersistenceObjects();
50d06d8f 2943 Scale (theCamera, theCamera->ViewDimensions().X() * (aZoomCoef + theMargin), theCamera->ViewDimensions().Y() * (aZoomCoef + theMargin));
197ac94e 2944 return Standard_True;
b5ac8292 2945}
2946
2947// =======================================================================
197ac94e 2948// function : Scale
2949// purpose : Internal
b5ac8292 2950// =======================================================================
197ac94e 2951void V3d_View::Scale (const Handle(Graphic3d_Camera)& theCamera,
2952 const Standard_Real theSizeXv,
2953 const Standard_Real theSizeYv) const
b5ac8292 2954{
197ac94e 2955 Standard_Real anAspect = theCamera->Aspect();
ab1c121b 2956 if (anAspect > 1.0)
2957 {
2958 theCamera->SetScale (Max (theSizeXv / anAspect, theSizeYv));
2959 }
2960 else
2961 {
2962 theCamera->SetScale (Max (theSizeXv, theSizeYv * anAspect));
2963 }
7b17aba7 2964 Invalidate();
b5ac8292 2965}
2966
2967// =======================================================================
197ac94e 2968// function : Translate
2969// purpose : Internal
b5ac8292 2970// =======================================================================
197ac94e 2971void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
2972 const Standard_Real theDXv,
2973 const Standard_Real theDYv) const
2974{
2975 const gp_Pnt& aCenter = theCamera->Center();
2976 const gp_Dir& aDir = theCamera->Direction();
2977 const gp_Dir& anUp = theCamera->Up();
2978 gp_Ax3 aCameraCS (aCenter, aDir.Reversed(), aDir ^ anUp);
2979
2980 gp_Vec aCameraPanXv = gp_Vec (aCameraCS.XDirection()) * theDXv;
2981 gp_Vec aCameraPanYv = gp_Vec (aCameraCS.YDirection()) * theDYv;
2982 gp_Vec aCameraPan = aCameraPanXv + aCameraPanYv;
2983 gp_Trsf aPanTrsf;
2984 aPanTrsf.SetTranslation (aCameraPan);
2985
2986 theCamera->Transform (aPanTrsf);
7b17aba7 2987 Invalidate();
b5ac8292 2988}
b7cd4ba7 2989
2990// =======================================================================
26d9c835 2991// function : DiagnosticInformation
2992// purpose :
2993// =======================================================================
2994void V3d_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
2995 Graphic3d_DiagnosticInfo theFlags) const
2996{
2997 myView->DiagnosticInformation (theDict, theFlags);
2998}
ebc369da 2999
79b544e6 3000//=======================================================================
3001//function : StatisticInformation
3002//purpose :
3003//=======================================================================
3004void V3d_View::StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const
3005{
3006 myView->StatisticInformation (theDict);
3007}
3008
3009// =======================================================================
3010// function : StatisticInformation
3011// purpose :
3012// =======================================================================
3013TCollection_AsciiString V3d_View::StatisticInformation() const
3014{
3015 return myView->StatisticInformation();
3016}
3017
ebc369da 3018//=============================================================================
3019//function : RenderingParams
3020//purpose :
3021//=============================================================================
3022const Graphic3d_RenderingParams& V3d_View::RenderingParams() const
3023{
3024 return myView->RenderingParams();
3025}
3026
3027//=============================================================================
3028//function : ChangeRenderingParams
3029//purpose :
3030//=============================================================================
3031Graphic3d_RenderingParams& V3d_View::ChangeRenderingParams()
3032{
3033 return myView->ChangeRenderingParams();
3034}
a5162275 3035
478862fc 3036
3037//=============================================================================
3038//function : SetLightOn
3039//purpose :
3040//=============================================================================
3041void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
3042{
3043 if (!myActiveLights.Contains (theLight))
3044 {
3045 myActiveLights.Append (theLight);
3046 UpdateLights();
3047 }
3048}
3049
3050//=============================================================================
3051//function : SetLightOff
3052//purpose :
3053//=============================================================================
3054void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
3055{
3056 if (MyViewer->IsGlobalLight (theLight))
3057 throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
3058 myActiveLights.Remove (theLight);
3059 UpdateLights();
3060}
3061
3062//=============================================================================
3063//function : IsActiveLight
3064//purpose :
3065//=============================================================================
3066Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
3067{
3068 return !theLight.IsNull()
3069 && myActiveLights.Contains (theLight);
3070}
3071
3072//=============================================================================
3073//function : SetLightOn
3074//purpose :
3075//=============================================================================
3076void V3d_View::SetLightOn()
3077{
3078 for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
3079 {
3080 if (!myActiveLights.Contains (aDefLightIter.Value()))
3081 {
3082 myActiveLights.Append (aDefLightIter.Value());
3083 }
3084 }
3085 UpdateLights();
3086}
3087
3088//=============================================================================
3089//function : SetLightOff
3090//purpose :
3091//=============================================================================
3092void V3d_View::SetLightOff()
3093{
3094 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
3095 {
3096 if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
3097 {
3098 myActiveLights.Remove (anActiveLightIter);
3099 }
3100 else
3101 {
3102 anActiveLightIter.Next();
3103 }
3104 }
3105 UpdateLights();
3106}
3107
3108//=============================================================================
3109//function : IfMoreLights
3110//purpose :
3111//=============================================================================
3112Standard_Boolean V3d_View::IfMoreLights() const
3113{
3114 return myActiveLights.Extent() < LightLimit();
3115}
3116
3117//=======================================================================
3118//function : LightLimit
3119//purpose :
3120//=======================================================================
3121Standard_Integer V3d_View::LightLimit() const
3122{
3123 return Viewer()->Driver()->InquireLightLimit();
3124}
3125
3126//=======================================================================
3127//function : AddClipPlane
3128//purpose :
3129//=======================================================================
3130void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
3131{
3132 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
3133 if (aSeqOfPlanes.IsNull())
3134 {
3135 aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
3136 }
3137 else
3138 {
3139 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
3140 {
3141 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
3142 if (aPlane == thePlane)
3143 {
3144 // plane is already defined in view
3145 return;
3146 }
3147 }
3148 }
3149
3150 aSeqOfPlanes->Append (thePlane);
3151 SetClipPlanes (aSeqOfPlanes);
3152}
3153
3154//=======================================================================
3155//function : RemoveClipPlane
3156//purpose :
3157//=======================================================================
3158void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
3159{
3160 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
3161 if (aSeqOfPlanes.IsNull())
3162 {
3163 return;
3164 }
3165
3166 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
3167 {
3168 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
3169 if (aPlane != thePlane)
3170 {
3171 continue;
3172 }
3173
3174 aSeqOfPlanes->Remove (aPlaneIt);
3175 SetClipPlanes (aSeqOfPlanes);
3176 return;
3177 }
3178}
3179
3180//=======================================================================
3181//function : SetClipPlanes
3182//purpose :
3183//=======================================================================
3184void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
3185{
3186 myView->SetClipPlanes (thePlanes);
3187}
3188
3189//=======================================================================
3190//function : ClipPlanes
3191//purpose :
3192//=======================================================================
3193const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
3194{
3195 return myView->ClipPlanes();
3196}
3197
3198//=======================================================================
3199//function : PlaneLimit
3200//purpose :
3201//=======================================================================
3202Standard_Integer V3d_View::PlaneLimit() const
3203{
3204 return Viewer()->Driver()->InquirePlaneLimit();
3205}
3206
3207//=============================================================================
3208//function : Move
3209//purpose :
3210//=============================================================================
3211void V3d_View::Move (const Standard_Real theDx,
3212 const Standard_Real theDy,
3213 const Standard_Real theDz,
3214 const Standard_Boolean theStart)
3215{
3216 Handle(Graphic3d_Camera) aCamera = Camera();
3217 if (theStart)
3218 {
3219 myCamStartOpEye = aCamera->Eye();
3220
3221 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
3222 gp_Dir anUp (aCamera->Up());
3223 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
3224 {
3225 throw V3d_BadValue ("V3d_View::Translate, alignment of Eye,At,Up");
3226 }
3227 }
3228
3229 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
3230 myXscreenAxis.Coord (XX,XY,XZ);
3231 myYscreenAxis.Coord (YX,YY,YZ);
3232 myZscreenAxis.Coord (ZX,ZY,ZZ);
3233
3234 aCamera->SetEye (myCamStartOpEye);
3235
3236 aCamera->SetEye (aCamera->Eye().XYZ()
3237 + theDx * gp_Pnt (XX, XY, XZ).XYZ()
3238 + theDy * gp_Pnt (YX, YY, YZ).XYZ()
3239 + theDz * gp_Pnt (ZX, ZY, ZZ).XYZ()
3240 );
3241
3242 ImmediateUpdate();
3243}
3244
3245//=============================================================================
3246//function : Move
3247//purpose :
3248//=============================================================================
3249void V3d_View::Move (const Standard_Real theLength, const Standard_Boolean theStart)
3250{
3251 Handle(Graphic3d_Camera) aCamera = Camera();
3252 if (theStart)
3253 {
3254 myCamStartOpEye = aCamera->Eye();
3255 }
3256 aCamera->SetEye (myCamStartOpEye);
3257 aCamera->SetEye (aCamera->Eye().XYZ() + theLength * myDefaultViewAxis.XYZ());
3258
3259 ImmediateUpdate();
3260}
3261
3262//=============================================================================
3263//function : Move
3264//purpose :
3265//=============================================================================
3266void V3d_View::Move (const V3d_TypeOfAxe theAxe,
3267 const Standard_Real theLength,
3268 const Standard_Boolean theStart)
3269{
3270 switch (theAxe)
3271 {
3272 case V3d_X:
3273 Move (theLength,0.,0.,theStart);
3274 break;
3275 case V3d_Y:
3276 Move (0.,theLength,0.,theStart);
3277 break;
3278 case V3d_Z:
3279 Move (0.,0.,theLength,theStart);
3280 break;
3281 }
3282}
3283
3284//=============================================================================
3285//function : Translate
3286//purpose :
3287//=============================================================================
3288void V3d_View::Translate (const Standard_Real theDx,
3289 const Standard_Real theDy,
3290 const Standard_Real theDz,
3291 const Standard_Boolean theStart)
3292{
3293 Handle(Graphic3d_Camera) aCamera = Camera();
3294 if (theStart)
3295 {
3296 myCamStartOpEye = aCamera->Eye();
3297 myCamStartOpCenter = aCamera->Center();
3298
3299 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
3300 gp_Dir anUp (aCamera->Up());
3301 if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
3302 {
3303 throw V3d_BadValue ("V3d_View::Translate, alignment of Eye,At,Up");
3304 }
3305 }
3306
3307 aCamera->SetEye (myCamStartOpEye);
3308 aCamera->SetCenter (myCamStartOpCenter);
3309
3310 aCamera->SetCenter (aCamera->Center().XYZ()
3311 - theDx * myXscreenAxis.XYZ()
3312 - theDy * myYscreenAxis.XYZ()
3313 - theDz * myZscreenAxis.XYZ()
3314 );
3315
3316 aCamera->SetEye (aCamera->Eye().XYZ()
3317 - theDx * myXscreenAxis.XYZ()
3318 - theDy * myYscreenAxis.XYZ()
3319 - theDz * myZscreenAxis.XYZ()
3320 );
3321
3322 ImmediateUpdate();
3323}
3324
3325//=============================================================================
3326//function : Translate
3327//purpose :
3328//=============================================================================
3329void V3d_View::Translate (const V3d_TypeOfAxe theAxe, const Standard_Real theLength,const Standard_Boolean theStart)
3330{
3331 switch (theAxe)
3332 {
3333 case V3d_X:
3334 Translate (theLength,0.,0., theStart);
3335 break;
3336 case V3d_Y:
3337 Translate (0.,theLength,0., theStart);
3338 break;
3339 case V3d_Z:
3340 Translate (0.,0.,theLength, theStart);
3341 break;
3342 }
3343}
3344
3345//=======================================================================
3346//function : Place
3347//purpose :
3348//=======================================================================
3349void V3d_View::Place (const Standard_Integer theXp,
3350 const Standard_Integer theYp,
3351 const Standard_Real theZoomFactor)
3352{
3353 Standard_Integer aWinWidth = 0;
3354 Standard_Integer aWinHeight = 0;
3355 View()->Window()->Size (aWinWidth, aWinHeight);
3356
3357 Standard_Integer aWinCXp = aWinWidth / 2;
3358 Standard_Integer aWinCYp = aWinHeight / 2;
3359 Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
3360}
3361
3362//=======================================================================
3363//function : Translate
3364//purpose :
3365//=======================================================================
3366void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart)
3367{
3368 Handle(Graphic3d_Camera) aCamera = Camera();
3369 if (theStart)
3370 {
3371 myCamStartOpCenter = aCamera->Center() ;
3372 }
3373
3374 gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - myDefaultViewAxis.XYZ() * theLength);
3375 aCamera->SetCenter (aNewCenter);
3376
3377 ImmediateUpdate();
3378}
3379
3380//=============================================================================
3381//function : SetGrid
3382//purpose :
3383//=============================================================================
3384void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid)
3385{
3386 MyPlane = aPlane;
3387 MyGrid = aGrid;
3388
3389 Standard_Real xl, yl, zl;
3390 Standard_Real xdx, xdy, xdz;
3391 Standard_Real ydx, ydy, ydz;
3392 Standard_Real dx, dy, dz;
3393 aPlane.Location ().Coord (xl, yl, zl);
3394 aPlane.XDirection ().Coord (xdx, xdy, xdz);
3395 aPlane.YDirection ().Coord (ydx, ydy, ydz);
3396 aPlane.Direction ().Coord (dx, dy, dz);
3397
3398 Standard_Real CosAlpha = Cos (MyGrid->RotationAngle ());
3399 Standard_Real SinAlpha = Sin (MyGrid->RotationAngle ());
3400
3401 TColStd_Array2OfReal Trsf1 (1, 4, 1, 4);
3402 Trsf1 (4, 4) = 1.0;
3403 Trsf1 (4, 1) = Trsf1 (4, 2) = Trsf1 (4, 3) = 0.0;
3404 // Translation
3405 Trsf1 (1, 4) = xl,
3406 Trsf1 (2, 4) = yl,
3407 Trsf1 (3, 4) = zl;
3408 // Transformation change of marker
3409 Trsf1 (1, 1) = xdx,
3410 Trsf1 (2, 1) = xdy,
3411 Trsf1 (3, 1) = xdz,
3412 Trsf1 (1, 2) = ydx,
3413 Trsf1 (2, 2) = ydy,
3414 Trsf1 (3, 2) = ydz,
3415 Trsf1 (1, 3) = dx,
3416 Trsf1 (2, 3) = dy,
3417 Trsf1 (3, 3) = dz;
3418
3419 TColStd_Array2OfReal Trsf2 (1, 4, 1, 4);
3420 Trsf2 (4, 4) = 1.0;
3421 Trsf2 (4, 1) = Trsf2 (4, 2) = Trsf2 (4, 3) = 0.0;
3422 // Translation of the origin
3423 Trsf2 (1, 4) = -MyGrid->XOrigin (),
3424 Trsf2 (2, 4) = -MyGrid->YOrigin (),
3425 Trsf2 (3, 4) = 0.0;
3426 // Rotation Alpha around axis -Z
3427 Trsf2 (1, 1) = CosAlpha,
3428 Trsf2 (2, 1) = -SinAlpha,
3429 Trsf2 (3, 1) = 0.0,
3430 Trsf2 (1, 2) = SinAlpha,
3431 Trsf2 (2, 2) = CosAlpha,
3432 Trsf2 (3, 2) = 0.0,
3433 Trsf2 (1, 3) = 0.0,
3434 Trsf2 (2, 3) = 0.0,
3435 Trsf2 (3, 3) = 1.0;
3436
3437 Standard_Real valuetrsf;
3438 Standard_Real valueoldtrsf;
3439 Standard_Real valuenewtrsf;
3440 Standard_Integer i, j, k;
3441 // Calculation of the product of matrices
3442 for (i=1; i<=4; i++)
3443 for (j=1; j<=4; j++) {
3444 MyTrsf (i, j) = 0.0;
3445 for (k=1; k<=4; k++) {
3446 valueoldtrsf = Trsf1 (i, k);
3447 valuetrsf = Trsf2 (k, j);
3448 valuenewtrsf = MyTrsf (i, j) + valueoldtrsf * valuetrsf;
3449 MyTrsf (i, j) = valuenewtrsf;
3450 }
3451 }
3452}
3453
3454//=============================================================================
3455//function : SetGridActivity
3456//purpose :
3457//=============================================================================
3458void V3d_View::SetGridActivity (const Standard_Boolean AFlag)
3459{
3460 if (AFlag) MyGrid->Activate ();
3461 else MyGrid->Deactivate ();
3462}
3463
3464//=============================================================================
3465//function : toPolarCoords
3466//purpose :
3467//=============================================================================
3468void toPolarCoords (const Standard_Real theX, const Standard_Real theY,
3469 Standard_Real& theR, Standard_Real& thePhi)
3470{
3471 theR = Sqrt (theX * theX + theY * theY);
3472 thePhi = ATan2 (theY, theX);
3473}
3474
3475//=============================================================================
3476//function : toCartesianCoords
3477//purpose :
3478//=============================================================================
3479void toCartesianCoords (const Standard_Real theR, const Standard_Real thePhi,
3480 Standard_Real& theX, Standard_Real& theY)
3481{
3482 theX = theR * Cos (thePhi);
3483 theY = theR * Sin (thePhi);
3484}
3485
3486//=============================================================================
3487//function : Compute
3488//purpose :
3489//=============================================================================
3490Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex& theVertex) const
3491{
3492 const Handle(Graphic3d_Camera)& aCamera = Camera();
3493 gp_Dir VPN = aCamera->Direction().Reversed(); // RefPlane
3494 gp_Dir GPN = MyPlane.Direction();
3495
3496 Standard_Real XPp = 0.0, YPp = 0.0;
3497 Project (theVertex.X(), theVertex.Y(), theVertex.Z(), XPp, YPp);
3498
3499 // Casw when the plane of the grid and the plane of the view
3500 // are perpendicular to MYEPSILON2 close radians
3501 #define MYEPSILON2 M_PI / 180.0 // Delta between 2 angles
3502 if (Abs (VPN.Angle (GPN) - M_PI / 2.) < MYEPSILON2)
3503 {
3504 return theVertex;
3505 }
3506
3507 const gp_XYZ aPnt0 = V3d_View::TrsPoint (Graphic3d_Vertex (0.0, 0.0, 0.0), MyTrsf);
3508
3509 // get grid axes in world space
3510 const gp_XYZ aPnt1 = V3d_View::TrsPoint (Graphic3d_Vertex (1.0, 0.0, 0.0), MyTrsf);
3511 gp_Vec aGridX (aPnt0, aPnt1);
3512 aGridX.Normalize();
3513
3514 const gp_XYZ aPnt2 = V3d_View::TrsPoint (Graphic3d_Vertex (0.0, 1.0, 0.0), MyTrsf);
3515 gp_Vec aGridY (aPnt0, aPnt2);
3516 aGridY.Normalize();
3517
3518 // project ray from camera onto grid plane
3519 const gp_Vec aProjection = aCamera->IsOrthographic()
3520 ? gp_Vec (aCamera->Direction())
3521 : gp_Vec (aCamera->Eye(), gp_Pnt (theVertex.X(), theVertex.Y(), theVertex.Z())).Normalized();
3522 const gp_Vec aPointOrigin = gp_Vec (gp_Pnt (theVertex.X(), theVertex.Y(), theVertex.Z()), aPnt0);
3523 const Standard_Real aT = aPointOrigin.Dot (MyPlane.Direction()) / aProjection.Dot (MyPlane.Direction());
3524 const gp_XYZ aPointOnPlane = gp_XYZ (theVertex.X(), theVertex.Y(), theVertex.Z()) + aProjection.XYZ() * aT;
3525
3526 if (Handle(Aspect_RectangularGrid) aRectGrid = Handle(Aspect_RectangularGrid)::DownCast (MyGrid))
3527 {
3528 // project point on plane to grid local space
3529 const gp_Vec aToPoint (aPnt0, aPointOnPlane);
3530 const Standard_Real anXSteps = Round (aGridX.Dot (aToPoint) / aRectGrid->XStep());
3531 const Standard_Real anYSteps = Round (aGridY.Dot (aToPoint) / aRectGrid->YStep());
3532
3533 // clamp point to grid
3534 const gp_Vec aResult = aGridX * anXSteps * aRectGrid->XStep()
3535 + aGridY * anYSteps * aRectGrid->YStep()
3536 + gp_Vec (aPnt0);
3537 return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
3538 }
3539 else if (Handle(Aspect_CircularGrid) aCircleGrid = Handle(Aspect_CircularGrid)::DownCast (MyGrid))
3540 {
3541 const Standard_Real anAlpha = M_PI / Standard_Real (aCircleGrid->DivisionNumber());
3542
3543 // project point on plane to grid local space
3544 const gp_Vec aToPoint (aPnt0, aPointOnPlane);
3545 Standard_Real aLocalX = aGridX.Dot (aToPoint);
3546 Standard_Real aLocalY = aGridY.Dot (aToPoint);
3547 Standard_Real anR = 0.0, aPhi = 0.0;
3548 toPolarCoords (aLocalX, aLocalY, anR, aPhi);
3549
3550 // clamp point to grid
3551 const Standard_Real anRSteps = Round (anR / aCircleGrid->RadiusStep());
3552 const Standard_Real aPhiSteps = Round (aPhi / anAlpha);
3553 toCartesianCoords (anRSteps * aCircleGrid->RadiusStep(), aPhiSteps * anAlpha, aLocalX, aLocalY);
3554
3555 const gp_Vec aResult = aGridX * aLocalX + aGridY * aLocalY + gp_Vec (aPnt0);
3556 return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
3557 }
3558 return Graphic3d_Vertex (0.0, 0.0, 0.0);
3559}
3560
3561//=============================================================================
3562//function : ZBufferTriedronSetup
3563//purpose :
3564//=============================================================================
3565void V3d_View::ZBufferTriedronSetup (const Quantity_Color& theXColor,
3566 const Quantity_Color& theYColor,
3567 const Quantity_Color& theZColor,
3568 const Standard_Real theSizeRatio,
3569 const Standard_Real theAxisDiametr,
3570 const Standard_Integer theNbFacettes)
3571{
3572 const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
3573 aTrihedron->SetArrowsColor (theXColor, theYColor, theZColor);
3574 aTrihedron->SetSizeRatio (theSizeRatio);
3575 aTrihedron->SetNbFacets (theNbFacettes);
3576 aTrihedron->SetArrowDiameter (theAxisDiametr);
3577}
3578
3579//=============================================================================
3580//function : TriedronDisplay
3581//purpose :
3582//=============================================================================
3583void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
3584 const Quantity_Color& theColor,
3585 const Standard_Real theScale,
3586 const V3d_TypeOfVisualization theMode)
3587{
3588 const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
3589 aTrihedron->SetLabelsColor (theColor);
3590 aTrihedron->SetScale (theScale);
3591 aTrihedron->SetPosition (thePosition);
3592 aTrihedron->SetWireframe (theMode == V3d_WIREFRAME);
3593
3594 aTrihedron->Display (*this);
3595}
3596
3597//=============================================================================
3598//function : TriedronErase
3599//purpose :
3600//=============================================================================
3601void V3d_View::TriedronErase()
3602{
3603 if (!myTrihedron.IsNull())
3604 {
3605 myTrihedron->Erase();
3606 }
3607}
3608
3609//=============================================================================
3610//function : GetGraduatedTrihedron
3611//purpose :
3612//=============================================================================
3613const Graphic3d_GraduatedTrihedron& V3d_View::GetGraduatedTrihedron() const
3614{
3615 return myView->GetGraduatedTrihedron();
3616}
3617
3618//=============================================================================
3619//function : GraduatedTrihedronDisplay
3620//purpose :
3621//=============================================================================
3622void V3d_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
3623{
3624 myView->GraduatedTrihedronDisplay (theTrihedronData);
3625}
3626
3627//=============================================================================
3628//function : GraduatedTrihedronErase
3629//purpose :
3630//=============================================================================
3631void V3d_View::GraduatedTrihedronErase()
3632{
3633 myView->GraduatedTrihedronErase();
3634}
3635
a5162275 3636// =======================================================================
3637// function : DumpJson
3638// purpose :
3639// =======================================================================
3640void V3d_View::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
3641{
3642 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
3643
3644 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOldMouseX)
3645 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOldMouseY)
3646 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpUp)
3647 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpDir)
3648 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpEye)
3649 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpCenter)
3650 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDefaultCamera.get())
3651 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myView.get())
3652 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myImmediateUpdate)
3653 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsInvalidatedImmediate)
3654
3655 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, MyViewer)
3656 for (V3d_ListOfLight::Iterator anIterator (myActiveLights); anIterator.More(); anIterator.Next())
3657 {
3658 class Handle(Graphic3d_CLight)& anActiveLight = anIterator.Value();
3659 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, anActiveLight)
3660 }
3661 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultViewAxis)
3662 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultViewPoint)
3663 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyWindow.get())
3664 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, sx)
3665 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, sy)
3666 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, rx)
3667 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, ry)
3668 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myRotateGravity)
3669 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComputedMode)
3670 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, SwitchSetFront)
3671 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myZRotation)
3672 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, MyZoomAtPointX)
3673 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, MyZoomAtPointY)
3674 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTrihedron.get())
3675 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGrid.get())
3676 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &MyPlane)
3677 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGridEchoStructure.get())
3678 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGridEchoGroup.get())
3679 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myXscreenAxis)
3680 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myYscreenAxis)
3681 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myZscreenAxis)
3682 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myViewAxis)
3683 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGravityReferencePoint)
3684 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoZFitIsOn)
3685 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoZFitScaleFactor)
3686}