1 // Copyright (c) 2015 OPEN CASCADE SAS 2 // 3 // This file is part of Open CASCADE Technology software library. 4 // 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 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. 10 // 11 // Alternatively, this file may be used under the terms of Open CASCADE 12 // commercial license or contractual agreement. 13 14 #ifndef _Graphic3d_CView_HeaderFile 15 #define _Graphic3d_CView_HeaderFile 16 17 #include <Aspect_Handle.hxx> 18 #include <Aspect_RenderingContext.hxx> 19 #include <Aspect_Window.hxx> 20 #include <Graphic3d_BufferType.hxx> 21 #include <Graphic3d_Camera.hxx> 22 #include <Graphic3d_CubeMap.hxx> 23 #include <Graphic3d_CLight.hxx> 24 #include <Graphic3d_CStructure.hxx> 25 #include <Graphic3d_DataStructureManager.hxx> 26 #include <Graphic3d_DiagnosticInfo.hxx> 27 #include <Graphic3d_GraduatedTrihedron.hxx> 28 #include <Graphic3d_MapOfStructure.hxx> 29 #include <Graphic3d_NMapOfTransient.hxx> 30 #include <Graphic3d_RenderingParams.hxx> 31 #include <Graphic3d_SequenceOfHClipPlane.hxx> 32 #include <Graphic3d_SequenceOfStructure.hxx> 33 #include <Graphic3d_Structure.hxx> 34 #include <Graphic3d_Texture2Dmanual.hxx> 35 #include <Graphic3d_TextureEnv.hxx> 36 #include <Graphic3d_TypeOfAnswer.hxx> 37 #include <Graphic3d_TypeOfBackfacingModel.hxx> 38 #include <Graphic3d_TypeOfBackground.hxx> 39 #include <Graphic3d_TypeOfShadingModel.hxx> 40 #include <Graphic3d_TypeOfVisualization.hxx> 41 #include <Graphic3d_Vec3.hxx> 42 #include <Graphic3d_ZLayerId.hxx> 43 #include <Graphic3d_ZLayerSettings.hxx> 44 #include <Image_PixMap.hxx> 45 #include <Quantity_NameOfColor.hxx> 46 #include <Standard_Address.hxx> 47 #include <Standard_Transient.hxx> 48 #include <TColStd_IndexedDataMapOfStringString.hxx> 49 50 class Aspect_XRSession; 51 class Graphic3d_CView; 52 class Graphic3d_Layer; 53 class Graphic3d_StructureManager; 54 55 DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager) 56 57 //! Base class of a graphical view that carries out rendering process for a concrete 58 //! implementation of graphical driver. Provides virtual interfaces for redrawing its 59 //! contents, management of displayed structures and render settings. The source code 60 //! of the class itself implements functionality related to management of 61 //! computed (HLR or "view-dependent") structures. 62 class Graphic3d_CView : public Graphic3d_DataStructureManager 63 { 64 friend class Graphic3d_StructureManager; 65 DEFINE_STANDARD_RTTIEXT(Graphic3d_CView, Graphic3d_DataStructureManager) 66 public: 67 68 //! Constructor. 69 Standard_EXPORT Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr); 70 71 //! Destructor. 72 Standard_EXPORT virtual ~Graphic3d_CView(); 73 74 //! Returns the identification number of the view. Identification() const75 Standard_Integer Identification() const { return myId; } 76 77 //! Activates the view. Maps presentations defined within structure manager onto this view. 78 Standard_EXPORT virtual void Activate(); 79 80 //! Deactivates the view. Unmaps presentations defined within structure manager. 81 //! The view in deactivated state will ignore actions on structures such as Display(). 82 Standard_EXPORT virtual void Deactivate(); 83 84 //! Returns the activity flag of the view. IsActive() const85 Standard_Boolean IsActive() const { return myIsActive; } 86 87 //! Erases the view and removes from graphic driver. 88 //! No more graphic operations are allowed in this view after the call. 89 Standard_EXPORT virtual void Remove(); 90 91 //! Returns true if the view was removed. IsRemoved() const92 Standard_Boolean IsRemoved() const { return myIsRemoved; } 93 94 //! Returns camera object of the view. Handle(Graphic3d_Camera)95 virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; } 96 97 //! Sets camera used by the view. SetCamera(const Handle (Graphic3d_Camera)& theCamera)98 virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; } 99 100 public: 101 102 //! Returns default Shading Model of the view; Graphic3d_TypeOfShadingModel_Phong by default. ShadingModel() const103 Graphic3d_TypeOfShadingModel ShadingModel() const { return myRenderParams.ShadingModel; } 104 105 //! Sets default Shading Model of the view. 106 //! Will throw an exception on attempt to set Graphic3d_TypeOfShadingModel_DEFAULT. 107 Standard_EXPORT void SetShadingModel (Graphic3d_TypeOfShadingModel theModel); 108 109 //! Return backfacing model used for the view; Graphic3d_TypeOfBackfacingModel_Auto by default, 110 //! which means that backface culling is defined by each presentation. BackfacingModel() const111 Graphic3d_TypeOfBackfacingModel BackfacingModel() const { return myBackfacing; } 112 113 //! Sets backfacing model for the view. SetBackfacingModel(const Graphic3d_TypeOfBackfacingModel theModel)114 void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) { myBackfacing = theModel; } 115 116 //! Returns visualization type of the view. VisualizationType() const117 Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; } 118 119 //! Sets visualization type of the view. SetVisualizationType(const Graphic3d_TypeOfVisualization theType)120 void SetVisualizationType (const Graphic3d_TypeOfVisualization theType) { myVisualization = theType; } 121 122 //! Switches computed HLR mode in the view 123 Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode); 124 125 //! Returns the computed HLR mode state ComputedMode() const126 Standard_Boolean ComputedMode() const { return myIsInComputedMode; } 127 128 //! Computes the new presentation of the structure displayed in this view with the type Graphic3d_TOS_COMPUTED. 129 Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure); 130 131 //! Invalidates bounding box of specified ZLayerId. 132 Standard_EXPORT void Update (const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN); 133 134 //! Computes the new presentation of the structures displayed in this view with the type Graphic3d_TOS_COMPUTED. 135 Standard_EXPORT void Compute(); 136 137 //! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles. 138 Standard_EXPORT Standard_Boolean ContainsFacet() const; 139 140 //! Returns Standard_True if one of the structures in the set contains Polygons, Triangles or Quadrangles. 141 Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& theSet) const; 142 143 //! Returns the set of structures displayed in this view. 144 Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const; 145 146 //! Returns number of displayed structures in the view. NumberOfDisplayedStructures() const147 virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); } 148 149 //! Returns map of objects hidden within this specific view (not viewer-wise). Handle(Graphic3d_NMapOfTransient)150 const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; } 151 152 //! Returns map of objects hidden within this specific view (not viewer-wise). Handle(Graphic3d_NMapOfTransient)153 Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; } 154 155 //! Returns Standard_True in case if the structure with the given <theStructId> is 156 //! in list of structures to be computed and stores computed struct to <theComputedStruct>. 157 Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId, 158 Handle(Graphic3d_Structure)& theComputedStruct) const; 159 160 //! Returns the bounding box of all structures displayed in the view. 161 //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits 162 //! of graphical elements forming parts of infinite and other auxiliary structures. 163 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence) 164 //! @return computed bounding box 165 Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary = Standard_False) const; 166 167 //! Returns the coordinates of the boundary box of all structures in the set <theSet>. 168 //! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box 169 //! also includes minimum and maximum limits of graphical elements 170 //! forming parts of infinite structures. 171 Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet, 172 const Standard_Boolean theToIncludeAuxiliary = Standard_False) const; 173 174 //! Returns the structure manager handle which manage structures associated with this view. Handle(Graphic3d_StructureManager)175 const Handle(Graphic3d_StructureManager)& StructureManager() const { return myStructureManager; } 176 177 private: 178 179 //! Is it possible to display the structure in the view? 180 Standard_EXPORT Graphic3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const; 181 182 //! Clears the structure in this view. 183 Standard_EXPORT void Clear (Graphic3d_Structure* theStructure, 184 const Standard_Boolean theWithDestruction); 185 186 //! Connects the structures. 187 Standard_EXPORT void Connect (const Graphic3d_Structure* theMother, 188 const Graphic3d_Structure* theDaughter); 189 190 //! Disconnects the structures. 191 Standard_EXPORT void Disconnect (const Graphic3d_Structure* theMother, 192 const Graphic3d_Structure* theDaughter); 193 194 //! Displays the structure in the view. 195 Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure); 196 197 //! Erases the structure from the view. 198 Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure); 199 200 //! Highlights the structure in the view. 201 Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& theStructure); 202 203 //! Transforms the structure in the view. 204 Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure, 205 const Handle(TopLoc_Datum3D)& theTrsf); 206 207 //! Suppress the highlighting on the structure <AStructure> 208 //! in the view <me>. 209 Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& theStructure); 210 211 //! Returns an index != 0 if the structure have another structure computed for the view <me>. 212 Standard_EXPORT Standard_Integer IsComputed (const Graphic3d_Structure* theStructure) const; 213 IsComputed(const Handle (Graphic3d_Structure)& theStructure) const214 Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& theStructure) const { return IsComputed (theStructure.get()); } 215 216 //! Returns true if the structure is displayed in the view. 217 Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const; 218 219 //! Changes the display priority of the structure. 220 Standard_EXPORT void ChangePriority (const Handle(Graphic3d_Structure)& theStructure, 221 const Standard_Integer theOldPriority, 222 const Standard_Integer theNewPriority); 223 224 //! Change Z layer of already displayed structure in the view. 225 Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, 226 const Graphic3d_ZLayerId theLayerId); 227 228 //! Returns an index != 0 if the structure have the same owner than another structure 229 //! in the sequence of the computed structures. 230 Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const; 231 232 public: 233 234 //! Redraw content of the view. 235 virtual void Redraw() = 0; 236 237 //! Redraw immediate content of the view. 238 virtual void RedrawImmediate() = 0; 239 240 //! Invalidates content of the view but does not redraw it. 241 virtual void Invalidate() = 0; 242 243 //! Return true if view content cache has been invalidated. 244 virtual Standard_Boolean IsInvalidated() = 0; 245 246 //! Handle changing size of the rendering window. 247 virtual void Resized() = 0; 248 249 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode: 250 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image. 251 //! Fast, so preferred for interactive work (used by default). 252 //! However these extra drawings will be missed in image dump since it is performed from back buffer. 253 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen 254 //! in run-time (in case of slow hardware) and/or tearing may appear. 255 //! So this is strongly recommended to draw only simple (fast) structures. 256 //! 2. FALSE. Drawing immediate mode structures to the back buffer. 257 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync 258 //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read 259 //! from the back buffer. 260 //! @return previous mode. 261 virtual Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) = 0; 262 263 //! Creates and maps rendering window to the view. 264 //! @param theWindow [in] the window. 265 //! @param theContext [in] the rendering context. If NULL the context will be created internally. 266 virtual void SetWindow (const Handle(Aspect_Window)& theWindow, 267 const Aspect_RenderingContext theContext = NULL) = 0; 268 269 //! Returns the window associated to the view. 270 virtual Handle(Aspect_Window) Window() const = 0; 271 272 //! Returns True if the window associated to the view is defined. 273 virtual Standard_Boolean IsDefined() const = 0; 274 275 //! Dump active rendering buffer into specified memory buffer. 276 virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0; 277 278 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated. 279 virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) = 0; 280 281 //! Add a layer to the view. 282 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers). 283 //! @param theSettings [in] new layer settings 284 //! @param theLayerAfter [in] id of layer to append new layer before 285 virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId, 286 const Graphic3d_ZLayerSettings& theSettings, 287 const Graphic3d_ZLayerId theLayerAfter) = 0; 288 289 //! Add a layer to the view. 290 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers). 291 //! @param theSettings [in] new layer settings 292 //! @param theLayerBefore [in] id of layer to append new layer after 293 virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId, 294 const Graphic3d_ZLayerSettings& theSettings, 295 const Graphic3d_ZLayerId theLayerBefore) = 0; 296 297 //! Returns the maximum Z layer ID. 298 //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax(). 299 virtual Standard_Integer ZLayerMax() const = 0; 300 301 //! Returns the list of layers. 302 virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const = 0; 303 304 //! Returns layer with given ID or NULL if undefined. 305 virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const = 0; 306 307 //! Returns the bounding box of all structures displayed in the Z layer. 308 Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId); 309 310 //! Remove Z layer from the specified view. All structures 311 //! displayed at the moment in layer will be displayed in default layer 312 //! ( the bottom-level z layer ). To unset layer ID from associated 313 //! structures use method UnsetZLayer (...). 314 virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0; 315 316 //! Sets the settings for a single Z layer of specified view. 317 virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, 318 const Graphic3d_ZLayerSettings& theSettings) = 0; 319 320 //! Returns zoom-scale factor. 321 Standard_EXPORT Standard_Real ConsiderZoomPersistenceObjects(); 322 323 //! Returns pointer to an assigned framebuffer object. 324 virtual Handle(Standard_Transient) FBO() const = 0; 325 326 //! Sets framebuffer object for offscreen rendering. 327 virtual void SetFBO (const Handle(Standard_Transient)& theFbo) = 0; 328 329 //! Generate offscreen FBO in the graphic library. 330 //! If not supported on hardware returns NULL. 331 virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth, 332 const Standard_Integer theHeight) = 0; 333 334 //! Remove offscreen FBO from the graphic library 335 virtual void FBORelease (Handle(Standard_Transient)& theFbo) = 0; 336 337 //! Read offscreen FBO configuration. 338 virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo, 339 Standard_Integer& theWidth, 340 Standard_Integer& theHeight, 341 Standard_Integer& theWidthMax, 342 Standard_Integer& theHeightMax) = 0; 343 344 //! Change offscreen FBO viewport. 345 virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo, 346 const Standard_Integer theWidth, 347 const Standard_Integer theHeight) = 0; 348 349 public: 350 351 //! Copy visualization settings from another view. 352 //! Method is used for cloning views in viewer when its required to create view 353 //! with same view properties. 354 Standard_EXPORT virtual void CopySettings (const Handle(Graphic3d_CView)& theOther); 355 356 //! Returns current rendering parameters and effect settings. RenderingParams() const357 const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; } 358 359 //! Returns reference to current rendering parameters and effect settings. ChangeRenderingParams()360 Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; } 361 362 public: 363 364 //! Returns background fill color. Background() const365 virtual Aspect_Background Background() const { return Aspect_Background (myBgColor.GetRGB()); } 366 367 //! Sets background fill color. SetBackground(const Aspect_Background & theBackground)368 virtual void SetBackground (const Aspect_Background& theBackground) { myBgColor.SetRGB (theBackground.Color()); } 369 370 //! Returns gradient background fill colors. 371 virtual Aspect_GradientBackground GradientBackground() const = 0; 372 373 //! Sets gradient background fill colors. 374 virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0; 375 376 //! Returns background image texture map. Handle(Graphic3d_TextureMap)377 const Handle(Graphic3d_TextureMap)& BackgroundImage() { return myBackgroundImage; } 378 379 //! Returns cubemap being set last time on background. Handle(Graphic3d_CubeMap)380 const Handle(Graphic3d_CubeMap)& BackgroundCubeMap() const { return myCubeMapBackground; } 381 382 //! Returns cubemap being set last time on background. Handle(Graphic3d_CubeMap)383 const Handle(Graphic3d_CubeMap)& IBLCubeMap() const { return myCubeMapIBL; } 384 385 //! Sets image texture or environment cubemap as background. 386 //! @param theTextureMap [in] source to set a background; 387 //! should be either Graphic3d_Texture2D or Graphic3d_CubeMap 388 //! @param theToUpdatePBREnv [in] defines whether IBL maps will be generated or not 389 //! (see GeneratePBREnvironment()) 390 virtual void SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap, 391 Standard_Boolean theToUpdatePBREnv = Standard_True) = 0; 392 393 //! Returns background image fill style. 394 virtual Aspect_FillMethod BackgroundImageStyle() const = 0; 395 396 //! Sets background image fill style. 397 virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0; 398 399 //! Returns background type. BackgroundType() const400 Graphic3d_TypeOfBackground BackgroundType() const { return myBackgroundType; } 401 402 //! Sets background type. SetBackgroundType(Graphic3d_TypeOfBackground theType)403 void SetBackgroundType (Graphic3d_TypeOfBackground theType) { myBackgroundType = theType; } 404 405 //! Enables or disables IBL (Image Based Lighting) from background cubemap. 406 //! Has no effect if PBR is not used. 407 //! @param[in] theToEnableIBL enable or disable IBL from background cubemap 408 //! @param[in] theToUpdate redraw the view 409 virtual void SetImageBasedLighting (Standard_Boolean theToEnableIBL) = 0; 410 411 //! Returns environment texture set for the view. Handle(Graphic3d_TextureEnv)412 const Handle(Graphic3d_TextureEnv)& TextureEnv() const { return myTextureEnvData; } 413 414 //! Sets environment texture for the view. 415 virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0; 416 417 public: 418 419 //! Returns list of lights of the view. 420 virtual const Handle(Graphic3d_LightSet)& Lights() const = 0; 421 422 //! Sets list of lights for the view. 423 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) = 0; 424 425 //! Returns list of clip planes set for the view. 426 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const = 0; 427 428 //! Sets list of clip planes for the view. 429 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) = 0; 430 431 //! Fill in the dictionary with diagnostic info. 432 //! Should be called within rendering thread. 433 //! 434 //! This API should be used only for user output or for creating automated reports. 435 //! The format of returned information (e.g. key-value layout) 436 //! is NOT part of this API and can be changed at any time. 437 //! Thus application should not parse returned information to weed out specific parameters. 438 Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict, 439 Graphic3d_DiagnosticInfo theFlags) const = 0; 440 441 //! Returns string with statistic performance info. 442 virtual TCollection_AsciiString StatisticInformation() const = 0; 443 444 //! Fills in the dictionary with statistic performance info. 445 virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const = 0; 446 447 public: 448 449 //! Return unit scale factor defined as scale factor for m (meters); 1.0 by default. 450 //! Normally, view definition is unitless, however some operations like VR input requires proper units mapping. UnitFactor() const451 Standard_Real UnitFactor() const { return myUnitFactor; } 452 453 //! Set unit scale factor. 454 Standard_EXPORT void SetUnitFactor (Standard_Real theFactor); 455 456 //! Return XR session. Handle(Aspect_XRSession)457 const Handle(Aspect_XRSession)& XRSession() const { return myXRSession; } 458 459 //! Set XR session. SetXRSession(const Handle (Aspect_XRSession)& theSession)460 void SetXRSession (const Handle(Aspect_XRSession)& theSession) { myXRSession = theSession; } 461 462 //! Return TRUE if there is active XR session. 463 Standard_EXPORT bool IsActiveXR() const; 464 465 //! Initialize XR session. 466 Standard_EXPORT virtual bool InitXR(); 467 468 //! Release XR session. 469 Standard_EXPORT virtual void ReleaseXR(); 470 471 //! Process input. 472 Standard_EXPORT virtual void ProcessXRInput(); 473 474 //! Compute PosedXRCamera() based on current XR head pose and make it active. 475 Standard_EXPORT void SetupXRPosedCamera(); 476 477 //! Set current camera back to BaseXRCamera() and copy temporary modifications of PosedXRCamera(). 478 //! Calls SynchronizeXRPosedToBaseCamera() beforehand. 479 Standard_EXPORT void UnsetXRPosedCamera(); 480 481 //! Returns transient XR camera position with tracked head orientation applied. Handle(Graphic3d_Camera)482 const Handle(Graphic3d_Camera)& PosedXRCamera() const { return myPosedXRCamera; } 483 484 //! Sets transient XR camera position with tracked head orientation applied. SetPosedXRCamera(const Handle (Graphic3d_Camera)& theCamera)485 void SetPosedXRCamera (const Handle(Graphic3d_Camera)& theCamera) { myPosedXRCamera = theCamera; } 486 487 //! Returns anchor camera definition (without tracked head orientation). Handle(Graphic3d_Camera)488 const Handle(Graphic3d_Camera)& BaseXRCamera() const { return myBaseXRCamera; } 489 490 //! Sets anchor camera definition. SetBaseXRCamera(const Handle (Graphic3d_Camera)& theCamera)491 void SetBaseXRCamera (const Handle(Graphic3d_Camera)& theCamera) { myBaseXRCamera = theCamera; } 492 493 //! Convert XR pose to world space. 494 //! @param thePoseXR [in] transformation defined in VR local coordinate system, 495 //! oriented as Y-up, X-right and -Z-forward 496 //! @return transformation defining orientation of XR pose in world space PoseXRToWorld(const gp_Trsf & thePoseXR) const497 gp_Trsf PoseXRToWorld (const gp_Trsf& thePoseXR) const 498 { 499 const Handle(Graphic3d_Camera)& anOrigin = myBaseXRCamera; 500 const gp_Ax3 anAxVr (gp::Origin(), gp::DZ(), gp::DX()); 501 const gp_Ax3 aCameraCS (anOrigin->Eye().XYZ(), -anOrigin->Direction(), -anOrigin->SideRight()); 502 gp_Trsf aTrsfCS; 503 aTrsfCS.SetTransformation (aCameraCS, anAxVr); 504 return aTrsfCS * thePoseXR; 505 } 506 507 //! Returns view direction in the world space based on XR pose. 508 //! @param thePoseXR [in] transformation defined in VR local coordinate system, 509 //! oriented as Y-up, X-right and -Z-forward ViewAxisInWorld(const gp_Trsf & thePoseXR) const510 gp_Ax1 ViewAxisInWorld (const gp_Trsf& thePoseXR) const 511 { 512 return gp_Ax1 (gp::Origin(), -gp::DZ()).Transformed (PoseXRToWorld (thePoseXR)); 513 } 514 515 //! Recomputes PosedXRCamera() based on BaseXRCamera() and head orientation. 516 Standard_EXPORT void SynchronizeXRBaseToPosedCamera(); 517 518 //! Checks if PosedXRCamera() has been modified since SetupXRPosedCamera() 519 //! and copies these modifications to BaseXRCamera(). 520 Standard_EXPORT void SynchronizeXRPosedToBaseCamera(); 521 522 //! Compute camera position based on XR pose. 523 Standard_EXPORT void ComputeXRPosedCameraFromBase (Graphic3d_Camera& theCam, 524 const gp_Trsf& theXRTrsf) const; 525 526 //! Update based camera from posed camera by applying reversed transformation. 527 Standard_EXPORT void ComputeXRBaseCameraFromPosed (const Graphic3d_Camera& theCamPosed, 528 const gp_Trsf& thePoseTrsf); 529 530 //! Turn XR camera direction using current (head) eye position as anchor. 531 Standard_EXPORT void TurnViewXRCamera (const gp_Trsf& theTrsfTurn); 532 533 public: //! @name obsolete Graduated Trihedron functionality 534 535 //! Returns data of a graduated trihedron GetGraduatedTrihedron()536 virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; } 537 538 //! Displays Graduated Trihedron. GraduatedTrihedronDisplay(const Graphic3d_GraduatedTrihedron & theTrihedronData)539 virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) { (void )theTrihedronData; } 540 541 //! Erases Graduated Trihedron. GraduatedTrihedronErase()542 virtual void GraduatedTrihedronErase() {} 543 544 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object. 545 //! @param theMin [in] the minimum point of scene. 546 //! @param theMax [in] the maximum point of scene. GraduatedTrihedronMinMaxValues(const Graphic3d_Vec3 theMin,const Graphic3d_Vec3 theMax)547 virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) 548 { 549 (void )theMin; 550 (void )theMax; 551 } 552 553 //! Dumps the content of me into the stream 554 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; 555 556 private: 557 558 //! Adds the structure to display lists of the view. 559 virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure, 560 const Standard_Integer thePriority) = 0; 561 562 //! Erases the structure from display lists of the view. 563 virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) = 0; 564 565 //! Change Z layer of a structure already presented in view. 566 virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure, 567 const Graphic3d_ZLayerId theNewLayerId) = 0; 568 569 //! Changes the priority of a structure within its Z layer in the specified view. 570 virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure, 571 const Standard_Integer theNewPriority) = 0; 572 573 protected: 574 575 Standard_Integer myId; 576 Graphic3d_RenderingParams myRenderParams; 577 578 Quantity_ColorRGBA myBgColor; 579 Handle(Graphic3d_TextureMap) myBackgroundImage; 580 Handle(Graphic3d_CubeMap) myCubeMapBackground; //!< Cubemap displayed at background 581 Handle(Graphic3d_CubeMap) myCubeMapIBL; //!< Cubemap used for environment lighting 582 Handle(Graphic3d_TextureEnv) myTextureEnvData; 583 Graphic3d_TypeOfBackground myBackgroundType; //!< Current type of background 584 585 Handle(Graphic3d_StructureManager) myStructureManager; 586 Handle(Graphic3d_Camera) myCamera; 587 Graphic3d_SequenceOfStructure myStructsToCompute; 588 Graphic3d_SequenceOfStructure myStructsComputed; 589 Graphic3d_MapOfStructure myStructsDisplayed; 590 Handle(Graphic3d_NMapOfTransient) myHiddenObjects; 591 Standard_Boolean myIsInComputedMode; 592 Standard_Boolean myIsActive; 593 Standard_Boolean myIsRemoved; 594 Graphic3d_TypeOfBackfacingModel myBackfacing; 595 Graphic3d_TypeOfVisualization myVisualization; 596 597 Handle(Aspect_XRSession) myXRSession; 598 Handle(Graphic3d_Camera) myBackXRCamera; //!< camera projection parameters to restore after closing XR session (FOV, aspect and similar) 599 Handle(Graphic3d_Camera) myBaseXRCamera; //!< neutral camera orientation defining coordinate system in which head tracking is defined 600 Handle(Graphic3d_Camera) myPosedXRCamera; //!< transient XR camera orientation with tracked head orientation applied (based on myBaseXRCamera) 601 Handle(Graphic3d_Camera) myPosedXRCameraCopy; //!< neutral camera orientation copy at the beginning of processing input 602 Standard_Real myUnitFactor; //!< unit scale factor defined as scale factor for m (meters) 603 604 protected: 605 606 Graphic3d_GraduatedTrihedron myGTrihedronData; 607 608 }; 609 610 #endif // _Graphic3d_CView_HeaderFile 611