RINGMesh  Version 5.0.0
A programming library for geological model meshes
geogram_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 
49 
55 namespace RINGMesh
56 {
57 #define COMMON_GEOGRAM_GFX_IMPLEMENTATION( Class ) \
58 public: \
59  void draw_vertices() override \
60  { \
61  mesh_gfx_.draw_vertices(); \
62  } \
63  void set_vertex_color( float r, float g, float b ) override \
64  { \
65  mesh_gfx_.set_points_color( r, g, b ); \
66  } \
67  void set_vertex_size( index_t s ) override \
68  { \
69  mesh_gfx_.set_points_size( static_cast< float >( s ) ); \
70  } \
71  void set_scalar_attribute( GEO::MeshElementsFlags subelements, \
72  const std::string& name, double attr_min, double attr_max, \
73  GLuint colormap_texture ) override \
74  { \
75  mesh_gfx_.set_scalar_attribute( \
76  subelements, name, attr_min, attr_max, colormap_texture ); \
77  } \
78  void unset_scalar_attribute() override \
79  { \
80  mesh_gfx_.unset_scalar_attribute(); \
81  } \
82  \
83 private: \
84  GEO::MeshGfx mesh_gfx_
85 
86  template < index_t DIMENSION >
87  class GeogramPointSetMeshGfx : public PointSetMeshGfx< DIMENSION >
88  {
89  COMMON_GEOGRAM_GFX_IMPLEMENTATION( GeogramPointSetMeshGfx );
90 
91  public:
92  explicit GeogramPointSetMeshGfx( const PointSetMesh< DIMENSION >& mesh )
93  {
94  mesh_gfx_.set_mesh(
95  &dynamic_cast< const GeogramPointSetMesh< DIMENSION >& >( mesh )
96  .gfx_mesh() );
97  set_vertex_color( 1, 0, 0 );
98  }
99  };
100  ALIAS_2D_AND_3D( GeogramPointSetMeshGfx );
101 
102  template < index_t DIMENSION >
103  class GeogramLineMeshGfx : public LineMeshGfx< DIMENSION >
104  {
105  COMMON_GEOGRAM_GFX_IMPLEMENTATION( GeogramLineMeshGfx );
106 
107  public:
108  explicit GeogramLineMeshGfx( const LineMesh< DIMENSION >& mesh )
109  {
110  mesh_gfx_.set_mesh(
111  &dynamic_cast< const GeogramLineMesh< DIMENSION >& >( mesh )
112  .gfx_mesh() );
113  set_vertex_color( 1, 1, 1 );
114  set_edge_color( 1, 1, 1 );
115  }
116 
117  void draw_edges() override
118  {
119  mesh_gfx_.draw_edges();
120  }
121 
122  void set_edge_color( float r, float g, float b ) override
123  {
124  mesh_gfx_.set_mesh_color( r, g, b );
125  }
126 
127  void set_edge_width( index_t s ) override
128  {
129  mesh_gfx_.set_mesh_width( s );
130  }
131  };
132  ALIAS_2D_AND_3D( GeogramLineMeshGfx );
133 
134  template < index_t DIMENSION >
135  class GeogramSurfaceMeshGfx : public SurfaceMeshGfx< DIMENSION >
136  {
137  COMMON_GEOGRAM_GFX_IMPLEMENTATION( GeogramSurfaceMeshGfx );
138 
139  public:
140  explicit GeogramSurfaceMeshGfx( const SurfaceMesh< DIMENSION >& mesh )
141  {
142  mesh_gfx_.set_mesh(
143  &dynamic_cast< const GeogramSurfaceMesh< DIMENSION >& >( mesh )
144  .gfx_mesh() );
145  }
146 
147  void draw_surface() override
148  {
149  mesh_gfx_.draw_surface();
150  }
151 
152  void set_surface_color( float r, float g, float b ) override
153  {
154  mesh_gfx_.set_surface_color( r, g, b );
155  }
156 
157  void set_backface_surface_color( float r, float g, float b ) override
158  {
159  mesh_gfx_.set_backface_surface_color( r, g, b );
160  }
161 
162  void set_mesh_color( float r, float g, float b ) override
163  {
164  mesh_gfx_.set_mesh_color( r, g, b );
165  }
166 
167  void set_mesh_visibility( bool b ) override
168  {
169  mesh_gfx_.set_show_mesh( b );
170  }
171 
172  void set_mesh_width( index_t s ) override
173  {
174  mesh_gfx_.set_mesh_width( s );
175  }
176  };
177  ALIAS_2D_AND_3D( GeogramSurfaceMeshGfx );
178 
179  template < index_t DIMENSION >
180  class GeogramVolumeMeshGfx : public VolumeMeshGfx< DIMENSION >
181  {
182  COMMON_GEOGRAM_GFX_IMPLEMENTATION( GeogramVolumeMeshGfx );
183 
184  public:
185  explicit GeogramVolumeMeshGfx( const VolumeMesh< DIMENSION >& mesh )
186  {
187  mesh_gfx_.set_mesh(
188  &dynamic_cast< const GeogramVolumeMesh< DIMENSION >& >( mesh )
189  .gfx_mesh() );
190  }
191 
192  void draw_volume() override
193  {
194  mesh_gfx_.draw_volume();
195  }
196 
197  void set_draw_cells( CellType type, bool x ) override
198  {
199  mesh_gfx_.set_draw_cells(
200  static_cast< GEO::MeshCellType >( type ), x );
201  }
202 
203  void set_cell_colors_by_type() override
204  {
205  mesh_gfx_.set_cells_colors_by_type();
206  }
207 
208  void set_cells_color( float r, float g, float b ) override
209  {
210  mesh_gfx_.set_cells_color( r, g, b );
211  }
212 
213  void set_mesh_color( float r, float g, float b ) override
214  {
215  mesh_gfx_.set_mesh_color( r, g, b );
216  }
217 
218  void set_mesh_visibility( bool b ) override
219  {
220  mesh_gfx_.set_show_mesh( b );
221  }
222 
223  void set_mesh_width( index_t s ) override
224  {
225  mesh_gfx_.set_mesh_width( s );
226  }
227 
228  void set_shrink( double s ) override
229  {
230  mesh_gfx_.set_shrink( s );
231  }
232  };
233  using GeogramVolumeMeshGfx3D = GeogramVolumeMeshGfx< 3 >;
234 
235  void register_geogram_mesh_gfx();
236 } // namespace RINGMesh
237 
238 #endif
ALIAS_2D_AND_3D(Box)
CellType
Definition: types.h:89
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48