RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_entity_gfx.cpp
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 
42 
43 #ifdef RINGMESH_WITH_GRAPHICS
44 
49 
53 
54 namespace RINGMesh
55 {
56  template < index_t DIMENSION >
57  GeoModelGfxEntity< DIMENSION >::GeoModelGfxEntity(
58  GeoModelGfx< DIMENSION >& gfx )
59  : gfx_( gfx )
60  {
61  }
62 
63  template < index_t DIMENSION >
64  void GeoModelGfxEntity< DIMENSION >::set_scalar_attribute(
65  GEO::MeshElementsFlags subelements,
66  const std::string& name,
67  double attr_min,
68  double attr_max,
69  GLuint colormap_texture )
70  {
71  for( std::unique_ptr< MeshEntityGfx< DIMENSION > >& e : entities_ )
72  {
73  e->set_scalar_attribute(
74  subelements, name, attr_min, attr_max, colormap_texture );
75  }
76  }
77 
78  template < index_t DIMENSION >
79  void GeoModelGfxEntity< DIMENSION >::unset_scalar_attribute()
80  {
81  for( std::unique_ptr< MeshEntityGfx< DIMENSION > >& e : entities_ )
82  {
83  e->unset_scalar_attribute();
84  }
85  }
86 
87  template < index_t DIMENSION >
88  void GeoModelGfxEntity< DIMENSION >::set_vertex_visibility(
89  bool is_visible )
90  {
91  for( auto e : range( entities_.size() ) )
92  {
93  set_vertex_visibility( e, is_visible );
94  }
95  }
96 
97  template < index_t DIMENSION >
98  void GeoModelGfxEntity< DIMENSION >::set_vertex_visibility(
99  index_t entity_id, bool is_visible )
100  {
101  entities_[entity_id]->set_vertex_visible( is_visible );
102  }
103 
104  template < index_t DIMENSION >
105  void GeoModelGfxEntity< DIMENSION >::set_vertex_color(
106  float red, float green, float blue )
107  {
108  for( auto e : range( entities_.size() ) )
109  {
110  set_vertex_color( e, red, green, blue );
111  }
112  }
113 
114  template < index_t DIMENSION >
115  void GeoModelGfxEntity< DIMENSION >::set_vertex_color(
116  index_t entity_id, float red, float green, float blue )
117  {
118  entities_[entity_id]->set_vertex_color( red, green, blue );
119  }
120 
121  template < index_t DIMENSION >
122  void GeoModelGfxEntity< DIMENSION >::set_vertex_size( index_t s )
123  {
124  for( auto e : range( entities_.size() ) )
125  {
126  set_vertex_size( e, s );
127  }
128  }
129 
130  template < index_t DIMENSION >
131  void GeoModelGfxEntity< DIMENSION >::set_vertex_size(
132  index_t entity_id, index_t s )
133  {
134  entities_[entity_id]->set_vertex_size( s );
135  }
136 
137  /*****************************************************************/
138 
139  template < index_t DIMENSION >
140  CornerGfxEntity< DIMENSION >::CornerGfxEntity(
141  GeoModelGfx< DIMENSION >& gfx )
142  : GeoModelGfxEntity< DIMENSION >( gfx )
143  {
144  }
145 
146  template < index_t DIMENSION >
147  PointSetMeshGfx< DIMENSION >& CornerGfxEntity< DIMENSION >::corner(
148  index_t corner_id )
149  {
150  ringmesh_assert( corner_id < this->entities_.size() );
151  return static_cast< PointSetMeshGfx< DIMENSION >& >(
152  *this->entities_[corner_id] );
153  }
154 
155  template < index_t DIMENSION >
156  void CornerGfxEntity< DIMENSION >::initialize()
157  {
158  if( this->entities_.empty() )
159  {
160  this->entities_.reserve( this->gfx_.geomodel()->nb_corners() );
161  for( const auto& corner : this->gfx_.geomodel()->corners() )
162  {
163  this->entities_.push_back(
164  PointSetMeshGfx< DIMENSION >::create_gfx( corner.mesh() ) );
165  }
166  }
167  }
168 
169  template < index_t DIMENSION >
170  void CornerGfxEntity< DIMENSION >::draw()
171  {
172  for( auto c : range( this->entities_.size() ) )
173  {
174  PointSetMeshGfx< DIMENSION >& pointset = corner( c );
175  if( pointset.get_vertex_visible() )
176  pointset.draw_vertices();
177  }
178  }
179 
180  /*****************************************************************/
181 
182  template < index_t DIMENSION >
183  LineGfxEntity< DIMENSION >::LineGfxEntity( GeoModelGfx< DIMENSION >& gfx )
184  : GeoModelGfxEntity< DIMENSION >( gfx )
185  {
186  }
187 
188  template < index_t DIMENSION >
189  LineMeshGfx< DIMENSION >& LineGfxEntity< DIMENSION >::line(
190  index_t line_id )
191  {
192  ringmesh_assert( line_id < this->entities_.size() );
193  return static_cast< LineMeshGfx< DIMENSION >& >(
194  *this->entities_[line_id] );
195  }
196 
197  template < index_t DIMENSION >
198  void LineGfxEntity< DIMENSION >::initialize()
199  {
200  if( this->entities_.empty() )
201  {
202  this->entities_.reserve( this->gfx_.geomodel()->nb_lines() );
203  for( const auto& line : this->gfx_.geomodel()->lines() )
204  {
205  this->entities_.push_back(
206  LineMeshGfx< DIMENSION >::create_gfx( line.mesh() ) );
207  }
208  }
209  }
210 
211  template < index_t DIMENSION >
212  void LineGfxEntity< DIMENSION >::draw()
213  {
214  for( auto l : range( this->entities_.size() ) )
215  {
216  LineMeshGfx< DIMENSION >& line = this->line( l );
217  if( line.get_vertex_visible() )
218  line.draw_vertices();
219  if( line.get_edge_visible() )
220  line.draw_edges();
221  }
222  }
223 
224  template < index_t DIMENSION >
225  void LineGfxEntity< DIMENSION >::set_line_color(
226  float red, float green, float blue )
227  {
228  for( auto l : range( this->entities_.size() ) )
229  {
230  set_line_color( l, red, green, blue );
231  }
232  }
233 
234  template < index_t DIMENSION >
235  void LineGfxEntity< DIMENSION >::set_line_color(
236  index_t line_id, float red, float green, float blue )
237  {
238  line( line_id ).set_edge_color( red, green, blue );
239  }
240 
241  template < index_t DIMENSION >
242  void LineGfxEntity< DIMENSION >::set_line_visibility( bool is_visible )
243  {
244  for( auto l : range( this->entities_.size() ) )
245  {
246  set_line_visibility( l, is_visible );
247  }
248  }
249 
250  template < index_t DIMENSION >
251  void LineGfxEntity< DIMENSION >::set_line_visibility(
252  index_t line_id, bool is_visible )
253  {
254  line( line_id ).set_edge_visible( is_visible );
255  }
256 
257  template < index_t DIMENSION >
258  void LineGfxEntity< DIMENSION >::set_line_size( index_t size )
259  {
260  for( auto l : range( this->entities_.size() ) )
261  {
262  set_line_size( l, size );
263  }
264  }
265 
266  template < index_t DIMENSION >
267  void LineGfxEntity< DIMENSION >::set_line_size(
268  index_t line_id, index_t size )
269  {
270  line( line_id ).set_edge_width( size );
271  }
272 
273  /*****************************************************************/
274 
275  template < index_t DIMENSION >
276  SurfaceGfxEntity< DIMENSION >::SurfaceGfxEntity(
277  GeoModelGfx< DIMENSION >& gfx )
278  : GeoModelGfxEntity< DIMENSION >( gfx )
279  {
280  }
281 
282  template < index_t DIMENSION >
283  SurfaceMeshGfx< DIMENSION >& SurfaceGfxEntity< DIMENSION >::surface(
284  index_t surface_id )
285  {
286  ringmesh_assert( surface_id < this->entities_.size() );
287  return static_cast< SurfaceMeshGfx< DIMENSION >& >(
288  *this->entities_[surface_id] );
289  }
290 
291  template < index_t DIMENSION >
292  void SurfaceGfxEntity< DIMENSION >::initialize()
293  {
294  if( this->entities_.empty() )
295  {
296  this->entities_.reserve( this->gfx_.geomodel()->nb_surfaces() );
297  for( const auto& surface : this->gfx_.geomodel()->surfaces() )
298  {
299  this->entities_.push_back(
300  SurfaceMeshGfx< DIMENSION >::create_gfx( surface.mesh() ) );
301  }
302  }
303  }
304 
305  template < index_t DIMENSION >
306  void SurfaceGfxEntity< DIMENSION >::draw()
307  {
308  for( auto s : range( this->entities_.size() ) )
309  {
310  SurfaceMeshGfx< DIMENSION >& surface = this->surface( s );
311  if( surface.get_vertex_visible() )
312  surface.draw_vertices();
313  if( surface.get_surface_visible() )
314  surface.draw_surface();
315  }
316  }
317 
318  template < index_t DIMENSION >
319  void SurfaceGfxEntity< DIMENSION >::set_surface_color(
320  float red, float green, float blue )
321  {
322  for( auto s : range( this->entities_.size() ) )
323  {
324  set_surface_color( s, red, green, blue );
325  }
326  }
327 
328  template < index_t DIMENSION >
329  void SurfaceGfxEntity< DIMENSION >::set_surface_color(
330  index_t surface_id, float red, float green, float blue )
331  {
332  surface( surface_id ).set_surface_color( red, green, blue );
333  }
334 
335  template < index_t DIMENSION >
336  void SurfaceGfxEntity< DIMENSION >::set_backface_surface_color(
337  float red, float green, float blue )
338  {
339  for( auto s : range( this->entities_.size() ) )
340  {
341  set_backface_surface_color( s, red, green, blue );
342  }
343  }
344 
345  template < index_t DIMENSION >
346  void SurfaceGfxEntity< DIMENSION >::set_backface_surface_color(
347  index_t surface_id, float red, float green, float blue )
348  {
349  surface( surface_id ).set_backface_surface_color( red, green, blue );
350  }
351 
352  template < index_t DIMENSION >
353  void SurfaceGfxEntity< DIMENSION >::set_surface_visibility(
354  bool is_visible )
355  {
356  for( auto s : range( this->entities_.size() ) )
357  {
358  set_surface_visibility( s, is_visible );
359  }
360  }
361 
362  template < index_t DIMENSION >
363  void SurfaceGfxEntity< DIMENSION >::set_surface_visibility(
364  index_t surface_id, bool is_visible )
365  {
366  surface( surface_id ).set_surface_visible( is_visible );
367  }
368 
369  template < index_t DIMENSION >
370  void SurfaceGfxEntity< DIMENSION >::set_mesh_color(
371  float red, float green, float blue )
372  {
373  for( auto s : range( this->entities_.size() ) )
374  {
375  set_mesh_color( s, red, green, blue );
376  }
377  }
378 
379  template < index_t DIMENSION >
380  void SurfaceGfxEntity< DIMENSION >::set_mesh_color(
381  index_t surface_id, float red, float green, float blue )
382  {
383  surface( surface_id ).set_mesh_color( red, green, blue );
384  }
385 
386  template < index_t DIMENSION >
387  void SurfaceGfxEntity< DIMENSION >::set_mesh_visibility( bool is_visible )
388  {
389  for( auto s : range( this->entities_.size() ) )
390  {
391  set_mesh_visibility( s, is_visible );
392  }
393  }
394 
395  template < index_t DIMENSION >
396  void SurfaceGfxEntity< DIMENSION >::set_mesh_visibility(
397  index_t surface_id, bool is_visible )
398  {
399  surface( surface_id ).set_mesh_visibility( is_visible );
400  }
401 
402  template < index_t DIMENSION >
403  void SurfaceGfxEntity< DIMENSION >::set_mesh_size( index_t size )
404  {
405  for( auto s : range( this->entities_.size() ) )
406  {
407  set_mesh_size( s, size );
408  }
409  }
410 
411  template < index_t DIMENSION >
412  void SurfaceGfxEntity< DIMENSION >::set_mesh_size(
413  index_t surface_id, index_t size )
414  {
415  surface( surface_id ).set_mesh_width( size );
416  }
417 
418  /*****************************************************************/
419 
420  template < index_t DIMENSION >
421  RegionGfxEntity< DIMENSION >::RegionGfxEntity( GeoModelGfx3D& gfx )
422  : GeoModelGfxEntity< DIMENSION >( gfx )
423  {
424  }
425 
426  template < index_t DIMENSION >
427  VolumeMeshGfx< DIMENSION >& RegionGfxEntity< DIMENSION >::region(
428  index_t region_id )
429  {
430  ringmesh_assert( region_id < entities_.size() );
431  return static_cast< VolumeMeshGfx< DIMENSION >& >(
432  *entities_[region_id] );
433  }
434 
435  template < index_t DIMENSION >
436  void RegionGfxEntity< DIMENSION >::initialize()
437  {
438  if( entities_.empty() )
439  {
440  entities_.reserve( gfx_.geomodel()->nb_regions() );
441  for( const auto& region : gfx_.geomodel()->regions() )
442  {
443  entities_.push_back(
444  VolumeMeshGfx< DIMENSION >::create_gfx( region.mesh() ) );
445  }
446  }
447  }
448 
449  template < index_t DIMENSION >
450  void RegionGfxEntity< DIMENSION >::draw()
451  {
452  for( auto r : range( entities_.size() ) )
453  {
454  VolumeMeshGfx< DIMENSION >& region = this->region( r );
455  if( region.get_vertex_visible() )
456  region.draw_vertices();
457  if( region.get_region_visible() )
458  region.draw_volume();
459  }
460  }
461 
462  template < index_t DIMENSION >
463  void RegionGfxEntity< DIMENSION >::set_mesh_color(
464  float red, float green, float blue )
465  {
466  for( auto r : range( entities_.size() ) )
467  {
468  set_mesh_color( r, red, green, blue );
469  }
470  }
471 
472  template < index_t DIMENSION >
473  void RegionGfxEntity< DIMENSION >::set_mesh_color(
474  index_t region_id, float red, float green, float blue )
475  {
476  region( region_id ).set_mesh_color( red, green, blue );
477  }
478 
479  template < index_t DIMENSION >
480  void RegionGfxEntity< DIMENSION >::set_cell_colors_by_type()
481  {
482  for( auto r : range( entities_.size() ) )
483  {
484  set_cell_colors_by_type( r );
485  }
486  }
487 
488  template < index_t DIMENSION >
489  void RegionGfxEntity< DIMENSION >::set_draw_cells( CellType type, bool x )
490  {
491  for( auto r : range( entities_.size() ) )
492  {
493  set_draw_cells( r, type, x );
494  }
495  }
496 
497  template < index_t DIMENSION >
498  void RegionGfxEntity< DIMENSION >::set_draw_cells(
499  index_t region_id, CellType type, bool x )
500  {
501  region( region_id ).set_draw_cells( type, x );
502  }
503 
504  template < index_t DIMENSION >
505  void RegionGfxEntity< DIMENSION >::set_cell_colors_by_type(
506  index_t region_id )
507  {
508  region( region_id ).set_cell_colors_by_type();
509  }
510 
511  template < index_t DIMENSION >
512  void RegionGfxEntity< DIMENSION >::set_mesh_visibility( bool is_visible )
513  {
514  for( auto r : range( entities_.size() ) )
515  {
516  set_mesh_visibility( r, is_visible );
517  }
518  }
519 
520  template < index_t DIMENSION >
521  void RegionGfxEntity< DIMENSION >::set_mesh_visibility(
522  index_t region_id, bool is_visible )
523  {
524  region( region_id ).set_mesh_visibility( is_visible );
525  }
526 
527  template < index_t DIMENSION >
528  void RegionGfxEntity< DIMENSION >::set_mesh_size( index_t size )
529  {
530  for( auto r : range( entities_.size() ) )
531  {
532  set_mesh_size( r, size );
533  }
534  }
535 
536  template < index_t DIMENSION >
537  void RegionGfxEntity< DIMENSION >::set_mesh_size(
538  index_t region_id, index_t size )
539  {
540  region( region_id ).set_mesh_width( size );
541  }
542 
543  template < index_t DIMENSION >
544  void RegionGfxEntity< DIMENSION >::set_region_color(
545  float red, float green, float blue )
546  {
547  for( auto r : range( entities_.size() ) )
548  {
549  set_region_color( r, red, green, blue );
550  }
551  }
552 
553  template < index_t DIMENSION >
554  void RegionGfxEntity< DIMENSION >::set_region_color(
555  index_t region_id, float red, float green, float blue )
556  {
557  region( region_id ).set_cells_color( red, green, blue );
558  }
559 
560  template < index_t DIMENSION >
561  void RegionGfxEntity< DIMENSION >::set_region_visibility( bool is_visible )
562  {
563  for( auto r : range( entities_.size() ) )
564  {
565  set_region_visibility( r, is_visible );
566  }
567  }
568 
569  template < index_t DIMENSION >
570  void RegionGfxEntity< DIMENSION >::set_region_visibility(
571  index_t region_id, bool is_visible )
572  {
573  region( region_id ).set_region_visible( is_visible );
574  }
575 
576  template < index_t DIMENSION >
577  void RegionGfxEntity< DIMENSION >::set_cell_type_visibility(
578  CellType t, bool is_visible )
579  {
580  for( auto r : range( entities_.size() ) )
581  {
582  set_cell_type_visibility( r, t, is_visible );
583  }
584  }
585 
586  template < index_t DIMENSION >
587  void RegionGfxEntity< DIMENSION >::set_cell_type_visibility(
588  index_t region_id, CellType t, bool is_visible )
589  {
590  region( region_id ).set_draw_cells( t, is_visible );
591  }
592 
593  template < index_t DIMENSION >
594  void RegionGfxEntity< DIMENSION >::set_shrink( double shrink )
595  {
596  for( auto r : range( entities_.size() ) )
597  {
598  set_shrink( r, shrink );
599  }
600  }
601 
602  template < index_t DIMENSION >
603  void RegionGfxEntity< DIMENSION >::set_shrink(
604  index_t region_id, double shrink )
605  {
606  region( region_id ).set_shrink( shrink );
607  }
608 
609  template class RINGMESH_API GeoModelGfxEntity< 2 >;
610  template class RINGMESH_API CornerGfxEntity< 2 >;
611  template class RINGMESH_API LineGfxEntity< 2 >;
612  template class RINGMESH_API SurfaceGfxEntity< 2 >;
613 
614  template class RINGMESH_API GeoModelGfxEntity< 3 >;
615  template class RINGMESH_API CornerGfxEntity< 3 >;
616  template class RINGMESH_API LineGfxEntity< 3 >;
617  template class RINGMESH_API SurfaceGfxEntity< 3 >;
618  template class RINGMESH_API RegionGfxEntity< 3 >;
619 } // namespace RINGMesh
620 
621 #endif
CellType
Definition: types.h:89
#define ringmesh_assert(x)
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48