RINGMesh  Version 5.0.0
A programming library for geological model meshes
gfx_application.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). 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  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #pragma once
37 
38 #include <ringmesh/basic/common.h>
39 
40 #ifdef RINGMESH_WITH_GRAPHICS
41 
42 #include <geogram_gfx/glup_viewer/glup_viewer_gui.h>
43 
44 #include <ringmesh/basic/box.h>
46 
48 
54 namespace RINGMesh
55 {
56  class RINGMESH_API RINGMeshApplication : public GEO::Application
57  {
58  ringmesh_disable_copy_and_move( RINGMeshApplication );
59 
60  public:
61  enum struct ViewerType
62  {
63  GEOMODEL2D,
64  GEOMODEL3D,
65  MESH,
66  NONE
67  };
68 
69  RINGMeshApplication( int argc, char** argv );
70  ~RINGMeshApplication() = default;
71 
72  virtual void quit();
73 
74  protected:
75  static RINGMeshApplication* instance();
76 
77  std::string supported_read_file_extensions() override;
78  std::string supported_geogram_read_file_extensions();
79  void init_graphics() override;
80  bool load( const std::string& filename ) override;
81  void draw_scene() override;
82  void draw_object_properties() override;
83  void draw_viewer_properties() override;
84  void draw_application_menus() override;
85 
86  bool load_geogram( const std::string& filename );
87  bool can_load_geogram( const std::string& filename );
88  void browse_geogram( const std::string& path );
89  void update_region_of_interest();
90 
91  static void show_color_table_popup( ImColor& color );
92 
93  private:
94  void create_point( std::string name = "debug",
95  double x = 0,
96  double y = 0,
97  double z = 0 );
98 
99  void create_aabbox( std::string name = "box",
100  double xmin = 0,
101  double ymin = 0,
102  double zmin = 0,
103  double xmax = 1,
104  double ymax = 1,
105  double zmax = 1 );
106 
107  private:
108  template < index_t DIMENSION >
109  class GeoModelViewerBase
110  {
111  ringmesh_disable_copy_and_move( GeoModelViewerBase );
112 
113  public:
114  struct OldNewStatus
115  {
116  OldNewStatus& operator=( bool value )
117  {
118  old_status = value;
119  new_status = value;
120  return *this;
121  }
122  bool need_to_update() const
123  {
124  return old_status != new_status;
125  }
126  void update()
127  {
128  old_status = new_status;
129  }
130  bool old_status{ false };
131  bool new_status{ false };
132  };
133  struct EntityStyle
134  {
135  ImColor color_;
136  int size_{ 1 };
137  bool visible_vertices_{ false };
138  ImColor vertex_color_;
139  int vertex_size_{ 1 };
140  };
141 
142  public:
143  GeoModelViewerBase(
144  RINGMeshApplication& app, const std::string& filename );
145  virtual ~GeoModelViewerBase() = default;
146 
147  virtual void draw_scene();
148  virtual void draw_object_properties();
149  void draw_viewer_properties();
150  void draw_colormap();
151 
152  void reset_attribute_name();
153  void set_attribute_names( const std::vector< std::string >& names );
154  void autorange();
155  void draw_entity_style_editor(
156  const std::string& label, EntityStyle& style );
157  void draw_entity_vertex_style_editor(
158  const std::string& label, EntityStyle& style );
159  void update_entity_visibility();
160  virtual void update_all_entity_visibility( bool value );
161 
162  void toggle_corner_visibility( index_t corner_id );
163  void toggle_line_and_boundaries_visibility( index_t line_id );
164  void toggle_surface_and_boundaries_visibility( index_t surface_id );
165  void toggle_geological_entity_visibility(
166  const gmge_id& entity_id );
167  virtual void toggle_mesh_entity_and_boundaries_visibility(
168  const gmme_id& entity_id );
169 
170  virtual ViewerType type() = 0;
171 
172  public:
173  RINGMeshApplication& app_;
174  bool is_visible_{ true };
175  GeoModel< DIMENSION > GM_;
176  GeoModelGfx< DIMENSION > GM_gfx_;
177  Box< DIMENSION > bbox_;
178  std::vector< std::string > entity_types_;
179  int selected_entity_type_{ 0 };
180  int selected_entity_id_{ 0 };
181 
182  bool show_corners_{ true };
183  EntityStyle corner_style_;
184  bool show_lines_{ true };
185  EntityStyle line_style_;
186  bool show_surface_{ true };
187  EntityStyle surface_style_;
188  bool show_voi_{ false };
189  bool show_colormap_{ false };
190 
191  bool mesh_visible_{ true };
192  ImColor mesh_color_;
193  bool show_attributes_{ false };
194  float attribute_min_{ 0 };
195  float attribute_max_{ 0 };
196  };
197 
198  ALIAS_2D_AND_3D( GeoModelViewerBase );
199 
200  template < index_t DIMENSION >
201  class GeoModelViewer final : public GeoModelViewerBase< DIMENSION >
202  {
203  };
204 
205  ALIAS_2D_AND_3D( GeoModelViewer );
206 
207  class MeshViewer
208  {
209  ringmesh_disable_copy_and_move( MeshViewer );
210 
211  public:
212  MeshViewer( RINGMeshApplication& app, const std::string& filename );
213  ~MeshViewer() = default;
214 
215  void draw_object_properties();
216  void draw_scene();
217 
218  void autorange();
219  std::string attribute_names();
220  void set_attribute( const std::string& attribute );
221 
222  public:
223  RINGMeshApplication& app_;
224  bool is_visible_{ true };
225  GEO::Mesh mesh_;
226  GEO::MeshGfx mesh_gfx_;
227  Box3D bbox_;
228  std::string name_;
229 
230  bool show_vertices_{ false };
231  float vertices_size_{ 1 };
232  ImColor vertices_color_;
233 
234  bool show_surface_{ true };
235  bool show_surface_colors_{ true };
236  bool show_mesh_{ true };
237  bool show_surface_borders_{ false };
238 
239  bool show_volume_{ false };
240  float cells_shrink_{ 0 };
241  bool show_colored_cells_{ false };
242  bool show_hexes_{ true };
243 
244  bool show_attributes_{ false };
245  GLuint current_colormap_texture_{ 0 };
246  std::string attribute_ = std::string{ "vertices.point_fp32[0]" };
247  GEO::MeshElementsFlags attribute_subelements_{ GEO::MESH_VERTICES };
248  std::string attribute_name_;
249  float attribute_min_{ 0 };
250  float attribute_max_{ 0 };
251  };
252 
253  template < index_t DIMENSION >
254  void draw_geomodel_viewer_properties(
255  std::vector< std::unique_ptr< GeoModelViewer< DIMENSION > > >&
256  geomodels,
257  int& id );
258 
259  protected:
260  std::vector< std::unique_ptr< GeoModelViewer3D > > geomodels3d_;
261  std::vector< std::unique_ptr< GeoModelViewer2D > > geomodels2d_;
262  std::vector< std::unique_ptr< MeshViewer > > meshes_;
263  std::string ringmesh_file_extensions_;
264  std::string geogram_file_extensions_;
265  index_t current_viewer_{ NO_ID };
266  ViewerType current_viewer_type_{ ViewerType::NONE };
267 
268  static std::vector< std::vector< ImColor > > color_table_;
269  };
270 
271  template <>
272  class RINGMeshApplication::GeoModelViewer< 2 > final
273  : public GeoModelViewerBase< 2 >
274  {
275  public:
276  GeoModelViewer( RINGMeshApplication& app, const std::string& filename );
277  ViewerType type() override
278  {
279  return ViewerType::GEOMODEL2D;
280  }
281  };
282 
283  template <>
284  class RINGMeshApplication::GeoModelViewer< 3 > final
285  : public GeoModelViewerBase< 3 >
286  {
287  public:
288  GeoModelViewer( RINGMeshApplication& app, const std::string& filename );
289  ViewerType type() override
290  {
291  return ViewerType::GEOMODEL3D;
292  }
293 
294  void draw_scene() override;
295  void draw_object_properties() override;
296  void update_all_entity_visibility( bool value ) override;
297 
298  void toggle_colored_cells();
299  void toggle_colored_regions();
300  void toggle_colored_layers();
301  void toggle_region_and_boundaries_visibility( index_t region_id );
302  void toggle_mesh_entity_and_boundaries_visibility(
303  const gmme_id& entity_id ) override;
304 
305  public:
306  bool show_hex_{ true };
307  bool show_prism_{ true };
308  bool show_pyramid_{ true };
309  bool show_tetra_{ true };
310 
311  float shrink_{ 0 };
312  bool meshed_regions_{ false };
313  bool show_volume_{ false };
314  EntityStyle volume_style_;
315 
316  OldNewStatus colored_cells_;
317  OldNewStatus show_colored_regions_;
318  OldNewStatus show_colored_layers_;
319  };
320 } // namespace RINGMesh
321 
322 #endif
#define ringmesh_disable_copy_and_move(Class)
Definition: common.h:76
ALIAS_2D_AND_3D(Box)
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48