Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 09:20:00

0001 // Copyright (c) 2011-2019 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_Layer_HeaderFile
0015 #define _Graphic3d_Layer_HeaderFile
0016 
0017 #include <Graphic3d_BvhCStructureSet.hxx>
0018 #include <Graphic3d_BvhCStructureSetTrsfPers.hxx>
0019 #include <Graphic3d_DisplayPriority.hxx>
0020 #include <Graphic3d_ZLayerId.hxx>
0021 #include <Graphic3d_ZLayerSettings.hxx>
0022 #include <Graphic3d_RenderingParams.hxx>
0023 #include <NCollection_Array1.hxx>
0024 #include <NCollection_IndexedMap.hxx>
0025 
0026 #include <array>
0027 
0028 //! Defines index map of structures.
0029 
0030 //! Defines array of indexed maps of structures.
0031 typedef std::array<NCollection_IndexedMap<const Graphic3d_CStructure*>,
0032                    Graphic3d_DisplayPriority_NB>
0033   Graphic3d_ArrayOfIndexedMapOfStructure;
0034 
0035 class Graphic3d_CullingTool;
0036 
0037 //! Presentations list sorted within priorities.
0038 class Graphic3d_Layer : public Standard_Transient
0039 {
0040   DEFINE_STANDARD_RTTIEXT(Graphic3d_Layer, Standard_Transient)
0041 public:
0042   //! Initializes associated priority list and layer properties
0043   Standard_EXPORT Graphic3d_Layer(Graphic3d_ZLayerId                theId,
0044                                   const occ::handle<BVH_Builder3d>& theBuilder);
0045 
0046   //! Destructor.
0047   Standard_EXPORT ~Graphic3d_Layer() override;
0048 
0049   //! Return layer id.
0050   Graphic3d_ZLayerId LayerId() const { return myLayerId; }
0051 
0052   //! Returns BVH tree builder for frustum culling.
0053   const occ::handle<BVH_Builder3d>& FrustumCullingBVHBuilder() const
0054   {
0055     return myBVHPrimitivesTrsfPers.Builder();
0056   }
0057 
0058   //! Assigns BVH tree builder for frustum culling.
0059   void SetFrustumCullingBVHBuilder(const occ::handle<BVH_Builder3d>& theBuilder)
0060   {
0061     myBVHPrimitivesTrsfPers.SetBuilder(theBuilder);
0062   }
0063 
0064   //! Return true if layer was marked with immediate flag.
0065   bool IsImmediate() const { return myLayerSettings.IsImmediate(); }
0066 
0067   //! Returns settings of the layer object.
0068   const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; };
0069 
0070   //! Sets settings of the layer object.
0071   Standard_EXPORT void SetLayerSettings(const Graphic3d_ZLayerSettings& theSettings);
0072 
0073   Standard_EXPORT void Add(const Graphic3d_CStructure* theStruct,
0074                            Graphic3d_DisplayPriority   thePriority,
0075                            bool                        isForChangePriority = false);
0076 
0077   //! Remove structure and returns its priority, if the structure is not found, method returns
0078   //! negative value
0079   Standard_EXPORT bool Remove(const Graphic3d_CStructure* theStruct,
0080                               Graphic3d_DisplayPriority&  thePriority,
0081                               bool                        isForChangePriority = false);
0082 
0083   //! @return the number of structures
0084   int NbStructures() const { return myNbStructures; }
0085 
0086   //! Number of NOT culled structures in the layer.
0087   int NbStructuresNotCulled() const { return myNbStructuresNotCulled; }
0088 
0089   //! Returns the number of available priority levels
0090   int NbPriorities() const { return Graphic3d_DisplayPriority_NB; }
0091 
0092   //! Append layer of acceptable type (with similar number of priorities or less).
0093   //! Returns false if the list can not be accepted.
0094   Standard_EXPORT bool Append(const Graphic3d_Layer& theOther);
0095 
0096   //! Returns array of structures.
0097   const Graphic3d_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
0098 
0099   //! Returns structures for specified priority.
0100   const NCollection_IndexedMap<const Graphic3d_CStructure*>& Structures(
0101     Graphic3d_DisplayPriority thePriority) const
0102   {
0103     return myArray[thePriority];
0104   }
0105 
0106   //! Marks BVH tree for given priority list as dirty and
0107   //! marks primitive set for rebuild.
0108   Standard_EXPORT void InvalidateBVHData();
0109 
0110   //! Marks cached bounding box as obsolete.
0111   void InvalidateBoundingBox() const
0112   {
0113     myIsBoundingBoxNeedsReset[0] = myIsBoundingBoxNeedsReset[1] = true;
0114   }
0115 
0116   //! Returns layer bounding box.
0117   //! @param theViewId             view index to consider View Affinity in structure
0118   //! @param theCamera             camera definition
0119   //! @param theWindowWidth        viewport width  (for applying transformation-persistence)
0120   //! @param theWindowHeight       viewport height (for applying transformation-persistence)
0121   //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with
0122   //! trihedron transformation persistence)
0123   //! @return computed bounding box
0124   Standard_EXPORT Bnd_Box BoundingBox(int                                  theViewId,
0125                                       const occ::handle<Graphic3d_Camera>& theCamera,
0126                                       int                                  theWindowWidth,
0127                                       int                                  theWindowHeight,
0128                                       bool theToIncludeAuxiliary) const;
0129 
0130   //! Returns zoom-scale factor.
0131   Standard_EXPORT double considerZoomPersistenceObjects(
0132     int                                  theViewId,
0133     const occ::handle<Graphic3d_Camera>& theCamera,
0134     int                                  theWindowWidth,
0135     int                                  theWindowHeight) const;
0136 
0137   //! Update culling state - should be called before rendering.
0138   //! Traverses through BVH tree to determine which structures are in view volume.
0139   Standard_EXPORT void UpdateCulling(
0140     int                                             theViewId,
0141     const Graphic3d_CullingTool&                    theSelector,
0142     const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState);
0143 
0144   //! Returns TRUE if layer is empty or has been discarded entirely by culling test.
0145   bool IsCulled() const { return myNbStructuresNotCulled == 0; }
0146 
0147   //! Returns number of transform persistence objects.
0148   int NbOfTransformPersistenceObjects() const { return myBVHPrimitivesTrsfPers.Size(); }
0149 
0150 public:
0151   //! Returns set of Graphic3d_CStructures structures for building BVH tree.
0152   const Graphic3d_BvhCStructureSet& CullableStructuresBVH() const { return myBVHPrimitives; }
0153 
0154   //! Returns set of transform persistent Graphic3d_CStructures for building BVH tree.
0155   const Graphic3d_BvhCStructureSetTrsfPers& CullableTrsfPersStructuresBVH() const
0156   {
0157     return myBVHPrimitivesTrsfPers;
0158   }
0159 
0160   //! Returns indexed map of always rendered structures.
0161   const NCollection_IndexedMap<const Graphic3d_CStructure*>& NonCullableStructures() const
0162   {
0163     return myAlwaysRenderedMap;
0164   }
0165 
0166   //! Dumps the content of me into the stream
0167   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0168 
0169 protected:
0170   //! Updates BVH trees if their state has been invalidated.
0171   Standard_EXPORT void updateBVH() const;
0172 
0173 private:
0174   //! Array of Graphic3d_CStructures by priority rendered in layer.
0175   Graphic3d_ArrayOfIndexedMapOfStructure myArray;
0176 
0177   //! Overall number of structures rendered in the layer.
0178   int myNbStructures;
0179 
0180   //! Number of NOT culled structures in the layer.
0181   int myNbStructuresNotCulled;
0182 
0183   //! Layer setting flags.
0184   Graphic3d_ZLayerSettings myLayerSettings;
0185 
0186   //! Layer id.
0187   Graphic3d_ZLayerId myLayerId;
0188 
0189   //! Set of Graphic3d_CStructures structures for building BVH tree.
0190   mutable Graphic3d_BvhCStructureSet myBVHPrimitives;
0191 
0192   //! Set of transform persistent Graphic3d_CStructures for building BVH tree.
0193   mutable Graphic3d_BvhCStructureSetTrsfPers myBVHPrimitivesTrsfPers;
0194 
0195   //! Indexed map of always rendered structures.
0196   mutable NCollection_IndexedMap<const Graphic3d_CStructure*> myAlwaysRenderedMap;
0197 
0198   //! Is needed for implementation of stochastic order of BVH traverse.
0199   bool myBVHIsLeftChildQueuedFirst;
0200 
0201   //! Defines if the primitive set for BVH is outdated.
0202   mutable bool myIsBVHPrimitivesNeedsReset;
0203 
0204   //! Defines if the cached bounding box is outdated.
0205   mutable bool myIsBoundingBoxNeedsReset[2];
0206 
0207   //! Cached layer bounding box.
0208   mutable Bnd_Box myBoundingBox[2];
0209 };
0210 
0211 #endif // _Graphic3d_Layer_HeaderFile