0024393: Visualization - objects position with enchanced precision
[occt.git] / src / OpenGl / OpenGl_BVHClipPrimitiveTrsfPersSet.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
16#ifndef _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
17#define _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
18
19#include <BVH_Builder.hxx>
20#include <BVH_Set.hxx>
21#include <BVH_Tree.hxx>
22#include <Graphic3d_BndBox4f.hxx>
23#include <Graphic3d_WorldViewProjState.hxx>
7c3ef2f7 24#include <NCollection_Shared.hxx>
825aa485 25#include <NCollection_IndexedMap.hxx>
26#include <OpenGl_Structure.hxx>
27#include <OpenGl_Vec.hxx>
28
29//! Set of transformation persistent OpenGl_Structure for building BVH tree.
30//! Provides built-in mechanism to invalidate tree when world view projection state changes.
31//! Due to frequent invalidation of BVH tree the choice of BVH tree builder is made
32//! in favor of BVH linear builder (quick rebuild).
7c3ef2f7 33class OpenGl_BVHClipPrimitiveTrsfPersSet : public BVH_Set<Standard_Real, 3>
825aa485 34{
35private:
36
7c3ef2f7 37 typedef NCollection_Shared<Graphic3d_BndBox3d> HBndBox3d;
825aa485 38
39public:
40
41 //! Creates an empty primitive set for BVH clipping.
42 OpenGl_BVHClipPrimitiveTrsfPersSet();
43
44 //! Returns total number of structures.
45 virtual Standard_Integer Size() const Standard_OVERRIDE;
46
47 //! Returns AABB of the structure.
7c3ef2f7 48 virtual Graphic3d_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
825aa485 49
50 //! Calculates center of the AABB along given axis.
7c3ef2f7 51 virtual Standard_Real Center (const Standard_Integer theIdx,
52 const Standard_Integer theAxis) const Standard_OVERRIDE;
825aa485 53
54 //! Swaps structures with the given indices.
55 virtual void Swap (const Standard_Integer theIdx1,
56 const Standard_Integer theIdx2) Standard_OVERRIDE;
57
58 //! Adds structure to the set.
59 //! @return true if structure added, otherwise returns false (structure already in the set).
60 Standard_Boolean Add (const OpenGl_Structure* theStruct);
61
62 //! Removes the given structure from the set.
63 //! @return true if structure removed, otherwise returns false (structure is not in the set).
64 Standard_Boolean Remove (const OpenGl_Structure* theStruct);
65
66 //! Cleans the whole primitive set.
67 void Clear();
68
69 //! Returns the structure corresponding to the given ID.
70 const OpenGl_Structure* GetStructureById (Standard_Integer theId);
71
72 //! Marks object state as outdated (needs BVH rebuilding).
73 void MarkDirty()
74 {
75 myIsDirty = Standard_True;
76 }
77
78 //! Returns BVH tree for the given world view projection (builds it if necessary).
7c3ef2f7 79 const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& BVH (const Handle(Graphic3d_Camera)& theCamera,
80 const OpenGl_Mat4d& theProjectionMatrix,
81 const OpenGl_Mat4d& theWorldViewMatrix,
82 const Standard_Integer theViewportWidth,
83 const Standard_Integer theViewportHeight,
84 const Graphic3d_WorldViewProjState& theWVPState);
825aa485 85
86private:
87
88 //! Marks internal object state as outdated.
89 Standard_Boolean myIsDirty;
90
91 //! Constructed bottom-level BVH.
7c3ef2f7 92 NCollection_Handle<BVH_Tree<Standard_Real, 3> > myBVH;
825aa485 93
94 //! Builder for bottom-level BVH.
7c3ef2f7 95 NCollection_Handle<BVH_Builder<Standard_Real, 3> > myBuilder;
825aa485 96
97 //! Indexed map of structures.
98 NCollection_IndexedMap<const OpenGl_Structure*> myStructs;
99
100 //! Cached set of bounding boxes precomputed for transformation persistent selectable objects.
101 //! Cache exists only during computation of BVH Tree. Bounding boxes are world view projection
102 //! dependent and should by synchronized.
7c3ef2f7 103 NCollection_IndexedMap<Handle(HBndBox3d)> myStructBoxes;
825aa485 104
105 //! State of world view projection used for generation of transformation persistence bounding boxes.
106 Graphic3d_WorldViewProjState myStructBoxesState;
107};
108
109#endif // _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile