Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:16:35

0001 // Copyright (c) 2015 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Graphic3d_CView_HeaderFile
0015 #define _Graphic3d_CView_HeaderFile
0016 
0017 #include <Aspect_GridParams.hxx>
0018 #include <Aspect_RenderingContext.hxx>
0019 #include <Aspect_SkydomeBackground.hxx>
0020 #include <Aspect_Window.hxx>
0021 #include <gp_Ax3.hxx>
0022 #include <Graphic3d_BufferType.hxx>
0023 #include <Graphic3d_CubeMap.hxx>
0024 #include <Graphic3d_DataStructureManager.hxx>
0025 #include <Graphic3d_DiagnosticInfo.hxx>
0026 #include <Graphic3d_GraduatedTrihedron.hxx>
0027 #include <Graphic3d_Vertex.hxx>
0028 #include <Standard_Transient.hxx>
0029 #include <NCollection_Map.hxx>
0030 #include <NCollection_Shared.hxx>
0031 #include <Graphic3d_RenderingParams.hxx>
0032 #include <Graphic3d_Structure.hxx>
0033 #include <NCollection_Sequence.hxx>
0034 #include <Graphic3d_TextureEnv.hxx>
0035 #include <Graphic3d_TypeOfAnswer.hxx>
0036 #include <Graphic3d_TypeOfBackfacingModel.hxx>
0037 #include <Graphic3d_TypeOfBackground.hxx>
0038 #include <Graphic3d_TypeOfShadingModel.hxx>
0039 #include <Graphic3d_TypeOfVisualization.hxx>
0040 #include <NCollection_Vec3.hxx>
0041 #include <Standard_TypeDef.hxx>
0042 #include <Graphic3d_ZLayerId.hxx>
0043 #include <Graphic3d_ZLayerSettings.hxx>
0044 #include <Image_PixMap.hxx>
0045 #include <TCollection_AsciiString.hxx>
0046 #include <NCollection_IndexedDataMap.hxx>
0047 
0048 class Aspect_NeutralWindow;
0049 class Aspect_XRSession;
0050 class Graphic3d_CView;
0051 class Graphic3d_Layer;
0052 class Graphic3d_StructureManager;
0053 
0054 //! Base class of a graphical view that carries out rendering process for a concrete
0055 //! implementation of graphical driver. Provides virtual interfaces for redrawing its
0056 //! contents, management of displayed structures and render settings. The source code
0057 //! of the class itself implements functionality related to management of
0058 //! computed (HLR or "view-dependent") structures.
0059 class Graphic3d_CView : public Graphic3d_DataStructureManager
0060 {
0061   friend class Graphic3d_StructureManager;
0062   DEFINE_STANDARD_RTTIEXT(Graphic3d_CView, Graphic3d_DataStructureManager)
0063 public:
0064   //! Constructor.
0065   Standard_EXPORT Graphic3d_CView(const occ::handle<Graphic3d_StructureManager>& theMgr);
0066 
0067   //! Destructor.
0068   Standard_EXPORT ~Graphic3d_CView() override;
0069 
0070   //! Returns the identification number of the view.
0071   int Identification() const { return myId; }
0072 
0073   //! Activates the view. Maps presentations defined within structure manager onto this view.
0074   Standard_EXPORT virtual void Activate();
0075 
0076   //! Deactivates the view. Unmaps presentations defined within structure manager.
0077   //! The view in deactivated state will ignore actions on structures such as Display().
0078   Standard_EXPORT virtual void Deactivate();
0079 
0080   //! Returns the activity flag of the view.
0081   bool IsActive() const { return myIsActive; }
0082 
0083   //! Erases the view and removes from graphic driver.
0084   //! No more graphic operations are allowed in this view after the call.
0085   Standard_EXPORT virtual void Remove();
0086 
0087   //! Returns true if the view was removed.
0088   bool IsRemoved() const { return myIsRemoved; }
0089 
0090   //! Returns camera object of the view.
0091   const occ::handle<Graphic3d_Camera>& Camera() const override { return myCamera; }
0092 
0093   //! Sets camera used by the view.
0094   virtual void SetCamera(const occ::handle<Graphic3d_Camera>& theCamera) { myCamera = theCamera; }
0095 
0096   //! Returns necessity to flip OY in projection matrix
0097   virtual bool ToFlipOutput() const { return false; }
0098 
0099   //! Sets state of flip OY necessity in projection matrix
0100   virtual void SetToFlipOutput(const bool) {}
0101 
0102 public:
0103   //! Returns default Shading Model of the view; Graphic3d_TypeOfShadingModel_Phong by default.
0104   Graphic3d_TypeOfShadingModel ShadingModel() const { return myRenderParams.ShadingModel; }
0105 
0106   //! Sets default Shading Model of the view.
0107   //! Will throw an exception on attempt to set Graphic3d_TypeOfShadingModel_DEFAULT.
0108   Standard_EXPORT void SetShadingModel(Graphic3d_TypeOfShadingModel theModel);
0109 
0110   //! Return backfacing model used for the view; Graphic3d_TypeOfBackfacingModel_Auto by default,
0111   //! which means that backface culling is defined by each presentation.
0112   Graphic3d_TypeOfBackfacingModel BackfacingModel() const { return myBackfacing; }
0113 
0114   //! Sets backfacing model for the view.
0115   void SetBackfacingModel(const Graphic3d_TypeOfBackfacingModel theModel)
0116   {
0117     myBackfacing = theModel;
0118   }
0119 
0120   //! Returns visualization type of the view.
0121   Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; }
0122 
0123   //! Sets visualization type of the view.
0124   void SetVisualizationType(const Graphic3d_TypeOfVisualization theType)
0125   {
0126     myVisualization = theType;
0127   }
0128 
0129   //! Returns ZLayerId target
0130   Graphic3d_ZLayerId ZLayerTarget() const { return myZLayerTarget; }
0131 
0132   //! Sets ZLayerId target.
0133   void SetZLayerTarget(const Graphic3d_ZLayerId theTarget) { myZLayerTarget = theTarget; }
0134 
0135   //! Returns ZLayerId redraw mode
0136   bool ZLayerRedrawMode() const { return myZLayerRedrawMode; }
0137 
0138   //! Sets ZLayerId redraw mode.
0139   void SetZLayerRedrawMode(const bool theMode) { myZLayerRedrawMode = theMode; }
0140 
0141   //! Switches computed HLR mode in the view
0142   Standard_EXPORT void SetComputedMode(const bool theMode);
0143 
0144   //! Returns the computed HLR mode state
0145   bool ComputedMode() const { return myIsInComputedMode; }
0146 
0147   //! Computes the new presentation of the structure  displayed in this view with the type
0148   //! Graphic3d_TOS_COMPUTED.
0149   Standard_EXPORT void ReCompute(const occ::handle<Graphic3d_Structure>& theStructure);
0150 
0151   //! Invalidates bounding box of specified ZLayerId.
0152   Standard_EXPORT void Update(const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN);
0153 
0154   //! Computes the new presentation of the structures displayed in this view with the type
0155   //! Graphic3d_TOS_COMPUTED.
0156   Standard_EXPORT void Compute();
0157 
0158   //! Returns the set of structures displayed in this view.
0159   Standard_EXPORT void DisplayedStructures(
0160     NCollection_Map<occ::handle<Graphic3d_Structure>>& theStructures) const;
0161 
0162   //! Returns number of displayed structures in the view.
0163   virtual int NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
0164 
0165   //! Returns true in case if the structure with the given <theStructId> is
0166   //! in list of structures to be computed and stores computed struct to <theComputedStruct>.
0167   Standard_EXPORT bool IsComputed(const int                         theStructId,
0168                                   occ::handle<Graphic3d_Structure>& theComputedStruct) const;
0169 
0170   //! Returns the bounding box of all structures displayed in the view.
0171   //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum
0172   //! limits of graphical elements forming parts of infinite and other auxiliary structures.
0173   //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with
0174   //! trihedron transformation persistence)
0175   //! @return computed bounding box
0176   Standard_EXPORT virtual Bnd_Box MinMaxValues(const bool theToIncludeAuxiliary = false) const;
0177 
0178   //! Return primary and graphical bounding boxes used by camera Z fitting.
0179   virtual void ZFitAllBounds(Bnd_Box& thePrimaryBox, Bnd_Box& theGraphicBox) const
0180   {
0181     thePrimaryBox = MinMaxValues(false);
0182     theGraphicBox = MinMaxValues(true);
0183   }
0184 
0185   //! Returns the coordinates of the boundary box of all structures in the set <theSet>.
0186   //! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box
0187   //! also includes minimum and maximum limits of graphical elements
0188   //! forming parts of infinite structures.
0189   Standard_EXPORT Bnd_Box
0190     MinMaxValues(const NCollection_Map<occ::handle<Graphic3d_Structure>>& theSet,
0191                  const bool theToIncludeAuxiliary = false) const;
0192 
0193   //! Returns the structure manager handle which manage structures associated with this view.
0194   const occ::handle<Graphic3d_StructureManager>& StructureManager() const
0195   {
0196     return myStructureManager;
0197   }
0198 
0199 private:
0200   //! Is it possible to display the structure in the view?
0201   Standard_EXPORT Graphic3d_TypeOfAnswer
0202     acceptDisplay(const Graphic3d_TypeOfStructure theStructType) const;
0203 
0204   //! Clears the structure in this view.
0205   Standard_EXPORT void Clear(Graphic3d_Structure* theStructure, const bool theWithDestruction);
0206 
0207   //! Connects the structures.
0208   Standard_EXPORT void Connect(const Graphic3d_Structure* theMother,
0209                                const Graphic3d_Structure* theDaughter);
0210 
0211   //! Disconnects the structures.
0212   Standard_EXPORT void Disconnect(const Graphic3d_Structure* theMother,
0213                                   const Graphic3d_Structure* theDaughter);
0214 
0215   //! Displays the structure in the view.
0216   Standard_EXPORT void Display(const occ::handle<Graphic3d_Structure>& theStructure);
0217 
0218   //! Erases the structure from the view.
0219   Standard_EXPORT void Erase(const occ::handle<Graphic3d_Structure>& theStructure);
0220 
0221   //! Highlights the structure in the view.
0222   Standard_EXPORT void Highlight(const occ::handle<Graphic3d_Structure>& theStructure);
0223 
0224   //! Transforms the structure in the view.
0225   Standard_EXPORT void SetTransform(const occ::handle<Graphic3d_Structure>& theStructure,
0226                                     const occ::handle<TopLoc_Datum3D>&      theTrsf);
0227 
0228   //! Suppress the highlighting on the structure <AStructure>
0229   //! in the view <me>.
0230   Standard_EXPORT void UnHighlight(const occ::handle<Graphic3d_Structure>& theStructure);
0231 
0232   //! Returns an index != 0 if the structure have another structure computed for the view <me>.
0233   Standard_EXPORT int IsComputed(const Graphic3d_Structure* theStructure) const;
0234 
0235   int IsComputed(const occ::handle<Graphic3d_Structure>& theStructure) const
0236   {
0237     return IsComputed(theStructure.get());
0238   }
0239 
0240   //! Returns true if the structure is displayed in the view.
0241   Standard_EXPORT bool IsDisplayed(const occ::handle<Graphic3d_Structure>& theStructure) const;
0242 
0243   //! Changes the display priority of the structure.
0244   Standard_EXPORT void ChangePriority(const occ::handle<Graphic3d_Structure>& theStructure,
0245                                       const Graphic3d_DisplayPriority         theOldPriority,
0246                                       const Graphic3d_DisplayPriority         theNewPriority);
0247 
0248   //! Change Z layer of already displayed structure in the view.
0249   Standard_EXPORT void ChangeZLayer(const occ::handle<Graphic3d_Structure>& theStructure,
0250                                     const Graphic3d_ZLayerId                theLayerId);
0251 
0252   //! Returns an index != 0 if the structure have the same owner than another structure
0253   //! in the sequence of the computed structures.
0254   Standard_EXPORT int HaveTheSameOwner(const occ::handle<Graphic3d_Structure>& theStructure) const;
0255 
0256 public:
0257   //! Redraw content of the view.
0258   virtual void Redraw() = 0;
0259 
0260   //! Redraw immediate content of the view.
0261   virtual void RedrawImmediate() = 0;
0262 
0263   //! Invalidates content of the view but does not redraw it.
0264   virtual void Invalidate() = 0;
0265 
0266   //! Return true if view content cache has been invalidated.
0267   virtual bool IsInvalidated() = 0;
0268 
0269   //! Handle changing size of the rendering window.
0270   Standard_EXPORT virtual void Resized() = 0;
0271 
0272   //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
0273   //! 1. TRUE.  Drawing immediate mode structures directly to the front buffer over the scene image.
0274   //! Fast, so preferred for interactive work (used by default).
0275   //! However these extra drawings will be missed in image dump since it is performed from back
0276   //! buffer. Notice that since no pre-buffering used the V-Sync will be ignored and rendering could
0277   //! be seen in run-time (in case of slow hardware) and/or tearing may appear. So this is strongly
0278   //! recommended to draw only simple (fast) structures.
0279   //! 2. FALSE. Drawing immediate mode structures to the back buffer.
0280   //! The complete scene is redrawn first, so this mode is slower if scene contains complex data
0281   //! and/or V-Sync is turned on. But it works in any case and is especially useful for view dump
0282   //! because the dump image is read from the back buffer.
0283   //! @return previous mode.
0284   virtual bool SetImmediateModeDrawToFront(const bool theDrawToFrontBuffer) = 0;
0285 
0286   //! Creates and maps rendering window to the view.
0287   //! @param[in] theParentVIew parent view or NULL
0288   //! @param[in] theWindow the window
0289   //! @param[in] theContext the rendering context; if NULL the context will be created internally
0290   virtual void SetWindow(const occ::handle<Graphic3d_CView>& theParentVIew,
0291                          const occ::handle<Aspect_Window>&   theWindow,
0292                          const Aspect_RenderingContext       theContext) = 0;
0293 
0294   //! Returns the window associated to the view.
0295   virtual occ::handle<Aspect_Window> Window() const = 0;
0296 
0297   //! Returns True if the window associated to the view is defined.
0298   virtual bool IsDefined() const = 0;
0299 
0300   //! Dump active rendering buffer into specified memory buffer.
0301   virtual bool BufferDump(Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
0302 
0303   //! Dumps the graphical contents of a shadowmap framebuffer into an image.
0304   //! @param theImage the image to store the shadow map.
0305   //! @param[in] theLightName  name of the light used to generate the shadow map.
0306   virtual bool ShadowMapDump(Image_PixMap&                  theImage,
0307                              const TCollection_AsciiString& theLightName) = 0;
0308 
0309   //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId
0310   //! as outdated.
0311   virtual void InvalidateBVHData(const Graphic3d_ZLayerId theLayerId) = 0;
0312 
0313   //! Add a layer to the view.
0314   //! @param[in] theNewLayerId  id of new layer, should be > 0 (negative values are reserved for
0315   //! default layers).
0316   //! @param[in] theSettings    new layer settings
0317   //! @param[in] theLayerAfter  id of layer to append new layer before
0318   virtual void InsertLayerBefore(const Graphic3d_ZLayerId        theNewLayerId,
0319                                  const Graphic3d_ZLayerSettings& theSettings,
0320                                  const Graphic3d_ZLayerId        theLayerAfter) = 0;
0321 
0322   //! Add a layer to the view.
0323   //! @param[in] theNewLayerId   id of new layer, should be > 0 (negative values are reserved for
0324   //! default layers).
0325   //! @param[in] theSettings     new layer settings
0326   //! @param[in] theLayerBefore  id of layer to append new layer after
0327   virtual void InsertLayerAfter(const Graphic3d_ZLayerId        theNewLayerId,
0328                                 const Graphic3d_ZLayerSettings& theSettings,
0329                                 const Graphic3d_ZLayerId        theLayerBefore) = 0;
0330 
0331   //! Returns the maximum Z layer ID.
0332   //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
0333   virtual int ZLayerMax() const = 0;
0334 
0335   //! Returns the list of layers.
0336   virtual const NCollection_List<occ::handle<Graphic3d_Layer>>& Layers() const = 0;
0337 
0338   //! Returns layer with given ID or NULL if undefined.
0339   virtual occ::handle<Graphic3d_Layer> Layer(const Graphic3d_ZLayerId theLayerId) const = 0;
0340 
0341   //! Returns the bounding box of all structures displayed in the Z layer.
0342   Standard_EXPORT virtual void InvalidateZLayerBoundingBox(const Graphic3d_ZLayerId theLayerId);
0343 
0344   //! Remove Z layer from the specified view. All structures
0345   //! displayed at the moment in layer will be displayed in default layer
0346   //! ( the bottom-level z layer ). To unset layer ID from associated
0347   //! structures use method UnsetZLayer (...).
0348   virtual void RemoveZLayer(const Graphic3d_ZLayerId theLayerId) = 0;
0349 
0350   //! Sets the settings for a single Z layer of specified view.
0351   virtual void SetZLayerSettings(const Graphic3d_ZLayerId        theLayerId,
0352                                  const Graphic3d_ZLayerSettings& theSettings) = 0;
0353 
0354   //! Returns zoom-scale factor.
0355   Standard_EXPORT double ConsiderZoomPersistenceObjects();
0356 
0357   //! Returns pointer to an assigned framebuffer object.
0358   virtual occ::handle<Standard_Transient> FBO() const = 0;
0359 
0360   //! Sets framebuffer object for offscreen rendering.
0361   virtual void SetFBO(const occ::handle<Standard_Transient>& theFbo) = 0;
0362 
0363   //! Generate offscreen FBO in the graphic library.
0364   //! If not supported on hardware returns NULL.
0365   virtual occ::handle<Standard_Transient> FBOCreate(const int theWidth, const int theHeight) = 0;
0366 
0367   //! Remove offscreen FBO from the graphic library
0368   virtual void FBORelease(occ::handle<Standard_Transient>& theFbo) = 0;
0369 
0370   //! Read offscreen FBO configuration.
0371   virtual void FBOGetDimensions(const occ::handle<Standard_Transient>& theFbo,
0372                                 int&                                   theWidth,
0373                                 int&                                   theHeight,
0374                                 int&                                   theWidthMax,
0375                                 int&                                   theHeightMax) = 0;
0376 
0377   //! Change offscreen FBO viewport.
0378   virtual void FBOChangeViewport(const occ::handle<Standard_Transient>& theFbo,
0379                                  const int                              theWidth,
0380                                  const int                              theHeight) = 0;
0381 
0382 public:
0383   //! Copy visualization settings from another view.
0384   //! Method is used for cloning views in viewer when its required to create view
0385   //! with same view properties.
0386   Standard_EXPORT virtual void CopySettings(const occ::handle<Graphic3d_CView>& theOther);
0387 
0388   //! Returns current rendering parameters and effect settings.
0389   const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; }
0390 
0391   //! Returns reference to current rendering parameters and effect settings.
0392   Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; }
0393 
0394 public:
0395   //! Returns background  fill color.
0396   virtual Aspect_Background Background() const { return Aspect_Background(myBgColor.GetRGB()); }
0397 
0398   //! Sets background fill color.
0399   virtual void SetBackground(const Aspect_Background& theBackground)
0400   {
0401     myBgColor.SetRGB(theBackground.Color());
0402   }
0403 
0404   //! Returns gradient background fill colors.
0405   virtual Aspect_GradientBackground GradientBackground() const = 0;
0406 
0407   //! Sets gradient background fill colors.
0408   virtual void SetGradientBackground(const Aspect_GradientBackground& theBackground) = 0;
0409 
0410   //! Returns background image texture map.
0411   const occ::handle<Graphic3d_TextureMap>& BackgroundImage() { return myBackgroundImage; }
0412 
0413   //! Returns cubemap being set last time on background.
0414   const occ::handle<Graphic3d_CubeMap>& BackgroundCubeMap() const { return myCubeMapBackground; }
0415 
0416   //! Returns cubemap being set last time on background.
0417   const occ::handle<Graphic3d_CubeMap>& IBLCubeMap() const { return myCubeMapIBL; }
0418 
0419   //! Sets image texture or environment cubemap as background.
0420   //! @param[in] theTextureMap  source to set a background;
0421   //!                           should be either Graphic3d_Texture2D or Graphic3d_CubeMap
0422   //! @param[in] theToUpdatePBREnv  defines whether IBL maps will be generated or not
0423   //!                               (see GeneratePBREnvironment())
0424   virtual void SetBackgroundImage(const occ::handle<Graphic3d_TextureMap>& theTextureMap,
0425                                   bool theToUpdatePBREnv = true) = 0;
0426 
0427   //! Returns background image fill style.
0428   virtual Aspect_FillMethod BackgroundImageStyle() const = 0;
0429 
0430   //! Sets background image fill style.
0431   virtual void SetBackgroundImageStyle(const Aspect_FillMethod theFillStyle) = 0;
0432 
0433   //! Returns background type.
0434   Graphic3d_TypeOfBackground BackgroundType() const { return myBackgroundType; }
0435 
0436   //! Sets background type.
0437   void SetBackgroundType(Graphic3d_TypeOfBackground theType) { myBackgroundType = theType; }
0438 
0439   //! Returns skydome aspect;
0440   const Aspect_SkydomeBackground& BackgroundSkydome() const { return mySkydomeAspect; }
0441 
0442   //! Sets skydome aspect
0443   Standard_EXPORT void SetBackgroundSkydome(const Aspect_SkydomeBackground& theAspect,
0444                                             bool theToUpdatePBREnv = true);
0445 
0446   //! Enables or disables IBL (Image Based Lighting) from background cubemap.
0447   //! Has no effect if PBR is not used.
0448   //! @param[in] theToEnableIBL enable or disable IBL from background cubemap
0449   virtual void SetImageBasedLighting(bool theToEnableIBL) = 0;
0450 
0451   //! Display a shader-rendered grid on the given plane.
0452   //! The default implementation is a no-op; drivers with shader support override it.
0453   //! @param[in] theParams appearance parameters
0454   //! @param[in] thePlane  grid plane in world coordinates (origin + X/Y directions)
0455   virtual void GridDisplay(const Aspect_GridParams& theParams, const gp_Ax3& thePlane)
0456   {
0457     (void)theParams;
0458     (void)thePlane;
0459   }
0460 
0461   //! Erase the shader-rendered grid.
0462   //! The default implementation is a no-op; drivers with shader support override it.
0463   virtual void GridErase() {}
0464 
0465   //! Return snapped point for the shader-rendered grid under the window pixel.
0466   //! The default implementation is a no-op; drivers with shader grid support override it.
0467   virtual bool ShaderGridEcho(const int theX, const int theY, Graphic3d_Vertex& thePoint) const
0468   {
0469     (void)theX;
0470     (void)theY;
0471     (void)thePoint;
0472     return false;
0473   }
0474 
0475   //! Return snapped point and display point for the shader-rendered grid under the window pixel.
0476   //! The snapped point is the geometric grid point in world coordinates.
0477   //! The display point is a clip-safe proxy projected to the same window position for echo marker
0478   //! presentation; it should not be used as the geometric snap result.
0479   virtual bool ShaderGridEcho(const int         theX,
0480                               const int         theY,
0481                               Graphic3d_Vertex& thePoint,
0482                               Graphic3d_Vertex& theDisplayPoint) const
0483   {
0484     if (!ShaderGridEcho(theX, theY, thePoint))
0485     {
0486       return false;
0487     }
0488     theDisplayPoint = thePoint;
0489     return true;
0490   }
0491 
0492   //! Return snapped point for the shader-rendered grid from an arbitrary world point.
0493   //! The default implementation is a no-op; drivers with shader grid support override it.
0494   virtual bool ShaderGridSnapPoint(const Graphic3d_Vertex& thePoint,
0495                                    Graphic3d_Vertex&       theGridPoint) const
0496   {
0497     (void)thePoint;
0498     (void)theGridPoint;
0499     return false;
0500   }
0501 
0502   //! Returns environment texture set for the view.
0503   const occ::handle<Graphic3d_TextureEnv>& TextureEnv() const { return myTextureEnvData; }
0504 
0505   //! Sets environment texture for the view.
0506   virtual void SetTextureEnv(const occ::handle<Graphic3d_TextureEnv>& theTextureEnv) = 0;
0507 
0508 public:
0509   //! Returns list of lights of the view.
0510   virtual const occ::handle<Graphic3d_LightSet>& Lights() const = 0;
0511 
0512   //! Sets list of lights for the view.
0513   virtual void SetLights(const occ::handle<Graphic3d_LightSet>& theLights) = 0;
0514 
0515   //! Returns list of clip planes set for the view.
0516   virtual const occ::handle<Graphic3d_SequenceOfHClipPlane>& ClipPlanes() const = 0;
0517 
0518   //! Sets list of clip planes for the view.
0519   virtual void SetClipPlanes(const occ::handle<Graphic3d_SequenceOfHClipPlane>& thePlanes) = 0;
0520 
0521   //! Fill in the dictionary with diagnostic info.
0522   //! Should be called within rendering thread.
0523   //!
0524   //! This API should be used only for user output or for creating automated reports.
0525   //! The format of returned information (e.g. key-value layout)
0526   //! is NOT part of this API and can be changed at any time.
0527   //! Thus application should not parse returned information to weed out specific parameters.
0528   Standard_EXPORT virtual void DiagnosticInformation(
0529     NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>& theDict,
0530     Graphic3d_DiagnosticInfo theFlags) const = 0;
0531 
0532   //! Returns string with statistic performance info.
0533   virtual TCollection_AsciiString StatisticInformation() const = 0;
0534 
0535   //! Fills in the dictionary with statistic performance info.
0536   virtual void StatisticInformation(
0537     NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>& theDict)
0538     const = 0;
0539 
0540 public:
0541   //! Return unit scale factor defined as scale factor for m (meters); 1.0 by default.
0542   //! Normally, view definition is unitless, however some operations like VR input requires proper
0543   //! units mapping.
0544   double UnitFactor() const { return myUnitFactor; }
0545 
0546   //! Set unit scale factor.
0547   Standard_EXPORT void SetUnitFactor(double theFactor);
0548 
0549   //! Return XR session.
0550   const occ::handle<Aspect_XRSession>& XRSession() const { return myXRSession; }
0551 
0552   //! Set XR session.
0553   void SetXRSession(const occ::handle<Aspect_XRSession>& theSession) { myXRSession = theSession; }
0554 
0555   //! Return TRUE if there is active XR session.
0556   Standard_EXPORT bool IsActiveXR() const;
0557 
0558   //! Initialize XR session.
0559   Standard_EXPORT virtual bool InitXR();
0560 
0561   //! Release XR session.
0562   Standard_EXPORT virtual void ReleaseXR();
0563 
0564   //! Process input.
0565   Standard_EXPORT virtual void ProcessXRInput();
0566 
0567   //! Compute PosedXRCamera() based on current XR head pose and make it active.
0568   Standard_EXPORT void SetupXRPosedCamera();
0569 
0570   //! Set current camera back to BaseXRCamera() and copy temporary modifications of PosedXRCamera().
0571   //! Calls SynchronizeXRPosedToBaseCamera() beforehand.
0572   Standard_EXPORT void UnsetXRPosedCamera();
0573 
0574   //! Returns transient XR camera position with tracked head orientation applied.
0575   const occ::handle<Graphic3d_Camera>& PosedXRCamera() const { return myPosedXRCamera; }
0576 
0577   //! Sets transient XR camera position with tracked head orientation applied.
0578   void SetPosedXRCamera(const occ::handle<Graphic3d_Camera>& theCamera)
0579   {
0580     myPosedXRCamera = theCamera;
0581   }
0582 
0583   //! Returns anchor camera definition (without tracked head orientation).
0584   const occ::handle<Graphic3d_Camera>& BaseXRCamera() const { return myBaseXRCamera; }
0585 
0586   //! Sets anchor camera definition.
0587   void SetBaseXRCamera(const occ::handle<Graphic3d_Camera>& theCamera)
0588   {
0589     myBaseXRCamera = theCamera;
0590   }
0591 
0592   //! Convert XR pose to world space.
0593   //! @param[in] thePoseXR  transformation defined in VR local coordinate system,
0594   //!                       oriented as Y-up, X-right and -Z-forward
0595   //! @return transformation defining orientation of XR pose in world space
0596   gp_Trsf PoseXRToWorld(const gp_Trsf& thePoseXR) const
0597   {
0598     const occ::handle<Graphic3d_Camera>& anOrigin = myBaseXRCamera;
0599     const gp_Ax3                         anAxVr(gp::Origin(), gp::DZ(), gp::DX());
0600     const gp_Ax3 aCameraCS(anOrigin->Eye().XYZ(), -anOrigin->Direction(), -anOrigin->SideRight());
0601     gp_Trsf      aTrsfCS;
0602     aTrsfCS.SetTransformation(aCameraCS, anAxVr);
0603     return aTrsfCS * thePoseXR;
0604   }
0605 
0606   //! Returns view direction in the world space based on XR pose.
0607   //! @param[in] thePoseXR  transformation defined in VR local coordinate system,
0608   //!                       oriented as Y-up, X-right and -Z-forward
0609   gp_Ax1 ViewAxisInWorld(const gp_Trsf& thePoseXR) const
0610   {
0611     return gp_Ax1(gp::Origin(), -gp::DZ()).Transformed(PoseXRToWorld(thePoseXR));
0612   }
0613 
0614   //! Recomputes PosedXRCamera() based on BaseXRCamera() and head orientation.
0615   Standard_EXPORT void SynchronizeXRBaseToPosedCamera();
0616 
0617   //! Checks if PosedXRCamera() has been modified since SetupXRPosedCamera()
0618   //! and copies these modifications to BaseXRCamera().
0619   Standard_EXPORT void SynchronizeXRPosedToBaseCamera();
0620 
0621   //! Compute camera position based on XR pose.
0622   Standard_EXPORT void ComputeXRPosedCameraFromBase(Graphic3d_Camera& theCam,
0623                                                     const gp_Trsf&    theXRTrsf) const;
0624 
0625   //! Update based camera from posed camera by applying reversed transformation.
0626   Standard_EXPORT void ComputeXRBaseCameraFromPosed(const Graphic3d_Camera& theCamPosed,
0627                                                     const gp_Trsf&          thePoseTrsf);
0628 
0629   //! Turn XR camera direction using current (head) eye position as anchor.
0630   Standard_EXPORT void TurnViewXRCamera(const gp_Trsf& theTrsfTurn);
0631 
0632 public: //! @name obsolete Graduated Trihedron functionality
0633   //! Returns data of a graduated trihedron
0634   virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; }
0635 
0636   //! Displays Graduated Trihedron.
0637   virtual void GraduatedTrihedronDisplay(const Graphic3d_GraduatedTrihedron& theTrihedronData)
0638   {
0639     (void)theTrihedronData;
0640   }
0641 
0642   //! Erases Graduated Trihedron.
0643   virtual void GraduatedTrihedronErase() {}
0644 
0645   //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in
0646   //! graphic view object.
0647   //! @param[in] theMin  the minimum point of scene.
0648   //! @param[in] theMax  the maximum point of scene.
0649   virtual void GraduatedTrihedronMinMaxValues(const NCollection_Vec3<float> theMin,
0650                                               const NCollection_Vec3<float> theMax)
0651   {
0652     (void)theMin;
0653     (void)theMax;
0654   }
0655 
0656   //! Dumps the content of me into the stream
0657   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0658 
0659 public: //! @name subview properties
0660   //! Return TRUE if this is a subview of another view.
0661   bool IsSubview() const { return myParentView != nullptr; }
0662 
0663   //! Return parent View or NULL if this is not a subview.
0664   Graphic3d_CView* ParentView() { return myParentView; }
0665 
0666   //! Return TRUE if this is view performs rendering of subviews and nothing else; FALSE by default.
0667   //! By default, view with subviews will render main scene and blit subviews on top of it.
0668   //! Rendering of main scene might become redundant in case if subviews cover entire window of
0669   //! parent view. This flag allows to disable rendering of the main scene in such scenarios without
0670   //! creation of a dedicated V3d_Viewer instance just for composing subviews.
0671   bool IsSubviewComposer() const { return myIsSubviewComposer; }
0672 
0673   //! Set if this view should perform composing of subviews and nothing else.
0674   void SetSubviewComposer(bool theIsComposer) { myIsSubviewComposer = theIsComposer; }
0675 
0676   //! Return subview list.
0677   const NCollection_Sequence<occ::handle<Graphic3d_CView>>& Subviews() const { return mySubviews; }
0678 
0679   //! Add subview to the list.
0680   Standard_EXPORT void AddSubview(const occ::handle<Graphic3d_CView>& theView);
0681 
0682   //! Remove subview from the list.
0683   Standard_EXPORT bool RemoveSubview(const Graphic3d_CView* theView);
0684 
0685   //! Return subview position within parent view; Aspect_TOTP_LEFT_UPPER by default.
0686   Aspect_TypeOfTriedronPosition SubviewCorner() const { return mySubviewCorner; }
0687 
0688   //! Set subview position within parent view.
0689   void SetSubviewCorner(Aspect_TypeOfTriedronPosition thePos) { mySubviewCorner = thePos; }
0690 
0691   //! Return subview top-left position relative to parent view in pixels.
0692   const NCollection_Vec2<int>& SubviewTopLeft() const { return mySubviewTopLeft; }
0693 
0694   //! Return TRUE if subview size is set as proportions relative to parent view.
0695   bool IsSubViewRelativeSize() const
0696   {
0697     return mySubviewSize.x() <= 1.0 && mySubviewSize.y() <= 1.0;
0698   }
0699 
0700   //! Return subview dimensions; (1.0, 1.0) by default.
0701   //! Values >= 2   define size in pixels;
0702   //! Values <= 1.0 define size as fraction of parent view.
0703   const NCollection_Vec2<double>& SubviewSize() const { return mySubviewSize; }
0704 
0705   //! Set subview size relative to parent view.
0706   void SetSubviewSize(const NCollection_Vec2<double>& theSize) { mySubviewSize = theSize; }
0707 
0708   //! Return corner offset within parent view; (0.0,0.0) by default.
0709   //! Values >= 2   define offset in pixels;
0710   //! Values <= 1.0 define offset as fraction of parent view dimensions.
0711   const NCollection_Vec2<double>& SubviewOffset() const { return mySubviewOffset; }
0712 
0713   //! Set corner offset within parent view.
0714   void SetSubviewOffset(const NCollection_Vec2<double>& theOffset) { mySubviewOffset = theOffset; }
0715 
0716   //! Return subview margins in pixels; (0,0) by default
0717   const NCollection_Vec2<int>& SubviewMargins() const { return mySubviewMargins; }
0718 
0719   //! Set subview margins in pixels.
0720   void SetSubviewMargins(const NCollection_Vec2<int>& theMargins) { mySubviewMargins = theMargins; }
0721 
0722   //! Update subview position and dimensions.
0723   Standard_EXPORT void SubviewResized(const occ::handle<Aspect_NeutralWindow>& theWindow);
0724 
0725 private:
0726   //! Adds the structure to display lists of the view.
0727   virtual void displayStructure(const occ::handle<Graphic3d_CStructure>& theStructure,
0728                                 const Graphic3d_DisplayPriority          thePriority) = 0;
0729 
0730   //! Erases the structure from display lists of the view.
0731   virtual void eraseStructure(const occ::handle<Graphic3d_CStructure>& theStructure) = 0;
0732 
0733   //! Change Z layer of a structure already presented in view.
0734   virtual void changeZLayer(const occ::handle<Graphic3d_CStructure>& theCStructure,
0735                             const Graphic3d_ZLayerId                 theNewLayerId) = 0;
0736 
0737   //! Changes the priority of a structure within its Z layer in the specified view.
0738   virtual void changePriority(const occ::handle<Graphic3d_CStructure>& theCStructure,
0739                               const Graphic3d_DisplayPriority          theNewPriority) = 0;
0740 
0741 protected:
0742   int                       myId;
0743   Graphic3d_RenderingParams myRenderParams;
0744 
0745   NCollection_Sequence<occ::handle<Graphic3d_CView>> mySubviews; //!< list of child views
0746   Graphic3d_CView* myParentView;           //!< back-pointer to the parent view
0747                                            // clang-format off
0748   bool              myIsSubviewComposer;        //!< flag to skip rendering of viewer contents
0749   Aspect_TypeOfTriedronPosition mySubviewCorner;            //!< position within parent view
0750   NCollection_Vec2<int>               mySubviewTopLeft;           //!< subview top-left position relative to parent view
0751   NCollection_Vec2<int>               mySubviewMargins;           //!< subview margins in pixels
0752   NCollection_Vec2<double>               mySubviewSize;              //!< subview size
0753   NCollection_Vec2<double>               mySubviewOffset;            //!< subview corner offset within parent view
0754                                            // clang-format on
0755 
0756   occ::handle<Graphic3d_StructureManager>                myStructureManager;
0757   occ::handle<Graphic3d_Camera>                          myCamera;
0758   NCollection_Sequence<occ::handle<Graphic3d_Structure>> myStructsToCompute;
0759   NCollection_Sequence<occ::handle<Graphic3d_Structure>> myStructsComputed;
0760   NCollection_Map<occ::handle<Graphic3d_Structure>>      myStructsDisplayed;
0761   bool                                                   myIsInComputedMode;
0762   bool                                                   myIsActive;
0763   bool                                                   myIsRemoved;
0764   Graphic3d_TypeOfBackfacingModel                        myBackfacing;
0765   Graphic3d_TypeOfVisualization                          myVisualization;
0766 
0767   // clang-format off
0768   Graphic3d_ZLayerId      myZLayerTarget;      //!< ZLayerId for redrawing the content of specific zlayers.
0769   bool        myZLayerRedrawMode;  //!< If true redraws single layer, otherwise redraws group of layers.
0770   // clang-format on
0771 
0772   Quantity_ColorRGBA                myBgColor;
0773   occ::handle<Graphic3d_TextureMap> myBackgroundImage;
0774   occ::handle<Graphic3d_CubeMap>    myCubeMapBackground; //!< Cubemap displayed at background
0775   occ::handle<Graphic3d_CubeMap>    myCubeMapIBL;        //!< Cubemap used for environment lighting
0776   occ::handle<Graphic3d_TextureEnv> myTextureEnvData;
0777   Graphic3d_GraduatedTrihedron      myGTrihedronData;
0778   Graphic3d_TypeOfBackground        myBackgroundType; //!< Current type of background
0779   Aspect_SkydomeBackground          mySkydomeAspect;
0780   bool                              myToUpdateSkydome;
0781 
0782   occ::handle<Aspect_XRSession> myXRSession;
0783   // clang-format off
0784   occ::handle<Graphic3d_Camera> myBackXRCamera;       //!< camera projection parameters to restore after closing XR session (FOV, aspect and similar)
0785   occ::handle<Graphic3d_Camera> myBaseXRCamera;       //!< neutral camera orientation defining coordinate system in which head tracking is defined
0786   occ::handle<Graphic3d_Camera> myPosedXRCamera;      //!< transient XR camera orientation with tracked head orientation applied (based on myBaseXRCamera)
0787   occ::handle<Graphic3d_Camera> myPosedXRCameraCopy;  //!< neutral camera orientation copy at the beginning of processing input
0788   double            myUnitFactor;         //!< unit scale factor defined as scale factor for m (meters)
0789   // clang-format on
0790 };
0791 
0792 #endif // _Graphic3d_CView_HeaderFile