40 #ifdef RINGMESH_WITH_GRAPHICS 44 #include <geogram/basic/factory.h> 46 #include <geogram_gfx/glup_viewer/glup_viewer_gui.h> 71 template < index_t DIMENSION >
78 virtual ~MeshEntityGfx() =
default;
80 virtual void draw_vertices() = 0;
81 virtual void set_vertex_color(
float red,
float green,
float blue ) = 0;
82 virtual void set_vertex_size( index_t s ) = 0;
84 virtual void set_scalar_attribute( GEO::MeshElementsFlags subelements,
85 const std::string& name,
88 GLuint colormap_texture ) = 0;
89 virtual void unset_scalar_attribute() = 0;
91 void set_vertex_visible(
bool is_visible )
93 vertex_visible_ = is_visible;
96 bool get_vertex_visible()
const 98 return vertex_visible_;
102 MeshEntityGfx() =
default;
105 bool vertex_visible_{
false };
108 template < index_t DIMENSION >
109 class PointSetMeshGfx :
public MeshEntityGfx< DIMENSION >
112 static std::unique_ptr< PointSetMeshGfx< DIMENSION > > create_gfx(
113 const PointSetMesh< DIMENSION >& mesh );
118 this->set_vertex_visible(
true );
122 template < index_t DIMENSION >
123 using PointSetMeshGfxFactory = Factory<
MeshType,
124 PointSetMeshGfx< DIMENSION >,
125 const PointSetMesh< DIMENSION >& >;
128 template < index_t DIMENSION >
129 class LineMeshGfx :
public MeshEntityGfx< DIMENSION >
132 static std::unique_ptr< LineMeshGfx< DIMENSION > > create_gfx(
133 const LineMesh< DIMENSION >& mesh );
135 void set_edge_visible(
bool is_visible )
137 edge_visible_ = is_visible;
139 bool get_edge_visible()
const 141 return edge_visible_;
144 virtual void draw_edges() = 0;
145 virtual void set_edge_color(
float red,
float green,
float blue ) = 0;
146 virtual void set_edge_width( index_t s ) = 0;
151 this->set_vertex_visible(
false );
155 bool edge_visible_{
true };
158 template < index_t DIMENSION >
159 using LineMeshGfxFactory = Factory<
MeshType,
160 LineMeshGfx< DIMENSION >,
161 const LineMesh< DIMENSION >& >;
164 template < index_t DIMENSION >
165 class SurfaceMeshGfx :
public MeshEntityGfx< DIMENSION >
168 static std::unique_ptr< SurfaceMeshGfx< DIMENSION > > create_gfx(
169 const SurfaceMesh< DIMENSION >& mesh );
171 virtual void draw_surface() = 0;
172 virtual void set_surface_color(
173 float red,
float green,
float blue ) = 0;
174 virtual void set_backface_surface_color(
175 float red,
float green,
float blue ) = 0;
176 virtual void set_mesh_color(
float red,
float green,
float blue ) = 0;
177 virtual void set_mesh_visibility(
bool is_visible ) = 0;
178 virtual void set_mesh_width( index_t s ) = 0;
180 void set_surface_visible(
bool is_visible )
182 surface_visible_ = is_visible;
184 bool get_surface_visible()
const 186 return surface_visible_;
192 this->set_vertex_visible(
false );
196 bool surface_visible_{
true };
199 template < index_t DIMENSION >
200 using SurfaceMeshGfxFactory = Factory<
MeshType,
201 SurfaceMeshGfx< DIMENSION >,
202 const SurfaceMesh< DIMENSION >& >;
205 template < index_t DIMENSION >
206 class VolumeMeshGfx :
public MeshEntityGfx< DIMENSION >
209 static std::unique_ptr< VolumeMeshGfx< DIMENSION > > create_gfx(
210 const VolumeMesh< DIMENSION >& mesh );
212 void set_region_visible(
bool is_visible )
214 region_visible_ = is_visible;
216 bool get_region_visible()
const 218 return region_visible_;
221 virtual void draw_volume() = 0;
222 virtual void set_draw_cells(
CellType type,
bool x ) = 0;
223 virtual void set_cell_colors_by_type() = 0;
224 virtual void set_cells_color(
float red,
float green,
float blue ) = 0;
225 virtual void set_mesh_color(
float red,
float green,
float blue ) = 0;
226 virtual void set_mesh_visibility(
bool b ) = 0;
227 virtual void set_mesh_width( index_t s ) = 0;
228 virtual void set_shrink(
double s ) = 0;
233 this->set_vertex_visible(
false );
237 bool region_visible_{
true };
240 template < index_t DIMENSION >
241 using VolumeMeshGfxFactory = Factory<
MeshType,
242 VolumeMeshGfx< DIMENSION >,
243 const VolumeMesh< DIMENSION >& >;
246 #define ringmesh_register_volume_gfx_2d( type ) \ 247 geo_register_creator( RINGMesh::VolumeMeshGfxFactory2D, type##Gfx, \ 248 type::type_name_static() ) 250 #define ringmesh_register_volume_gfx_3d( type ) \ 251 geo_register_creator( RINGMesh::VolumeMeshGfxFactory3D, type##Gfx, \ 252 type::type_name_static() ) 254 template < index_t DIMENSION >
255 class AttributeGfxManagerBase
260 virtual ~AttributeGfxManagerBase() =
default;
262 GeoModelGfx< DIMENSION >& gfx()
267 void compute_range();
269 void unbind_attribute();
271 void bind_attribute();
273 void set_maximum(
double max )
278 double maximum()
const 283 void set_minimum(
double min )
288 double minimum()
const 293 void set_location(
const std::string& location )
295 const auto& it = factory_.find( location );
296 if( it != factory_.end() )
298 attribute_.reset( ( *it->second )() );
299 attribute_->set_manager( *
this );
303 std::string location_name()
const;
305 index_t nb_coordinates()
const;
307 void set_coordinate(
const index_t& coordinate )
309 coordinate_ = coordinate;
312 const index_t& coordinate()
const 317 void set_name(
const std::string& name )
322 const std::string& name()
const 327 void set_colormap( GLuint colormap )
329 colormap_texture_ = colormap;
332 GLuint colormap()
const 334 return colormap_texture_;
337 template <
template < index_t >
class TYPE >
338 void register_attribute_location()
340 factory_.emplace( TYPE< DIMENSION >::location_name_static(),
341 FactoryCreator::template create< TYPE< DIMENSION > > );
344 std::vector< std::string > registered_locations()
const 346 std::vector< std::string > locations;
347 for(
const auto& location : factory_ )
349 locations.push_back( location.first );
354 std::vector< std::string > get_attribute_names();
357 explicit AttributeGfxManagerBase( GeoModelGfx< DIMENSION >& gfx );
360 GeoModelGfx< DIMENSION >& gfx_;
363 index_t coordinate_{ 0 };
364 GLuint colormap_texture_{ 0 };
365 double minimum_{ 0 };
366 double maximum_{ 0 };
368 using FactoryCreator =
369 GEO::FactoryCreator0< AttributeGfx< DIMENSION > >;
370 std::map< std::string, typename FactoryCreator::CreatorType > factory_;
371 std::unique_ptr< AttributeGfx< DIMENSION > > attribute_;
374 template < index_t DIMENSION >
375 class AttributeGfxManager final
376 :
public AttributeGfxManagerBase< DIMENSION >
379 explicit AttributeGfxManager( GeoModelGfx< DIMENSION >& gfx )
380 : AttributeGfxManagerBase< DIMENSION >( gfx )
386 class RINGMESH_API AttributeGfxManager< 3 > final
387 :
public AttributeGfxManagerBase< 3 >
390 explicit AttributeGfxManager( GeoModelGfx3D& gfx );
393 template < index_t DIMENSION >
399 AttributeGfx() =
default;
401 virtual ~AttributeGfx() =
default;
403 void set_manager( AttributeGfxManagerBase< DIMENSION >& manager )
408 virtual std::string location_name()
const = 0;
411 double attribute_min = max_float64();
412 double attribute_max = min_float64();
413 do_compute_range( attribute_min, attribute_max );
414 manager_->set_minimum( attribute_min );
415 manager_->set_maximum( attribute_max );
417 std::vector< std::string > get_attribute_names()
419 const GEO::AttributesManager& attributes = get_attribute_manager();
420 GEO::vector< std::string > attribute_names;
421 attributes.list_attribute_names( attribute_names );
422 std::vector< std::string > names;
423 for(
const std::string& name : attribute_names )
425 const GEO::AttributeStore* store =
426 attributes.find_attribute_store( name );
427 if( GEO::ReadOnlyScalarAttributeAdapter::can_be_bound_to(
430 names.push_back( name );
435 virtual GEO::AttributesManager& get_attribute_manager() = 0;
436 virtual void bind_attribute() = 0;
437 virtual void unbind_attribute() = 0;
438 virtual index_t nb_coordinates() = 0;
441 virtual void do_compute_range(
442 double& attribute_min,
double& attribute_max ) = 0;
445 AttributeGfxManagerBase< DIMENSION >* manager_{
nullptr };
#define ringmesh_disable_copy_and_move(Class)
#define ringmesh_template_assert_2d_or_3d(type)
Classes to build GeoModel from various inputs.
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)