0030635: Visualization - move OpenGl_Layer to Graphic3d_Layer
[occt.git] / src / Graphic3d / Graphic3d_CView.hxx
1 // Copyright (c) 2015 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Graphic3d_CView_HeaderFile
15 #define _Graphic3d_CView_HeaderFile
16
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>
46
47 class Graphic3d_CView;
48 class Graphic3d_GraphicDriver;
49 class Graphic3d_StructureManager;
50
51 DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager)
52
53 //! Base class of a graphical view that carries out rendering process for a concrete
54 //! implementation of graphical driver. Provides virtual interfaces for redrawing its
55 //! contents, management of displayed structures and render settings. The source code 
56 //! of the class itself implements functionality related to management of
57 //! computed (HLR or "view-dependent") structures.
58 class Graphic3d_CView : public Graphic3d_DataStructureManager
59 {
60   friend class Graphic3d_StructureManager;
61   DEFINE_STANDARD_RTTIEXT(Graphic3d_CView, Graphic3d_DataStructureManager)
62 public:
63
64   //! Constructor.
65   Standard_EXPORT Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr);
66
67   //! Destructor.
68   Standard_EXPORT virtual ~Graphic3d_CView();
69
70   //! Returns the identification number of the view.
71   Standard_Integer Identification() const { return myId; }
72
73   //! Activates the view. Maps presentations defined within structure manager onto this view.
74   Standard_EXPORT virtual void Activate();
75
76   //! Deactivates the view. Unmaps presentations defined within structure manager.
77   //! The view in deactivated state will ignore actions on structures such as Display().
78   Standard_EXPORT virtual void Deactivate();
79
80   //! Returns the activity flag of the view.
81   Standard_Boolean IsActive() const { return myIsActive; }
82
83   //! Erases the view and removes from graphic driver.
84   //! No more graphic operations are allowed in this view after the call.
85   Standard_EXPORT virtual void Remove();
86
87   //! Returns true if the view was removed.
88   Standard_Boolean IsRemoved() const { return myIsRemoved; }
89
90   //! Returns camera object of the view.
91   virtual const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
92
93   //! Sets camera used by the view.
94   virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
95
96 public:
97
98   //! Returns default Shading Model of the view; Graphic3d_TOSM_FRAGMENT by default.
99   Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
100
101   //! Sets default Shading Model of the view.
102   //! Will throw an exception on attempt to set Graphic3d_TOSM_DEFAULT.
103   Standard_EXPORT void SetShadingModel (Graphic3d_TypeOfShadingModel theModel);
104
105   //! Returns visualization type of the view.
106   Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; }
107
108   //! Sets visualization type of the view.
109   void SetVisualizationType (const Graphic3d_TypeOfVisualization theType) { myVisualization = theType; }
110
111   //! Switches computed HLR mode in the view
112   Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode);
113
114   //! Returns the computed HLR mode state
115   Standard_Boolean ComputedMode() const { return myIsInComputedMode; }
116
117   //! Computes the new presentation of the structure  displayed in this view with the type Graphic3d_TOS_COMPUTED.
118   Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure);
119
120   //! Invalidates bounding box of specified ZLayerId.
121   Standard_EXPORT void Update (const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN);
122
123   //! Computes the new presentation of the structures displayed in this view with the type Graphic3d_TOS_COMPUTED.
124   Standard_EXPORT void Compute();
125
126   //! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles.
127   Standard_EXPORT Standard_Boolean ContainsFacet() const;
128
129   //! Returns Standard_True if one of the structures in the set contains Polygons, Triangles or Quadrangles.
130   Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& theSet) const;
131
132   //! Returns the set of structures displayed in this view.
133   Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const;
134
135   //! Returns number of displayed structures in the view.
136   virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
137
138   //! Returns map of objects hidden within this specific view (not viewer-wise).
139   const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; }
140
141   //! Returns map of objects hidden within this specific view (not viewer-wise).
142   Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; }
143
144   //! Returns Standard_True in case if the structure with the given <theStructId> is
145   //! in list of structures to be computed and stores computed struct to <theComputedStruct>.
146   Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId,
147                                                Handle(Graphic3d_Structure)& theComputedStruct) const;
148
149   //! Returns the bounding box of all structures displayed in the view.
150   //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
151   //! of graphical elements forming parts of infinite and other auxiliary structures.
152   //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
153   //! @return computed bounding box
154   Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
155
156   //! Returns the coordinates of the boundary box of all structures in the set <theSet>.
157   //! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box
158   //! also includes minimum and maximum limits of graphical elements
159   //! forming parts of infinite structures.
160   Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet,
161                                         const Standard_Boolean theToIncludeAuxiliary = Standard_False) const;
162
163   //! Returns the structure manager handle which manage structures associated with this view.
164   const Handle(Graphic3d_StructureManager)& StructureManager() const { return myStructureManager; }
165
166 private:
167
168   //! Is it possible to display the structure in the view?
169   Standard_EXPORT Graphic3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const;
170
171   //! Clears the structure in this view.
172   Standard_EXPORT void Clear (const Handle(Graphic3d_Structure)& theStructure, const Standard_Boolean theWithDestruction);
173
174   //! Connects the structures.
175   Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& theMother,
176                                 const Handle(Graphic3d_Structure)& theDaughter);
177
178   //! Disconnects the structures.
179   Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& theMother,
180                                    const Handle(Graphic3d_Structure)& theDaughter);
181
182   //! Displays the structure in the view.
183   Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure);
184
185   //! Erases the structure from the view.
186   Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure);
187
188   //! Highlights the structure in the view.
189   Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& theStructure);
190
191   //! Transforms the structure in the view.
192   Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure,
193                                      const Handle(Geom_Transformation)& theTrsf);
194
195   //! Suppress the highlighting on the structure <AStructure>
196   //! in the view <me>.
197   Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& theStructure);
198
199   //! Returns an index != 0 if the structure have another structure computed for the view <me>.
200   Standard_EXPORT Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& theStructure) const;
201
202   //! Returns true if the structure is displayed in the view.
203   Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const;
204
205   //! Changes the display priority of the structure.
206   Standard_EXPORT void ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
207                                        const Standard_Integer theOldPriority,
208                                        const Standard_Integer theNewPriority);
209
210   //! Change Z layer of already displayed structure in the view.
211   Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
212                                      const Graphic3d_ZLayerId theLayerId);
213
214   //! Returns an index != 0 if the structure have the same owner than another structure
215   //! in the sequence of the computed structures.
216   Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const;
217
218 public:
219
220   //! Redraw content of the view.
221   virtual void Redraw() = 0;
222
223   //! Redraw immediate content of the view.
224   virtual void RedrawImmediate() = 0;
225
226   //! Invalidates content of the view but does not redraw it.
227   virtual void Invalidate() = 0;
228
229   //! Return true if view content cache has been invalidated.
230   virtual Standard_Boolean IsInvalidated() = 0;
231
232   //! Handle changing size of the rendering window.
233   virtual void Resized() = 0;
234
235   //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
236   //! 1. TRUE.  Drawing immediate mode structures directly to the front buffer over the scene image.
237   //! Fast, so preferred for interactive work (used by default).
238   //! However these extra drawings will be missed in image dump since it is performed from back buffer.
239   //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
240   //! in run-time (in case of slow hardware) and/or tearing may appear.
241   //! So this is strongly recommended to draw only simple (fast) structures.
242   //! 2. FALSE. Drawing immediate mode structures to the back buffer.
243   //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
244   //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
245   //! from the back buffer.
246   //! @return previous mode.
247   virtual Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) = 0;
248
249   //! Creates and maps rendering window to the view.
250   //! @param theWindow [in] the window.
251   //! @param theContext [in] the rendering context. If NULL the context will be created internally.
252   virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
253                           const Aspect_RenderingContext theContext = NULL) = 0;
254
255   //! Returns the window associated to the view.
256   virtual Handle(Aspect_Window) Window() const = 0;
257
258   //! Returns True if the window associated to the view is defined.
259   virtual Standard_Boolean IsDefined() const = 0;
260
261   //! Dump active rendering buffer into specified memory buffer.
262   virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
263
264   //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
265   virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) = 0;
266
267   //! Add a new top-level z layer with ID <theLayerId> for
268   //! the view. Z layers allow drawing structures in higher layers
269   //! in foreground of structures in lower layers. To add a structure
270   //! to desired layer on display it is necessary to set the layer
271   //! ID for the structure.
272   virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
273
274   //! Returns the maximum Z layer ID.
275   //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
276   virtual Standard_Integer ZLayerMax() const = 0;
277
278   //! Returns the bounding box of all structures displayed in the Z layer.
279   virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const = 0;
280
281   //! Returns the bounding box of all structures displayed in the Z layer.
282   //! @param theLayerId            layer identifier
283   //! @param theCamera             camera definition
284   //! @param theWindowWidth        viewport width  (for applying transformation-persistence)
285   //! @param theWindowHeight       viewport height (for applying transformation-persistence)
286   //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
287   //! @return computed bounding box
288   virtual Bnd_Box ZLayerBoundingBox (const Graphic3d_ZLayerId        theLayerId,
289                                      const Handle(Graphic3d_Camera)& theCamera,
290                                      const Standard_Integer          theWindowWidth,
291                                      const Standard_Integer          theWindowHeight,
292                                      const Standard_Boolean          theToIncludeAuxiliary) const = 0;
293
294   //! Remove Z layer from the specified view. All structures
295   //! displayed at the moment in layer will be displayed in default layer
296   //! ( the bottom-level z layer ). To unset layer ID from associated
297   //! structures use method UnsetZLayer (...).
298   virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
299
300   //! Sets the settings for a single Z layer of specified view.
301   virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
302                                   const Graphic3d_ZLayerSettings& theSettings) = 0;
303
304   //! Returns zoom-scale factor.
305   Standard_EXPORT Standard_Real ConsiderZoomPersistenceObjects();
306
307   //! Returns pointer to an assigned framebuffer object.
308   virtual Handle(Standard_Transient) FBO() const = 0;
309
310   //! Sets framebuffer object for offscreen rendering.
311   virtual void SetFBO (const Handle(Standard_Transient)& theFbo) = 0;
312
313   //! Generate offscreen FBO in the graphic library.
314   //! If not supported on hardware returns NULL.
315   virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
316                                                 const Standard_Integer theHeight) = 0;
317
318   //! Remove offscreen FBO from the graphic library
319   virtual void FBORelease (Handle(Standard_Transient)& theFbo) = 0;
320
321   //! Read offscreen FBO configuration.
322   virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
323                                  Standard_Integer& theWidth,
324                                  Standard_Integer& theHeight,
325                                  Standard_Integer& theWidthMax,
326                                  Standard_Integer& theHeightMax) = 0;
327
328   //! Change offscreen FBO viewport.
329   virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
330                                   const Standard_Integer theWidth,
331                                   const Standard_Integer theHeight) = 0;
332
333 public:
334
335   //! Copy visualization settings from another view.
336   //! Method is used for cloning views in viewer when its required to create view
337   //! with same view properties.
338   Standard_EXPORT virtual void CopySettings (const Handle(Graphic3d_CView)& theOther);
339
340   //! Returns current rendering parameters and effect settings.
341   const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; }
342
343   //! Returns reference to current rendering parameters and effect settings.
344   Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; }
345
346   //! Returns background  fill color.
347   virtual Aspect_Background Background() const { return Aspect_Background (myBgColor.GetRGB()); }
348
349   //! Sets background fill color.
350   virtual void SetBackground (const Aspect_Background& theBackground) { myBgColor.SetRGB (theBackground.Color()); }
351
352   //! Returns gradient background fill colors.
353   virtual Aspect_GradientBackground GradientBackground() const = 0;
354
355   //! Sets gradient background fill colors.
356   virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0;
357
358   //! Returns background image texture file path.
359   virtual TCollection_AsciiString BackgroundImage() = 0;
360
361   //! Sets background image texture file path.
362   virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) = 0;
363
364   //! Returns background image fill style.
365   virtual Aspect_FillMethod BackgroundImageStyle() const = 0;
366
367   //! Sets background image fill style.
368   virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0;
369
370   //! Returns environment texture set for the view.
371   virtual Handle(Graphic3d_TextureEnv) TextureEnv() const = 0; 
372
373   //! Sets environment texture for the view.
374   virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0;
375
376   //! Return backfacing model used for the view.
377   virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const = 0;
378
379   //! Sets backfacing model for the view.
380   virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) = 0;
381
382   //! Returns list of lights of the view.
383   virtual const Handle(Graphic3d_LightSet)& Lights() const = 0;
384
385   //! Sets list of lights for the view.
386   virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) = 0;
387
388   //! Returns list of clip planes set for the view.
389   virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const = 0;
390
391   //! Sets list of clip planes for the view.
392   virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) = 0;
393
394   //! Fill in the dictionary with diagnostic info.
395   //! Should be called within rendering thread.
396   //!
397   //! This API should be used only for user output or for creating automated reports.
398   //! The format of returned information (e.g. key-value layout)
399   //! is NOT part of this API and can be changed at any time.
400   //! Thus application should not parse returned information to weed out specific parameters.
401   virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
402                                       Graphic3d_DiagnosticInfo theFlags) const = 0;
403
404   //! Returns string with statistic performance info.
405   virtual TCollection_AsciiString StatisticInformation() const = 0;
406
407   //! Fills in the dictionary with statistic performance info.
408   virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const = 0;
409
410 public: //! @name obsolete Graduated Trihedron functionality
411
412   //! Returns data of a graduated trihedron
413   virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; }
414
415   //! Displays Graduated Trihedron.
416   virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) { (void )theTrihedronData; }
417
418   //! Erases Graduated Trihedron.
419   virtual void GraduatedTrihedronErase() {}
420
421   //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
422   //! @param theMin [in] the minimum point of scene.
423   //! @param theMax [in] the maximum point of scene.
424   virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
425   {
426     (void )theMin;
427     (void )theMax;
428   }
429
430 private:
431
432   //! Adds the structure to display lists of the view.
433   virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
434                                  const Standard_Integer thePriority) = 0;
435
436   //! Erases the structure from display lists of the view.
437   virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) = 0;
438
439   //! Change Z layer of a structure already presented in view.
440   virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
441                              const Graphic3d_ZLayerId theNewLayerId) = 0;
442
443   //! Changes the priority of a structure within its Z layer in the specified view.
444   virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
445                                const Standard_Integer theNewPriority) = 0;
446
447   //! Returns zoom-scale factor.
448   virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId        theLayerId,
449                                                         const Handle(Graphic3d_Camera)& theCamera,
450                                                         const Standard_Integer          theWindowWidth,
451                                                         const Standard_Integer          theWindowHeight) const = 0;
452
453 protected:
454
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;
469
470 protected:
471
472   Graphic3d_GraduatedTrihedron myGTrihedronData;
473
474 };
475
476 #endif // _Graphic3d_CView_HeaderFile