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_ExportFormat.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_SortType.hxx>
34 #include <Graphic3d_Structure.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_TypeOfAnswer.hxx>
37 #include <Graphic3d_TypeOfBackfacingModel.hxx>
38 #include <Graphic3d_TypeOfShadingModel.hxx>
39 #include <Graphic3d_TypeOfVisualization.hxx>
40 #include <Graphic3d_Vec3.hxx>
41 #include <Graphic3d_ZLayerId.hxx>
42 #include <Graphic3d_ZLayerSettings.hxx>
43 #include <Image_PixMap.hxx>
44 #include <Quantity_NameOfColor.hxx>
45 #include <Standard_Address.hxx>
46 #include <Standard_Transient.hxx>
47 #include <TColStd_IndexedDataMapOfStringString.hxx>
49 class Graphic3d_CView;
50 class Graphic3d_GraphicDriver;
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; }
94 //! Returns default Shading Model of the view; Graphic3d_TOSM_FRAGMENT by default.
95 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
97 //! Sets default Shading Model of the view.
98 //! Will throw an exception on attempt to set Graphic3d_TOSM_DEFAULT.
99 Standard_EXPORT void SetShadingModel (Graphic3d_TypeOfShadingModel theModel);
101 //! Returns visualization type of the view.
102 Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; }
104 //! Sets visualization type of the view.
105 void SetVisualizationType (const Graphic3d_TypeOfVisualization theType) { myVisualization = theType; }
107 //! Switches computed HLR mode in the view
108 Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode);
110 //! Returns the computed HLR mode state
111 Standard_Boolean ComputedMode() const { return myIsInComputedMode; }
113 //! Computes the new presentation of the structure displayed in this view with the type Graphic3d_TOS_COMPUTED.
114 Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure);
116 //! Invalidates bounding box of specified ZLayerId.
117 Standard_EXPORT void Update (const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN);
119 //! Computes the new presentation of the structures displayed in this view with the type Graphic3d_TOS_COMPUTED.
120 Standard_EXPORT void Compute();
122 //! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles.
123 Standard_EXPORT Standard_Boolean ContainsFacet() const;
125 //! Returns Standard_True if one of the structures in the set contains Polygons, Triangles or Quadrangles.
126 Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& theSet) const;
128 //! Returns the set of structures displayed in this view.
129 Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const;
131 //! Returns number of displayed structures in the view.
132 virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
134 //! Returns map of objects hidden within this specific view (not viewer-wise).
135 const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; }
137 //! Returns map of objects hidden within this specific view (not viewer-wise).
138 Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; }
140 //! Returns Standard_True in case if the structure with the given <theStructId> is
141 //! in list of structures to be computed and stores computed struct to <theComputedStruct>.
142 Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId,
143 Handle(Graphic3d_Structure)& theComputedStruct) const;
145 //! Returns the bounding box of all structures displayed in the view.
146 //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
147 //! of graphical elements forming parts of infinite and other auxiliary structures.
148 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
149 //! @return computed bounding box
150 Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
152 //! Returns the coordinates of the boundary box of all structures in the set <theSet>.
153 //! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box
154 //! also includes minimum and maximum limits of graphical elements
155 //! forming parts of infinite structures.
156 Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet,
157 const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
159 //! Returns the structure manager handle which manage structures associated with this view.
160 const Handle(Graphic3d_StructureManager)& StructureManager() const { return myStructureManager; }
164 //! Is it possible to display the structure in the view?
165 Standard_EXPORT Graphic3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const;
167 //! Clears the structure in this view.
168 Standard_EXPORT void Clear (const Handle(Graphic3d_Structure)& theStructure, const Standard_Boolean theWithDestruction);
170 //! Connects the structures.
171 Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& theMother,
172 const Handle(Graphic3d_Structure)& theDaughter);
174 //! Disconnects the structures.
175 Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& theMother,
176 const Handle(Graphic3d_Structure)& theDaughter);
178 //! Displays the structure in the view.
179 Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure);
181 //! Erases the structure from the view.
182 Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure);
184 //! Highlights the structure in the view.
185 Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& theStructure);
187 //! Transforms the structure in the view.
188 Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure,
189 const Handle(Geom_Transformation)& theTrsf);
191 //! Suppress the highlighting on the structure <AStructure>
192 //! in the view <me>.
193 Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& theStructure);
195 //! Returns an index != 0 if the structure have another structure computed for the view <me>.
196 Standard_EXPORT Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& theStructure) const;
198 //! Returns true if the structure is displayed in the view.
199 Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const;
201 //! Changes the display priority of the structure.
202 Standard_EXPORT void ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
203 const Standard_Integer theOldPriority,
204 const Standard_Integer theNewPriority);
206 //! Change Z layer of already displayed structure in the view.
207 Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
208 const Graphic3d_ZLayerId theLayerId);
210 //! Returns an index != 0 if the structure have the same owner than another structure
211 //! in the sequence of the computed structures.
212 Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const;
216 //! Redraw content of the view.
217 virtual void Redraw() = 0;
219 //! Redraw immediate content of the view.
220 virtual void RedrawImmediate() = 0;
222 //! Invalidates content of the view but does not redraw it.
223 virtual void Invalidate() = 0;
225 //! Return true if view content cache has been invalidated.
226 virtual Standard_Boolean IsInvalidated() = 0;
228 //! Handle changing size of the rendering window.
229 virtual void Resized() = 0;
231 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
232 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
233 //! Fast, so preferred for interactive work (used by default).
234 //! However these extra drawings will be missed in image dump since it is performed from back buffer.
235 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
236 //! in run-time (in case of slow hardware) and/or tearing may appear.
237 //! So this is strongly recommended to draw only simple (fast) structures.
238 //! 2. FALSE. Drawing immediate mode structures to the back buffer.
239 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
240 //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
241 //! from the back buffer.
242 //! @return previous mode.
243 virtual Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) = 0;
245 //! Creates and maps rendering window to the view.
246 //! @param theWindow [in] the window.
247 //! @param theContext [in] the rendering context. If NULL the context will be created internally.
248 virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
249 const Aspect_RenderingContext theContext = NULL) = 0;
251 //! Returns the window associated to the view.
252 virtual Handle(Aspect_Window) Window() const = 0;
254 //! Returns True if the window associated to the view is defined.
255 virtual Standard_Boolean IsDefined() const = 0;
257 //! Returns data of a graduated trihedron
258 virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() = 0;
260 //! Displays Graduated Trihedron.
261 virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) = 0;
263 //! Erases Graduated Trihedron.
264 virtual void GraduatedTrihedronErase() = 0;
266 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
267 //! @param theMin [in] the minimum point of scene.
268 //! @param theMax [in] the maximum point of scene.
269 virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) = 0;
271 //! Dump active rendering buffer into specified memory buffer.
272 virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
274 //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
275 //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits
276 //! on printing to laser printer). Notice however that results may differ a lot and
277 //! do not contain some elements.
278 virtual Standard_Boolean Export (const Standard_CString theFileName,
279 const Graphic3d_ExportFormat theFormat,
280 const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree) = 0;
282 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
283 virtual void InvalidateBVHData (const Standard_Integer theLayerId) = 0;
285 //! Add a new top-level z layer with ID <theLayerId> for
286 //! the view. Z layers allow drawing structures in higher layers
287 //! in foreground of structures in lower layers. To add a structure
288 //! to desired layer on display it is necessary to set the layer
289 //! ID for the structure.
290 virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
292 //! Returns the maximum Z layer ID.
293 //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
294 virtual Standard_Integer ZLayerMax() const = 0;
296 //! Returns the bounding box of all structures displayed in the Z layer.
297 virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const = 0;
299 //! Returns the bounding box of all structures displayed in the Z layer.
300 //! @param theLayerId layer identifier
301 //! @param theCamera camera definition
302 //! @param theWindowWidth viewport width (for applying transformation-persistence)
303 //! @param theWindowHeight viewport height (for applying transformation-persistence)
304 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
305 //! @return computed bounding box
306 virtual Bnd_Box ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
307 const Handle(Graphic3d_Camera)& theCamera,
308 const Standard_Integer theWindowWidth,
309 const Standard_Integer theWindowHeight,
310 const Standard_Boolean theToIncludeAuxiliary) const = 0;
312 //! Remove Z layer from the specified view. All structures
313 //! displayed at the moment in layer will be displayed in default layer
314 //! ( the bottom-level z layer ). To unset layer ID from associated
315 //! structures use method UnsetZLayer (...).
316 virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
318 //! Sets the settings for a single Z layer of specified view.
319 virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
320 const Graphic3d_ZLayerSettings& theSettings) = 0;
322 //! Returns zoom-scale factor.
323 Standard_EXPORT Standard_Real ConsiderZoomPersistenceObjects();
325 //! Returns pointer to an assigned framebuffer object.
326 virtual Handle(Standard_Transient) FBO() const = 0;
328 //! Sets framebuffer object for offscreen rendering.
329 virtual void SetFBO (const Handle(Standard_Transient)& theFbo) = 0;
331 //! Generate offscreen FBO in the graphic library.
332 //! If not supported on hardware returns NULL.
333 virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
334 const Standard_Integer theHeight) = 0;
336 //! Remove offscreen FBO from the graphic library
337 virtual void FBORelease (Handle(Standard_Transient)& theFbo) = 0;
339 //! Read offscreen FBO configuration.
340 virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
341 Standard_Integer& theWidth,
342 Standard_Integer& theHeight,
343 Standard_Integer& theWidthMax,
344 Standard_Integer& theHeightMax) = 0;
346 //! Change offscreen FBO viewport.
347 virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
348 const Standard_Integer theWidth,
349 const Standard_Integer theHeight) = 0;
353 //! Copy visualization settings from another view.
354 //! Method is used for cloning views in viewer when its required to create view
355 //! with same view properties.
356 Standard_EXPORT virtual void CopySettings (const Handle(Graphic3d_CView)& theOther);
358 //! Returns current rendering parameters and effect settings.
359 const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; }
361 //! Returns reference to current rendering parameters and effect settings.
362 Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; }
364 //! Returns background fill color.
365 virtual Aspect_Background Background() const = 0;
367 //! Sets background fill color.
368 virtual void SetBackground (const Aspect_Background& theBackground) = 0;
370 //! Returns gradient background fill colors.
371 virtual Aspect_GradientBackground GradientBackground() const = 0;
373 //! Sets gradient background fill colors.
374 virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0;
376 //! Returns background image texture file path.
377 virtual TCollection_AsciiString BackgroundImage() = 0;
379 //! Sets background image texture file path.
380 virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) = 0;
382 //! Returns background image fill style.
383 virtual Aspect_FillMethod BackgroundImageStyle() const = 0;
385 //! Sets background image fill style.
386 virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0;
388 //! Returns environment texture set for the view.
389 virtual Handle(Graphic3d_TextureEnv) TextureEnv() const = 0;
391 //! Sets environment texture for the view.
392 virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0;
394 //! Returns the state of frustum culling optimization.
395 virtual Standard_Boolean IsCullingEnabled() const = 0;
397 //! Enables or disables frustum culling optimization.
398 virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) = 0;
400 //! Return backfacing model used for the view.
401 virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const = 0;
403 //! Sets backfacing model for the view.
404 virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) = 0;
406 //! Returns camera object of the view.
407 virtual const Handle(Graphic3d_Camera)& Camera() const = 0;
409 //! Sets camera used by the view.
410 virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) = 0;
412 //! Returns list of lights of the view.
413 virtual const Handle(Graphic3d_LightSet)& Lights() const = 0;
415 //! Sets list of lights for the view.
416 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) = 0;
418 //! Returns list of clip planes set for the view.
419 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const = 0;
421 //! Sets list of clip planes for the view.
422 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) = 0;
424 //! Fill in the dictionary with diagnostic info.
425 //! Should be called within rendering thread.
427 //! This API should be used only for user output or for creating automated reports.
428 //! The format of returned information (e.g. key-value layout)
429 //! is NOT part of this API and can be changed at any time.
430 //! Thus application should not parse returned information to weed out specific parameters.
431 virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
432 Graphic3d_DiagnosticInfo theFlags) const = 0;
436 //! Adds the structure to display lists of the view.
437 virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
438 const Standard_Integer thePriority) = 0;
440 //! Erases the structure from display lists of the view.
441 virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) = 0;
443 //! Change Z layer of a structure already presented in view.
444 virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
445 const Graphic3d_ZLayerId theNewLayerId) = 0;
447 //! Changes the priority of a structure within its Z layer in the specified view.
448 virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
449 const Standard_Integer theNewPriority) = 0;
451 //! Returns zoom-scale factor.
452 virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
453 const Handle(Graphic3d_Camera)& theCamera,
454 const Standard_Integer theWindowWidth,
455 const Standard_Integer theWindowHeight) const = 0;
459 Standard_Integer myId;
460 Graphic3d_RenderingParams myRenderParams;
461 Handle(Graphic3d_StructureManager) myStructureManager;
462 Graphic3d_SequenceOfStructure myStructsToCompute;
463 Graphic3d_SequenceOfStructure myStructsComputed;
464 Graphic3d_MapOfStructure myStructsDisplayed;
465 Handle(Graphic3d_NMapOfTransient) myHiddenObjects;
466 Standard_Boolean myIsInComputedMode;
467 Standard_Boolean myIsActive;
468 Standard_Boolean myIsRemoved;
469 Graphic3d_TypeOfShadingModel myShadingModel;
470 Graphic3d_TypeOfVisualization myVisualization;
474 #endif // _Graphic3d_CView_HeaderFile