0031511: Point Cloud Rendering, Volume Rendering - reuse Graphic3d_CullingTool
[occt.git] / src / Graphic3d / Graphic3d_BvhCStructureSetTrsfPers.hxx
CommitLineData
825aa485 1// Created on: 2015-06-30
2// Created by: Anton POLETAEV
3// Copyright (c) 2015 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
d325cb7f 16#ifndef _Graphic3d_BvhCStructureSetTrsfPers_HeaderFile
17#define _Graphic3d_BvhCStructureSetTrsfPers_HeaderFile
825aa485 18
825aa485 19#include <BVH_Set.hxx>
20#include <BVH_Tree.hxx>
d325cb7f 21#include <Graphic3d_BndBox3d.hxx>
22#include <Graphic3d_Mat4d.hxx>
825aa485 23#include <Graphic3d_WorldViewProjState.hxx>
7c3ef2f7 24#include <NCollection_Shared.hxx>
825aa485 25#include <NCollection_IndexedMap.hxx>
f5b72419 26#include <Select3D_BVHBuilder3d.hxx>
825aa485 27
d325cb7f 28class Graphic3d_Camera;
29class Graphic3d_CStructure;
30
825aa485 31//! Set of transformation persistent OpenGl_Structure for building BVH tree.
32//! Provides built-in mechanism to invalidate tree when world view projection state changes.
33//! Due to frequent invalidation of BVH tree the choice of BVH tree builder is made
34//! in favor of BVH linear builder (quick rebuild).
d325cb7f 35class Graphic3d_BvhCStructureSetTrsfPers : public BVH_Set<Standard_Real, 3>
825aa485 36{
37private:
38
7c3ef2f7 39 typedef NCollection_Shared<Graphic3d_BndBox3d> HBndBox3d;
825aa485 40
41public:
42
43 //! Creates an empty primitive set for BVH clipping.
b31fbc83 44 Standard_EXPORT Graphic3d_BvhCStructureSetTrsfPers (const Handle(Select3D_BVHBuilder3d)& theBuilder);
825aa485 45
46 //! Returns total number of structures.
b31fbc83 47 Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
825aa485 48
49 //! Returns AABB of the structure.
b31fbc83 50 Standard_EXPORT virtual Graphic3d_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
825aa485 51
52 //! Calculates center of the AABB along given axis.
b31fbc83 53 Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
54 const Standard_Integer theAxis) const Standard_OVERRIDE;
825aa485 55
56 //! Swaps structures with the given indices.
b31fbc83 57 Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
58 const Standard_Integer theIdx2) Standard_OVERRIDE;
825aa485 59
60 //! Adds structure to the set.
61 //! @return true if structure added, otherwise returns false (structure already in the set).
b31fbc83 62 Standard_EXPORT Standard_Boolean Add (const Graphic3d_CStructure* theStruct);
825aa485 63
64 //! Removes the given structure from the set.
65 //! @return true if structure removed, otherwise returns false (structure is not in the set).
b31fbc83 66 Standard_EXPORT Standard_Boolean Remove (const Graphic3d_CStructure* theStruct);
825aa485 67
68 //! Cleans the whole primitive set.
b31fbc83 69 Standard_EXPORT void Clear();
825aa485 70
71 //! Returns the structure corresponding to the given ID.
b31fbc83 72 Standard_EXPORT const Graphic3d_CStructure* GetStructureById (Standard_Integer theId);
825aa485 73
15669413 74 //! Access directly a collection of structures.
d325cb7f 75 const NCollection_IndexedMap<const Graphic3d_CStructure*>& Structures() const { return myStructs; }
15669413 76
825aa485 77 //! Marks object state as outdated (needs BVH rebuilding).
78 void MarkDirty()
79 {
80 myIsDirty = Standard_True;
81 }
82
83 //! Returns BVH tree for the given world view projection (builds it if necessary).
b31fbc83 84 Standard_EXPORT const opencascade::handle<BVH_Tree<Standard_Real, 3> >& BVH (const Handle(Graphic3d_Camera)& theCamera,
85 const Graphic3d_Mat4d& theProjectionMatrix,
86 const Graphic3d_Mat4d& theWorldViewMatrix,
87 const Standard_Integer theViewportWidth,
88 const Standard_Integer theViewportHeight,
89 const Graphic3d_WorldViewProjState& theWVPState);
f5b72419 90
91 //! Returns builder for bottom-level BVH.
92 const Handle(Select3D_BVHBuilder3d)& Builder() const { return myBuilder; }
93
94 //! Assigns builder for bottom-level BVH.
95 void SetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myBuilder = theBuilder; }
825aa485 96
97private:
98
99 //! Marks internal object state as outdated.
100 Standard_Boolean myIsDirty;
101
102 //! Constructed bottom-level BVH.
f5b72419 103 opencascade::handle<BVH_Tree<Standard_Real, 3> > myBVH;
825aa485 104
105 //! Builder for bottom-level BVH.
f5b72419 106 Handle(Select3D_BVHBuilder3d) myBuilder;
825aa485 107
108 //! Indexed map of structures.
d325cb7f 109 NCollection_IndexedMap<const Graphic3d_CStructure*> myStructs;
825aa485 110
111 //! Cached set of bounding boxes precomputed for transformation persistent selectable objects.
112 //! Cache exists only during computation of BVH Tree. Bounding boxes are world view projection
113 //! dependent and should by synchronized.
7c3ef2f7 114 NCollection_IndexedMap<Handle(HBndBox3d)> myStructBoxes;
825aa485 115
116 //! State of world view projection used for generation of transformation persistence bounding boxes.
117 Graphic3d_WorldViewProjState myStructBoxesState;
118};
119
d325cb7f 120#endif // _Graphic3d_BvhCStructureSetTrsfPers_HeaderFile