Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:48

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