1 // Copyright (c) 2011-2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Graphic3d_Layer_HeaderFile
15 #define _Graphic3d_Layer_HeaderFile
17 #include <Graphic3d_BvhCStructureSet.hxx>
18 #include <Graphic3d_BvhCStructureSetTrsfPers.hxx>
19 #include <Graphic3d_Camera.hxx>
20 #include <Graphic3d_ZLayerSettings.hxx>
21 #include <Graphic3d_RenderingParams.hxx>
22 #include <NCollection_Array1.hxx>
23 #include <NCollection_IndexedMap.hxx>
24 #include <NCollection_Sequence.hxx>
26 //! Defines index map of structures.
27 typedef NCollection_IndexedMap<const Graphic3d_CStructure*> Graphic3d_IndexedMapOfStructure;
29 //! Defines array of indexed maps of structures.
30 typedef NCollection_Array1<Graphic3d_IndexedMapOfStructure> Graphic3d_ArrayOfIndexedMapOfStructure;
32 class Graphic3d_CullingTool;
34 //! Presentations list sorted within priorities.
35 class Graphic3d_Layer : public Standard_Transient
37 DEFINE_STANDARD_RTTIEXT(Graphic3d_Layer, Standard_Transient)
40 //! Initializes associated priority list and layer properties
41 Standard_EXPORT Graphic3d_Layer (Standard_Integer theNbPriorities,
42 const Handle(Select3D_BVHBuilder3d)& theBuilder);
45 Standard_EXPORT virtual ~Graphic3d_Layer();
47 //! Returns BVH tree builder for frustom culling.
48 const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHPrimitivesTrsfPers.Builder(); }
50 //! Assigns BVH tree builder for frustom culling.
51 void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myBVHPrimitivesTrsfPers.SetBuilder (theBuilder); }
53 //! Return true if layer was marked with immediate flag.
54 Standard_Boolean IsImmediate() const { return myLayerSettings.IsImmediate(); }
56 //! Returns settings of the layer object.
57 const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; };
59 //! Sets settings of the layer object.
60 Standard_EXPORT void SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings);
62 Standard_EXPORT void Add (const Graphic3d_CStructure* theStruct,
63 Standard_Integer thePriority,
64 Standard_Boolean isForChangePriority = Standard_False);
66 //! Remove structure and returns its priority, if the structure is not found, method returns negative value
67 Standard_EXPORT bool Remove (const Graphic3d_CStructure* theStruct,
68 Standard_Integer& thePriority,
69 Standard_Boolean isForChangePriority = Standard_False);
71 //! @return the number of structures
72 Standard_Integer NbStructures() const { return myNbStructures; }
74 //! Number of NOT culled structures in the layer.
75 Standard_Integer NbStructuresNotCulled() const { return myNbStructuresNotCulled; }
77 //! Returns the number of available priority levels
78 Standard_Integer NbPriorities() const { return myArray.Length(); }
80 //! Append layer of acceptable type (with similar number of priorities or less).
81 //! Returns Standard_False if the list can not be accepted.
82 Standard_EXPORT Standard_Boolean Append (const Graphic3d_Layer& theOther);
84 //! Returns array of structures.
85 const Graphic3d_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
87 //! Marks BVH tree for given priority list as dirty and
88 //! marks primitive set for rebuild.
89 Standard_EXPORT void InvalidateBVHData();
91 //! Marks cached bounding box as obsolete.
92 void InvalidateBoundingBox() const
94 myIsBoundingBoxNeedsReset[0] = myIsBoundingBoxNeedsReset[1] = true;
97 //! Returns layer bounding box.
98 //! @param theViewId view index to consider View Affinity in structure
99 //! @param theCamera camera definition
100 //! @param theWindowWidth viewport width (for applying transformation-persistence)
101 //! @param theWindowHeight viewport height (for applying transformation-persistence)
102 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
103 //! @return computed bounding box
104 Standard_EXPORT Bnd_Box BoundingBox (Standard_Integer theViewId,
105 const Handle(Graphic3d_Camera)& theCamera,
106 Standard_Integer theWindowWidth,
107 Standard_Integer theWindowHeight,
108 Standard_Boolean theToIncludeAuxiliary) const;
110 //! Returns zoom-scale factor.
111 Standard_EXPORT Standard_Real considerZoomPersistenceObjects (Standard_Integer theViewId,
112 const Handle(Graphic3d_Camera)& theCamera,
113 Standard_Integer theWindowWidth,
114 Standard_Integer theWindowHeight) const;
116 //! Update culling state - should be called before rendering.
117 //! Traverses through BVH tree to determine which structures are in view volume.
118 Standard_EXPORT void UpdateCulling (Standard_Integer theViewId,
119 const Graphic3d_CullingTool& theSelector,
120 const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState);
122 //! Returns TRUE if layer is empty or has been discarded entirely by culling test.
123 bool IsCulled() const { return myNbStructuresNotCulled == 0; }
125 //! Returns number of transform persistence objects.
126 Standard_Integer NbOfTransformPersistenceObjects() const
128 return myBVHPrimitivesTrsfPers.Size();
133 //! Returns set of Graphic3d_CStructures structures for building BVH tree.
134 const Graphic3d_BvhCStructureSet& CullableStructuresBVH() const { return myBVHPrimitives; }
136 //! Returns set of transform persistent Graphic3d_CStructures for building BVH tree.
137 const Graphic3d_BvhCStructureSetTrsfPers& CullableTrsfPersStructuresBVH() const { return myBVHPrimitivesTrsfPers; }
139 //! Returns indexed map of always rendered structures.
140 const NCollection_IndexedMap<const Graphic3d_CStructure*>& NonCullableStructures() const { return myAlwaysRenderedMap; }
144 //! Updates BVH trees if their state has been invalidated.
145 Standard_EXPORT void updateBVH() const;
149 //! Array of Graphic3d_CStructures by priority rendered in layer.
150 Graphic3d_ArrayOfIndexedMapOfStructure myArray;
152 //! Overall number of structures rendered in the layer.
153 Standard_Integer myNbStructures;
155 //! Number of NOT culled structures in the layer.
156 Standard_Integer myNbStructuresNotCulled;
158 //! Layer setting flags.
159 Graphic3d_ZLayerSettings myLayerSettings;
161 //! Set of Graphic3d_CStructures structures for building BVH tree.
162 mutable Graphic3d_BvhCStructureSet myBVHPrimitives;
164 //! Set of transform persistent Graphic3d_CStructures for building BVH tree.
165 mutable Graphic3d_BvhCStructureSetTrsfPers myBVHPrimitivesTrsfPers;
167 //! Indexed map of always rendered structures.
168 mutable NCollection_IndexedMap<const Graphic3d_CStructure*> myAlwaysRenderedMap;
170 //! Is needed for implementation of stochastic order of BVH traverse.
171 Standard_Boolean myBVHIsLeftChildQueuedFirst;
173 //! Defines if the primitive set for BVH is outdated.
174 mutable Standard_Boolean myIsBVHPrimitivesNeedsReset;
176 //! Defines if the cached bounding box is outdated.
177 mutable bool myIsBoundingBoxNeedsReset[2];
179 //! Cached layer bounding box.
180 mutable Bnd_Box myBoundingBox[2];
184 #endif // _Graphic3d_Layer_HeaderFile