43 #ifdef RINGMESH_WITH_GRAPHICS 57 std::string get_attribute_name_with_coordinate(
58 const std::string& name, index_t coordinate )
60 return name +
"[" + std::to_string( coordinate ) +
"]";
63 void compute_attribute_range(
64 GEO::ReadOnlyScalarAttributeAdapter& attribute,
68 if( attribute.is_bound() )
70 for(
auto i :
range( attribute.size() ) )
72 double value = attribute[i];
73 min = GEO::geo_min( min, value );
74 max = GEO::geo_max( max, value );
82 template < index_t DIMENSION >
83 class CellAttributeGfx :
public AttributeGfx< DIMENSION >
86 CellAttributeGfx() =
default;
88 virtual ~CellAttributeGfx() =
default;
90 static std::string location_name_static()
95 std::string location_name()
const override 97 return location_name_static();
100 void bind_attribute()
override 102 std::string attribute_name = get_attribute_name_with_coordinate(
103 this->manager_->name(), this->manager_->coordinate() );
104 this->manager_->gfx().regions.set_scalar_attribute( GEO::MESH_CELLS,
105 attribute_name, this->manager_->minimum(),
106 this->manager_->maximum(), this->manager_->colormap() );
109 void unbind_attribute()
override 111 this->manager_->gfx().regions.unset_scalar_attribute();
114 index_t nb_coordinates()
override 116 GEO::AttributeStore* store =
117 get_attribute_manager().find_attribute_store(
118 this->manager_->name() );
120 if( store ==
nullptr )
122 return store->dimension();
125 GEO::AttributesManager& get_attribute_manager()
override 128 this->manager_->gfx().geomodel();
129 return geomodel->region( 0 ).cell_attribute_manager();
133 void do_compute_range(
134 double& attribute_min,
double& attribute_max )
override 136 std::string attribute_name = get_attribute_name_with_coordinate(
137 this->manager_->name(), this->manager_->coordinate() );
139 this->manager_->gfx().geomodel();
140 for(
const auto& region : geomodel->regions() )
142 GEO::ReadOnlyScalarAttributeAdapter attribute(
143 region.cell_attribute_manager(), attribute_name );
144 compute_attribute_range(
145 attribute, attribute_min, attribute_max );
150 template < index_t DIMENSION >
151 class CellVertexAttributeGfx :
public AttributeGfx< DIMENSION >
154 CellVertexAttributeGfx() =
default;
156 virtual ~CellVertexAttributeGfx() =
default;
158 static std::string location_name_static()
160 return "cell_vertices";
163 std::string location_name()
const override 165 return location_name_static();
168 void bind_attribute()
override 170 std::string attribute_name = get_attribute_name_with_coordinate(
171 this->manager_->name(), this->manager_->coordinate() );
172 this->manager_->gfx().regions.set_scalar_attribute(
173 GEO::MESH_VERTICES, attribute_name, this->manager_->minimum(),
174 this->manager_->maximum(), this->manager_->colormap() );
177 void unbind_attribute()
override 179 this->manager_->gfx().regions.unset_scalar_attribute();
182 index_t nb_coordinates()
override 184 GEO::AttributeStore* store =
185 get_attribute_manager().find_attribute_store(
186 this->manager_->name() );
188 if( store ==
nullptr )
190 return store->dimension();
193 GEO::AttributesManager& get_attribute_manager()
override 196 this->manager_->gfx().geomodel();
197 return geomodel->region( 0 ).vertex_attribute_manager();
201 void do_compute_range(
202 double& attribute_min,
double& attribute_max )
override 204 std::string attribute_name = get_attribute_name_with_coordinate(
205 this->manager_->name(), this->manager_->coordinate() );
207 this->manager_->gfx().geomodel();
208 for(
const auto& region : geomodel->regions() )
210 GEO::ReadOnlyScalarAttributeAdapter attribute(
211 region.vertex_attribute_manager(), attribute_name );
212 compute_attribute_range(
213 attribute, attribute_min, attribute_max );
218 template < index_t DIMENSION >
219 class PolygonAttributeGfx :
public AttributeGfx< DIMENSION >
222 PolygonAttributeGfx() =
default;
224 virtual ~PolygonAttributeGfx() =
default;
226 static std::string location_name_static()
231 std::string location_name()
const override 233 return location_name_static();
236 void bind_attribute()
override 238 std::string attribute_name = get_attribute_name_with_coordinate(
239 this->manager_->name(), this->manager_->coordinate() );
240 this->manager_->gfx().surfaces.set_scalar_attribute(
241 GEO::MESH_FACETS, attribute_name, this->manager_->minimum(),
242 this->manager_->maximum(), this->manager_->colormap() );
245 void unbind_attribute()
override 247 this->manager_->gfx().surfaces.unset_scalar_attribute();
250 index_t nb_coordinates()
override 252 GEO::AttributeStore* store =
253 get_attribute_manager().find_attribute_store(
254 this->manager_->name() );
256 if( store ==
nullptr )
258 return store->dimension();
261 GEO::AttributesManager& get_attribute_manager()
override 264 this->manager_->gfx().geomodel();
265 return geomodel->
surface( 0 ).polygon_attribute_manager();
269 void do_compute_range(
270 double& attribute_min,
double& attribute_max )
override 272 std::string attribute_name = get_attribute_name_with_coordinate(
273 this->manager_->name(), this->manager_->coordinate() );
275 this->manager_->gfx().geomodel();
276 for(
const auto& surface : geomodel->surfaces() )
278 GEO::ReadOnlyScalarAttributeAdapter attribute(
279 surface.polygon_attribute_manager(), attribute_name );
280 compute_attribute_range(
281 attribute, attribute_min, attribute_max );
286 template < index_t DIMENSION >
287 class PolygonVertexAttributeGfx :
public AttributeGfx< DIMENSION >
290 PolygonVertexAttributeGfx() =
default;
292 virtual ~PolygonVertexAttributeGfx() =
default;
294 static std::string location_name_static()
296 return "polygon_vertices";
299 std::string location_name()
const override 301 return location_name_static();
303 void bind_attribute()
override 305 std::string attribute_name = get_attribute_name_with_coordinate(
306 this->manager_->name(), this->manager_->coordinate() );
307 this->manager_->gfx().surfaces.set_scalar_attribute(
308 GEO::MESH_VERTICES, attribute_name, this->manager_->minimum(),
309 this->manager_->maximum(), this->manager_->colormap() );
311 void unbind_attribute()
override 313 this->manager_->gfx().surfaces.unset_scalar_attribute();
315 index_t nb_coordinates()
override 317 GEO::AttributeStore* store =
318 get_attribute_manager().find_attribute_store(
319 this->manager_->name() );
321 if( store ==
nullptr )
323 return store->dimension();
326 GEO::AttributesManager& get_attribute_manager()
override 329 this->manager_->gfx().geomodel();
330 return geomodel->
surface( 0 ).vertex_attribute_manager();
334 void do_compute_range(
335 double& attribute_min,
double& attribute_max )
override 337 std::string attribute_name = get_attribute_name_with_coordinate(
338 this->manager_->name(), this->manager_->coordinate() );
340 this->manager_->gfx().geomodel();
341 for(
const auto& surface : geomodel->surfaces() )
343 GEO::ReadOnlyScalarAttributeAdapter attribute(
344 surface.vertex_attribute_manager(), attribute_name );
345 compute_attribute_range(
346 attribute, attribute_min, attribute_max );
351 template < index_t DIMENSION >
352 AttributeGfxManagerBase< DIMENSION >::AttributeGfxManagerBase(
353 GeoModelGfx< DIMENSION >& gfx )
356 register_attribute_location< PolygonVertexAttributeGfx >();
357 register_attribute_location< PolygonAttributeGfx >();
360 template < index_t DIMENSION >
361 std::string AttributeGfxManagerBase< DIMENSION >::location_name()
const 365 return attribute_->location_name();
373 template < index_t DIMENSION >
374 void AttributeGfxManagerBase< DIMENSION >::compute_range()
378 attribute_->compute_range();
382 template < index_t DIMENSION >
383 void AttributeGfxManagerBase< DIMENSION >::bind_attribute()
387 attribute_->bind_attribute();
391 template < index_t DIMENSION >
392 std::vector< std::string >
393 AttributeGfxManagerBase< DIMENSION >::get_attribute_names()
397 return attribute_->get_attribute_names();
399 return std::vector< std::string >();
402 template < index_t DIMENSION >
403 void AttributeGfxManagerBase< DIMENSION >::unbind_attribute()
407 attribute_->unbind_attribute();
411 template < index_t DIMENSION >
412 index_t AttributeGfxManagerBase< DIMENSION >::nb_coordinates()
const 416 return attribute_->nb_coordinates();
421 AttributeGfxManager< 3 >::AttributeGfxManager( GeoModelGfx< 3 >& gfx )
422 : AttributeGfxManagerBase< 3 >( gfx )
424 this->register_attribute_location< CellVertexAttributeGfx >();
425 this->register_attribute_location< CellAttributeGfx >();
428 template < index_t DIMENSION >
429 std::unique_ptr< PointSetMeshGfx< DIMENSION > >
430 PointSetMeshGfx< DIMENSION >::create_gfx(
433 auto gfx = PointSetMeshGfxFactory< DIMENSION >::create(
438 "Could not create mesh gfx data structure: ",
444 template < index_t DIMENSION >
445 std::unique_ptr< LineMeshGfx< DIMENSION > >
446 LineMeshGfx< DIMENSION >::create_gfx(
450 LineMeshGfxFactory< DIMENSION >::create( mesh.
type_name(), mesh );
454 "Could not create mesh gfx data structure: ",
460 template < index_t DIMENSION >
461 std::unique_ptr< SurfaceMeshGfx< DIMENSION > >
462 SurfaceMeshGfx< DIMENSION >::create_gfx(
465 auto gfx = SurfaceMeshGfxFactory< DIMENSION >::create(
470 "Could not create mesh gfx data structure: ",
476 template < index_t DIMENSION >
477 std::unique_ptr< VolumeMeshGfx< DIMENSION > >
478 VolumeMeshGfx< DIMENSION >::create_gfx(
482 VolumeMeshGfxFactory< DIMENSION >::create( mesh.
type_name(), mesh );
486 "Could not create mesh gfx data structure: ",
492 template std::unique_ptr< PointSetMeshGfx< 2 > > RINGMESH_API
494 template std::unique_ptr< LineMeshGfx< 2 > >
495 RINGMESH_API LineMeshGfx< 2 >::create_gfx(
const LineMesh< 2 >& );
496 template std::unique_ptr< SurfaceMeshGfx< 2 > >
498 template class RINGMESH_API AttributeGfxManagerBase< 2 >;
499 template class RINGMESH_API AttributeGfxManager< 2 >;
501 template std::unique_ptr< PointSetMeshGfx< 3 > > RINGMESH_API
503 template std::unique_ptr< LineMeshGfx< 3 > >
504 RINGMESH_API LineMeshGfx< 3 >::create_gfx(
const LineMesh< 3 >& );
505 template std::unique_ptr< SurfaceMeshGfx< 3 > >
507 template std::unique_ptr< VolumeMeshGfx< 3 > >
509 template class RINGMESH_API AttributeGfxManagerBase< 3 >;
virtual MeshType type_name() const =0
const Surface< DIMENSION > & surface(index_t index) const
Classes to build GeoModel from various inputs.