1 // Copyright (c) 2018 GeometryFactory Sarl (France) 2 // All rights reserved. 3 // 4 // This file is part of CGAL (www.cgal.org). 5 // 6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Three/include/CGAL/Three/Scene_item_rendering_helper.h $ 7 // $Id: Scene_item_rendering_helper.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot 8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial 9 // 10 // Author(s) : Maxime Gimeno 11 12 #ifndef SCENE_ITEM_RENDERING_HELPER_H 13 #define SCENE_ITEM_RENDERING_HELPER_H 14 15 #include <CGAL/license/Three.h> 16 17 18 #include <CGAL/Three/Scene_item.h> 19 20 21 #ifdef demo_framework_EXPORTS 22 # define DEMO_FRAMEWORK_EXPORT Q_DECL_EXPORT 23 #else 24 # define DEMO_FRAMEWORK_EXPORT Q_DECL_IMPORT 25 #endif 26 27 struct PRIV; 28 class QMenu; 29 class QSlider; 30 namespace CGAL { 31 namespace Three{ 32 33 class Viewer_interface; 34 struct Triangle_container; 35 struct Edge_container; 36 struct Point_container; 37 38 //! 39 //! \brief The Scene_item_rendering_helper class is a convenience class for constructing an item. 40 //! It is more elaborated than a `Scene_item` and facilitates the process of creating an item that can 41 //! be rendered. 42 //! 43 class DEMO_FRAMEWORK_EXPORT Scene_item_rendering_helper 44 :public Scene_item 45 { 46 Q_OBJECT 47 public: 48 Scene_item_rendering_helper(); 49 ~Scene_item_rendering_helper(); 50 51 //! 52 //! \brief The `Gl_data_name` enum is used as a flag to specify what should be 53 //! re-computed during `computeElements()`. The flag corresponding to this enum is 54 //! `Gl_data_names`, and multiple flags can be combined whith the operator `|`. 55 //! For instance, you can use `GEOMETRY|COLORS` as a single value. 56 //! @todo Review Laurent Rineau We need to find a better name. 1. Do not refer to OpenGL. 2. Why "name"? 57 //! 58 enum Gl_data_name{ 59 GEOMETRY = 0x1, //!< Invalidates the vertices, edges and faces. 60 COLORS = 0x2, //!< Invalidates the color of each vertex 61 NORMALS = 0x4, //!< Invalidate the normal of each vertex. 62 NOT_INSTANCED = 0x8, //!< Invalidate the centers/radius of each sphere. 63 ALL = GEOMETRY|COLORS|NORMALS|NOT_INSTANCED //!< Invalidate everything 64 }; 65 #ifdef DOXYGEN_RUNNING 66 //! \brief Flag interface for Scene_item::Gl_data_name. 67 //! \todo Review Laurent Rineau: Should be explained better. Points to `QFlags`... 68 enum Gl_data_names{}; 69 #endif 70 Q_DECLARE_FLAGS(Gl_data_names, Gl_data_name) 71 72 QMenu* contextMenu() Q_DECL_OVERRIDE; 73 74 /*! 75 * \brief processData calls `computeElements()` 76 * 77 * @todo in a dedicated thread so the 78 * application does not get stuck while the processing is performed. 79 * Emits `dataProcessed()`. 80 */ 81 virtual void processData(Gl_data_names name) const; 82 83 //! 84 //! \brief setAlpha sets the integer value of the alpha channel of this item. 85 //! Also updates the slider value. 86 //! It must be between 0 and 255. 87 //! \param alpha the integer value for the alpha channel. 88 //! 89 void setAlpha(int alpha) Q_DECL_OVERRIDE; 90 //! \brief The item's bounding box. 91 //! 92 //! If the Bbox has never been computed, computes it and 93 //! saves the result for further calls. 94 //! @returns the item's bounding box. 95 Scene_item::Bbox bbox()const Q_DECL_OVERRIDE; 96 //! 97 //! \brief getTriangleContainer returns the `id`th `Triangle_container`. 98 //! 99 CGAL::Three::Triangle_container* getTriangleContainer(std::size_t id) const; 100 //! 101 //! \brief getEdgeContainer returns the `id`th `Edge_container`. 102 //! 103 CGAL::Three::Edge_container* getEdgeContainer(std::size_t id)const; 104 //! 105 //! \brief getPointContainer returns the `id`th `Point_container`. 106 //! 107 CGAL::Three::Point_container* getPointContainer(std::size_t id)const; 108 109 //! 110 //! \brief setTriangleContainer sets the `id`th `Triangle_container` to `tc`. 111 //! 112 //! If `id` is bigger than the current size of the container vector, this vector is 113 //! resized accordingly. This means that for optimisation reasons, containers should be created 114 //! decreasingly. 115 //! 116 void setTriangleContainer(std::size_t id, 117 Triangle_container* tc); 118 119 //! 120 //! \brief setEdgeContainer sets the `id`th `Edge_container` to `tc`. 121 //! 122 //! If `id` is bigger than the current size of the container vector, this vector is 123 //! resized accordingly. This means that for optimisation reasons, containers should be created 124 //! decreasingly. 125 //! 126 void setEdgeContainer(std::size_t id, 127 Edge_container* tc); 128 129 //! 130 //! \brief setPointContainer sets the `id`th `Point_container` to `tc`. 131 //! 132 //! If `id` is bigger than the current size of the container vector, this vector is 133 //! resized accordingly. This means that for optimisation reasons, containers should be created 134 //! decreasingly. 135 //! 136 void setPointContainer(std::size_t id, 137 Point_container* tc); 138 139 //! 140 //! \brief setBuffersFilled specifies if the data should be re-computed. 141 //! 142 //! If called with `false`, the item rendering data will be re-computed at the next `draw()`. 143 //! If called with `true`, the item rendering data is considered ready and will not be computed 144 //! until `setBuffersFilled()` is called with `false` again. 145 //! 146 void setBuffersFilled(bool b) const; 147 148 //! 149 //! \brief getBuffersFilled returns `false` if the item rendering data needs to be re-computed., 150 //! `true` otherwise. 151 //! \see `setBuffersFilled()` 152 bool getBuffersFilled()const; 153 154 //! 155 //! \brief getBuffersInit returns true if the `Vao`s of `viewer` are ready 156 //! for rendering. 157 //! 158 bool getBuffersInit(Viewer_interface *viewer)const; 159 160 //! 161 //! \brief setBuffersInit specifies if the `Vbo`s need to be initialized. 162 //! 163 //! If called with `false`, the item `Vbo`s will be refilled at the next `draw()`. 164 //! If called with `true`, the item `Vbo`s are considered ready and will not be refilled 165 //! until `setBuffersInit()` is called with `false` again. 166 //! 167 //! This function should be called in the drawing functions, when `getBuffersFilled()` is `true`. 168 //! 169 void setBuffersInit(Viewer_interface *viewer, bool val) const; 170 171 //! \brief the item's bounding box's diagonal length. 172 //! 173 //! If the diagonal's length has never been computed, computes it and 174 //! saves the result for further calls. 175 //! @returns the item's bounding box's diagonal length. 176 //! @todo must replace the one from Scene_item eventually 177 virtual double diagonalBbox() const Q_DECL_OVERRIDE; 178 //! 179 //! \brief newViewer adds Vaos for `viewer`. 180 //! \param viewer the new viewer. 181 //! 182 void newViewer(Viewer_interface *viewer) Q_DECL_OVERRIDE; 183 //! \brief removeViewer removes the Vaos for `viewer`. 184 //! \param viewer the viewer to be removed. 185 void removeViewer(Viewer_interface *viewer) Q_DECL_OVERRIDE; 186 protected: 187 188 189 //!Returns a pointer to the slider initialized in initGL(); 190 QSlider* alphaSlider(); 191 192 //!Returns`true` if `initGL()` was called for `viewer`. 193 bool isInit(CGAL::Three::Viewer_interface* viewer)const; 194 195 //!Returns the float alpha value of an item. 196 //! This value is between 0.0f and 1.0f. 197 float alpha() const Q_DECL_OVERRIDE; 198 199 /*! Fills the `Vbo`s with data. 200 */ initializeBuffers(Viewer_interface *)201 virtual void initializeBuffers(Viewer_interface*)const{} 202 203 //!Creates the VAOs and VBOs for viewer. 204 virtual void initGL(CGAL::Three::Viewer_interface* viewer) const; 205 //! 206 //! Computes the items Bbox and stores the result. Must be overridden. 207 //!@todo must replace the one from Scene_item eventually. 208 virtual void compute_bbox() const Q_DECL_OVERRIDE = 0; 209 //! 210 //! \brief setBbox allows to set the Bbox in compute_bbox(); 211 //! \param b 212 //! 213 void setBbox(Bbox b)const ; 214 computeElements()215 virtual void computeElements()const{} 216 protected: 217 friend struct PRIV; 218 mutable PRIV* priv; 219 };//end Scene_item_rendering_helper 220 221 }} 222 223 #endif // SCENE_ITEM_RENDERING_HELPER_H 224