1 // Copyright (c) 2015 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_CView_HeaderFile
15 #define _Graphic3d_CView_HeaderFile
17 #include <Aspect_Handle.hxx>
18 #include <Aspect_RenderingContext.hxx>
19 #include <Aspect_Window.hxx>
20 #include <Graphic3d_BufferType.hxx>
21 #include <Graphic3d_Camera.hxx>
22 #include <Graphic3d_CubeMap.hxx>
23 #include <Graphic3d_CLight.hxx>
24 #include <Graphic3d_CStructure.hxx>
25 #include <Graphic3d_DataStructureManager.hxx>
26 #include <Graphic3d_DiagnosticInfo.hxx>
27 #include <Graphic3d_GraduatedTrihedron.hxx>
28 #include <Graphic3d_MapOfStructure.hxx>
29 #include <Graphic3d_NMapOfTransient.hxx>
30 #include <Graphic3d_RenderingParams.hxx>
31 #include <Graphic3d_SequenceOfHClipPlane.hxx>
32 #include <Graphic3d_SequenceOfStructure.hxx>
33 #include <Graphic3d_Structure.hxx>
34 #include <Graphic3d_TextureEnv.hxx>
35 #include <Graphic3d_TypeOfAnswer.hxx>
36 #include <Graphic3d_TypeOfBackfacingModel.hxx>
37 #include <Graphic3d_TypeOfShadingModel.hxx>
38 #include <Graphic3d_TypeOfVisualization.hxx>
39 #include <Graphic3d_Vec3.hxx>
40 #include <Graphic3d_ZLayerId.hxx>
41 #include <Graphic3d_ZLayerSettings.hxx>
42 #include <Image_PixMap.hxx>
43 #include <Quantity_NameOfColor.hxx>
44 #include <Standard_Address.hxx>
45 #include <Standard_Transient.hxx>
46 #include <TColStd_IndexedDataMapOfStringString.hxx>
48 class Graphic3d_CView;
49 class Graphic3d_GraphicDriver;
50 class Graphic3d_Layer;
51 class Graphic3d_StructureManager;
53 DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager)
55 //! Base class of a graphical view that carries out rendering process for a concrete
56 //! implementation of graphical driver. Provides virtual interfaces for redrawing its
57 //! contents, management of displayed structures and render settings. The source code
58 //! of the class itself implements functionality related to management of
59 //! computed (HLR or "view-dependent") structures.
60 class Graphic3d_CView : public Graphic3d_DataStructureManager
62 friend class Graphic3d_StructureManager;
63 DEFINE_STANDARD_RTTIEXT(Graphic3d_CView, Graphic3d_DataStructureManager)
67 Standard_EXPORT Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr);
70 Standard_EXPORT virtual ~Graphic3d_CView();
72 //! Returns the identification number of the view.
73 Standard_Integer Identification() const { return myId; }
75 //! Activates the view. Maps presentations defined within structure manager onto this view.
76 Standard_EXPORT virtual void Activate();
78 //! Deactivates the view. Unmaps presentations defined within structure manager.
79 //! The view in deactivated state will ignore actions on structures such as Display().
80 Standard_EXPORT virtual void Deactivate();
82 //! Returns the activity flag of the view.
83 Standard_Boolean IsActive() const { return myIsActive; }
85 //! Erases the view and removes from graphic driver.
86 //! No more graphic operations are allowed in this view after the call.
87 Standard_EXPORT virtual void Remove();
89 //! Returns true if the view was removed.
90 Standard_Boolean IsRemoved() const { return myIsRemoved; }
92 //! Returns camera object of the view.
93 virtual const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
95 //! Sets camera used by the view.
96 virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
100 //! Returns default Shading Model of the view; Graphic3d_TOSM_FRAGMENT by default.
101 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
103 //! Sets default Shading Model of the view.
104 //! Will throw an exception on attempt to set Graphic3d_TOSM_DEFAULT.
105 Standard_EXPORT void SetShadingModel (Graphic3d_TypeOfShadingModel theModel);
107 //! Returns visualization type of the view.
108 Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; }
110 //! Sets visualization type of the view.
111 void SetVisualizationType (const Graphic3d_TypeOfVisualization theType) { myVisualization = theType; }
113 //! Switches computed HLR mode in the view
114 Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode);
116 //! Returns the computed HLR mode state
117 Standard_Boolean ComputedMode() const { return myIsInComputedMode; }
119 //! Computes the new presentation of the structure displayed in this view with the type Graphic3d_TOS_COMPUTED.
120 Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure);
122 //! Invalidates bounding box of specified ZLayerId.
123 Standard_EXPORT void Update (const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN);
125 //! Computes the new presentation of the structures displayed in this view with the type Graphic3d_TOS_COMPUTED.
126 Standard_EXPORT void Compute();
128 //! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles.
129 Standard_EXPORT Standard_Boolean ContainsFacet() const;
131 //! Returns Standard_True if one of the structures in the set contains Polygons, Triangles or Quadrangles.
132 Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& theSet) const;
134 //! Returns the set of structures displayed in this view.
135 Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const;
137 //! Returns number of displayed structures in the view.
138 virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
140 //! Returns map of objects hidden within this specific view (not viewer-wise).
141 const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; }
143 //! Returns map of objects hidden within this specific view (not viewer-wise).
144 Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; }
146 //! Returns Standard_True in case if the structure with the given <theStructId> is
147 //! in list of structures to be computed and stores computed struct to <theComputedStruct>.
148 Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId,
149 Handle(Graphic3d_Structure)& theComputedStruct) const;
151 //! Returns the bounding box of all structures displayed in the view.
152 //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
153 //! of graphical elements forming parts of infinite and other auxiliary structures.
154 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
155 //! @return computed bounding box
156 Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
158 //! Returns the coordinates of the boundary box of all structures in the set <theSet>.
159 //! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box
160 //! also includes minimum and maximum limits of graphical elements
161 //! forming parts of infinite structures.
162 Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet,
163 const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
165 //! Returns the structure manager handle which manage structures associated with this view.
166 const Handle(Graphic3d_StructureManager)& StructureManager() const { return myStructureManager; }
170 //! Is it possible to display the structure in the view?
171 Standard_EXPORT Graphic3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const;
173 //! Clears the structure in this view.
174 Standard_EXPORT void Clear (Graphic3d_Structure* theStructure,
175 const Standard_Boolean theWithDestruction);
177 //! Connects the structures.
178 Standard_EXPORT void Connect (const Graphic3d_Structure* theMother,
179 const Graphic3d_Structure* theDaughter);
181 //! Disconnects the structures.
182 Standard_EXPORT void Disconnect (const Graphic3d_Structure* theMother,
183 const Graphic3d_Structure* theDaughter);
185 //! Displays the structure in the view.
186 Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure);
188 //! Erases the structure from the view.
189 Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure);
191 //! Highlights the structure in the view.
192 Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& theStructure);
194 //! Transforms the structure in the view.
195 Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure,
196 const Handle(Geom_Transformation)& theTrsf);
198 //! Suppress the highlighting on the structure <AStructure>
199 //! in the view <me>.
200 Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& theStructure);
202 //! Returns an index != 0 if the structure have another structure computed for the view <me>.
203 Standard_EXPORT Standard_Integer IsComputed (const Graphic3d_Structure* theStructure) const;
205 Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& theStructure) const { return IsComputed (theStructure.get()); }
207 //! Returns true if the structure is displayed in the view.
208 Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const;
210 //! Changes the display priority of the structure.
211 Standard_EXPORT void ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
212 const Standard_Integer theOldPriority,
213 const Standard_Integer theNewPriority);
215 //! Change Z layer of already displayed structure in the view.
216 Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
217 const Graphic3d_ZLayerId theLayerId);
219 //! Returns an index != 0 if the structure have the same owner than another structure
220 //! in the sequence of the computed structures.
221 Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const;
225 //! Redraw content of the view.
226 virtual void Redraw() = 0;
228 //! Redraw immediate content of the view.
229 virtual void RedrawImmediate() = 0;
231 //! Invalidates content of the view but does not redraw it.
232 virtual void Invalidate() = 0;
234 //! Return true if view content cache has been invalidated.
235 virtual Standard_Boolean IsInvalidated() = 0;
237 //! Handle changing size of the rendering window.
238 virtual void Resized() = 0;
240 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
241 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
242 //! Fast, so preferred for interactive work (used by default).
243 //! However these extra drawings will be missed in image dump since it is performed from back buffer.
244 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
245 //! in run-time (in case of slow hardware) and/or tearing may appear.
246 //! So this is strongly recommended to draw only simple (fast) structures.
247 //! 2. FALSE. Drawing immediate mode structures to the back buffer.
248 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
249 //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
250 //! from the back buffer.
251 //! @return previous mode.
252 virtual Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) = 0;
254 //! Creates and maps rendering window to the view.
255 //! @param theWindow [in] the window.
256 //! @param theContext [in] the rendering context. If NULL the context will be created internally.
257 virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
258 const Aspect_RenderingContext theContext = NULL) = 0;
260 //! Returns the window associated to the view.
261 virtual Handle(Aspect_Window) Window() const = 0;
263 //! Returns True if the window associated to the view is defined.
264 virtual Standard_Boolean IsDefined() const = 0;
266 //! Dump active rendering buffer into specified memory buffer.
267 virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
269 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
270 virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) = 0;
272 //! Add a layer to the view.
273 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
274 //! @param theSettings [in] new layer settings
275 //! @param theLayerAfter [in] id of layer to append new layer before
276 virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
277 const Graphic3d_ZLayerSettings& theSettings,
278 const Graphic3d_ZLayerId theLayerAfter) = 0;
280 //! Add a layer to the view.
281 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
282 //! @param theSettings [in] new layer settings
283 //! @param theLayerBefore [in] id of layer to append new layer after
284 virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
285 const Graphic3d_ZLayerSettings& theSettings,
286 const Graphic3d_ZLayerId theLayerBefore) = 0;
288 //! Returns the maximum Z layer ID.
289 //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
290 virtual Standard_Integer ZLayerMax() const = 0;
292 //! Returns the list of layers.
293 virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const = 0;
295 //! Returns layer with given ID or NULL if undefined.
296 virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const = 0;
298 //! Returns the bounding box of all structures displayed in the Z layer.
299 Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId);
301 //! Remove Z layer from the specified view. All structures
302 //! displayed at the moment in layer will be displayed in default layer
303 //! ( the bottom-level z layer ). To unset layer ID from associated
304 //! structures use method UnsetZLayer (...).
305 virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
307 //! Sets the settings for a single Z layer of specified view.
308 virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
309 const Graphic3d_ZLayerSettings& theSettings) = 0;
311 //! Returns zoom-scale factor.
312 Standard_EXPORT Standard_Real ConsiderZoomPersistenceObjects();
314 //! Returns pointer to an assigned framebuffer object.
315 virtual Handle(Standard_Transient) FBO() const = 0;
317 //! Sets framebuffer object for offscreen rendering.
318 virtual void SetFBO (const Handle(Standard_Transient)& theFbo) = 0;
320 //! Generate offscreen FBO in the graphic library.
321 //! If not supported on hardware returns NULL.
322 virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
323 const Standard_Integer theHeight) = 0;
325 //! Remove offscreen FBO from the graphic library
326 virtual void FBORelease (Handle(Standard_Transient)& theFbo) = 0;
328 //! Read offscreen FBO configuration.
329 virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
330 Standard_Integer& theWidth,
331 Standard_Integer& theHeight,
332 Standard_Integer& theWidthMax,
333 Standard_Integer& theHeightMax) = 0;
335 //! Change offscreen FBO viewport.
336 virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
337 const Standard_Integer theWidth,
338 const Standard_Integer theHeight) = 0;
342 //! Copy visualization settings from another view.
343 //! Method is used for cloning views in viewer when its required to create view
344 //! with same view properties.
345 Standard_EXPORT virtual void CopySettings (const Handle(Graphic3d_CView)& theOther);
347 //! Returns current rendering parameters and effect settings.
348 const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; }
350 //! Returns reference to current rendering parameters and effect settings.
351 Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; }
353 //! Returns background fill color.
354 virtual Aspect_Background Background() const { return Aspect_Background (myBgColor.GetRGB()); }
356 //! Sets background fill color.
357 virtual void SetBackground (const Aspect_Background& theBackground) { myBgColor.SetRGB (theBackground.Color()); }
359 //! Returns gradient background fill colors.
360 virtual Aspect_GradientBackground GradientBackground() const = 0;
362 //! Sets gradient background fill colors.
363 virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0;
365 //! Returns background image texture file path.
366 virtual TCollection_AsciiString BackgroundImage() = 0;
368 //! Sets background image texture file path.
369 virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) = 0;
371 //! Returns background image fill style.
372 virtual Aspect_FillMethod BackgroundImageStyle() const = 0;
374 //! Sets background image fill style.
375 virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0;
377 //! Returns cubemap being setted last time on background.
378 virtual Handle(Graphic3d_CubeMap) BackgroundCubeMap() const = 0;
380 //! Sets environment cubemap as background.
381 //! @param theCubeMap cubemap source to be set as background
382 //! @param theToUpdatePBREnv defines whether IBL maps will be generated or not (see 'GeneratePBREnvironment')
383 virtual void SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
384 Standard_Boolean theToUpdatePBREnv = Standard_True) = 0;
386 //! Generates PBR specular probe and irradiance map
387 //! in order to provide environment indirect illumination in PBR shading model (Image Based Lighting).
388 //! The source of environment data is background cubemap.
389 //! If PBR is unavailable it does nothing.
390 //! If PBR is available but there is no cubemap being set to background it clears all IBL maps (see 'ClearPBREnvironment').
391 virtual void GeneratePBREnvironment() = 0;
393 //! Fills PBR specular probe and irradiance map with white color.
394 //! So that environment indirect illumination will be constant
395 //! and will be fully controlled by ambient light sources.
396 //! If PBR is unavailable it does nothing.
397 virtual void ClearPBREnvironment() = 0;
399 //! Returns environment texture set for the view.
400 virtual Handle(Graphic3d_TextureEnv) TextureEnv() const = 0;
402 //! Sets environment texture for the view.
403 virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0;
405 //! Return backfacing model used for the view.
406 virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const = 0;
408 //! Sets backfacing model for the view.
409 virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) = 0;
411 //! Returns list of lights of the view.
412 virtual const Handle(Graphic3d_LightSet)& Lights() const = 0;
414 //! Sets list of lights for the view.
415 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) = 0;
417 //! Returns list of clip planes set for the view.
418 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const = 0;
420 //! Sets list of clip planes for the view.
421 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) = 0;
423 //! Fill in the dictionary with diagnostic info.
424 //! Should be called within rendering thread.
426 //! This API should be used only for user output or for creating automated reports.
427 //! The format of returned information (e.g. key-value layout)
428 //! is NOT part of this API and can be changed at any time.
429 //! Thus application should not parse returned information to weed out specific parameters.
430 virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
431 Graphic3d_DiagnosticInfo theFlags) const = 0;
433 //! Returns string with statistic performance info.
434 virtual TCollection_AsciiString StatisticInformation() const = 0;
436 //! Fills in the dictionary with statistic performance info.
437 virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const = 0;
439 public: //! @name obsolete Graduated Trihedron functionality
441 //! Returns data of a graduated trihedron
442 virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; }
444 //! Displays Graduated Trihedron.
445 virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) { (void )theTrihedronData; }
447 //! Erases Graduated Trihedron.
448 virtual void GraduatedTrihedronErase() {}
450 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
451 //! @param theMin [in] the minimum point of scene.
452 //! @param theMax [in] the maximum point of scene.
453 virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
461 //! Adds the structure to display lists of the view.
462 virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
463 const Standard_Integer thePriority) = 0;
465 //! Erases the structure from display lists of the view.
466 virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) = 0;
468 //! Change Z layer of a structure already presented in view.
469 virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
470 const Graphic3d_ZLayerId theNewLayerId) = 0;
472 //! Changes the priority of a structure within its Z layer in the specified view.
473 virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
474 const Standard_Integer theNewPriority) = 0;
478 Standard_Integer myId;
479 Graphic3d_RenderingParams myRenderParams;
480 Quantity_ColorRGBA myBgColor;
481 Handle(Graphic3d_StructureManager) myStructureManager;
482 Handle(Graphic3d_Camera) myCamera;
483 Graphic3d_SequenceOfStructure myStructsToCompute;
484 Graphic3d_SequenceOfStructure myStructsComputed;
485 Graphic3d_MapOfStructure myStructsDisplayed;
486 Handle(Graphic3d_NMapOfTransient) myHiddenObjects;
487 Standard_Boolean myIsInComputedMode;
488 Standard_Boolean myIsActive;
489 Standard_Boolean myIsRemoved;
490 Graphic3d_TypeOfShadingModel myShadingModel;
491 Graphic3d_TypeOfVisualization myVisualization;
495 Graphic3d_GraduatedTrihedron myGTrihedronData;
499 #endif // _Graphic3d_CView_HeaderFile