ccGLWindowInterface.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //Local
  19. #include "ccGLWindowSignalEmitter.h"
  20. //qCC_db
  21. #include <ccGenericGLDisplay.h>
  22. #include <ccGLUtils.h>
  23. #include <ccBBox.h>
  24. //qCC
  25. #include "ccGuiParameters.h"
  26. //Qt
  27. #include <QElapsedTimer>
  28. #include <QOpenGLExtensions>
  29. #include <QOpenGLTexture>
  30. #include <QTimer>
  31. //system
  32. #include <list>
  33. class QDragEnterEvent;
  34. class QDropEvent;
  35. class QEvent;
  36. class QLayout;
  37. class QMouseEvent;
  38. class QOpenGLDebugMessage;
  39. class QOpenGLBuffer;
  40. class QOpenGLContext;
  41. class QWheelEvent;
  42. class ccColorRampShader;
  43. class ccFrameBufferObject;
  44. class ccGlFilter;
  45. class ccInteractor;
  46. class ccPolyline;
  47. class ccShader;
  48. struct HotZone;
  49. //! OpenGL 3D view interface
  50. class CCGLWINDOW_LIB_API ccGLWindowInterface : public ccGenericGLDisplay
  51. {
  52. public:
  53. //! Picking mode
  54. enum PICKING_MODE { NO_PICKING,
  55. ENTITY_PICKING,
  56. ENTITY_RECT_PICKING,
  57. FAST_PICKING,
  58. POINT_PICKING,
  59. TRIANGLE_PICKING,
  60. POINT_OR_TRIANGLE_PICKING,
  61. POINT_OR_TRIANGLE_OR_LABEL_PICKING,
  62. LABEL_PICKING,
  63. DEFAULT_PICKING,
  64. };
  65. //! Interaction flags (mostly with the mouse)
  66. enum INTERACTION_FLAG
  67. {
  68. //no interaction
  69. INTERACT_NONE = 0,
  70. //camera interactions
  71. INTERACT_ROTATE = 1,
  72. INTERACT_PAN = 2,
  73. INTERACT_CTRL_PAN = 4,
  74. INTERACT_ZOOM_CAMERA = 8,
  75. INTERACT_2D_ITEMS = 16, //labels, etc.
  76. INTERACT_CLICKABLE_ITEMS = 32, //hot zone
  77. //options / modifiers
  78. INTERACT_TRANSFORM_ENTITIES = 64,
  79. //signals
  80. INTERACT_SIG_RB_CLICKED = 128, //right button clicked
  81. INTERACT_SIG_LB_CLICKED = 256, //left button clicked
  82. INTERACT_SIG_MOUSE_MOVED = 512, //mouse moved (only if a button is clicked)
  83. INTERACT_SIG_BUTTON_RELEASED = 1024, //mouse button released
  84. INTERACT_SIG_MB_CLICKED = 2048, //middle button clicked
  85. INTERACT_SEND_ALL_SIGNALS = INTERACT_SIG_RB_CLICKED | INTERACT_SIG_LB_CLICKED | INTERACT_SIG_MB_CLICKED | INTERACT_SIG_MOUSE_MOVED | INTERACT_SIG_BUTTON_RELEASED,
  86. // default modes
  87. MODE_PAN_ONLY = INTERACT_PAN | INTERACT_ZOOM_CAMERA | INTERACT_2D_ITEMS | INTERACT_CLICKABLE_ITEMS,
  88. MODE_TRANSFORM_CAMERA = INTERACT_ROTATE | MODE_PAN_ONLY,
  89. MODE_TRANSFORM_ENTITIES = INTERACT_ROTATE | INTERACT_PAN | INTERACT_ZOOM_CAMERA | INTERACT_TRANSFORM_ENTITIES | INTERACT_CLICKABLE_ITEMS,
  90. };
  91. Q_DECLARE_FLAGS(INTERACTION_FLAGS, INTERACTION_FLAG)
  92. //! Default message positions on screen
  93. enum MessagePosition { LOWER_LEFT_MESSAGE,
  94. UPPER_CENTER_MESSAGE,
  95. SCREEN_CENTER_MESSAGE,
  96. };
  97. //! Message type
  98. enum MessageType { CUSTOM_MESSAGE = 0,
  99. SCREEN_SIZE_MESSAGE,
  100. PERSPECTIVE_STATE_MESSAGE,
  101. SUN_LIGHT_STATE_MESSAGE,
  102. CUSTOM_LIGHT_STATE_MESSAGE,
  103. MANUAL_TRANSFORMATION_MESSAGE,
  104. MANUAL_SEGMENTATION_MESSAGE,
  105. ROTAION_LOCK_MESSAGE,
  106. FULL_SCREEN_MESSAGE,
  107. };
  108. //! Pivot symbol visibility
  109. enum PivotVisibility { PIVOT_HIDE,
  110. PIVOT_SHOW_ON_MOVE,
  111. PIVOT_ALWAYS_SHOW,
  112. };
  113. //! Default constructor
  114. ccGLWindowInterface(QObject* parent = nullptr, bool silentInitialization = false);
  115. //! Destructor
  116. virtual ~ccGLWindowInterface();
  117. //! Returns whether this window is a stereo display or not
  118. virtual bool isStereo() const = 0;
  119. // Qt-equivalent shortcuts
  120. virtual qreal getDevicePixelRatio() const = 0;
  121. virtual QFont getFont() const = 0;
  122. virtual QOpenGLContext* getOpenGLContext() const = 0;
  123. virtual void setWindowCursor(const QCursor&) = 0;
  124. virtual void doMakeCurrent() {};
  125. virtual QObject* asQObject() = 0;
  126. virtual const QObject* asQObject() const = 0;
  127. virtual QString getWindowTitle() const = 0;
  128. virtual void doGrabMouse() = 0;
  129. virtual void doReleaseMouse() = 0;
  130. virtual QPoint doMapFromGlobal(const QPoint &) const = 0;
  131. virtual void doShowMaximized() = 0;
  132. virtual void doResize(int w, int h) = 0;
  133. virtual void doResize(const QSize &) = 0;
  134. virtual QImage doGrabFramebuffer() = 0;
  135. //inherited from ccGenericGLDisplay
  136. void refresh(bool only2D = false) override;
  137. void redraw(bool only2D = false, bool resetLOD = true) override;
  138. //! Sets 'scene graph' root
  139. void setSceneDB(ccHObject* root);
  140. //! Returns current 'scene graph' root
  141. inline ccHObject* getSceneDB() { return m_globalDBRoot; }
  142. //replacement for the missing methods of QGLWidget
  143. void renderText(int x, int y, const QString & str, uint16_t uniqueID = 0, const QFont & font = QFont());
  144. void renderText(double x, double y, double z, const QString & str, const QFont & font = QFont());
  145. //inherited from ccGenericGLDisplay
  146. void toBeRefreshed() override;
  147. void invalidateViewport() override { m_validProjectionMatrix = false; }
  148. void deprecate3DLayer() override { m_updateFBO = true; }
  149. void display3DLabel(const QString& str, const CCVector3& pos3D, const ccColor::Rgba* color = nullptr, const QFont& font = QFont()) override;
  150. void displayText(QString text, int x, int y, unsigned char align = ALIGN_DEFAULT, float bkgAlpha = 0.0f, const ccColor::Rgba* color = nullptr, const QFont* font = nullptr) override;
  151. QFont getTextDisplayFont() const override; //takes rendering zoom into account!
  152. QFont getLabelDisplayFont() const override; //takes rendering zoom into account!
  153. const ccViewportParameters& getViewportParameters() const override { return m_viewportParams; }
  154. QPointF toCenteredGLCoordinates(int x, int y) const override;
  155. QPointF toCornerGLCoordinates(int x, int y) const override;
  156. void setupProjectiveViewport(const ccGLMatrixd& cameraMatrix, float fov_deg = 0.0f, bool viewerBasedPerspective = true, bool bubbleViewMode = false) override;
  157. void aboutToBeRemoved(ccDrawableObject* entity) override;
  158. void getGLCameraParameters(ccGLCameraParameters& params) override;
  159. //! Displays a status message in the bottom-left corner
  160. /** WARNING: currently, 'append' is not supported for SCREEN_CENTER_MESSAGE
  161. \param message message (if message is empty and append is 'false', all messages will be cleared)
  162. \param pos message position on screen
  163. \param append whether to append the message or to replace existing one(s) (only messages of the same type are impacted)
  164. \param displayMaxDelay_sec minimum display duration
  165. \param type message type (if not custom, only one message of this type at a time is accepted)
  166. **/
  167. void displayNewMessage( const QString& message,
  168. MessagePosition pos,
  169. bool append=false,
  170. int displayMaxDelay_sec = 2,
  171. MessageType type = CUSTOM_MESSAGE);
  172. //! Activates sun light
  173. void setSunLight(bool state);
  174. //! Toggles sun light
  175. void toggleSunLight();
  176. //! Returns whether sun light is enabled or not
  177. inline bool sunLightEnabled() const { return m_sunLightEnabled; }
  178. //! Activates custom light
  179. void setCustomLight(bool state);
  180. //! Toggles custom light
  181. void toggleCustomLight();
  182. //! Returns whether custom light is enabled or not
  183. inline bool customLightEnabled() const { return m_customLightEnabled; }
  184. //! Returns the current position of the custom light
  185. const CCVector3f getCustomLightPosition() const { return CCVector3f(m_customLightPos); }
  186. //! Sets the position of the custom light
  187. void setCustomLightPosition(const CCVector3f& pos);
  188. //! Sets pivot visibility
  189. void setPivotVisibility(PivotVisibility vis);
  190. //! Returns pivot visibility
  191. inline PivotVisibility getPivotVisibility() const { return m_pivotVisibility; }
  192. //! Shows or hide the pivot symbol
  193. /** Warnings:
  194. - not to be mistaken with setPivotVisibility
  195. - only taken into account if pivot visibility is set to PIVOT_SHOW_ON_MOVE
  196. **/
  197. void showPivotSymbol(bool state);
  198. //! Sets pivot point
  199. /** Emits the 'pivotPointChanged' signal.
  200. **/
  201. void setPivotPoint( const CCVector3d& P,
  202. bool autoUpdateCameraPos = false,
  203. bool verbose = false);
  204. //! Sets camera position
  205. /** Emits the 'cameraPosChanged' signal.
  206. **/
  207. void setCameraPos(const CCVector3d& P);
  208. //! Displaces camera
  209. /** Values are given in objects world along the current camera
  210. viewing directions (we use the right hand rule):
  211. * X: horizontal axis (right)
  212. * Y: vertical axis (up)
  213. * Z: depth axis (pointing out of the screen)
  214. \param v displacement vector
  215. **/
  216. void moveCamera(CCVector3d& v);
  217. //! Sets the OpenGL camera 'focal' distance to achieve a given width (in 'metric' units)
  218. /** The camera will be positionned relatively to the current pivot point
  219. **/
  220. void setCameraFocalToFitWidth(double width);
  221. //! Sets the focal distance
  222. void setFocalDistance(double focalDistance);
  223. //! Set perspective state/mode
  224. /** Persepctive mode can be:
  225. - object-centered (moving the mouse make the object rotate)
  226. - viewer-centered (moving the mouse make the camera move)
  227. \warning Disables bubble-view mode automatically
  228. \param state whether perspective mode is enabled or not
  229. \param objectCenteredView whether view is object- or viewer-centered (forced to true in ortho. mode)
  230. **/
  231. void setPerspectiveState(bool state, bool objectCenteredView);
  232. //! Toggles perspective mode
  233. /** If perspective is activated, the user must specify if it should be
  234. object or viewer based (see setPerspectiveState)
  235. **/
  236. void togglePerspective(bool objectCentered);
  237. //! Returns perspective mode
  238. bool getPerspectiveState(bool& objectCentered) const;
  239. //! Shortcut: returns whether object-based perspective mode is enabled
  240. bool objectPerspectiveEnabled() const;
  241. //! Shortcut: returns whether viewer-based perspective mode is enabled
  242. bool viewerPerspectiveEnabled() const;
  243. //! Sets bubble-view mode state
  244. /** Bubble-view is a kind of viewer-based perspective mode where
  245. the user can't displace the camera (apart from up-down or
  246. left-right rotations). The f.o.v. is also maximized.
  247. \warning Any call to a method that changes the perpsective will
  248. automatically disable this mode.
  249. **/
  250. void setBubbleViewMode(bool state);
  251. //! Returns whether bubble-view mode is enabled or no
  252. inline bool bubbleViewModeEnabled() const { return m_bubbleViewModeEnabled; }
  253. //! Set bubble-view f.o.v. (in degrees)
  254. void setBubbleViewFov(float fov_deg);
  255. //! Center and zoom on a given bounding box
  256. /** If no bounding box is defined, the current displayed 'scene graph'
  257. bounding box is used.
  258. \param boundingBox bounding box to zoom on
  259. **/
  260. void updateConstellationCenterAndZoom(const ccBBox* boundingBox = nullptr);
  261. //! Returns the visible objects bounding-box
  262. void getVisibleObjectsBB(ccBBox& box) const;
  263. //! Rotates the base view matrix
  264. /** Warning: 'base view' marix is either:
  265. - the rotation around the object in object-centered mode
  266. - the rotation around the camera center in viewer-centered mode
  267. (see setPerspectiveState).
  268. **/
  269. void rotateBaseViewMat(const ccGLMatrixd& rotMat);
  270. //! Returns the base view matrix
  271. /** Warning: 'base view' marix is either:
  272. - the rotation around the object in object-centered mode
  273. - the rotation around the camera center in viewer-centered mode
  274. (see setPerspectiveState).
  275. **/
  276. const ccGLMatrixd& getBaseViewMat() { return m_viewportParams.viewMat; }
  277. //! Sets the base view matrix
  278. /** Warning: 'base view' marix is either:
  279. - the rotation around the object in object-centered mode
  280. - the rotation around the camera center in viewer-centered mode
  281. (see setPerspectiveState).
  282. **/
  283. void setBaseViewMat(ccGLMatrixd& mat);
  284. //! Sets camera to a predefined view (top, bottom, etc.)
  285. void setView(CC_VIEW_ORIENTATION orientation, bool redraw = true);
  286. //! Sets camera to a custom view (forward and up directions must be specified)
  287. void setCustomView(const CCVector3d& forward, const CCVector3d& up, bool forceRedraw = true);
  288. //! Sets current interaction flags
  289. void setInteractionMode(INTERACTION_FLAGS flags);
  290. //! Returns the current interaction flags
  291. inline virtual INTERACTION_FLAGS getInteractionMode() const { return m_interactionFlags; }
  292. //! Sets current picking mode
  293. /** Picking can be applied to entities (default), points, triangles, etc.)
  294. \param mode picking mode
  295. \param defaultCursorShape default cursor shape for default, entity or no picking modes
  296. **/
  297. void setPickingMode(PICKING_MODE mode = DEFAULT_PICKING, Qt::CursorShape defaultCursorShape = Qt::ArrowCursor);
  298. //! Returns current picking mode
  299. inline virtual PICKING_MODE getPickingMode() const { return m_pickingMode; }
  300. //! Locks picking mode
  301. /** \warning Bes sure to unlock it at some point ;)
  302. **/
  303. inline virtual void lockPickingMode(bool state) { m_pickingModeLocked = state; }
  304. //! Returns whether picking mode is locked or not
  305. inline virtual bool isPickingModeLocked() const { return m_pickingModeLocked; }
  306. //! Specify whether this 3D window can be closed by the user or not
  307. inline void setUnclosable(bool state) { m_unclosable = state; }
  308. //! Returns context information
  309. virtual void getContext(CC_DRAW_CONTEXT& context);
  310. //! Minimum point size
  311. static constexpr float MIN_POINT_SIZE_F = 1.0f;
  312. //! Maximum point size
  313. static constexpr float MAX_POINT_SIZE_F = 16.0f;
  314. //! Sets point size
  315. /** \param size point size (between MIN_POINT_SIZE_F and MAX_POINT_SIZE_F)
  316. \param silent whether this function can log and/or display messages on the screen
  317. **/
  318. void setPointSize(float size, bool silent = false);
  319. //! Minimum line width
  320. static constexpr float MIN_LINE_WIDTH_F = 1.0f;
  321. //! Maximum line width
  322. static constexpr float MAX_LINE_WIDTH_F = 16.0f;
  323. //! Sets line width
  324. /** \param width lines width (between MIN_LINE_WIDTH_F and MAX_LINE_WIDTH_F)
  325. \param silent whether this function can log and/or display messages on the screen
  326. **/
  327. void setLineWidth(float width, bool silent = false);
  328. //! Returns current font size
  329. int getFontPointSize() const;
  330. //! Returns current font size for labels
  331. int getLabelFontPointSize() const;
  332. //! Returns window own DB
  333. inline ccHObject* getOwnDB() { return m_winDBRoot; }
  334. //! Adds an entity to window own DB
  335. /** By default no dependency link is established between the entity and the window (DB).
  336. **/
  337. void addToOwnDB(ccHObject* obj, bool noDependency = true);
  338. //! Removes an entity from window own DB
  339. void removeFromOwnDB(ccHObject* obj);
  340. //! Sets viewport parameters (all at once)
  341. void setViewportParameters(const ccViewportParameters& params);
  342. //! Sets current camera f.o.v. (field of view) in degrees
  343. /** FOV is only used in perspective mode.
  344. **/
  345. void setFov(float fov);
  346. //! Returns the current f.o.v. (field of view) in degrees
  347. float getFov() const;
  348. //! Whether to allow near and far clipping planes or not
  349. inline void setClippingPlanesEnabled(bool enabled) { m_clippingPlanesEnabled = enabled; }
  350. //! Whether to near and far clipping planes are enabled or not
  351. inline bool clippingPlanesEnabled() const { return m_clippingPlanesEnabled; }
  352. //! Sets near clipping plane depth (or disable it if NaN)
  353. /** \return whether the plane depth was actually changed
  354. **/
  355. bool setNearClippingPlaneDepth(double depth);
  356. //! Sets far clipping plane depth (or disable it if NaN)
  357. /** \return whether the plane depth was actually changed
  358. **/
  359. bool setFarClippingPlaneDepth(double depth);
  360. //! Invalidate current visualization state
  361. /** Forces view matrix update and 3D/FBO display.
  362. **/
  363. inline void invalidateVisualization() { m_validModelviewMatrix = false; }
  364. //! Renders screen to an image
  365. QImage renderToImage( float zoomFactor = 1.0f,
  366. bool dontScaleFeatures = false,
  367. bool renderOverlayItems = false,
  368. bool silent = false );
  369. //! Renders screen to a file
  370. bool renderToFile( QString filename,
  371. float zoomFactor = 1.0f,
  372. bool dontScaleFeatures = false,
  373. bool renderOverlayItems = false );
  374. static void SetShaderPath(const QString &path);
  375. static QString GetShaderPath();
  376. void setShader(ccShader* shader);
  377. void setGlFilter(ccGlFilter* filter);
  378. inline ccGlFilter* getGlFilter() { return m_activeGLFilter; }
  379. inline const ccGlFilter* getGlFilter() const { return m_activeGLFilter; }
  380. inline bool areShadersEnabled() const { return m_shadersEnabled; }
  381. inline bool areGLFiltersEnabled() const { return m_glFiltersEnabled; }
  382. //! Returns the actual pixel size on screen (taking zoom or perspective parameters into account)
  383. /** In perspective mode, this value is approximate (especially if we are in 'viewer-based' viewing mode).
  384. **/
  385. double computeActualPixelSize() const;
  386. //! Returns whether the ColorRamp shader is supported or not
  387. inline bool hasColorRampShader() const { return m_colorRampShader != nullptr; }
  388. //! Returns whether rectangular picking is allowed or not
  389. inline bool isRectangularPickingAllowed() const { return m_allowRectangularEntityPicking; }
  390. //! Sets whether rectangular picking is allowed or not
  391. inline void setRectangularPickingAllowed(bool state) { m_allowRectangularEntityPicking = state; }
  392. //! Returns current parameters for this display (const version)
  393. /** Warning: may return overridden parameters!
  394. **/
  395. const ccGui::ParamStruct& getDisplayParameters() const;
  396. //! Sets current parameters for this display
  397. void setDisplayParameters(const ccGui::ParamStruct& params, bool thisWindowOnly = false);
  398. //! Whether display parameters are overidden for this window
  399. inline bool hasOverriddenDisplayParameters() const { return m_overriddenDisplayParametersEnabled; }
  400. //! Sets picking radius
  401. inline void setPickingRadius(int radius) { m_pickRadius = radius; }
  402. //! Returns the current picking radius
  403. inline int getPickingRadius() const { return m_pickRadius; }
  404. //! Sets whether overlay entities (scale and trihedron) should be displayed or not
  405. inline void displayOverlayEntities(bool showScale, bool showTrihedron) { m_showScale = showScale; m_showTrihedron = showTrihedron; }
  406. //! Returns whether the scale bar is displayed or not
  407. inline bool scaleIsDisplayed() const { return m_showScale; }
  408. //! Returns whether the trihedron is displayed or not
  409. inline bool trihedronIsDisplayed() const { return m_showTrihedron; }
  410. //! Computes the trihedron size (in pixels)
  411. float computeTrihedronLength() const;
  412. //! Returns the height of the 'GL filter' banner
  413. int getGlFilterBannerHeight() const;
  414. //! Returns the extents of the vertical area available for displaying the color ramp
  415. void computeColorRampAreaLimits(int& yStart, int& yStop) const;
  416. //! Backprojects a 2D points on a 3D triangle
  417. /** \warning Uses the current display parameters!
  418. \param P2D point on the screen
  419. \param A3D first vertex of the 3D triangle
  420. \param B3D second vertex of the 3D triangle
  421. \param C3D third vertex of the 3D triangle
  422. \return backprojected point
  423. **/
  424. CCVector3 backprojectPointOnTriangle( const CCVector2i& P2D,
  425. const CCVector3& A3D,
  426. const CCVector3& B3D,
  427. const CCVector3& C3D );
  428. //! Returns unique ID
  429. inline int getUniqueID() const { return m_uniqueID; }
  430. //! Returns the widget width (in pixels)
  431. virtual int qtWidth() const = 0;
  432. //! Returns the widget height (in pixels)
  433. virtual int qtHeight() const = 0;
  434. //! Returns the widget size (in pixels)
  435. virtual QSize qtSize() const = 0;
  436. //! Returns the OpenGL context width
  437. inline int glWidth() const { return m_glViewport.width(); }
  438. //! Returns the OpenGL context height
  439. inline int glHeight() const { return m_glViewport.height(); }
  440. //! Returns the OpenGL context size
  441. inline QSize glSize() const { return m_glViewport.size(); }
  442. public: //LOD
  443. //! Returns whether LOD is enabled on this display or not
  444. inline bool isLODEnabled() const { return m_LODEnabled; }
  445. //! Enables or disables LOD on this display
  446. /** \return success
  447. **/
  448. bool setLODEnabled(bool state, bool autoDisable = false);
  449. public: //fullscreen
  450. //! Toggles (exclusive) full-screen mode
  451. void toggleExclusiveFullScreen(bool state);
  452. //! Returns whether the window is in exclusive full screen mode or not
  453. inline bool exclusiveFullScreen() const { return m_exclusiveFullscreen; }
  454. public: //debug traces on screen
  455. //! Shows debug info on screen
  456. inline void enableDebugTrace(bool state) { m_showDebugTraces = state; }
  457. //! Toggles debug info on screen
  458. inline void toggleDebugTrace() { m_showDebugTraces = !m_showDebugTraces; }
  459. public: //stereo mode
  460. //! Seterovision parameters
  461. struct CCGLWINDOW_LIB_API StereoParams
  462. {
  463. StereoParams();
  464. //! Glass/HMD type
  465. enum GlassType { RED_BLUE = 1,
  466. BLUE_RED = 2,
  467. RED_CYAN = 3,
  468. CYAN_RED = 4,
  469. NVIDIA_VISION = 5,
  470. OCULUS = 6,
  471. GENERIC_STEREO_DISPLAY = 7
  472. };
  473. //! Whether stereo-mode is 'analgyph' or real stereo mode
  474. inline bool isAnaglyph() const { return glassType <= 4; }
  475. int screenWidth_mm;
  476. int screenDistance_mm;
  477. int eyeSeparation_mm;
  478. int stereoStrength;
  479. GlassType glassType;
  480. };
  481. //! Enables stereo display mode
  482. virtual bool enableStereoMode(const StereoParams& params);
  483. //! Disables stereo display mode
  484. virtual void disableStereoMode();
  485. //! Returns whether the stereo display mode is enabled or not
  486. inline bool stereoModeIsEnabled() const { return m_stereoModeEnabled; }
  487. //! Returns the current stereo mode parameters
  488. inline const StereoParams& getStereoParams() const { return m_stereoParams; }
  489. //! Sets whether to display the coordinates of the point below the cursor position
  490. inline void showCursorCoordinates(bool state) { m_showCursorCoordinates = state; }
  491. //! Whether the coordinates of the point below the cursor position are displayed or not
  492. inline bool cursorCoordinatesShown() const { return m_showCursorCoordinates; }
  493. //! Toggles the automatic setting of the pivot point at the center of the screen
  494. void setAutoPickPivotAtCenter(bool state);
  495. //! Whether the pivot point is automatically set at the center of the screen
  496. inline bool autoPickPivotAtCenter() const { return m_autoPickPivotAtCenter; }
  497. //! Lock the rotation axis
  498. void lockRotationAxis(bool state, const CCVector3d& axis);
  499. //! Returns whether the rotation axis is locaked or not
  500. inline bool isRotationAxisLocked() const { return m_rotationAxisLocked; }
  501. public: // other methods
  502. //! Applies a 1:1 global zoom
  503. void zoomGlobal();
  504. //called when receiving mouse wheel is rotated
  505. void onWheelEvent(float wheelDelta_deg);
  506. //! Tests frame rate
  507. void startFrameRateTest();
  508. //! Request an update of the display
  509. /** The request will be executed if not in auto refresh mode already
  510. **/
  511. virtual void requestUpdate() = 0;
  512. //! Returns the signal emitter (const version)
  513. const ccGLWindowSignalEmitter* signalEmitter() const { return m_signalEmitter; }
  514. //! Returns the signal emitter
  515. ccGLWindowSignalEmitter* signalEmitter() { return m_signalEmitter; }
  516. static void Create( ccGLWindowInterface*& window,
  517. QWidget*& widget,
  518. bool stereoMode = false,
  519. bool silentInitialization = false);
  520. static ccGLWindowInterface* FromWidget(QWidget* widget);
  521. static ccGLWindowInterface* FromEmitter(QObject* object);
  522. static ccGLWindowInterface* FromQObject(QObject* object);
  523. static bool StereoSupported();
  524. static void SetStereoSupported(bool state);
  525. static bool TestStereoSupport(bool forceRetest = false);
  526. bool isQuadBufferSupported() const;
  527. //! Sets the display scale (multiplier)
  528. void setDisplayScale(const CCVector2d& scale) { m_displayScale = scale; }
  529. //! Returns the display scale (multiplier)
  530. const CCVector2d& getDisplayScale() const { return m_displayScale; }
  531. protected: //rendering
  532. //Default OpenGL functions set
  533. using ccQOpenGLFunctions = QOpenGLFunctions_2_1;
  534. //! Returns the set of OpenGL functions
  535. virtual ccQOpenGLFunctions* functions() const = 0;
  536. //! Called when the screen is resized
  537. void onResizeGL(int w, int h);
  538. //! Sets the OpenGL viewport
  539. void setGLViewport(const QRect& rect);
  540. //! Sets the OpenGL viewport (shortut)
  541. inline void setGLViewport(int x, int y, int w, int h) { setGLViewport(QRect(x, y, w, h)); }
  542. //! Initialize the OpenGL context
  543. bool initialize();
  544. //! Releases all textures, GL lists, etc.
  545. void uninitializeGL();
  546. //! Rendering method
  547. void doPaintGL();
  548. //! Rendering method custom initialzation step (to be overridden)
  549. virtual bool initPaintGL() { return true; }
  550. //! Swap the OpenGL buffers if necessary (to be overridden)
  551. virtual void swapGLBuffers() { }
  552. //! Called at the very beginning of the initialization process (see initialize)
  553. virtual bool preInitialize(bool& firstTime) { Q_UNUSED(firstTime); return true; }
  554. //! Called at the very end of the initialization process (see initialize)
  555. virtual bool postInitialize(bool firstTime) { Q_UNUSED(firstTime); return true; }
  556. //On some versions of Qt, QGLWidget::renderText seems to need glColorf instead of glColorub!
  557. // See https://bugreports.qt-project.org/browse/QTBUG-6217
  558. template<class QOpenGLFunctions> static void glColor3ubv_safe(QOpenGLFunctions* glFunc, const ccColor::Rgb& color)
  559. {
  560. assert(glFunc);
  561. glFunc->glColor3f( color.r / 255.0f,
  562. color.g / 255.0f,
  563. color.b / 255.0f);
  564. }
  565. template<class QOpenGLFunctions> static void glColor4ubv_safe(QOpenGLFunctions* glFunc, const ccColor::Rgba& color)
  566. {
  567. assert(glFunc);
  568. glFunc->glColor4f( color.r / 255.0f,
  569. color.g / 255.0f,
  570. color.b / 255.0f,
  571. color.a / 255.0f);
  572. }
  573. //! LOD state
  574. struct CCGLWINDOW_LIB_API LODState
  575. {
  576. LODState()
  577. : inProgress(false)
  578. , level(0)
  579. , startIndex(0)
  580. , progressIndicator(0)
  581. {}
  582. //! LOD display in progress
  583. bool inProgress;
  584. //! Currently rendered LOD level
  585. unsigned char level;
  586. //! Currently rendered LOD start index
  587. unsigned startIndex;
  588. //! Currently LOD progress indicator
  589. unsigned progressIndicator;
  590. };
  591. //! Stereo rendering pass
  592. enum StereoRenderingPass
  593. {
  594. MONO_OR_LEFT_RENDERING_PASS = 0,
  595. RIGHT_RENDERING_PASS = 1
  596. };
  597. //! Rendering params
  598. struct RenderingParams
  599. {
  600. // Next LOD state
  601. LODState nextLODState;
  602. // Current pass
  603. StereoRenderingPass pass = MONO_OR_LEFT_RENDERING_PASS;
  604. // 2D background
  605. bool drawBackground = true;
  606. bool clearDepthLayer = true;
  607. bool clearColorLayer = true;
  608. // 3D central layer
  609. bool draw3DPass = true;
  610. bool useFBO = false;
  611. bool draw3DCross = false;
  612. // 2D foreground
  613. bool drawForeground = true;
  614. //! Candidate pivot point(s) (will be used when the mouse is released)
  615. /** Up to 2 candidates, if stereo mode is enabled **/
  616. CCVector3d autoPivotCandidates[2];
  617. bool hasAutoPivotCandidates[2] = { false, false };
  618. };
  619. //! Draws the background layer
  620. /** Background + 2D background objects
  621. **/
  622. void drawBackground(CC_DRAW_CONTEXT& context, RenderingParams& params);
  623. //! Draws the main 3D layer
  624. void draw3D(CC_DRAW_CONTEXT& context, RenderingParams& params);
  625. //! Draws the foreground layer
  626. /** 2D foreground objects / text
  627. **/
  628. void drawForeground(CC_DRAW_CONTEXT& context, RenderingParams& params);
  629. //! Renders the next L.O.D. level
  630. void renderNextLODLevel();
  631. //! Full rendering pass (drawBackground + draw3D + drawForeground)
  632. void fullRenderingPass(CC_DRAW_CONTEXT& context, RenderingParams& params);
  633. //! Draws pivot point symbol in 3D
  634. void drawPivot();
  635. //! To be overriden
  636. /** \return whether the viewport is modified **/
  637. virtual bool prepareOtherStereoGlassType(CC_DRAW_CONTEXT& context, RenderingParams& params, ccFrameBufferObject*& currentFBO) { return false; }
  638. //! To be overriden
  639. virtual void processOtherStereoGlassType(RenderingParams& params) {}
  640. //! To be overriden
  641. /** \return whether a custom camera projection was set **/
  642. virtual bool setCustomCameraProjection(RenderingParams& params, ccGLMatrixd& modelViewMat, ccGLMatrixd& projectionMat) { return false; }
  643. protected: //other methods
  644. // Qt-equivalent shortcuts
  645. virtual QSurfaceFormat getSurfaceFormat() const = 0;
  646. virtual void doSetMouseTracking(bool enable) = 0;
  647. virtual void doShowFullScreen() = 0;
  648. virtual void doShowNormal() = 0;
  649. void processMousePressEvent(QMouseEvent *event);
  650. void processMouseDoubleClickEvent(QMouseEvent *event);
  651. void processMouseMoveEvent(QMouseEvent *event);
  652. void processMouseReleaseEvent(QMouseEvent *event);
  653. void processWheelEvent(QWheelEvent* event);
  654. //! Enables stereo display mode (advanced mode)
  655. bool enableStereoMode(const StereoParams& params, bool needSecondFBO, bool needAutoRefresh);
  656. //! Action when a 'drag' event is received
  657. void doDragEnterEvent(QDragEnterEvent* event);
  658. //! Action when a 'drop' event is received
  659. void doDropEvent(QDropEvent* event);
  660. //! Reacts to the itemPickedFast signal
  661. void onItemPickedFast(ccHObject* pickedEntity, int pickedItemIndex, int x, int y);
  662. //! Checks for scheduled redraw
  663. void checkScheduledRedraw();
  664. //! Performs standard picking at the last clicked mouse position (see m_lastMousePos)
  665. void doPicking();
  666. //! Binds an FBO or releases the current one (if input is nullptr)
  667. /** This method must be called instead of the FBO's own 'start' and 'stop' methods
  668. so as to properly handle the interactions with QOpenGLWidget's own FBO.
  669. **/
  670. bool bindFBO(ccFrameBufferObject* fbo);
  671. //these methods are now protected to prevent issues with Retina or other high DPI displays
  672. //(see glWidth(), glHeight(), qtWidth(), qtHeight(), qtSize(), glSize()
  673. virtual int width() const = 0;
  674. virtual int height() const = 0;
  675. virtual QSize size() const = 0;
  676. //! Returns the current (OpenGL) view matrix
  677. /** Warning: may be different from the 'view' matrix returned by getBaseViewMat.
  678. Will call automatically updateModelViewMatrix if necessary.
  679. **/
  680. const ccGLMatrixd& getModelViewMatrix();
  681. //! Returns the current (OpenGL) projection matrix
  682. /** Will call automatically updateProjectionMatrix if necessary.
  683. **/
  684. const ccGLMatrixd& getProjectionMatrix();
  685. //! Processes the clickable items
  686. /** \return true if an item has been clicked
  687. **/
  688. bool processClickableItems(int x, int y);
  689. //! Sets current font size
  690. /** Warning: only used internally.
  691. Change 'defaultFontSize' with setDisplayParameters instead!
  692. **/
  693. void setFontPointSize(int pixelSize);
  694. virtual GLuint defaultQtFBO() const = 0;
  695. //! Computes the model view matrix
  696. ccGLMatrixd computeModelViewMatrix() const;
  697. //! Optional output metrics (from computeProjectionMatrix)
  698. struct ProjectionMetrics;
  699. //! Computes the projection matrix
  700. /** \param[in] withGLfeatures whether to take additional elements (pivot symbol, custom light, etc.) into account or not
  701. \param[out] metrics [optional] output other metrics (Znear and Zfar, etc.)
  702. \param[out] eyeOffset [optional] eye offset (for stereo display)
  703. **/
  704. ccGLMatrixd computeProjectionMatrix( bool withGLfeatures,
  705. ProjectionMetrics* metrics = nullptr,
  706. double* eyeOffset = nullptr) const;
  707. void updateModelViewMatrix();
  708. void updateProjectionMatrix();
  709. void setStandardOrthoCenter();
  710. void setStandardOrthoCorner();
  711. //Lights controls (OpenGL scripts)
  712. void glEnableSunLight();
  713. void glDisableSunLight();
  714. void glEnableCustomLight();
  715. void glDisableCustomLight();
  716. void drawCustomLight();
  717. //! Picking parameters
  718. struct PickingParameters
  719. {
  720. //! Default constructor
  721. PickingParameters(PICKING_MODE _mode = NO_PICKING,
  722. int _centerX = 0,
  723. int _centerY = 0,
  724. int _pickWidth = 5,
  725. int _pickHeight = 5,
  726. bool _pickInSceneDB = true,
  727. bool _pickInLocalDB = true)
  728. : mode(_mode)
  729. , centerX(_centerX)
  730. , centerY(_centerY)
  731. , pickWidth(_pickWidth)
  732. , pickHeight(_pickHeight)
  733. , pickInSceneDB(_pickInSceneDB)
  734. , pickInLocalDB(_pickInLocalDB)
  735. {}
  736. PICKING_MODE mode;
  737. int centerX;
  738. int centerY;
  739. int pickWidth;
  740. int pickHeight;
  741. bool pickInSceneDB;
  742. bool pickInLocalDB;
  743. };
  744. //! Starts picking process
  745. /** \param params picking parameters
  746. **/
  747. void startPicking(PickingParameters& params);
  748. //! Performs the picking with OpenGL (color-based)
  749. void startOpenGLPicking(const PickingParameters& params);
  750. //! Starts OpenGL picking process
  751. void startCPUBasedPointPicking(const PickingParameters& params);
  752. //! Processes the picking process result and sends the corresponding signal
  753. void processPickingResult( const PickingParameters& params,
  754. ccHObject* pickedEntity,
  755. int pickedItemIndex,
  756. const CCVector3* nearestPoint = nullptr,
  757. const CCVector3d* nearestPointBC = nullptr, //barycentric coordinates
  758. const std::unordered_set<int>* selectedIDs = nullptr);
  759. //! Updates currently active items list (m_activeItems)
  760. /** The items must be currently displayed in this context
  761. AND at least one of them must be under the mouse cursor.
  762. **/
  763. void updateActiveItemsList(int x, int y, bool extendToSelectedLabels = false);
  764. //! Currently active items
  765. /** Active items can be moved with mouse, etc.
  766. **/
  767. std::unordered_set<ccInteractor*> m_activeItems;
  768. //! Inits FBO (frame buffer object)
  769. bool initFBO(int w, int h);
  770. //! Inits FBO (safe)
  771. bool initFBOSafe(ccFrameBufferObject* &fbo, int w, int h);
  772. //! Releases any active FBO
  773. void removeFBO();
  774. //! Releases any active FBO (safe)
  775. void removeFBOSafe(ccFrameBufferObject* &fbo);
  776. //! Inits active GL filter (advanced shader)
  777. bool initGLFilter(int w, int h, bool silent = false);
  778. //! Releases active GL filter
  779. void removeGLFilter();
  780. //! Converts a given (mouse) position in pixels to an orientation
  781. /** The orientation vector origin is the current pivot point!
  782. **/
  783. CCVector3d convertMousePositionToOrientation(int x, int y);
  784. //! Draws the 'hot zone' (+/- icons for point size), 'leave bubble-view' button, etc.
  785. void drawClickableItems(int xStart, int& yStart);
  786. //Graphical features controls
  787. void drawCross();
  788. void drawTrihedron();
  789. void drawScale(const ccColor::Rgbub& color);
  790. //! Disables current LOD rendering cycle
  791. void stopLODCycle();
  792. //! Schedules a full redraw
  793. /** Any previously scheduled redraw will be cancelled.
  794. \warning The redraw will be cancelled if redraw/update is called before.
  795. \param maxDelay_ms the maximum delay for the call to redraw (in ms)
  796. **/
  797. void scheduleFullRedraw(unsigned maxDelay_ms);
  798. //! Cancels any scheduled redraw
  799. /** See ccGLWindowInterface::scheduleFullRedraw.
  800. **/
  801. void cancelScheduledRedraw();
  802. //! Logs a GL error
  803. /** Logs a warning or error message corresponding to the input GL error.
  804. If error == GL_NO_ERROR, nothing is logged.
  805. \param error GL error code
  806. \param context name of the method/object that catched the error
  807. **/
  808. static void LogGLError(GLenum error, const char* context);
  809. //! Logs a GL error (shortcut)
  810. void logGLError(const char* context) const;
  811. //! Toggles auto-refresh mode
  812. void toggleAutoRefresh(bool state, int period_ms = 0);
  813. //! Returns the (relative) depth value at a given pixel position
  814. /** \return the (relative) depth or 1.0 if none is defined
  815. **/
  816. GLfloat getGLDepth(int x, int y, bool extendToNeighbors = false, bool usePBO = false);
  817. //! Returns the approximate 3D position of the clicked pixel
  818. bool getClick3DPos(int x, int y, CCVector3d& P3D, bool usePBO);
  819. //! Computes the default increment (for moving the perspective camera, the cutting planes, etc.)
  820. double computeDefaultIncrement() const;
  821. bool processEvents(QEvent* evt);
  822. //! Stops frame rate test
  823. void stopFrameRateTest();
  824. //! Returns whether the frame rate test is in progress or not
  825. bool isFrameRateTestInProgress();
  826. //! Updates the frame rate test
  827. /** \return whether the frame rate test is in progress or not
  828. **/
  829. void updateFrameRateTest();
  830. protected: //members
  831. //! Unique ID
  832. int m_uniqueID;
  833. //! Initialization state
  834. bool m_initialized;
  835. //! Trihedron GL list
  836. GLuint m_trihedronGLList;
  837. //! Pivot center GL list
  838. GLuint m_pivotGLList;
  839. //! Viewport parameters (zoom, etc.)
  840. ccViewportParameters m_viewportParams;
  841. //! Last mouse position
  842. QPoint m_lastMousePos;
  843. //! Complete visualization matrix (GL style - double version)
  844. ccGLMatrixd m_viewMatd;
  845. //! Whether the model veiw matrix is valid (or need to be recomputed)
  846. bool m_validModelviewMatrix;
  847. //! Projection matrix (GL style - double version)
  848. ccGLMatrixd m_projMatd;
  849. //! Whether the projection matrix is valid (or need to be recomputed)
  850. bool m_validProjectionMatrix;
  851. //! Bounding-box of the currently visible objects (updated by computeProjectionMatrix)
  852. ccBBox m_visibleObjectsBBox;
  853. //! GL viewport
  854. QRect m_glViewport;
  855. //! Whether L.O.D. (level of detail) is enabled or not
  856. bool m_LODEnabled;
  857. //! Whether L.O.D. should be automatically disabled at the end of the rendering cycle
  858. bool m_LODAutoDisable;
  859. //! Whether the display should be refreshed on next call to 'refresh'
  860. bool m_shouldBeRefreshed;
  861. //! Whether the mouse (cursor) has moved after being pressed or not
  862. bool m_mouseMoved;
  863. //! Whether the mouse is currently pressed or not
  864. bool m_mouseButtonPressed;
  865. //! Whether this 3D window can be closed by the user or not
  866. bool m_unclosable;
  867. //! Current intercation flags
  868. INTERACTION_FLAGS m_interactionFlags;
  869. //! Current picking mode
  870. PICKING_MODE m_pickingMode;
  871. //! Whether picking mode is locked or not
  872. bool m_pickingModeLocked;
  873. //! Display capturing mode options
  874. struct CCGLWINDOW_LIB_API CaptureModeOptions
  875. {
  876. //! Default constructor
  877. CaptureModeOptions()
  878. : enabled(false)
  879. , zoomFactor(1.0f)
  880. , renderOverlayItems(false)
  881. {}
  882. bool enabled;
  883. float zoomFactor;
  884. bool renderOverlayItems;
  885. };
  886. //! Display capturing mode options
  887. CaptureModeOptions m_captureMode;
  888. //! Temporary Message to display in the lower-left corner
  889. struct CCGLWINDOW_LIB_API MessageToDisplay
  890. {
  891. MessageToDisplay()
  892. : messageValidity_sec(0)
  893. , position(LOWER_LEFT_MESSAGE)
  894. , type(CUSTOM_MESSAGE)
  895. {}
  896. //! Message
  897. QString message;
  898. //! Message end time (sec)
  899. qint64 messageValidity_sec;
  900. //! Message position on screen
  901. MessagePosition position;
  902. //! Message type
  903. MessageType type;
  904. };
  905. //! List of messages to display
  906. std::list<MessageToDisplay> m_messagesToDisplay;
  907. //! Last click time (msec)
  908. qint64 m_lastClickTime_ticks;
  909. //! Sun light position
  910. /** Relative to screen.
  911. **/
  912. float m_sunLightPos[4];
  913. //! Whether sun light is enabled or not
  914. bool m_sunLightEnabled;
  915. //! Custom light position
  916. /** Relative to object.
  917. **/
  918. float m_customLightPos[4];
  919. //! Whether custom light is enabled or not
  920. bool m_customLightEnabled;
  921. //! Clickable item
  922. struct CCGLWINDOW_LIB_API ClickableItem
  923. {
  924. enum Role { NO_ROLE,
  925. INCREASE_POINT_SIZE,
  926. DECREASE_POINT_SIZE,
  927. INCREASE_LINE_WIDTH,
  928. DECREASE_LINE_WIDTH,
  929. LEAVE_BUBBLE_VIEW_MODE,
  930. LEAVE_FULLSCREEN_MODE,
  931. };
  932. ClickableItem(): role(NO_ROLE) {}
  933. ClickableItem(Role _role, QRect _area) : role(_role), area(_area) {}
  934. Role role;
  935. QRect area;
  936. };
  937. //! Currently displayed clickable items
  938. std::vector<ClickableItem> m_clickableItems;
  939. //! Whether clickable items are visible (= mouse over) or not
  940. bool m_clickableItemsVisible;
  941. //! Currently active shader
  942. ccShader* m_activeShader;
  943. //! Whether shaders are enabled or not
  944. bool m_shadersEnabled;
  945. //! Currently active FBO (frame buffer object)
  946. ccFrameBufferObject* m_activeFbo;
  947. //! First default FBO (frame buffer object)
  948. ccFrameBufferObject* m_fbo;
  949. //! Second default FBO (frame buffer object) - used for stereo rendering
  950. ccFrameBufferObject* m_fbo2;
  951. //! Picking FBO (frame buffer object)
  952. ccFrameBufferObject* m_pickingFbo;
  953. //! Whether to always use FBO or only for GL filters
  954. bool m_alwaysUseFBO;
  955. //! Whether FBO should be updated (or simply displayed as a texture = faster!)
  956. bool m_updateFBO;
  957. // Color ramp shader
  958. ccColorRampShader* m_colorRampShader;
  959. // Custom rendering shader (OpenGL 3.3+)
  960. ccShader* m_customRenderingShader;
  961. //! Active GL filter
  962. ccGlFilter* m_activeGLFilter;
  963. //! Whether GL filters are enabled or not
  964. bool m_glFiltersEnabled;
  965. //! Window own DB
  966. ccHObject* m_winDBRoot;
  967. //! CC main DB
  968. ccHObject* m_globalDBRoot;
  969. //! Default font
  970. QFont m_font;
  971. //! Pivot symbol visibility
  972. PivotVisibility m_pivotVisibility;
  973. //! Whether pivot symbol should be shown or not
  974. bool m_pivotSymbolShown;
  975. //! Whether rectangular picking is allowed or not
  976. bool m_allowRectangularEntityPicking;
  977. //! Rectangular picking polyline
  978. ccPolyline* m_rectPickingPoly;
  979. //! Overridden display parameter
  980. ccGui::ParamStruct m_overriddenDisplayParameters;
  981. //! Whether display parameters are overidden for this window
  982. bool m_overriddenDisplayParametersEnabled;
  983. //! Whether to display the scale bar
  984. bool m_showScale;
  985. //! Whether to display the trihedron
  986. bool m_showTrihedron;
  987. //! Whether initialization should be silent or not (i.e. no message to console)
  988. bool m_silentInitialization;
  989. //! Bubble-view mode state
  990. bool m_bubbleViewModeEnabled;
  991. //! Bubble-view mode f.o.v. (degrees)
  992. float m_bubbleViewFov_deg;
  993. //! Pre-bubble-view camera parameters (backup)
  994. ccViewportParameters m_preBubbleViewParameters;
  995. //! Current LOD state
  996. LODState m_currentLODState;
  997. //! LOD refresh signal sent
  998. bool m_LODPendingRefresh;
  999. //! LOD refresh signal should be ignored
  1000. bool m_LODPendingIgnore;
  1001. //! Internal timer
  1002. QElapsedTimer m_timer;
  1003. //! Touch event in progress
  1004. bool m_touchInProgress;
  1005. //! Touch gesture initial distance
  1006. qreal m_touchBaseDist;
  1007. //! Scheduler timer
  1008. QTimer m_scheduleTimer;
  1009. //! Scheduled full redraw (no LOD)
  1010. qint64 m_scheduledFullRedrawTime;
  1011. //! Seterovision mode parameters
  1012. StereoParams m_stereoParams;
  1013. //! Whether seterovision mode is enabled or not
  1014. bool m_stereoModeEnabled;
  1015. //! Former parent object (for exclusive full-screen display)
  1016. QWidget* m_formerParent;
  1017. //! Wether exclusive full screen is enabled or not
  1018. bool m_exclusiveFullscreen;
  1019. //! Former geometry (for exclusive full-screen display)
  1020. QByteArray m_formerGeometry;
  1021. //! Debug traces visibility
  1022. bool m_showDebugTraces;
  1023. //! Picking radius (pixels)
  1024. int m_pickRadius;
  1025. //! FBO support
  1026. QOpenGLExtension_ARB_framebuffer_object m_glExtFunc;
  1027. //! Whether FBO support is on
  1028. bool m_glExtFuncSupported;
  1029. //! Auto-refresh mode
  1030. bool m_autoRefresh;
  1031. //! Auto-refresh timer
  1032. QTimer m_autoRefreshTimer;
  1033. //! Precomputed stuff for the 'hot zone'
  1034. struct HotZone
  1035. {
  1036. //display font
  1037. QFont font;
  1038. //text height
  1039. int textHeight;
  1040. //text shift
  1041. int yTextBottomLineShift;
  1042. //default color
  1043. ccColor::Rgb color;
  1044. //bubble-view label rect.
  1045. QString bbv_label;
  1046. //bubble-view label rect.
  1047. QRect bbv_labelRect;
  1048. //bubble-view row width
  1049. int bbv_totalWidth;
  1050. //fullscreen label rect.
  1051. QString fs_label;
  1052. //fullscreen label rect.
  1053. QRect fs_labelRect;
  1054. //fullscreen row width
  1055. int fs_totalWidth;
  1056. //point size label
  1057. QString psi_label;
  1058. //point size label rect.
  1059. QRect psi_labelRect;
  1060. //point size row width
  1061. int psi_totalWidth;
  1062. //line size label
  1063. QString lsi_label;
  1064. //line size label rect.
  1065. QRect lsi_labelRect;
  1066. //line size row width
  1067. int lsi_totalWidth;
  1068. int margin;
  1069. int iconSize;
  1070. QPoint topCorner;
  1071. explicit HotZone(ccGLWindowInterface* win);
  1072. QRect rect(bool clickableItemsVisible, bool bubbleViewModeEnabled, bool fullScreenEnabled) const;
  1073. };
  1074. //! Hot zone
  1075. HotZone* m_hotZone;
  1076. //! Whether to display the coordinates of the point below the cursor position
  1077. bool m_showCursorCoordinates;
  1078. //! Whether the pivot point is automatically picked at the center of the screen (when possible)
  1079. bool m_autoPickPivotAtCenter;
  1080. //! Deferred picking
  1081. QTimer m_deferredPickingTimer;
  1082. //! Ignore next mouse release event
  1083. bool m_ignoreMouseReleaseEvent;
  1084. //! Wheter the rotation axis is locked or not
  1085. bool m_rotationAxisLocked;
  1086. //! Locked rotation axis
  1087. CCVector3d m_lockedRotationAxis;
  1088. //! Shared texture type
  1089. using SharedTexture = QSharedPointer<QOpenGLTexture>;
  1090. //! Reserved textures (for renderText)
  1091. QMap<uint16_t, SharedTexture> m_uniqueTextures;
  1092. //! Texture pool (for renderText)
  1093. std::vector<SharedTexture> m_texturePool;
  1094. //! Last texture pool index
  1095. size_t m_texturePoolLastIndex;
  1096. //! Fast pixel reading mechanism with PBO
  1097. struct PBOPicking
  1098. {
  1099. //! Whether the picking PBO seems supported or not
  1100. bool supported = true;
  1101. //! PBO object
  1102. QOpenGLBuffer* glBuffer = nullptr;
  1103. //! Last read operation timestamp
  1104. qint64 lastReadTime_ms = 0;
  1105. //! Elapsed timer
  1106. QElapsedTimer timer;
  1107. bool init();
  1108. void release();
  1109. };
  1110. //! Fast pixel reading mechanism with PBO
  1111. PBOPicking m_pickingPBO;
  1112. //! Whether to near and far clipping planes are enabled or not
  1113. bool m_clippingPlanesEnabled;
  1114. //! Default mouse cursor
  1115. Qt::CursorShape m_defaultCursorShape;
  1116. //! Signal emitter
  1117. ccGLWindowSignalEmitter* m_signalEmitter;
  1118. //! Display scale
  1119. CCVector2d m_displayScale;
  1120. };
  1121. Q_DECLARE_OPERATORS_FOR_FLAGS(ccGLWindowInterface::INTERACTION_FLAGS);