| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #ifndef H_GEOGRAM_GFX_GUI_SIMPLE_MESH_APPLICATION_H | ||
| 41 | #define H_GEOGRAM_GFX_GUI_SIMPLE_MESH_APPLICATION_H | ||
| 42 | |||
| 43 | #include <geogram_gfx/basic/common.h> | ||
| 44 | #include <geogram_gfx/gui/simple_application.h> | ||
| 45 | #include <geogram_gfx/mesh/mesh_gfx.h> | ||
| 46 | |||
| 47 | namespace GEO { | ||
| 48 | |||
| 49 | /** | ||
| 50 | * \brief An Application that manipulates a single Mesh. | ||
| 51 | */ | ||
| 52 | class GEOGRAM_GFX_API SimpleMeshApplication : public SimpleApplication { | ||
| 53 | public: | ||
| 54 | /** | ||
| 55 | * \brief Application constructor. | ||
| 56 | */ | ||
| 57 | SimpleMeshApplication(const std::string& name); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * \brief Installs key navigation callbacks. | ||
| 61 | * \details up,down,home,end keys navigate files in | ||
| 62 | * current directory. | ||
| 63 | */ | ||
| 64 | void install_key_file_navigation(); | ||
| 65 | |||
| 66 | protected: | ||
| 67 | |||
| 68 | /** | ||
| 69 | * \copydoc SimpleApplication::geogram_initialize() | ||
| 70 | */ | ||
| 71 | void geogram_initialize(int argc, char** argv) override; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * \copydoc SimpleApplication::supported_read_file_extensions() | ||
| 75 | */ | ||
| 76 | std::string supported_read_file_extensions() override; | ||
| 77 | |||
| 78 | /** | ||
| 79 | * \copydoc SimpleApplication::supported_write_file_extensions() | ||
| 80 | */ | ||
| 81 | std::string supported_write_file_extensions() override; | ||
| 82 | |||
| 83 | /** | ||
| 84 | * \copydoc SimpleApplication::draw_object_properties() | ||
| 85 | */ | ||
| 86 | void draw_object_properties() override; | ||
| 87 | |||
| 88 | /** | ||
| 89 | * \copydoc SimpleApplication::draw_scene() | ||
| 90 | */ | ||
| 91 | void draw_scene() override; | ||
| 92 | |||
| 93 | /** | ||
| 94 | * \copydoc SimpleApplication::GL_initialize() | ||
| 95 | */ | ||
| 96 | void GL_initialize() override; | ||
| 97 | |||
| 98 | /** | ||
| 99 | * \copydoc GEO::Application::GL_terminate() | ||
| 100 | */ | ||
| 101 | void GL_terminate() override; | ||
| 102 | |||
| 103 | /** | ||
| 104 | * \copydoc SimpleApplication::load() | ||
| 105 | */ | ||
| 106 | bool load(const std::string& filename) override; | ||
| 107 | |||
| 108 | /** | ||
| 109 | * \copydoc SimpleApplication::save() | ||
| 110 | */ | ||
| 111 | bool save(const std::string& filename) override; | ||
| 112 | |||
| 113 | /** | ||
| 114 | * \brief Gets the instance. | ||
| 115 | * \return a pointer to the current SimpleMeshApplication. | ||
| 116 | */ | ||
| 117 | ✗ | static SimpleMeshApplication* instance() { | |
| 118 | SimpleMeshApplication* result = | ||
| 119 | ✗ | dynamic_cast<SimpleMeshApplication*>( | |
| 120 | ✗ | SimpleApplication::instance() | |
| 121 | ✗ | ); | |
| 122 | ✗ | geo_assert(result != nullptr); | |
| 123 | ✗ | return result; | |
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | protected: | ||
| 128 | |||
| 129 | /** | ||
| 130 | * \brief Called at the beginning of draw_scene(). | ||
| 131 | * \details Configures mesh_graphics_ in function of | ||
| 132 | * drawing attributes. | ||
| 133 | */ | ||
| 134 | virtual void draw_points(); | ||
| 135 | virtual void draw_edges(); | ||
| 136 | virtual void draw_surface(); | ||
| 137 | virtual void draw_volume(); | ||
| 138 | |||
| 139 | /** | ||
| 140 | * \brief Gets the bounding box of a mesh animation. | ||
| 141 | * \details In animated mode, the mesh animation is stored as | ||
| 142 | * a mesh with 6d coordinates, that correspond to the geometric | ||
| 143 | * location at the vertices at time 0 and at time 1. | ||
| 144 | * \param[in] M_in the mesh | ||
| 145 | * \param[out] xyzmin a pointer to the three minimum coordinates | ||
| 146 | * \param[out] xyzmax a pointer to the three maximum coordinates | ||
| 147 | * \param[in] animate true if displaying a mesh animation | ||
| 148 | */ | ||
| 149 | void get_bbox( | ||
| 150 | const Mesh& M_in, double* xyzmin, double* xyzmax, bool animate | ||
| 151 | ); | ||
| 152 | |||
| 153 | /** | ||
| 154 | * \brief increments the animation time in the current instance. | ||
| 155 | * \details Callback bound to the 't' key | ||
| 156 | */ | ||
| 157 | static void increment_anim_time_callback(); | ||
| 158 | |||
| 159 | /** | ||
| 160 | * \brief derements the animation time in the current instance. | ||
| 161 | * \details Callback bound to the 'r' key | ||
| 162 | */ | ||
| 163 | static void decrement_anim_time_callback(); | ||
| 164 | |||
| 165 | /** | ||
| 166 | * \brief increments the cells shrinkage. | ||
| 167 | * \details Callback bound to the 'w' key | ||
| 168 | */ | ||
| 169 | static void increment_cells_shrink_callback(); | ||
| 170 | |||
| 171 | /** | ||
| 172 | * \brief decrements the cells shrinkage. | ||
| 173 | * \details Callback bound to the 'x' key | ||
| 174 | */ | ||
| 175 | static void decrement_cells_shrink_callback(); | ||
| 176 | |||
| 177 | |||
| 178 | /** | ||
| 179 | * \brief Loads the next file | ||
| 180 | * \details Call back bound to the 'arrow down' key | ||
| 181 | */ | ||
| 182 | static void next_file(); | ||
| 183 | |||
| 184 | /** | ||
| 185 | * \brief Loads the previous file | ||
| 186 | * \details Call back bound to the 'arrow up' key | ||
| 187 | */ | ||
| 188 | static void prev_file(); | ||
| 189 | |||
| 190 | /** | ||
| 191 | * \brief Loads the first file in the current directory | ||
| 192 | */ | ||
| 193 | static void first_file(); | ||
| 194 | |||
| 195 | /** | ||
| 196 | * \brief Loads the last file in the current directory | ||
| 197 | */ | ||
| 198 | static void last_file(); | ||
| 199 | |||
| 200 | |||
| 201 | void jump_to_file(int relative_index); | ||
| 202 | |||
| 203 | protected: | ||
| 204 | |||
| 205 | /** | ||
| 206 | * \brief Gets the mesh. | ||
| 207 | * \return a pointer to the Mesh. | ||
| 208 | */ | ||
| 209 | ✗ | Mesh* mesh() { | |
| 210 | ✗ | return &mesh_; | |
| 211 | } | ||
| 212 | |||
| 213 | /** | ||
| 214 | * \brief Gets the mesh graphics. | ||
| 215 | * \return a pointer to the MeshGfx. | ||
| 216 | */ | ||
| 217 | ✗ | MeshGfx* mesh_gfx() { | |
| 218 | ✗ | return &mesh_gfx_; | |
| 219 | } | ||
| 220 | |||
| 221 | /** | ||
| 222 | * \brief Makes the vertices visible. | ||
| 223 | */ | ||
| 224 | ✗ | void show_vertices() { | |
| 225 | ✗ | show_vertices_ = true; | |
| 226 | ✗ | } | |
| 227 | |||
| 228 | /** | ||
| 229 | * \brief Makes the vertices invisible. | ||
| 230 | */ | ||
| 231 | ✗ | void hide_vertices() { | |
| 232 | ✗ | show_vertices_ = false; | |
| 233 | ✗ | } | |
| 234 | |||
| 235 | /** | ||
| 236 | * \brief Makes the surface facets visible. | ||
| 237 | */ | ||
| 238 | ✗ | void show_surface() { | |
| 239 | ✗ | show_surface_ = true; | |
| 240 | ✗ | } | |
| 241 | |||
| 242 | /** | ||
| 243 | * \brief Makes the surface facets invisible. | ||
| 244 | */ | ||
| 245 | ✗ | void hide_surface() { | |
| 246 | ✗ | show_surface_ = false; | |
| 247 | ✗ | } | |
| 248 | |||
| 249 | /** | ||
| 250 | * \brief Makes the volume cells visible. | ||
| 251 | */ | ||
| 252 | ✗ | void show_volume() { | |
| 253 | ✗ | show_volume_ = true; | |
| 254 | ✗ | } | |
| 255 | |||
| 256 | /** | ||
| 257 | * \brief Makes the volume cells invisible. | ||
| 258 | */ | ||
| 259 | void hide_volume() { | ||
| 260 | show_volume_ = false; | ||
| 261 | } | ||
| 262 | |||
| 263 | /** | ||
| 264 | * \brief Makes the attributes visible. | ||
| 265 | */ | ||
| 266 | virtual void show_attributes(); | ||
| 267 | |||
| 268 | /** | ||
| 269 | * \brief Makes the attributes invisible. | ||
| 270 | */ | ||
| 271 | virtual void hide_attributes(); | ||
| 272 | |||
| 273 | /** | ||
| 274 | * \brief Adjusts the current minimum and maximum attribute value | ||
| 275 | * to the currently bound attribute if any. | ||
| 276 | */ | ||
| 277 | void autorange(); | ||
| 278 | |||
| 279 | /** | ||
| 280 | * \brief Gets the list of attribute names. | ||
| 281 | * \return the ';'-separated list of attribute names. | ||
| 282 | */ | ||
| 283 | std::string attribute_names(); | ||
| 284 | |||
| 285 | /** | ||
| 286 | * \brief Sets the currently displayed attribute. | ||
| 287 | * \param[in] attribute the name of the attribute | ||
| 288 | * to be displayed, prefixed by element type. | ||
| 289 | */ | ||
| 290 | void set_attribute(const std::string& attribute); | ||
| 291 | |||
| 292 | protected: | ||
| 293 | Mesh mesh_; | ||
| 294 | MeshGfx mesh_gfx_; | ||
| 295 | |||
| 296 | float anim_speed_; | ||
| 297 | float anim_time_; | ||
| 298 | |||
| 299 | bool show_vertices_; | ||
| 300 | bool show_vertices_selection_; | ||
| 301 | float vertices_size_; | ||
| 302 | vec4f vertices_color_; | ||
| 303 | float vertices_transparency_; | ||
| 304 | |||
| 305 | bool show_surface_; | ||
| 306 | bool show_surface_sides_; | ||
| 307 | vec4f surface_color_; | ||
| 308 | vec4f surface_color_2_; | ||
| 309 | |||
| 310 | bool show_mesh_; | ||
| 311 | float mesh_width_; | ||
| 312 | vec4f mesh_color_; | ||
| 313 | |||
| 314 | bool show_surface_borders_; | ||
| 315 | float surface_borders_width_; | ||
| 316 | vec4f surface_borders_color_; | ||
| 317 | |||
| 318 | bool show_volume_; | ||
| 319 | float cells_shrink_; | ||
| 320 | vec4f volume_color_; | ||
| 321 | bool show_colored_cells_; | ||
| 322 | bool show_hexes_; | ||
| 323 | bool show_connectors_; | ||
| 324 | |||
| 325 | bool show_attributes_; | ||
| 326 | index_t current_colormap_index_; | ||
| 327 | std::string attribute_; | ||
| 328 | MeshElementsFlags attribute_subelements_; | ||
| 329 | std::string attribute_name_; | ||
| 330 | float attribute_min_; | ||
| 331 | float attribute_max_; | ||
| 332 | }; | ||
| 333 | |||
| 334 | /*****************************************************************/ | ||
| 335 | } | ||
| 336 | |||
| 337 | #endif | ||
| 338 |