RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_entity_gfx.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 <memory>
43 
44 #include <geogram_gfx/glup_viewer/glup_viewer_gui.h>
45 
51 namespace RINGMesh
52 {
53  FORWARD_DECLARATION_DIMENSION_CLASS( PointSetMeshGfx );
55  FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMeshGfx );
56  FORWARD_DECLARATION_DIMENSION_CLASS( VolumeMeshGfx );
57  FORWARD_DECLARATION_DIMENSION_CLASS( MeshEntityGfx );
59 
60  ALIAS_3D( GeoModelGfx );
61 } // namespace RINGMesh
62 
63 namespace RINGMesh
64 {
65  template < index_t DIMENSION >
66  class GeoModelGfxEntity
67  {
68  ringmesh_disable_copy_and_move( GeoModelGfxEntity );
70 
71  public:
72  explicit GeoModelGfxEntity( GeoModelGfx< DIMENSION >& gfx );
73  virtual ~GeoModelGfxEntity() = default;
74 
75  virtual void draw() = 0;
76  virtual void initialize() = 0;
77  void set_scalar_attribute( GEO::MeshElementsFlags subelements,
78  const std::string& name,
79  double attr_min,
80  double attr_max,
81  GLuint colormap_texture );
82  void unset_scalar_attribute();
83 
90  void set_vertex_color( float red, float green, float blue );
98  void set_vertex_color(
99  index_t entity_id, float red, float green, float blue );
104  void set_vertex_visibility( bool is_visible );
110  void set_vertex_visibility( index_t entity_id, bool is_visible );
115  void set_vertex_size( index_t size );
121  void set_vertex_size( index_t entity_id, index_t size );
122 
123  protected:
124  GeoModelGfx< DIMENSION >& gfx_;
125  std::vector< std::unique_ptr< MeshEntityGfx< DIMENSION > > > entities_;
126  };
127 
128  template < index_t DIMENSION >
129  class CornerGfxEntity final : public GeoModelGfxEntity< DIMENSION >
130  {
131  public:
132  explicit CornerGfxEntity( GeoModelGfx< DIMENSION >& gfx );
133 
134  PointSetMeshGfx< DIMENSION >& corner( index_t corner_id );
135 
139  void draw() override;
140  void initialize() override;
141  };
142 
143  template < index_t DIMENSION >
144  class LineGfxEntity final : public GeoModelGfxEntity< DIMENSION >
145  {
146  public:
147  explicit LineGfxEntity( GeoModelGfx< DIMENSION >& gfx );
148 
149  LineMeshGfx< DIMENSION >& line( index_t line_id );
150 
154  void draw() override;
155  void initialize() override;
156 
163  void set_line_color( float red, float green, float blue );
171  void set_line_color(
172  index_t line_id, float red, float green, float blue );
177  void set_line_visibility( bool is_visible );
183  void set_line_visibility( index_t line_id, bool is_visible );
188  void set_line_size( index_t size );
194  void set_line_size( index_t line_id, index_t size );
195  };
196 
197  template < index_t DIMENSION >
198  class SurfaceGfxEntity final : public GeoModelGfxEntity< DIMENSION >
199  {
200  public:
201  explicit SurfaceGfxEntity( GeoModelGfx< DIMENSION >& gfx );
202 
203  SurfaceMeshGfx< DIMENSION >& surface( index_t surface_id );
204 
208  void draw() override;
209  void initialize() override;
216  void set_surface_color( float red, float green, float blue );
224  void set_surface_color(
225  index_t surface_id, float red, float green, float blue );
230  void set_surface_visibility( bool is_visible );
236  void set_surface_visibility( index_t surface_id, bool is_visible );
243  void set_backface_surface_color( float red, float green, float blue );
251  void set_backface_surface_color(
252  index_t surface_id, float red, float green, float blue );
259  void set_mesh_color( float red, float green, float blue );
267  void set_mesh_color(
268  index_t surface_id, float red, float green, float blue );
273  void set_mesh_visibility( bool is_visible );
279  void set_mesh_visibility( index_t surface_id, bool is_visible );
284  void set_mesh_size( index_t size );
290  void set_mesh_size( index_t surface_id, index_t size );
291  };
292 
293  template < index_t DIMENSION >
294  class RegionGfxEntity final : public GeoModelGfxEntity< 3 >
295  {
296  public:
297  explicit RegionGfxEntity( GeoModelGfx3D& gfx );
298 
299  VolumeMeshGfx< DIMENSION >& region( index_t region_id );
300 
304  void draw() override;
305  void initialize() override;
306 
313  void set_region_color( float red, float green, float blue );
321  void set_region_color(
322  index_t region_id, float red, float green, float blue );
327  void set_region_visibility( bool is_visible );
333  void set_region_visibility( index_t region_id, bool is_visible );
334 
341  void set_mesh_color( float red, float green, float blue );
349  void set_mesh_color(
350  index_t region_id, float red, float green, float blue );
355  void set_mesh_visibility( bool is_visible );
361  void set_mesh_visibility( index_t region_id, bool is_visible );
366  void set_mesh_size( index_t size );
372  void set_mesh_size( index_t region_id, index_t size );
373 
377  void set_draw_cells( CellType type, bool x );
381  void set_draw_cells( index_t region_id, CellType type, bool x );
385  void set_cell_colors_by_type();
390  void set_cell_colors_by_type( index_t region_id );
391  void set_cell_type_visibility( CellType t, bool is_visible );
392  void set_cell_type_visibility(
393  index_t region_id, CellType t, bool is_visible );
398  void set_shrink( double shrink );
404  void set_shrink( index_t region_id, double shrink );
405  };
406 
407  ALIAS_2D_AND_3D( RegionGfxEntity );
408 } // namespace RINGMesh
409 
410 #endif
#define ringmesh_disable_copy_and_move(Class)
Definition: common.h:76
ALIAS_3D(GeoModel)
#define ringmesh_template_assert_2d_or_3d(type)
Definition: common.h:80
ALIAS_2D_AND_3D(Box)
CellType
Definition: types.h:89
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)