0027607: Visualization - Implement adaptive screen space sampling in path tracing
[occt.git] / src / Graphic3d / Graphic3d_Structure.hxx
CommitLineData
42cf5bc1 1// Created on: 1991-06-12
2// Created by: NW,JPB,CAL
3// Copyright (c) 1991-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Graphic3d_Structure_HeaderFile
18#define _Graphic3d_Structure_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <Graphic3d_CStructure.hxx>
24#include <Graphic3d_IndexedMapOfAddress.hxx>
25#include <Quantity_Color.hxx>
26#include <Aspect_TypeOfHighlightMethod.hxx>
42cf5bc1 27#include <Standard_Address.hxx>
28#include <Graphic3d_TypeOfStructure.hxx>
29#include <MMgt_TShared.hxx>
30#include <Standard_Boolean.hxx>
31#include <Standard_Integer.hxx>
32#include <Graphic3d_ZLayerId.hxx>
33#include <Graphic3d_SequenceOfHClipPlane.hxx>
34#include <Standard_Real.hxx>
42cf5bc1 35#include <Graphic3d_SequenceOfGroup.hxx>
36#include <Graphic3d_TypeOfConnection.hxx>
37#include <Graphic3d_MapOfStructure.hxx>
38#include <Graphic3d_TypeOfComposition.hxx>
825aa485 39#include <Graphic3d_TransformPers.hxx>
42cf5bc1 40#include <Graphic3d_TransModeFlags.hxx>
41#include <Graphic3d_BndBox4f.hxx>
42#include <Graphic3d_BndBox4d.hxx>
43#include <Graphic3d_Vertex.hxx>
44class Graphic3d_PriorityDefinitionError;
45class Graphic3d_StructureDefinitionError;
46class Graphic3d_TransformError;
47class Graphic3d_Group;
48class Graphic3d_StructureManager;
49class Quantity_Color;
42cf5bc1 50class Graphic3d_DataStructureManager;
51class Bnd_Box;
52class gp_Pnt;
53class Graphic3d_Vector;
54
55
56class Graphic3d_Structure;
57DEFINE_STANDARD_HANDLE(Graphic3d_Structure, MMgt_TShared)
58
59//! This class allows the definition a graphic object.
60//! This graphic structure can be displayed,
61//! erased, or highlighted.
62//! This graphic structure can be connected with
63//! another graphic structure.
64//! Keywords: Structure, StructureManager, Display, Erase, Highlight,
65//! UnHighlight, Visible, Priority, Selectable, Visible,
66//! Visual, Connection, Ancestors, Descendants, Transformation
67class Graphic3d_Structure : public MMgt_TShared
68{
69
70public:
71
72
73 //! Creates a graphic object in the manager theManager.
74 //! It will appear in all the views of the visualiser.
42cf5bc1 75 //! The structure is not displayed when it is created.
76 Standard_EXPORT Graphic3d_Structure(const Handle(Graphic3d_StructureManager)& theManager);
77
78 //! Creates a shadow link to existing graphic object.
79 Standard_EXPORT Graphic3d_Structure(const Handle(Graphic3d_StructureManager)& theManager, const Handle(Graphic3d_Structure)& thePrs);
80
81 //! if WithDestruction == Standard_True then
82 //! suppress all the groups of primitives in the structure.
83 //! and it is mandatory to create a new group in <me>.
84 //! if WithDestruction == Standard_False then
85 //! clears all the groups of primitives in the structure.
86 //! and all the groups are conserved and empty.
87 //! They will be erased at the next screen update.
88 //! The structure itself is conserved.
89 //! The transformation and the attributes of <me> are conserved.
90 //! The childs of <me> are conserved.
91 Standard_EXPORT virtual void Clear (const Standard_Boolean WithDestruction = Standard_True);
92
93 //! Suppresses the structure <me>.
94 //! It will be erased at the next screen update.
e6f550da 95 Standard_EXPORT ~Graphic3d_Structure();
42cf5bc1 96
97 //! Displays the structure <me> in all the views of the visualiser.
98 Standard_EXPORT virtual void Display();
99
100 //! Returns the current display priority for the
101 //! structure <me>.
102 Standard_EXPORT Standard_Integer DisplayPriority() const;
103
104 //! Erases the structure <me> in all the views
105 //! of the visualiser.
106 Standard_EXPORT virtual void Erase();
107
108 //! Highlights the structure <me> in all the views of the visualiser, using the following methods:
109 //! TOHM_COLOR = drawn in the highlight color
110 //! TOHM_BOUNDBOX = enclosed by the boundary box
111 Standard_EXPORT void Highlight (const Aspect_TypeOfHighlightMethod theMethod, const Quantity_Color& theColor, const Standard_Boolean theToUpdateMgr = Standard_True);
112
113 //! Suppress the structure <me>.
114 //! It will be erased at the next screen update.
115 //! Warning: No more graphic operations in <me> after this call.
116 //! Category: Methods to modify the class definition
117 Standard_EXPORT void Remove();
118
119 //! Computes axis-aligned bounding box of a structure.
770fa4d4 120 Standard_EXPORT virtual void CalculateBoundBox();
42cf5bc1 121
122 //! If <theToSet> is Standard_True then <me> is infinite and
123 //! the MinMaxValues method method return :
124 //! theXMin = theYMin = theZMin = RealFirst().
125 //! theXMax = theYMax = theZMax = RealLast().
126 //! By default, <me> is not infinite but empty.
127 Standard_EXPORT void SetInfiniteState (const Standard_Boolean theToSet);
128
129 //! Modifies the order of displaying the structure.
130 //! Values are between 0 and 10.
131 //! Structures are drawn according to their display priorities
132 //! in ascending order.
133 //! A structure of priority 10 is displayed the last and appears over the others.
134 //! The default value is 5.
135 //! Category: Methods to modify the class definition
136 //! Warning: If <me> is displayed then the SetDisplayPriority
137 //! method erase <me> and display <me> with the
138 //! new priority.
139 //! Raises PriorityDefinitionError if <Priority> is
140 //! greater than 10 or a negative value.
141 Standard_EXPORT void SetDisplayPriority (const Standard_Integer Priority);
142
143 //! Reset the current priority of the structure to the
144 //! previous priority.
145 //! Category: Methods to modify the class definition
146 //! Warning: If <me> is displayed then the SetDisplayPriority
147 //! method erase <me> and display <me> with the
148 //! previous priority.
149 Standard_EXPORT void ResetDisplayPriority();
150
151 //! Set Z layer ID for the structure. The Z layer mechanism
152 //! allows to display structures presented in higher layers in overlay
153 //! of structures in lower layers by switching off z buffer depth
154 //! test between layers
155 Standard_EXPORT void SetZLayer (const Graphic3d_ZLayerId theLayerId);
156
157 //! Get Z layer ID of displayed structure. The method
158 //! returns -1 if the structure has no ID (deleted from graphic driver).
159 Standard_EXPORT Graphic3d_ZLayerId GetZLayer() const;
160
161 //! Changes a sequence of clip planes slicing the structure on rendering.
162 //! @param thePlanes [in] the set of clip planes.
3202bf1e 163 Standard_EXPORT void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
42cf5bc1 164
165 //! Get clip planes slicing the structure on rendering.
166 //! @return set of clip planes.
3202bf1e 167 Standard_EXPORT const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const;
2831708b 168
42cf5bc1 169 //! Modifies the visibility indicator to Standard_True or
170 //! Standard_False for the structure <me>.
171 //! The default value at the definition of <me> is
172 //! Standard_True.
173 Standard_EXPORT void SetVisible (const Standard_Boolean AValue);
174
175 //! Modifies the visualisation mode for the structure <me>.
176 Standard_EXPORT virtual void SetVisual (const Graphic3d_TypeOfStructure AVisual);
177
178 //! Modifies the minimum and maximum zoom coefficients
179 //! for the structure <me>.
180 //! The default value at the definition of <me> is unlimited.
181 //! Category: Methods to modify the class definition
182 //! Warning: Raises StructureDefinitionError if <LimitInf> is
183 //! greater than <LimitSup> or if <LimitInf> or
184 //! <LimitSup> is a negative value.
185 Standard_EXPORT void SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup);
186
187 //! marks the structure <me> representing wired structure needed for
188 //! highlight only so it won't be added to BVH tree.
189 //! Category: Methods to modify the class definition
190 Standard_EXPORT void SetIsForHighlight (const Standard_Boolean isForHighlight);
191
192 //! Suppresses the highlight for the structure <me>
193 //! in all the views of the visualiser.
194 Standard_EXPORT void UnHighlight();
195
196 Standard_EXPORT virtual void Compute();
197
198 //! Returns the new Structure defined for the new visualization
199 Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector);
200
201 //! Returns the new Structure defined for the new visualization
1f7f5a90 202 Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
203 const Handle(Geom_Transformation)& theTrsf);
42cf5bc1 204
205 //! Returns the new Structure defined for the new visualization
206 Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, Handle(Graphic3d_Structure)& aStructure);
207
208 //! Returns the new Structure defined for the new visualization
1f7f5a90 209 Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
210 const Handle(Geom_Transformation)& theTrsf,
211 Handle(Graphic3d_Structure)& theStructure);
212
42cf5bc1 213 //! Forces a new construction of the structure <me>
214 //! if <me> is displayed and TOS_COMPUTED.
215 Standard_EXPORT void ReCompute();
216
217 //! Forces a new construction of the structure <me>
218 //! if <me> is displayed in <aProjetor> and TOS_COMPUTED.
219 Standard_EXPORT void ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector);
220
221 //! Returns Standard_True if the structure <me> contains
222 //! Polygons, Triangles or Quadrangles.
223 Standard_EXPORT Standard_Boolean ContainsFacet() const;
2831708b 224
42cf5bc1 225 //! Returns the groups sequence included in the structure <me> (internal storage).
226 Standard_EXPORT const Graphic3d_SequenceOfGroup& Groups() const;
227
228 //! Returns the current number of groups in the
229 //! structure <me>.
230 Standard_EXPORT Standard_Integer NumberOfGroups() const;
231
232 //! Append new group to this structure.
233 Standard_EXPORT Handle(Graphic3d_Group) NewGroup();
234
235 //! Returns the highlight color for the Highlight method
236 //! with the highlight method TOHM_COLOR or TOHM_BOUNDBOX.
237 Standard_EXPORT const Quantity_Color& HighlightColor() const;
238
239 //! Returns Standard_True if the structure <me> is deleted.
240 //! <me> is deleted after the call Remove (me).
241 Standard_EXPORT Standard_Boolean IsDeleted() const;
242
243 //! Returns the display indicator for the structure <me>.
244 Standard_EXPORT virtual Standard_Boolean IsDisplayed() const;
245
246 //! Returns Standard_True if the structure <me> is empty.
247 //! Warning: A structure is empty if :
248 //! it do not have group or all the groups are empties
249 //! and it do not have descendant or all the descendants
250 //! are empties.
251 Standard_EXPORT Standard_Boolean IsEmpty() const;
252
253 //! Returns Standard_True if the structure <me> is infinite.
254 Standard_EXPORT Standard_Boolean IsInfinite() const;
255
256 //! Returns the highlight indicator for the structure <me>.
257 Standard_EXPORT virtual Standard_Boolean IsHighlighted() const;
258
42cf5bc1 259 //! Returns Standard_True if the structure <me> is transformed.
260 //! <=> The transformation != Identity.
261 Standard_EXPORT Standard_Boolean IsTransformed() const;
262
263 //! Returns the visibility indicator for the structure <me>.
264 Standard_EXPORT Standard_Boolean IsVisible() const;
2831708b 265
42cf5bc1 266 //! Returns the coordinates of the boundary box of the structure <me>.
267 //! If <theToIgnoreInfiniteFlag> is TRUE, the method returns actual graphical
268 //! boundaries of the Graphic3d_Group components. Otherwise, the
269 //! method returns boundaries taking into account infinite state
270 //! of the structure. This approach generally used for application
271 //! specific fit operation (e.g. fitting the model into screen,
272 //! not taking into accout infinite helper elements).
273 //! Warning: If the structure <me> is empty then the empty box is returned,
274 //! If the structure <me> is infinite then the whole box is returned.
275 Standard_EXPORT Bnd_Box MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
2831708b 276
42cf5bc1 277 //! Returns the visualisation mode for the structure <me>.
278 Standard_EXPORT Graphic3d_TypeOfStructure Visual() const;
279
280 //! Returns Standard_True if the connection is possible between
281 //! <AStructure1> and <AStructure2> without a creation
282 //! of a cycle.
283 //!
284 //! It's not possible to call the method
285 //! AStructure1->Connect (AStructure2, TypeOfConnection)
286 //! if
287 //! - the set of all ancestors of <AStructure1> contains
288 //! <AStructure1> and if the
289 //! TypeOfConnection == TOC_DESCENDANT
290 //! - the set of all descendants of <AStructure1> contains
291 //! <AStructure2> and if the
292 //! TypeOfConnection == TOC_ANCESTOR
293 Standard_EXPORT static Standard_Boolean AcceptConnection (const Handle(Graphic3d_Structure)& AStructure1, const Handle(Graphic3d_Structure)& AStructure2, const Graphic3d_TypeOfConnection AType);
294
295 //! Returns the group of structures to which <me> is connected.
296 Standard_EXPORT void Ancestors (Graphic3d_MapOfStructure& SG) const;
297
298 //! If Atype is TOC_DESCENDANT then add <AStructure>
299 //! as a child structure of <me>.
300 //! If Atype is TOC_ANCESTOR then add <AStructure>
301 //! as a parent structure of <me>.
302 //! The connection propagates Display, Highlight, Erase,
303 //! Remove, and stacks the transformations.
304 //! No connection if the graph of the structures
305 //! contains a cycle and <WithCheck> is Standard_True;
306 Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, const Standard_Boolean WithCheck = Standard_False);
307
308 //! Returns the group of structures connected to <me>.
309 Standard_EXPORT void Descendants (Graphic3d_MapOfStructure& SG) const;
310
311 //! Suppress the connection between <AStructure> and <me>.
312 Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& AStructure);
313
314 //! If Atype is TOC_DESCENDANT then suppress all
315 //! the connections with the child structures of <me>.
316 //! If Atype is TOC_ANCESTOR then suppress all
317 //! the connections with the parent structures of <me>.
318 Standard_EXPORT void DisconnectAll (const Graphic3d_TypeOfConnection AType);
319
320 //! Returns <ASet> the group of structures :
321 //! - directly or indirectly connected to <AStructure> if the
322 //! TypeOfConnection == TOC_DESCENDANT
323 //! - to which <AStructure> is directly or indirectly connected
324 //! if the TypeOfConnection == TOC_ANCESTOR
325 Standard_EXPORT static void Network (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, Graphic3d_MapOfStructure& ASet);
326
327 Standard_EXPORT void SetOwner (const Standard_Address Owner);
328
329 Standard_EXPORT Standard_Address Owner() const;
330
331 Standard_EXPORT void SetHLRValidation (const Standard_Boolean AFlag);
332
333 Standard_EXPORT Standard_Boolean HLRValidation() const;
6bd94e0d 334
1f7f5a90 335 //! Return local transformation.
336 const Handle(Geom_Transformation)& Transformation() const { return myCStructure->Transformation(); }
337
338 //! Modifies the current local transformation
339 Standard_EXPORT void SetTransformation (const Handle(Geom_Transformation)& theTrsf);
340
341 Standard_DEPRECATED("This method is deprecated - SetTransformation() should be called instead")
342 void Transform (const Handle(Geom_Transformation)& theTrsf) { SetTransformation (theTrsf); }
778cd667 343
344 //! Modifies the current transform persistence (pan, zoom or rotate)
345 Standard_EXPORT void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers);
825aa485 346
347 //! @return transform persistence of the presentable object.
778cd667 348 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myCStructure->TransformPersistence(); }
825aa485 349
42cf5bc1 350 //! Sets if the structure location has mutable nature (content or location will be changed regularly).
351 Standard_EXPORT void SetMutable (const Standard_Boolean theIsMutable);
352
353 //! Returns true if structure has mutable nature (content or location are be changed regularly).
354 //! Mutable structure will be managed in different way than static onces.
355 Standard_EXPORT Standard_Boolean IsMutable() const;
356
357 Standard_EXPORT Graphic3d_TypeOfStructure ComputeVisual() const;
358
359 //! Clears the structure <me>.
360 Standard_EXPORT void GraphicClear (const Standard_Boolean WithDestruction);
361
362 Standard_EXPORT void GraphicConnect (const Handle(Graphic3d_Structure)& ADaughter);
363
364 Standard_EXPORT void GraphicDisconnect (const Handle(Graphic3d_Structure)& ADaughter);
365
366 //! Highlights the structure <me>.
367 Standard_EXPORT void GraphicHighlight (const Aspect_TypeOfHighlightMethod Method);
368
1f7f5a90 369 //! Internal method which sets new transformation without calling graphic manager callbacks.
370 Standard_EXPORT void GraphicTransform (const Handle(Geom_Transformation)& theTrsf);
42cf5bc1 371
372 //! Suppress the highlight for the structure <me>.
373 Standard_EXPORT void GraphicUnHighlight();
374
375 //! Returns the identification number of the structure <me>.
376 Standard_EXPORT Standard_Integer Identification() const;
377
378 //! Prints informations about the network associated
379 //! with the structure <AStructure>.
380 Standard_EXPORT static void PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType);
381
382 //! Suppress the adress <APtr> in the list
383 //! of descendants or in the list of ancestors.
384 Standard_EXPORT void Remove (const Standard_Address APtr, const Graphic3d_TypeOfConnection AType);
385
386 Standard_EXPORT void SetComputeVisual (const Graphic3d_TypeOfStructure AVisual);
387
1f7f5a90 388 //! Transforms theX, theY, theZ with the transformation theTrsf.
389 Standard_EXPORT static void Transforms (const gp_Trsf& theTrsf,
390 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
391 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ);
392
42cf5bc1 393 //! Returns the low-level structure
778cd667 394 const Handle(Graphic3d_CStructure)& CStructure() const { return myCStructure; }
42cf5bc1 395
396friend class Graphic3d_Group;
397
398
92efcf78 399 DEFINE_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared)
42cf5bc1 400
401protected:
402
42cf5bc1 403 //! Transforms boundaries with <theTrsf> transformation.
1f7f5a90 404 Standard_EXPORT static void TransformBoundaries (const gp_Trsf& theTrsf,
405 Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
406 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax);
407
42cf5bc1 408 //! Appends new descendant structure.
409 Standard_EXPORT Standard_Boolean AppendDescendant (const Standard_Address theDescendant);
410
411 //! Removes the given descendant structure.
412 Standard_EXPORT Standard_Boolean RemoveDescendant (const Standard_Address theDescendant);
413
414 //! Appends new ancestor structure.
415 Standard_EXPORT Standard_Boolean AppendAncestor (const Standard_Address theAncestor);
416
417 //! Removes the given ancestor structure.
418 Standard_EXPORT Standard_Boolean RemoveAncestor (const Standard_Address theAncestor);
419
42cf5bc1 420private:
421
42cf5bc1 422 //! Suppress in the structure <me>, the group theGroup.
423 //! It will be erased at the next screen update.
424 Standard_EXPORT void Remove (const Handle(Graphic3d_Group)& theGroup);
425
426 //! Manages the number of groups in the structure <me>
427 //! which contains facet.
428 //! Polygons, Triangles or Quadrangles.
429 //! <ADelta> = +1 or -1
430 Standard_EXPORT void GroupsWithFacet (const Standard_Integer ADelta);
431
432 //! Returns the extreme coordinates found in the structure <me> without transformation applied.
433 Standard_EXPORT Graphic3d_BndBox4f minMaxCoord() const;
434
435 //! Gets untransformed bounding box from structure.
436 Standard_EXPORT void getBox (Graphic3d_BndBox4d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
437
438 //! Adds transformed (with myCStructure->Transformation) bounding box of structure to theBox.
439 Standard_EXPORT void addTransformed (Graphic3d_BndBox4d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
440
441 //! Returns the manager to which <me> is associated.
442 Standard_EXPORT Handle(Graphic3d_StructureManager) StructureManager() const;
443
50d06d8f 444 //! Calls the Update method of the StructureManager which contains the Structure <me>.
445 //! If theUpdateLayer is true then invalidates bounding box of ZLayer.
446 Standard_EXPORT void Update (const bool theUpdateLayer = false) const;
2831708b 447
448protected:
42cf5bc1 449
59ec40f8 450 Graphic3d_StructureManager* myStructureManager;
451 Graphic3d_StructureManager* myFirstStructureManager;
452 Graphic3d_TypeOfStructure myComputeVisual;
453
42cf5bc1 454 Handle(Graphic3d_CStructure) myCStructure;
455 Graphic3d_IndexedMapOfAddress myAncestors;
456 Graphic3d_IndexedMapOfAddress myDescendants;
457 Quantity_Color myHighlightColor;
458 Aspect_TypeOfHighlightMethod myHighlightMethod;
459 Standard_Address myOwner;
460 Graphic3d_TypeOfStructure myVisual;
461
42cf5bc1 462};
463
42cf5bc1 464#endif // _Graphic3d_Structure_HeaderFile