0030698: Volume Rendering - Early clipping of volume object's bounding box
[occt.git] / src / Graphic3d / Graphic3d_CStructure.hxx
... / ...
CommitLineData
1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _Graphic3d_CStructure_HeaderFile
16#define _Graphic3d_CStructure_HeaderFile
17
18#include <Graphic3d_BndBox3d.hxx>
19#include <Graphic3d_Group.hxx>
20#include <Graphic3d_PresentationAttributes.hxx>
21#include <Graphic3d_SequenceOfGroup.hxx>
22#include <Graphic3d_SequenceOfHClipPlane.hxx>
23#include <Graphic3d_TypeOfComposition.hxx>
24#include <Graphic3d_ViewAffinity.hxx>
25#include <Graphic3d_TransformPers.hxx>
26#include <Graphic3d_Vec3.hxx>
27#include <Graphic3d_ZLayerId.hxx>
28#include <Geom_Transformation.hxx>
29#include <NCollection_IndexedMap.hxx>
30
31class Graphic3d_GraphicDriver;
32class Graphic3d_StructureManager;
33
34//! Low-level graphic structure interface
35class Graphic3d_CStructure : public Standard_Transient
36{
37protected:
38
39 //! Auxiliary wrapper to iterate through structure list.
40 template<class Struct_t>
41 class SubclassStructIterator
42 {
43 public:
44 SubclassStructIterator (const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructs) : myIter (theStructs) {}
45 Standard_Boolean More() const { return myIter.More(); }
46 void Next() { myIter.Next(); }
47 const Struct_t* Value() const { return (const Struct_t* )(myIter.Value()); }
48 Struct_t* ChangeValue() { return (Struct_t* )(myIter.Value()); }
49 private:
50 NCollection_IndexedMap<const Graphic3d_CStructure*>::Iterator myIter;
51 };
52
53 //! Auxiliary wrapper to iterate through group sequence.
54 template<class Group_t>
55 class SubclassGroupIterator
56 {
57 public:
58 SubclassGroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
59 Standard_Boolean More() const { return myIter.More(); }
60 void Next() { myIter.Next(); }
61 const Group_t* Value() const { return (const Group_t* )(myIter.Value().get()); }
62 Group_t* ChangeValue() { return (Group_t* )(myIter.ChangeValue().get()); }
63 private:
64 Graphic3d_SequenceOfGroup::Iterator myIter;
65 };
66
67public:
68
69 //! @return graphic driver created this structure
70 const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const
71 {
72 return myGraphicDriver;
73 }
74
75 //! @return graphic groups
76 const Graphic3d_SequenceOfGroup& Groups() const
77 {
78 return myGroups;
79 }
80
81 //! Return transformation.
82 const Handle(Geom_Transformation)& Transformation() const { return myTrsf; }
83
84 //! Assign transformation.
85 virtual void SetTransformation (const Handle(Geom_Transformation)& theTrsf) { myTrsf = theTrsf; }
86
87 //! Return transformation persistence.
88 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; }
89
90 //! Set transformation persistence.
91 virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; }
92
93 //! @return associated clip planes
94 const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const
95 {
96 return myClipPlanes;
97 }
98
99 //! Pass clip planes to the associated graphic driver structure
100 void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) { myClipPlanes = thePlanes; }
101
102 //! @return bounding box of this presentation
103 const Graphic3d_BndBox3d& BoundingBox() const
104 {
105 return myBndBox;
106 }
107
108 //! @return bounding box of this presentation
109 //! without transformation matrix applied
110 Graphic3d_BndBox3d& ChangeBoundingBox()
111 {
112 return myBndBox;
113 }
114
115 //! Return structure visibility flag
116 bool IsVisible() const { return visible != 0; }
117
118 //! Return structure visibility considering both View Affinity and global visibility state.
119 bool IsVisible (const Standard_Integer theViewId) const
120 {
121 return visible != 0
122 && (ViewAffinity.IsNull()
123 || ViewAffinity->IsVisible (theViewId));
124 }
125
126 //! Set z layer ID to display the structure in specified layer
127 virtual void SetZLayer (const Graphic3d_ZLayerId theLayerIndex) { myZLayer = theLayerIndex; }
128
129 //! Get z layer ID
130 Graphic3d_ZLayerId ZLayer() const { return myZLayer; }
131
132 //! Returns valid handle to highlight style of the structure in case if
133 //! highlight flag is set to true
134 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
135
136public:
137
138 //! Returns FALSE if the structure hits the current view volume, otherwise returns TRUE.
139 Standard_Boolean IsCulled() const { return myIsCulled; }
140
141 //! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here!
142 void SetCulled (Standard_Boolean theIsCulled) const { myIsCulled = theIsCulled; }
143
144 //! Marks structure as overlapping the current view volume one.
145 //! The method is called during traverse of BVH tree.
146 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
147
148 //! Returns whether check of object's bounding box clipping is enabled before drawing of object; TRUE by default.
149 Standard_Boolean BndBoxClipCheck() const { return myBndBoxClipCheck; }
150
151 //! Enable/disable check of object's bounding box clipping before drawing of object.
152 void SetBndBoxClipCheck(Standard_Boolean theBndBoxClipCheck) { myBndBoxClipCheck = theBndBoxClipCheck; }
153
154 //! Checks if the structure should be included into BVH tree or not.
155 Standard_Boolean IsAlwaysRendered() const
156 {
157 return IsInfinite
158 || IsForHighlight
159 || IsMutable
160 || Is2dText
161 || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
162 }
163
164public:
165
166 //! Update structure visibility state
167 virtual void OnVisibilityChanged() = 0;
168
169 //! Clear graphic data
170 virtual void Clear() = 0;
171
172 //! Connect other structure to this one
173 virtual void Connect (Graphic3d_CStructure& theStructure) = 0;
174
175 //! Disconnect other structure to this one
176 virtual void Disconnect (Graphic3d_CStructure& theStructure) = 0;
177
178 //! Highlights structure with the given style
179 virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) = 0;
180
181 //! Unhighlights the structure and invalidates pointer to structure's highlight
182 //! style
183 virtual void GraphicUnhighlight() = 0;
184
185 //! Create shadow link to this structure
186 virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const = 0;
187
188 //! Create new group within this structure
189 virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) = 0;
190
191 //! Remove group from this structure
192 virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) = 0;
193
194 //! Update render transformation matrix.
195 virtual void updateLayerTransformation() {}
196
197public:
198
199 int Id;
200 Graphic3d_ZLayerId myZLayer;
201 int Priority;
202 int PreviousPriority;
203
204 int ContainsFacet;
205
206 Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask
207
208 unsigned IsInfinite : 1;
209 unsigned stick : 1; //!< displaying state - should be set when structure has been added to scene graph (but can be in hidden state)
210 unsigned highlight : 1;
211 unsigned visible : 1; //!< visibility flag - can be used to suppress structure while leaving it in the scene graph
212 unsigned HLRValidation : 1;
213 unsigned IsForHighlight : 1;
214 unsigned IsMutable : 1;
215 unsigned Is2dText : 1;
216
217protected:
218
219 //! Create empty structure.
220 Standard_EXPORT Graphic3d_CStructure (const Handle(Graphic3d_StructureManager)& theManager);
221
222protected:
223
224 Handle(Graphic3d_GraphicDriver) myGraphicDriver;
225 Graphic3d_SequenceOfGroup myGroups;
226 Graphic3d_BndBox3d myBndBox;
227 Handle(Geom_Transformation) myTrsf;
228 Handle(Graphic3d_TransformPers) myTrsfPers;
229 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
230 Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //! Current highlight style; is set only if highlight flag is true
231
232 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse
233 Standard_Boolean myBndBoxClipCheck; //!< Flag responsible for checking of bounding box clipping before drawing of object
234
235public:
236
237 DEFINE_STANDARD_RTTIEXT(Graphic3d_CStructure,Standard_Transient) // Type definition
238
239};
240
241DEFINE_STANDARD_HANDLE (Graphic3d_CStructure, Standard_Transient)
242
243#endif // _Graphic3d_CStructure_HeaderFile