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_CLight.hxx>
23 #include <Graphic3d_CStructure.hxx>
24 #include <Graphic3d_DataStructureManager.hxx>
25 #include <Graphic3d_DiagnosticInfo.hxx>
26 #include <Graphic3d_GraduatedTrihedron.hxx>
27 #include <Graphic3d_MapOfStructure.hxx>
28 #include <Graphic3d_NMapOfTransient.hxx>
29 #include <Graphic3d_RenderingParams.hxx>
30 #include <Graphic3d_SequenceOfHClipPlane.hxx>
31 #include <Graphic3d_SequenceOfStructure.hxx>
32 #include <Graphic3d_Structure.hxx>
33 #include <Graphic3d_TextureEnv.hxx>
34 #include <Graphic3d_TypeOfAnswer.hxx>
35 #include <Graphic3d_TypeOfBackfacingModel.hxx>
36 #include <Graphic3d_TypeOfShadingModel.hxx>
37 #include <Graphic3d_TypeOfVisualization.hxx>
38 #include <Graphic3d_Vec3.hxx>
39 #include <Graphic3d_ZLayerId.hxx>
40 #include <Graphic3d_ZLayerSettings.hxx>
41 #include <Image_PixMap.hxx>
42 #include <Quantity_NameOfColor.hxx>
43 #include <Standard_Address.hxx>
44 #include <Standard_Transient.hxx>
45 #include <TColStd_IndexedDataMapOfStringString.hxx>
47 class Graphic3d_CView;
48 class Graphic3d_GraphicDriver;
49 class Graphic3d_Layer;
50 class Graphic3d_StructureManager;
52 DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager)
54 //! Base class of a graphical view that carries out rendering process for a concrete
55 //! implementation of graphical driver. Provides virtual interfaces for redrawing its
56 //! contents, management of displayed structures and render settings. The source code
57 //! of the class itself implements functionality related to management of
58 //! computed (HLR or "view-dependent") structures.
59 class Graphic3d_CView : public Graphic3d_DataStructureManager
61 friend class Graphic3d_StructureManager;
62 DEFINE_STANDARD_RTTIEXT(Graphic3d_CView, Graphic3d_DataStructureManager)
66 Standard_EXPORT Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr);
69 Standard_EXPORT virtual ~Graphic3d_CView();
71 //! Returns the identification number of the view.
72 Standard_Integer Identification() const { return myId; }
74 //! Activates the view. Maps presentations defined within structure manager onto this view.
75 Standard_EXPORT virtual void Activate();
77 //! Deactivates the view. Unmaps presentations defined within structure manager.
78 //! The view in deactivated state will ignore actions on structures such as Display().
79 Standard_EXPORT virtual void Deactivate();
81 //! Returns the activity flag of the view.
82 Standard_Boolean IsActive() const { return myIsActive; }
84 //! Erases the view and removes from graphic driver.
85 //! No more graphic operations are allowed in this view after the call.
86 Standard_EXPORT virtual void Remove();
88 //! Returns true if the view was removed.
89 Standard_Boolean IsRemoved() const { return myIsRemoved; }
91 //! Returns camera object of the view.
92 virtual const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
94 //! Sets camera used by the view.
95 virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
99 //! Returns default Shading Model of the view; Graphic3d_TOSM_FRAGMENT by default.
100 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
102 //! Sets default Shading Model of the view.
103 //! Will throw an exception on attempt to set Graphic3d_TOSM_DEFAULT.
104 Standard_EXPORT void SetShadingModel (Graphic3d_TypeOfShadingModel theModel);
106 //! Returns visualization type of the view.
107 Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; }
109 //! Sets visualization type of the view.
110 void SetVisualizationType (const Graphic3d_TypeOfVisualization theType) { myVisualization = theType; }
112 //! Switches computed HLR mode in the view
113 Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode);
115 //! Returns the computed HLR mode state
116 Standard_Boolean ComputedMode() const { return myIsInComputedMode; }
118 //! Computes the new presentation of the structure displayed in this view with the type Graphic3d_TOS_COMPUTED.
119 Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure);
121 //! Invalidates bounding box of specified ZLayerId.
122 Standard_EXPORT void Update (const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN);
124 //! Computes the new presentation of the structures displayed in this view with the type Graphic3d_TOS_COMPUTED.
125 Standard_EXPORT void Compute();
127 //! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles.
128 Standard_EXPORT Standard_Boolean ContainsFacet() const;
130 //! Returns Standard_True if one of the structures in the set contains Polygons, Triangles or Quadrangles.
131 Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& theSet) const;
133 //! Returns the set of structures displayed in this view.
134 Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const;
136 //! Returns number of displayed structures in the view.
137 virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
139 //! Returns map of objects hidden within this specific view (not viewer-wise).
140 const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; }
142 //! Returns map of objects hidden within this specific view (not viewer-wise).
143 Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; }
145 //! Returns Standard_True in case if the structure with the given <theStructId> is
146 //! in list of structures to be computed and stores computed struct to <theComputedStruct>.
147 Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId,
148 Handle(Graphic3d_Structure)& theComputedStruct) const;
150 //! Returns the bounding box of all structures displayed in the view.
151 //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
152 //! of graphical elements forming parts of infinite and other auxiliary structures.
153 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
154 //! @return computed bounding box
155 Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
157 //! Returns the coordinates of the boundary box of all structures in the set <theSet>.
158 //! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box
159 //! also includes minimum and maximum limits of graphical elements
160 //! forming parts of infinite structures.
161 Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet,
162 const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
164 //! Returns the structure manager handle which manage structures associated with this view.
165 const Handle(Graphic3d_StructureManager)& StructureManager() const { return myStructureManager; }
169 //! Is it possible to display the structure in the view?
170 Standard_EXPORT Graphic3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const;
172 //! Clears the structure in this view.
173 Standard_EXPORT void Clear (Graphic3d_Structure* theStructure,
174 const Standard_Boolean theWithDestruction);
176 //! Connects the structures.
177 Standard_EXPORT void Connect (const Graphic3d_Structure* theMother,
178 const Graphic3d_Structure* theDaughter);
180 //! Disconnects the structures.
181 Standard_EXPORT void Disconnect (const Graphic3d_Structure* theMother,
182 const Graphic3d_Structure* theDaughter);
184 //! Displays the structure in the view.
185 Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure);
187 //! Erases the structure from the view.
188 Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure);
190 //! Highlights the structure in the view.
191 Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& theStructure);
193 //! Transforms the structure in the view.
194 Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure,
195 const Handle(Geom_Transformation)& theTrsf);
197 //! Suppress the highlighting on the structure <AStructure>
198 //! in the view <me>.
199 Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& theStructure);
201 //! Returns an index != 0 if the structure have another structure computed for the view <me>.
202 Standard_EXPORT Standard_Integer IsComputed (const Graphic3d_Structure* theStructure) const;
204 Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& theStructure) const { return IsComputed (theStructure.get()); }
206 //! Returns true if the structure is displayed in the view.
207 Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const;
209 //! Changes the display priority of the structure.
210 Standard_EXPORT void ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
211 const Standard_Integer theOldPriority,
212 const Standard_Integer theNewPriority);
214 //! Change Z layer of already displayed structure in the view.
215 Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
216 const Graphic3d_ZLayerId theLayerId);
218 //! Returns an index != 0 if the structure have the same owner than another structure
219 //! in the sequence of the computed structures.
220 Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const;
224 //! Redraw content of the view.
225 virtual void Redraw() = 0;
227 //! Redraw immediate content of the view.
228 virtual void RedrawImmediate() = 0;
230 //! Invalidates content of the view but does not redraw it.
231 virtual void Invalidate() = 0;
233 //! Return true if view content cache has been invalidated.
234 virtual Standard_Boolean IsInvalidated() = 0;
236 //! Handle changing size of the rendering window.
237 virtual void Resized() = 0;
239 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
240 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
241 //! Fast, so preferred for interactive work (used by default).
242 //! However these extra drawings will be missed in image dump since it is performed from back buffer.
243 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
244 //! in run-time (in case of slow hardware) and/or tearing may appear.
245 //! So this is strongly recommended to draw only simple (fast) structures.
246 //! 2. FALSE. Drawing immediate mode structures to the back buffer.
247 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
248 //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
249 //! from the back buffer.
250 //! @return previous mode.
251 virtual Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) = 0;
253 //! Creates and maps rendering window to the view.
254 //! @param theWindow [in] the window.
255 //! @param theContext [in] the rendering context. If NULL the context will be created internally.
256 virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
257 const Aspect_RenderingContext theContext = NULL) = 0;
259 //! Returns the window associated to the view.
260 virtual Handle(Aspect_Window) Window() const = 0;
262 //! Returns True if the window associated to the view is defined.
263 virtual Standard_Boolean IsDefined() const = 0;
265 //! Dump active rendering buffer into specified memory buffer.
266 virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
268 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
269 virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) = 0;
271 //! Add a layer to the view.
272 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
273 //! @param theSettings [in] new layer settings
274 //! @param theLayerAfter [in] id of layer to append new layer before
275 virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
276 const Graphic3d_ZLayerSettings& theSettings,
277 const Graphic3d_ZLayerId theLayerAfter) = 0;
279 //! Add a layer to the view.
280 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
281 //! @param theSettings [in] new layer settings
282 //! @param theLayerBefore [in] id of layer to append new layer after
283 virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
284 const Graphic3d_ZLayerSettings& theSettings,
285 const Graphic3d_ZLayerId theLayerBefore) = 0;
287 //! Returns the maximum Z layer ID.
288 //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
289 virtual Standard_Integer ZLayerMax() const = 0;
291 //! Returns the list of layers.
292 virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const = 0;
294 //! Returns layer with given ID or NULL if undefined.
295 virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const = 0;
297 //! Returns the bounding box of all structures displayed in the Z layer.
298 Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId);
300 //! Remove Z layer from the specified view. All structures
301 //! displayed at the moment in layer will be displayed in default layer
302 //! ( the bottom-level z layer ). To unset layer ID from associated
303 //! structures use method UnsetZLayer (...).
304 virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
306 //! Sets the settings for a single Z layer of specified view.
307 virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
308 const Graphic3d_ZLayerSettings& theSettings) = 0;
310 //! Returns zoom-scale factor.
311 Standard_EXPORT Standard_Real ConsiderZoomPersistenceObjects();
313 //! Returns pointer to an assigned framebuffer object.
314 virtual Handle(Standard_Transient) FBO() const = 0;
316 //! Sets framebuffer object for offscreen rendering.
317 virtual void SetFBO (const Handle(Standard_Transient)& theFbo) = 0;
319 //! Generate offscreen FBO in the graphic library.
320 //! If not supported on hardware returns NULL.
321 virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
322 const Standard_Integer theHeight) = 0;
324 //! Remove offscreen FBO from the graphic library
325 virtual void FBORelease (Handle(Standard_Transient)& theFbo) = 0;
327 //! Read offscreen FBO configuration.
328 virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
329 Standard_Integer& theWidth,
330 Standard_Integer& theHeight,
331 Standard_Integer& theWidthMax,
332 Standard_Integer& theHeightMax) = 0;
334 //! Change offscreen FBO viewport.
335 virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
336 const Standard_Integer theWidth,
337 const Standard_Integer theHeight) = 0;
341 //! Copy visualization settings from another view.
342 //! Method is used for cloning views in viewer when its required to create view
343 //! with same view properties.
344 Standard_EXPORT virtual void CopySettings (const Handle(Graphic3d_CView)& theOther);
346 //! Returns current rendering parameters and effect settings.
347 const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; }
349 //! Returns reference to current rendering parameters and effect settings.
350 Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; }
352 //! Returns background fill color.
353 virtual Aspect_Background Background() const { return Aspect_Background (myBgColor.GetRGB()); }
355 //! Sets background fill color.
356 virtual void SetBackground (const Aspect_Background& theBackground) { myBgColor.SetRGB (theBackground.Color()); }
358 //! Returns gradient background fill colors.
359 virtual Aspect_GradientBackground GradientBackground() const = 0;
361 //! Sets gradient background fill colors.
362 virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0;
364 //! Returns background image texture file path.
365 virtual TCollection_AsciiString BackgroundImage() = 0;
367 //! Sets background image texture file path.
368 virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) = 0;
370 //! Returns background image fill style.
371 virtual Aspect_FillMethod BackgroundImageStyle() const = 0;
373 //! Sets background image fill style.
374 virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0;
376 //! Returns environment texture set for the view.
377 virtual Handle(Graphic3d_TextureEnv) TextureEnv() const = 0;
379 //! Sets environment texture for the view.
380 virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0;
382 //! Return backfacing model used for the view.
383 virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const = 0;
385 //! Sets backfacing model for the view.
386 virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) = 0;
388 //! Returns list of lights of the view.
389 virtual const Handle(Graphic3d_LightSet)& Lights() const = 0;
391 //! Sets list of lights for the view.
392 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) = 0;
394 //! Returns list of clip planes set for the view.
395 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const = 0;
397 //! Sets list of clip planes for the view.
398 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) = 0;
400 //! Fill in the dictionary with diagnostic info.
401 //! Should be called within rendering thread.
403 //! This API should be used only for user output or for creating automated reports.
404 //! The format of returned information (e.g. key-value layout)
405 //! is NOT part of this API and can be changed at any time.
406 //! Thus application should not parse returned information to weed out specific parameters.
407 virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
408 Graphic3d_DiagnosticInfo theFlags) const = 0;
410 //! Returns string with statistic performance info.
411 virtual TCollection_AsciiString StatisticInformation() const = 0;
413 //! Fills in the dictionary with statistic performance info.
414 virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const = 0;
416 public: //! @name obsolete Graduated Trihedron functionality
418 //! Returns data of a graduated trihedron
419 virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; }
421 //! Displays Graduated Trihedron.
422 virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) { (void )theTrihedronData; }
424 //! Erases Graduated Trihedron.
425 virtual void GraduatedTrihedronErase() {}
427 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
428 //! @param theMin [in] the minimum point of scene.
429 //! @param theMax [in] the maximum point of scene.
430 virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
438 //! Adds the structure to display lists of the view.
439 virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
440 const Standard_Integer thePriority) = 0;
442 //! Erases the structure from display lists of the view.
443 virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) = 0;
445 //! Change Z layer of a structure already presented in view.
446 virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
447 const Graphic3d_ZLayerId theNewLayerId) = 0;
449 //! Changes the priority of a structure within its Z layer in the specified view.
450 virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
451 const Standard_Integer theNewPriority) = 0;
455 Standard_Integer myId;
456 Graphic3d_RenderingParams myRenderParams;
457 Quantity_ColorRGBA myBgColor;
458 Handle(Graphic3d_StructureManager) myStructureManager;
459 Handle(Graphic3d_Camera) myCamera;
460 Graphic3d_SequenceOfStructure myStructsToCompute;
461 Graphic3d_SequenceOfStructure myStructsComputed;
462 Graphic3d_MapOfStructure myStructsDisplayed;
463 Handle(Graphic3d_NMapOfTransient) myHiddenObjects;
464 Standard_Boolean myIsInComputedMode;
465 Standard_Boolean myIsActive;
466 Standard_Boolean myIsRemoved;
467 Graphic3d_TypeOfShadingModel myShadingModel;
468 Graphic3d_TypeOfVisualization myVisualization;
472 Graphic3d_GraduatedTrihedron myGTrihedronData;
476 #endif // _Graphic3d_CView_HeaderFile