43 #ifdef RINGMESH_WITH_GRAPHICS 45 #include <geogram/basic/command_line.h> 46 #include <geogram/basic/file_system.h> 48 #include <geogram/mesh/mesh_io.h> 50 #include <geogram_gfx/basic/GL.h> 52 #include <geogram_gfx/glup_viewer/glup_viewer.h> 54 #include <geogram_gfx/third_party/quicktext/glQuickText.h> 69 typedef std::vector< std::vector< ImColor > > ColorTable;
71 ImColor black( 0, 0, 0 );
72 ImColor dark_grey( 128, 128, 128 );
73 ImColor grey( 192, 192, 192 );
74 ImColor white( 255, 255, 255 );
76 ImColor violet( 71, 61, 139 );
77 ImColor blue( 0, 0, 255 );
78 ImColor other_blue( 100, 151, 237 );
79 ImColor light_blue( 136, 207, 235 );
81 ImColor grass_green( 85, 107, 47 );
82 ImColor green( 50, 205, 50 );
83 ImColor light_green( 175, 255, 47 );
84 ImColor brown( 160, 81, 45 );
86 ImColor red( 255, 0, 0 );
87 ImColor orange( 255, 162, 0 );
88 ImColor yellow( 255, 255, 0 );
89 ImColor pink( 255, 0, 255 );
91 ColorTable create_color_table()
93 ColorTable color_table_init( 4 );
94 color_table_init[0].push_back( black );
95 color_table_init[0].push_back( dark_grey );
96 color_table_init[0].push_back( grey );
97 color_table_init[0].push_back( white );
99 color_table_init[1].push_back( violet );
100 color_table_init[1].push_back( blue );
101 color_table_init[1].push_back( other_blue );
102 color_table_init[1].push_back( light_blue );
104 color_table_init[2].push_back( grass_green );
105 color_table_init[2].push_back( green );
106 color_table_init[2].push_back( light_green );
107 color_table_init[2].push_back( brown );
109 color_table_init[3].push_back( red );
110 color_table_init[3].push_back( orange );
111 color_table_init[3].push_back( yellow );
112 color_table_init[3].push_back( pink );
113 return color_table_init;
116 std::string path_to_label(
117 const std::string& viewer_path,
const std::string& path )
119 if( GEO::String::string_starts_with( path, viewer_path ) )
122 viewer_path.length(), path.length() - viewer_path.length() );
127 bool GetChar(
void* data,
int idx,
const char** out_text )
129 *out_text =
static_cast< const std::vector< std::string >*
>(
130 data )->at( static_cast< long unsigned int >( idx ) )
135 template < index_t DIMENSION >
136 void compute_mesh_entity_bbox(
147 template < index_t DIMENSION >
148 RINGMeshApplication::GeoModelViewerBase< DIMENSION >::GeoModelViewerBase(
149 RINGMeshApplication& app,
const std::string& filename )
152 corner_style_.color_ = red;
153 corner_style_.size_ = 1;
154 corner_style_.visible_vertices_ =
false;
155 corner_style_.vertex_color_ = pink;
156 corner_style_.vertex_size_ = 0;
158 line_style_.color_ = black;
159 line_style_.size_ = 1;
160 line_style_.visible_vertices_ =
false;
161 line_style_.vertex_color_ = orange;
162 line_style_.vertex_size_ = 3;
164 surface_style_.color_ = grey;
165 surface_style_.size_ = 1;
166 surface_style_.visible_vertices_ =
false;
167 surface_style_.vertex_color_ = light_blue;
168 surface_style_.vertex_size_ = 3;
171 reset_attribute_name();
176 if( GM_.nb_surfaces() > 0 )
178 for(
const auto& surface : GM_.surfaces() )
180 compute_mesh_entity_bbox( surface, bbox_ );
183 else if( GM_.nb_lines() > 0 )
185 for(
const auto& line : GM_.lines() )
187 compute_mesh_entity_bbox( line, bbox_ );
192 for(
const auto& corner : GM_.corners() )
194 compute_mesh_entity_bbox( corner, bbox_ );
198 const std::vector< MeshEntityType >& types =
199 GM_.entity_type_manager().mesh_entity_manager.mesh_entity_types();
200 entity_types_.reserve( types.size() + 1 );
201 entity_types_.emplace_back(
"All" );
204 entity_types_.emplace_back( type.string() );
206 for(
auto i :
range( GM_.nb_geological_entity_types() ) )
208 entity_types_.emplace_back(
209 GM_.geological_entity_type( i ).string() );
211 GM_gfx_.set_geomodel( GM_ );
212 if( !app.colormaps_.empty() )
214 GM_gfx_.attribute.set_colormap( app.colormaps_[0].texture );
218 template < index_t DIMENSION >
219 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
220 reset_attribute_name()
222 GM_gfx_.attribute.set_name(
"name" );
225 template < index_t DIMENSION >
226 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::draw_scene()
228 if( selected_entity_type_ != 0 )
230 index_t selected_entity_type_casted =
231 static_cast< index_t
>( selected_entity_type_ );
232 const std::string& type =
233 entity_types_[selected_entity_type_casted];
235 if( selected_entity_type_casted
236 < GM_.entity_type_manager()
237 .mesh_entity_manager.nb_mesh_entity_types()
241 selected_entity_id_ = std::min(
242 static_cast< int >( GM_.nb_mesh_entities( mesh_type ) - 1 ),
243 selected_entity_id_ );
245 mesh_type, static_cast< index_t >( selected_entity_id_ ) );
246 toggle_mesh_entity_and_boundaries_visibility( entity_id );
251 selected_entity_id_ =
252 std::min( static_cast< int >(
253 GM_.nb_geological_entities( geol_type ) - 1 ),
254 selected_entity_id_ );
256 geol_type, static_cast< index_t >( selected_entity_id_ ) );
257 toggle_geological_entity_visibility( entity_id );
261 if( show_attributes_ )
263 GM_gfx_.attribute.bind_attribute();
267 GM_gfx_.attribute.unbind_attribute();
272 GM_gfx_.corners.set_vertex_color( corner_style_.color_.Value.x,
273 corner_style_.color_.Value.y, corner_style_.color_.Value.z );
274 GM_gfx_.corners.set_vertex_size(
275 static_cast< index_t >( corner_style_.size_ ) );
276 GM_gfx_.corners.draw();
281 GM_gfx_.lines.set_line_color( line_style_.color_.Value.x,
282 line_style_.color_.Value.y, line_style_.color_.Value.z );
283 GM_gfx_.lines.set_line_size(
284 static_cast< index_t >( line_style_.size_ ) );
285 if( selected_entity_type_ == 0 )
287 GM_gfx_.lines.set_vertex_visibility(
288 line_style_.visible_vertices_ );
290 if( line_style_.visible_vertices_ )
292 GM_gfx_.lines.set_vertex_size(
293 static_cast< index_t >( line_style_.vertex_size_ ) );
294 GM_gfx_.lines.set_vertex_color(
295 line_style_.vertex_color_.Value.x,
296 line_style_.vertex_color_.Value.y,
297 line_style_.vertex_color_.Value.z );
299 GM_gfx_.lines.draw();
304 GM_gfx_.surfaces.set_mesh_visibility( mesh_visible_ );
305 GM_gfx_.surfaces.set_mesh_color(
306 mesh_color_.Value.x, mesh_color_.Value.y, mesh_color_.Value.z );
307 GM_gfx_.surfaces.set_surface_color( surface_style_.color_.Value.x,
308 surface_style_.color_.Value.y, surface_style_.color_.Value.z );
309 GM_gfx_.surfaces.set_mesh_size(
310 static_cast< index_t >( surface_style_.size_ ) );
311 if( selected_entity_type_ == 0 )
313 GM_gfx_.surfaces.set_vertex_visibility(
314 surface_style_.visible_vertices_ );
316 if( surface_style_.visible_vertices_ )
318 GM_gfx_.surfaces.set_vertex_size(
319 static_cast< index_t >( surface_style_.vertex_size_ ) );
320 GM_gfx_.surfaces.set_vertex_color(
321 surface_style_.vertex_color_.Value.x,
322 surface_style_.vertex_color_.Value.y,
323 surface_style_.vertex_color_.Value.z );
325 if( selected_entity_type_ == 0 )
327 for(
const auto& surface : GM_.surfaces() )
329 if( surface.is_on_voi() )
331 GM_gfx_.surfaces.set_surface_visibility(
332 surface.index(), show_voi_ );
336 GM_gfx_.surfaces.draw();
340 template < index_t DIMENSION >
341 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
342 set_attribute_names(
const std::vector< std::string >& names )
344 for(
const std::string& name : names )
346 if( ImGui::Button( name.c_str() ) )
348 GM_gfx_.attribute.set_name( name );
349 GM_gfx_.attribute.set_coordinate( 0 );
351 ImGui::CloseCurrentPopup();
356 template < index_t DIMENSION >
357 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::autorange()
359 GM_gfx_.attribute.compute_range();
360 attribute_max_ =
static_cast< float >( GM_gfx_.attribute.maximum() );
361 attribute_min_ =
static_cast< float >( GM_gfx_.attribute.minimum() );
364 template < index_t DIMENSION >
365 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
366 update_all_entity_visibility(
bool value )
368 GM_gfx_.corners.set_vertex_visibility( value );
369 GM_gfx_.lines.set_line_visibility( value );
370 GM_gfx_.surfaces.set_surface_visibility( value );
371 if( !value || line_style_.visible_vertices_ )
373 GM_gfx_.lines.set_vertex_visibility( value );
375 if( !value || surface_style_.visible_vertices_ )
377 GM_gfx_.surfaces.set_vertex_visibility( value );
381 template < index_t DIMENSION >
382 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
383 update_entity_visibility()
385 index_t selected_entity_type_casted =
386 static_cast< index_t
>( selected_entity_type_ );
387 const std::string& type = entity_types_[selected_entity_type_casted];
388 if( selected_entity_type_ == 0 )
390 update_all_entity_visibility(
true );
394 update_all_entity_visibility(
false );
395 if( selected_entity_type_casted
396 < GM_.entity_type_manager()
397 .mesh_entity_manager.nb_mesh_entity_types()
401 selected_entity_id_ = std::min(
402 static_cast< int >( GM_.nb_mesh_entities( mesh_type ) - 1 ),
403 selected_entity_id_ );
405 mesh_type, static_cast< index_t >( selected_entity_id_ ) );
406 toggle_mesh_entity_and_boundaries_visibility( entity_id );
411 selected_entity_id_ =
412 std::min( static_cast< int >(
413 GM_.nb_geological_entities( geol_type ) - 1 ),
414 selected_entity_id_ );
416 geol_type, static_cast< index_t >( selected_entity_id_ ) );
417 toggle_geological_entity_visibility( entity_id );
422 template < index_t DIMENSION >
423 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
424 toggle_mesh_entity_and_boundaries_visibility(
const gmme_id& entity_id )
427 GM_.entity_type_manager().mesh_entity_manager;
430 toggle_corner_visibility( entity_id.
index() );
434 toggle_line_and_boundaries_visibility( entity_id.
index() );
438 toggle_surface_and_boundaries_visibility( entity_id.
index() );
446 template < index_t DIMENSION >
447 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
448 toggle_corner_visibility( index_t corner_id )
450 GM_gfx_.corners.set_vertex_visibility( corner_id,
true );
453 template < index_t DIMENSION >
454 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
455 toggle_line_and_boundaries_visibility( index_t line_id )
457 GM_gfx_.lines.set_line_visibility( line_id,
true );
458 GM_gfx_.lines.set_vertex_visibility(
459 line_id, line_style_.visible_vertices_ );
467 template < index_t DIMENSION >
468 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
469 toggle_surface_and_boundaries_visibility( index_t surface_id )
471 GM_gfx_.surfaces.set_surface_visibility( surface_id,
true );
472 GM_gfx_.surfaces.set_vertex_visibility(
473 surface_id, surface_style_.visible_vertices_ );
477 toggle_line_and_boundaries_visibility(
482 template < index_t DIMENSION >
483 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
484 toggle_geological_entity_visibility(
const gmge_id& entity_id )
487 GM_.geological_entity( entity_id );
491 toggle_mesh_entity_and_boundaries_visibility( child_id );
495 template < index_t DIMENSION >
496 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
497 draw_object_properties()
499 if( ImGui::Combo(
"Type", &selected_entity_type_, GetChar,
500 static_cast< void* >( &entity_types_ ),
501 static_cast< int >( entity_types_.size() ) ) )
503 update_entity_visibility();
505 if( selected_entity_type_ > 0 )
507 if( ImGui::InputInt(
"Id", &selected_entity_id_, 1 ) )
509 selected_entity_id_ = std::max( 0, selected_entity_id_ );
510 update_entity_visibility();
514 ImGui::Checkbox(
"Attributes", &show_attributes_ );
515 if( show_attributes_ )
517 if( ImGui::Button( GM_gfx_.attribute.location_name().c_str(),
520 ImGui::OpenPopup(
"##Locations" );
522 if( ImGui::BeginPopup(
"##Locations" ) )
524 std::vector< std::string > locations =
525 GM_gfx_.attribute.registered_locations();
526 for(
const std::string& location : locations )
528 if( ImGui::Button( location.c_str() ) )
530 GM_gfx_.attribute.set_location( location );
531 reset_attribute_name();
532 ImGui::CloseCurrentPopup();
539 GM_gfx_.attribute.name().c_str(), ImVec2( -1, 0 ) ) )
541 ImGui::OpenPopup(
"##Attributes" );
543 if( ImGui::BeginPopup(
"##Attributes" ) )
545 set_attribute_names( GM_gfx_.attribute.get_attribute_names() );
548 if( GM_gfx_.attribute.location_name() !=
"location" 549 && GM_gfx_.attribute.nb_coordinates() > 1 )
552 std::to_string( GM_gfx_.attribute.coordinate() )
556 ImGui::OpenPopup(
"##Coordinates" );
558 if( ImGui::BeginPopup(
"##Coordinates" ) )
560 for(
auto i :
range( GM_gfx_.attribute.nb_coordinates() ) )
562 if( ImGui::Button( std::to_string( i ).c_str() ) )
564 GM_gfx_.attribute.set_coordinate( i );
566 ImGui::CloseCurrentPopup();
572 if( ImGui::InputFloat(
"min", &attribute_min_ ) )
574 GM_gfx_.attribute.set_minimum(
575 static_cast< double >( attribute_min_ ) );
577 if( ImGui::InputFloat(
"max", &attribute_max_ ) )
579 GM_gfx_.attribute.set_maximum(
580 static_cast< double >( attribute_max_ ) );
582 if( ImGui::Button(
"autorange", ImVec2( -1, 0 ) ) )
586 if( ImGui::ImageButton(
587 app_.convert_to_ImTextureID( GM_gfx_.attribute.colormap() ),
590 ImGui::OpenPopup(
"##Colormap" );
592 if( ImGui::BeginPopup(
"##Colormap" ) )
594 for(
const auto& colormap : app_.colormaps_ )
596 if( ImGui::ImageButton(
597 app_.convert_to_ImTextureID( colormap.texture ),
600 GM_gfx_.attribute.set_colormap( colormap.texture );
601 ImGui::CloseCurrentPopup();
606 ImGui::Checkbox(
"Colormap [M]", &show_colormap_ );
610 ImGui::Checkbox(
"VOI [V]", &show_voi_ );
611 ImGui::Checkbox(
"Mesh [m]", &mesh_visible_ );
613 ImGui::PushStyleColor( ImGuiCol_Button, mesh_color_ );
614 if( ImGui::Button(
" ##MeshColor" ) )
616 ImGui::OpenPopup(
"##MeshColorTable" );
618 ImGui::PopStyleColor();
619 if( ImGui::BeginPopup(
"##MeshColorTable" ) )
621 show_color_table_popup( mesh_color_ );
625 ImGui::Checkbox(
"Corner [c]", &show_corners_ );
626 draw_entity_style_editor(
"##CornerColor", corner_style_ );
629 ImGui::Checkbox(
"Line [e]", &show_lines_ );
630 draw_entity_style_editor(
"##LineColor", line_style_ );
631 ImGui::Checkbox(
"Vertices##Line", &line_style_.visible_vertices_ );
632 if( line_style_.visible_vertices_ )
634 draw_entity_vertex_style_editor(
"##LineVertexColor", line_style_ );
638 ImGui::Checkbox(
"Surface [s]", &show_surface_ );
639 draw_entity_style_editor(
"##SurfaceColor", surface_style_ );
641 "Vertices##Surface", &surface_style_.visible_vertices_ );
642 if( surface_style_.visible_vertices_ )
644 draw_entity_vertex_style_editor(
645 "##SurfaceVertexColor", surface_style_ );
649 template < index_t DIMENSION >
650 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
651 draw_entity_style_editor(
const std::string& label, EntityStyle& style )
653 ImGui::PushStyleColor( ImGuiCol_Button, style.color_ );
654 if( ImGui::Button( (
" " + label ).c_str() ) )
656 ImGui::OpenPopup( label.c_str() );
658 ImGui::PopStyleColor();
659 if( ImGui::BeginPopup( label.c_str() ) )
661 show_color_table_popup( style.color_ );
664 ImGui::InputInt(
"", &style.size_, 1 );
665 style.size_ = std::max( style.size_, 0 );
668 template < index_t DIMENSION >
669 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::
670 draw_entity_vertex_style_editor(
671 const std::string& label, EntityStyle& style )
673 ImGui::PushStyleColor( ImGuiCol_Button, style.vertex_color_ );
674 if( ImGui::Button( (
" " + label ).c_str() ) )
676 ImGui::OpenPopup( label.c_str() );
678 ImGui::PopStyleColor();
679 if( ImGui::BeginPopup( label.c_str() ) )
681 show_color_table_popup( style.vertex_color_ );
684 ImGui::InputInt(
"", &style.vertex_size_, 1 );
685 style.vertex_size_ = std::max( style.vertex_size_, 0 );
686 style.vertex_size_ = std::min( style.vertex_size_, 50 );
689 template < index_t DIMENSION >
690 void RINGMeshApplication::GeoModelViewerBase< DIMENSION >::draw_colormap()
692 GLUPboolean clipping_save = glupIsEnabled( GLUP_CLIPPING );
693 glupDisable( GLUP_CLIPPING );
695 glupMatrixMode( GLUP_TEXTURE_MATRIX );
698 glupMatrixMode( GLUP_PROJECTION_MATRIX );
702 glupMatrixMode( GLUP_MODELVIEW_MATRIX );
706 const double z = -1.0;
707 const double w = 0.3;
708 const double h = 0.1;
709 const double x1 = 0.;
710 const double y1 = -0.9;
711 const double tmin = GM_gfx_.attribute.minimum();
712 const double tmax = GM_gfx_.attribute.maximum();
713 GEO::glupMapTexCoords1d( tmin, tmax, 1. );
715 glupColor3d( 1.0, 1.0, 1.0 );
716 glupDisable( GLUP_LIGHTING );
717 glupEnable( GLUP_TEXTURING );
718 glupTextureMode( GLUP_TEXTURE_REPLACE );
719 glupTextureType( GLUP_TEXTURE_1D );
720 glupEnable( GLUP_DRAW_MESH );
721 glupSetColor3d( GLUP_MESH_COLOR, 0.0, 0.0, 0.0 );
722 glupSetMeshWidth( 2 );
723 glupSetCellsShrink( 0.0f );
725 glupBegin( GLUP_QUADS );
726 glupTexCoord1d( tmin );
727 glupVertex3d( x1 - w, y1, z );
728 glupTexCoord1d( tmax );
729 glupVertex3d( x1 + w, y1, z );
730 glupTexCoord1d( tmax );
731 glupVertex3d( x1 + w, y1 + h, z );
732 glupTexCoord1d( tmin );
733 glupVertex3d( x1 - w, y1 + h, z );
736 glupTextureType( GLUP_TEXTURE_2D );
737 glupMatrixMode( GLUP_TEXTURE_MATRIX );
739 glupMatrixMode( GLUP_MODELVIEW_MATRIX );
741 glupSetColor4d( GLUP_FRONT_AND_BACK_COLOR, 0.0, 0.0, 0.0, 1.0 );
743 const double font_sz = 0.003;
744 const double font_height = 0.4 * glQuickText::getFontHeight( font_sz );
746 std::string min_value = std::to_string( GM_gfx_.attribute.minimum() );
747 const double nb_min_letter =
static_cast< double >( min_value.size() );
748 glQuickText::printfAt( x1 - w - font_height * nb_min_letter * 0.3,
749 y1 - font_height, z, font_sz, min_value.c_str() );
751 std::string max_value = std::to_string( GM_gfx_.attribute.maximum() );
752 const double nb_max_letter =
static_cast< double >( max_value.size() );
753 glQuickText::printfAt( x1 + w - font_height * nb_max_letter * 0.3,
754 y1 - font_height, z, font_sz, max_value.c_str() );
756 glupMatrixMode( GLUP_PROJECTION_MATRIX );
759 glupMatrixMode( GLUP_MODELVIEW_MATRIX );
764 glupEnable( GLUP_CLIPPING );
768 RINGMeshApplication::GeoModelViewer< 2 >::GeoModelViewer(
769 RINGMeshApplication& app,
const std::string& filename )
770 : RINGMeshApplication::GeoModelViewerBase< 2 >( app, filename )
774 RINGMeshApplication::GeoModelViewer< 3 >::GeoModelViewer(
775 RINGMeshApplication& app,
const std::string& filename )
776 : RINGMeshApplication::GeoModelViewerBase< 3 >( app, filename )
778 volume_style_.color_ = grey;
779 volume_style_.size_ = 1;
780 volume_style_.visible_vertices_ =
false;
781 volume_style_.vertex_color_ = light_green;
782 volume_style_.vertex_size_ = 3;
784 if( GM_.nb_regions() > 0 )
786 meshed_regions_ = GM_.region( 0 ).is_meshed();
788 if( meshed_regions_ )
794 void RINGMeshApplication::GeoModelViewer< 3 >::toggle_colored_cells()
796 show_colored_regions_.new_status =
false;
797 show_colored_layers_.new_status =
false;
798 GM_gfx_.regions.set_cell_colors_by_type();
801 void RINGMeshApplication::GeoModelViewer< 3 >::toggle_colored_regions()
803 colored_cells_.new_status =
false;
804 show_colored_layers_.new_status =
false;
805 for(
auto r :
range( GM_.nb_regions() ) )
807 GM_gfx_.regions.set_region_color( r,
808 std::fmod( GEO::Numeric::random_float32(), 1.f ),
809 std::fmod( GEO::Numeric::random_float32(), 1.f ),
810 std::fmod( GEO::Numeric::random_float32(), 1.f ) );
814 void RINGMeshApplication::GeoModelViewer< 3 >::toggle_colored_layers()
818 if( !GM_.entity_type_manager().geological_entity_manager.is_valid_type(
819 Layer3D::type_name_static() ) )
821 show_colored_layers_.new_status =
false;
824 colored_cells_.new_status =
false;
825 show_colored_regions_.new_status =
false;
827 range( GM_.nb_geological_entities( Layer3D::type_name_static() ) ) )
829 float red = std::fmod( GEO::Numeric::random_float32(), 1.f );
830 float green = std::fmod( GEO::Numeric::random_float32(), 1.f );
831 float blue = std::fmod( GEO::Numeric::random_float32(), 1.f );
832 const GeoModelGeologicalEntity3D& cur_layer =
833 GM_.geological_entity( Layer3D::type_name_static(), l );
834 for(
auto r :
range( cur_layer.nb_children() ) )
835 GM_gfx_.regions.set_region_color(
836 cur_layer.child( r ).index(), red, green, blue );
840 void RINGMeshApplication::GeoModelViewer< 3 >::draw_scene()
842 GeoModelViewerBase3D::draw_scene();
844 if( show_volume_ && meshed_regions_ )
846 GM_gfx_.regions.set_mesh_visibility( mesh_visible_ );
847 if( colored_cells_.need_to_update() )
849 colored_cells_.update();
850 if( colored_cells_.new_status )
852 toggle_colored_cells();
855 else if( show_colored_regions_.need_to_update() )
857 show_colored_regions_.update();
858 if( show_colored_regions_.new_status )
860 toggle_colored_regions();
863 else if( show_colored_layers_.need_to_update() )
865 show_colored_layers_.update();
866 if( show_colored_layers_.new_status )
868 toggle_colored_layers();
871 if( !colored_cells_.new_status && !show_colored_regions_.new_status
872 && !show_colored_layers_.new_status )
874 colored_cells_.update();
875 show_colored_regions_.update();
876 show_colored_layers_.update();
877 GM_gfx_.regions.set_mesh_color( mesh_color_.Value.x,
878 mesh_color_.Value.y, mesh_color_.Value.z );
879 GM_gfx_.regions.set_region_color( volume_style_.color_.Value.x,
880 volume_style_.color_.Value.y,
881 volume_style_.color_.Value.z );
883 GM_gfx_.regions.set_mesh_size(
884 static_cast< index_t >( volume_style_.size_ ) );
885 if( selected_entity_type_ == 0 )
887 GM_gfx_.regions.set_vertex_visibility(
888 volume_style_.visible_vertices_ );
890 if( volume_style_.visible_vertices_ )
892 GM_gfx_.regions.set_vertex_size(
893 static_cast< index_t >( volume_style_.vertex_size_ ) );
894 GM_gfx_.regions.set_vertex_color(
895 volume_style_.vertex_color_.Value.x,
896 volume_style_.vertex_color_.Value.y,
897 volume_style_.vertex_color_.Value.z );
902 GM_gfx_.regions.set_draw_cells(
904 GM_gfx_.regions.set_shrink( static_cast< double >( shrink_ ) );
905 GM_gfx_.regions.draw();
909 void RINGMeshApplication::GeoModelViewer< 3 >::update_all_entity_visibility(
912 GeoModelViewerBase3D::update_all_entity_visibility( value );
913 GM_gfx_.regions.set_region_visibility( value );
914 if( volume_style_.visible_vertices_ )
916 GM_gfx_.regions.set_vertex_visibility( value );
920 void RINGMeshApplication::GeoModelViewer< 3 >::
921 toggle_region_and_boundaries_visibility( index_t region_id )
923 GM_gfx_.regions.set_region_visibility( region_id,
true );
924 GM_gfx_.regions.set_vertex_visibility(
925 region_id, volume_style_.visible_vertices_ );
926 const Region3D& region = GM_.region( region_id );
927 for(
auto i :
range( region.nb_boundaries() ) )
929 toggle_surface_and_boundaries_visibility(
930 region.boundary_gmme( i ).index() );
934 void RINGMeshApplication::GeoModelViewer< 3 >::
935 toggle_mesh_entity_and_boundaries_visibility(
const gmme_id& entity_id )
937 const MeshEntityTypeManager3D& manager =
938 GM_.entity_type_manager().mesh_entity_manager;
939 if( manager.is_region( entity_id.
type() ) )
941 toggle_region_and_boundaries_visibility( entity_id.
index() );
945 GeoModelViewerBase3D::toggle_mesh_entity_and_boundaries_visibility(
950 void RINGMeshApplication::GeoModelViewer< 3 >::draw_object_properties()
952 GeoModelViewerBase3D::draw_object_properties();
954 if( meshed_regions_ )
957 ImGui::Checkbox(
"Region [v]", &show_volume_ );
958 draw_entity_style_editor(
"##VolumeColor", volume_style_ );
960 "Vertices##Region", &volume_style_.visible_vertices_ );
961 if( volume_style_.visible_vertices_ )
963 draw_entity_vertex_style_editor(
964 "##VolumeVertexColor", volume_style_ );
968 ImGui::Checkbox(
"Col. cells [C]", &colored_cells_.new_status );
970 "Col. regions [r]", &show_colored_regions_.new_status );
971 if( GM_.entity_type_manager()
972 .geological_entity_manager.is_valid_type(
973 Layer3D::type_name_static() ) )
976 "Col. layers [R]", &show_colored_layers_.new_status );
978 ImGui::SliderFloat(
"Shrk.", &shrink_, 0.0f, 1.0f,
"%.1f" );
979 ImGui::Checkbox(
"Hex", &show_hex_ );
980 ImGui::Checkbox(
"Prism", &show_prism_ );
981 ImGui::Checkbox(
"Pyramid", &show_pyramid_ );
982 ImGui::Checkbox(
"Tetra", &show_tetra_ );
988 RINGMeshApplication::MeshViewer::MeshViewer(
989 RINGMeshApplication& app,
const std::string& filename )
992 vertices_color_ = green;
994 if( !filename.empty() )
996 GEO::mesh_load( filename, mesh_ );
997 name_ = GEO::FileSystem::base_name( filename,
true );
999 mesh_gfx_.set_mesh( &mesh_ );
1001 for(
auto v :
range( mesh_.vertices.nb() ) )
1003 bbox_.add_point( mesh_.vertices.point( v ) );
1007 void RINGMeshApplication::MeshViewer::draw_object_properties()
1009 ImGui::Checkbox(
"attributes", &show_attributes_ );
1010 if( show_attributes_ )
1012 if( attribute_min_ == 0.0f && attribute_max_ == 0.0f )
1017 ( attribute_ +
"##Attribute" ).c_str(), ImVec2( -1, 0 ) ) )
1019 ImGui::OpenPopup(
"##Attributes" );
1021 if( ImGui::BeginPopup(
"##Attributes" ) )
1023 std::vector< std::string > attributes;
1024 GEO::String::split_string( attribute_names(),
';', attributes );
1025 for(
const std::string& att : attributes )
1027 if( ImGui::Button( att.c_str() ) )
1029 set_attribute( att );
1030 ImGui::CloseCurrentPopup();
1035 ImGui::InputFloat(
"min", &attribute_min_ );
1036 ImGui::InputFloat(
"max", &attribute_max_ );
1037 if( ImGui::Button(
"autorange", ImVec2( -1, 0 ) ) )
1041 if( ImGui::ImageButton(
1042 app_.convert_to_ImTextureID( current_colormap_texture_ ),
1043 ImVec2( 115, 8 ) ) )
1045 ImGui::OpenPopup(
"##Colormap" );
1047 if( ImGui::BeginPopup(
"##Colormap" ) )
1049 for(
const auto& colormap : app_.colormaps_ )
1051 if( ImGui::ImageButton(
1052 app_.convert_to_ImTextureID( colormap.texture ),
1053 ImVec2( 100, 8 ) ) )
1055 current_colormap_texture_ = colormap.texture;
1056 ImGui::CloseCurrentPopup();
1064 ImGui::Checkbox(
"Vertices [p]", &show_vertices_ );
1065 if( show_vertices_ )
1067 ImGui::SliderFloat(
"sz.", &vertices_size_, 0.1f, 5.0f,
"%.1f" );
1068 ImGui::PushStyleColor( ImGuiCol_Button, vertices_color_ );
1069 if( ImGui::Button(
" ##VerticesColor" ) )
1071 ImGui::OpenPopup(
"##VerticesColorTable" );
1073 ImGui::PopStyleColor();
1074 if( ImGui::BeginPopup(
"##VerticesColorTable" ) )
1076 show_color_table_popup( vertices_color_ );
1079 ImGui::Text(
"color" );
1082 if( mesh_.facets.nb() != 0 )
1085 ImGui::Checkbox(
"Surface [S]", &show_surface_ );
1088 ImGui::Checkbox(
"colors [c]", &show_surface_colors_ );
1089 ImGui::Checkbox(
"mesh [m]", &show_mesh_ );
1090 ImGui::Checkbox(
"borders [B]", &show_surface_borders_ );
1094 if( mesh_.cells.nb() != 0 )
1097 ImGui::Checkbox(
"Volume [V]", &show_volume_ );
1101 "shrk.", &cells_shrink_, 0.0f, 1.0f,
"%.2f" );
1102 if( !mesh_.cells.are_simplices() )
1105 "colored cells [C]", &show_colored_cells_ );
1106 ImGui::Checkbox(
"hexes [j]", &show_hexes_ );
1112 void RINGMeshApplication::MeshViewer::draw_scene()
1114 mesh_gfx_.set_lighting( app_.lighting_ );
1116 if( show_attributes_ )
1118 mesh_gfx_.set_scalar_attribute( attribute_subelements_,
1119 attribute_name_,
double( attribute_min_ ),
1120 double( attribute_max_ ), current_colormap_texture_, 1 );
1124 mesh_gfx_.unset_scalar_attribute();
1127 if( show_vertices_ )
1129 mesh_gfx_.set_points_size( vertices_size_ );
1130 mesh_gfx_.set_points_color( vertices_color_.Value.x,
1131 vertices_color_.Value.y, vertices_color_.Value.z );
1132 mesh_gfx_.draw_vertices();
1135 if( app_.white_bg_ )
1137 mesh_gfx_.set_mesh_color( 0.0, 0.0, 0.0 );
1141 mesh_gfx_.set_mesh_color( 1.0, 1.0, 1.0 );
1144 if( show_surface_colors_ )
1146 if( mesh_.cells.nb() == 0 )
1148 mesh_gfx_.set_surface_color( 0.5f, 0.75f, 1.0f );
1149 mesh_gfx_.set_backface_surface_color( 1.0f, 0.0f, 0.0f );
1153 mesh_gfx_.set_surface_color( 0.7f, 0.0f, 0.0f );
1154 mesh_gfx_.set_backface_surface_color( 1.0f, 1.0f, 0.0f );
1159 if( app_.white_bg_ )
1161 mesh_gfx_.set_surface_color( 0.9f, 0.9f, 0.9f );
1165 mesh_gfx_.set_surface_color( 0.1f, 0.1f, 0.1f );
1169 mesh_gfx_.set_show_mesh( show_mesh_ );
1173 mesh_gfx_.draw_surface();
1176 if( show_surface_borders_ )
1178 mesh_gfx_.draw_surface_borders();
1183 mesh_gfx_.draw_edges();
1188 if( glupIsEnabled( GLUP_CLIPPING )
1189 && glupGetClipMode() == GLUP_CLIP_SLICE_CELLS )
1191 mesh_gfx_.set_lighting(
false );
1194 mesh_gfx_.set_shrink(
double( cells_shrink_ ) );
1195 mesh_gfx_.set_draw_cells( GEO::MESH_HEX, show_hexes_ );
1196 if( show_colored_cells_ )
1198 mesh_gfx_.set_cells_colors_by_type();
1202 mesh_gfx_.set_cells_color( 0.9f, 0.9f, 0.9f );
1204 mesh_gfx_.draw_volume();
1206 mesh_gfx_.set_lighting( app_.lighting_ );
1210 void RINGMeshApplication::MeshViewer::autorange()
1212 if( attribute_subelements_ != GEO::MESH_NONE )
1214 attribute_min_ = 0.0;
1215 attribute_max_ = 0.0;
1216 const GEO::MeshSubElementsStore& subelements =
1217 mesh_.get_subelements_by_type( attribute_subelements_ );
1218 GEO::ReadOnlyScalarAttributeAdapter attribute(
1219 subelements.attributes(), attribute_name_ );
1220 if( attribute.is_bound() )
1222 attribute_min_ = GEO::Numeric::max_float32();
1223 attribute_max_ = GEO::Numeric::min_float32();
1224 for(
auto i :
range( subelements.nb() ) )
1227 GEO::geo_min( attribute_min_,
float( attribute[i] ) );
1229 GEO::geo_max( attribute_max_,
float( attribute[i] ) );
1235 std::string RINGMeshApplication::MeshViewer::attribute_names()
1237 return mesh_.get_scalar_attributes();
1240 void RINGMeshApplication::MeshViewer::set_attribute(
1241 const std::string& attribute )
1243 attribute_ = attribute;
1244 std::string subelements_name;
1245 GEO::String::split_string(
1246 attribute_,
'.', subelements_name, attribute_name_ );
1247 attribute_subelements_ =
1248 mesh_.name_to_subelements_type( subelements_name );
1249 if( attribute_min_ == 0.0f && attribute_max_ == 0.0f )
1257 RINGMeshApplication::RINGMeshApplication(
int argc,
char** argv )
1258 :
GEO::Application( argc, argv,
"<filename>" )
1260 GEO::CmdLine::declare_arg(
"attributes",
true,
"load mesh attributes" );
1261 GEO::CmdLine::declare_arg(
1262 "single_precision",
false,
"use single precision vertices (FP32)" );
1265 auto ringmesh_2d_extensions =
1266 GeoModelIOHandlerFactory2D::list_creators();
1267 auto ringmesh_3d_extensions =
1268 GeoModelIOHandlerFactory3D::list_creators();
1269 ringmesh_file_extensions_ =
1270 GEO::String::join_strings( ringmesh_2d_extensions,
';' )
1271 + GEO::String::join_strings( ringmesh_3d_extensions,
';' );
1273 std::vector< std::string > geogram_extensions;
1274 GEO::MeshIOHandlerFactory::list_creators( geogram_extensions );
1275 geogram_file_extensions_ =
1276 GEO::String::join_strings( geogram_extensions,
';' );
1284 void RINGMeshApplication::quit()
1286 glup_viewer_exit_main_loop();
1290 RINGMeshApplication* RINGMeshApplication::instance()
1292 RINGMeshApplication* result =
dynamic_cast< RINGMeshApplication*
>(
1293 GEO::Application::instance() );
1298 void RINGMeshApplication::browse_geogram(
const std::string& path )
1300 std::vector< std::string > files;
1301 GEO::FileSystem::get_directory_entries( path, files );
1302 std::sort( files.begin(), files.end() );
1303 for(
const std::string& file : files )
1305 if( GEO::FileSystem::is_directory( file ) )
1307 if( ImGui::BeginMenu( path_to_label( path_, file ).c_str() ) )
1309 browse_geogram( file );
1315 if( can_load_geogram( file ) )
1317 if( ImGui::MenuItem(
1318 path_to_label( path_, file ).c_str() ) )
1320 load_geogram( file );
1327 bool RINGMeshApplication::can_load_geogram(
const std::string& filename )
1329 std::string extensions_str = supported_geogram_read_file_extensions();
1330 if( extensions_str ==
"" )
1334 if( extensions_str ==
"*" )
1338 std::string extension = GEO::FileSystem::extension( filename );
1339 std::vector< std::string > extensions;
1340 GEO::String::split_string( extensions_str,
';', extensions );
1341 for(
const std::string& ext : extensions )
1343 if( ext == extension )
1351 bool RINGMeshApplication::load_geogram(
const std::string& filename )
1353 if( !filename.empty() )
1355 meshes_.emplace_back(
new MeshViewer( *
this, filename ) );
1356 current_viewer_ =
static_cast< index_t
>( meshes_.size() - 1 );
1357 current_viewer_type_ = ViewerType::MESH;
1360 update_region_of_interest();
1364 void RINGMeshApplication::draw_application_menus()
1366 if( ImGui::BeginMenu(
"Debug" ) )
1368 if( ImGui::BeginMenu(
"Load..." ) )
1370 ImGui::Selectable(
".." );
1371 if( ImGui::IsItemClicked() )
1375 browse_geogram( path_ );
1380 if( ImGui::BeginMenu(
"Create..." ) )
1382 if( ImGui::MenuItem(
"point" ) )
1384 GEO::Command::set_current(
1385 "create_point(std::string name=\"debug\"," 1386 " double x=0, double y=0, double z=0)",
1387 this, &RINGMeshApplication::create_point );
1389 if( ImGui::MenuItem(
"AABB" ) )
1391 GEO::Command::set_current(
1392 "create_aabbox(std::string name=\"box\"," 1393 " double xmin=0, double ymin=0, double zmin=0," 1394 " double xmax=1, double ymax=1, double zmax=1)",
1395 this, &RINGMeshApplication::create_aabbox );
1401 void RINGMeshApplication::create_point(
1402 std::string name,
double x,
double y,
double z )
1404 MeshViewer* viewer{
nullptr };
1405 for(
auto& i : meshes_ )
1407 if( i->name_ == name )
1415 meshes_.emplace_back(
new MeshViewer( *
this,
"" ) );
1416 viewer = meshes_.back().get();
1418 vec3 point{ x, y, z };
1419 viewer->mesh_.vertices.create_vertex( point.data() );
1420 viewer->mesh_gfx_.set_mesh( &viewer->mesh_ );
1421 viewer->bbox_.add_point( point );
1422 viewer->name_ = name;
1423 viewer->show_vertices_ =
true;
1424 current_viewer_ =
static_cast< index_t
>( meshes_.size() - 1 );
1425 current_viewer_type_ = ViewerType::MESH;
1426 update_region_of_interest();
1429 void RINGMeshApplication::create_aabbox( std::string name,
1437 vec3 min{ xmin, ymin, zmin };
1438 vec3 max{ xmax, ymax, zmax };
1439 MeshViewer* viewer{
nullptr };
1440 for(
auto& i : meshes_ )
1442 if( i->name_ == name )
1450 meshes_.emplace_back(
new MeshViewer( *
this,
"" ) );
1451 viewer = meshes_.back().get();
1453 const index_t prev_nbv{ viewer->mesh_.vertices.nb() };
1454 vec3 box_other_vertex1{ min[0], min[1], max[2] };
1455 vec3 box_other_vertex2{ min[0], max[1], max[2] };
1456 vec3 box_other_vertex3{ max[0], min[1], max[2] };
1457 vec3 box_other_vertex4{ max[0], max[1], min[2] };
1458 vec3 box_other_vertex5{ max[0], min[1], min[2] };
1459 vec3 box_other_vertex6{ min[0], max[1], min[2] };
1460 viewer->mesh_.vertices.create_vertex( min.data() );
1461 viewer->mesh_.vertices.create_vertex( box_other_vertex1.data() );
1462 viewer->mesh_.vertices.create_vertex( box_other_vertex2.data() );
1463 viewer->mesh_.vertices.create_vertex( box_other_vertex3.data() );
1464 viewer->mesh_.vertices.create_vertex( box_other_vertex4.data() );
1465 viewer->mesh_.vertices.create_vertex( box_other_vertex5.data() );
1466 viewer->mesh_.vertices.create_vertex( box_other_vertex6.data() );
1467 viewer->mesh_.vertices.create_vertex( max.data() );
1468 viewer->mesh_.edges.create_edge( prev_nbv + 0, prev_nbv + 1 );
1469 viewer->mesh_.edges.create_edge( prev_nbv + 0, prev_nbv + 5 );
1470 viewer->mesh_.edges.create_edge( prev_nbv + 0, prev_nbv + 6 );
1471 viewer->mesh_.edges.create_edge( prev_nbv + 1, prev_nbv + 2 );
1472 viewer->mesh_.edges.create_edge( prev_nbv + 1, prev_nbv + 3 );
1473 viewer->mesh_.edges.create_edge( prev_nbv + 2, prev_nbv + 6 );
1474 viewer->mesh_.edges.create_edge( prev_nbv + 2, prev_nbv + 7 );
1475 viewer->mesh_.edges.create_edge( prev_nbv + 3, prev_nbv + 5 );
1476 viewer->mesh_.edges.create_edge( prev_nbv + 3, prev_nbv + 7 );
1477 viewer->mesh_.edges.create_edge( prev_nbv + 4, prev_nbv + 5 );
1478 viewer->mesh_.edges.create_edge( prev_nbv + 4, prev_nbv + 6 );
1479 viewer->mesh_.edges.create_edge( prev_nbv + 4, prev_nbv + 7 );
1480 viewer->mesh_.facets.create_quad(
1481 prev_nbv + 0, prev_nbv + 6, prev_nbv + 4, prev_nbv + 5 );
1482 viewer->mesh_.facets.create_quad(
1483 prev_nbv + 0, prev_nbv + 1, prev_nbv + 2, prev_nbv + 6 );
1484 viewer->mesh_.facets.create_quad(
1485 prev_nbv + 0, prev_nbv + 5, prev_nbv + 3, prev_nbv + 1 );
1486 viewer->mesh_.facets.create_quad(
1487 prev_nbv + 7, prev_nbv + 2, prev_nbv + 1, prev_nbv + 3 );
1488 viewer->mesh_.facets.create_quad(
1489 prev_nbv + 7, prev_nbv + 3, prev_nbv + 5, prev_nbv + 4 );
1490 viewer->mesh_.facets.create_quad(
1491 prev_nbv + 7, prev_nbv + 4, prev_nbv + 6, prev_nbv + 2 );
1492 viewer->mesh_gfx_.set_mesh( &viewer->mesh_ );
1493 viewer->bbox_.add_point( min );
1494 viewer->bbox_.add_point( max );
1495 viewer->name_ = name;
1496 viewer->show_vertices_ =
false;
1497 viewer->show_mesh_ =
true;
1498 viewer->show_surface_borders_ =
false;
1499 viewer->show_surface_colors_ =
false;
1500 current_viewer_ =
static_cast< index_t
>( meshes_.size() - 1 );
1501 current_viewer_type_ = ViewerType::MESH;
1502 update_region_of_interest();
1505 void RINGMeshApplication::init_graphics()
1507 GEO::Application::init_graphics();
1510 glup_viewer_disable( GLUP_VIEWER_BACKGROUND );
1513 void RINGMeshApplication::show_color_table_popup( ImColor& color )
1516 for(
const auto& colors : color_table_ )
1518 for(
auto j :
range( colors.size() ) )
1524 ImGui::PushID(
id++ );
1525 ImGui::PushStyleColor( ImGuiCol_Button, colors[j] );
1526 if( ImGui::Button(
" " ) )
1529 ImGui::CloseCurrentPopup();
1531 ImGui::PopStyleColor();
1538 bool RINGMeshApplication::load(
const std::string& filename )
1540 if( !filename.empty() && GEO::FileSystem::is_file( filename ) )
1543 if( dimension == 2 )
1545 geomodels2d_.emplace_back(
1546 new GeoModelViewer2D( *
this, filename ) );
1548 static_cast< index_t
>( geomodels2d_.size() - 1 );
1549 current_viewer_type_ = ViewerType::GEOMODEL2D;
1551 else if( dimension == 3 )
1553 geomodels3d_.emplace_back(
1554 new GeoModelViewer3D( *
this, filename ) );
1556 static_cast< index_t
>( geomodels3d_.size() - 1 );
1557 current_viewer_type_ = ViewerType::GEOMODEL3D;
1565 update_region_of_interest();
1569 void RINGMeshApplication::update_region_of_interest()
1572 for( std::unique_ptr< GeoModelViewer2D >& geomodel : geomodels2d_ )
1574 if( geomodel->is_visible_ )
1576 vec2 min = geomodel->bbox_.
min();
1577 vec2 max = geomodel->bbox_.max();
1578 bbox.add_point(
vec3( min.x, min.y, 0. ) );
1579 bbox.add_point(
vec3( max.x, max.y, 0. ) );
1582 for( std::unique_ptr< GeoModelViewer3D >& geomodel : geomodels3d_ )
1584 if( geomodel->is_visible_ )
1586 bbox.add_box( geomodel->bbox_ );
1589 for( std::unique_ptr< MeshViewer >& mesh : meshes_ )
1591 if( mesh->is_visible_ )
1593 bbox.add_box( mesh->bbox_ );
1597 if( bbox.initialized() )
1599 glup_viewer_set_region_of_interest(
float( bbox.min()[0] ),
1600 float( bbox.min()[1] ),
float( bbox.min()[2] ),
1601 float( bbox.max()[0] ),
float( bbox.max()[1] ),
1602 float( bbox.max()[2] ) );
1606 void RINGMeshApplication::draw_scene()
1608 if( current_viewer_ == NO_ID )
1611 for( std::unique_ptr< MeshViewer >& mesh : meshes_ )
1613 if( mesh->is_visible_ )
1618 for( std::unique_ptr< GeoModelViewer2D >& geomodel : geomodels2d_ )
1620 if( geomodel->is_visible_ )
1622 geomodel->draw_scene();
1625 for( std::unique_ptr< GeoModelViewer3D >& geomodel : geomodels3d_ )
1627 if( geomodel->is_visible_ )
1629 geomodel->draw_scene();
1633 if( current_viewer_type_ == ViewerType::GEOMODEL2D )
1635 GeoModelViewerBase2D& viewer = *geomodels2d_[current_viewer_];
1636 if( viewer.show_colormap_ )
1638 viewer.draw_colormap();
1641 if( current_viewer_type_ == ViewerType::GEOMODEL3D )
1643 GeoModelViewerBase3D& viewer = *geomodels3d_[current_viewer_];
1644 if( viewer.show_colormap_ )
1646 viewer.draw_colormap();
1651 std::string RINGMeshApplication::supported_read_file_extensions()
1653 return ringmesh_file_extensions_;
1655 std::string RINGMeshApplication::supported_geogram_read_file_extensions()
1657 return geogram_file_extensions_;
1660 template < index_t DIMENSION >
1661 void RINGMeshApplication::draw_geomodel_viewer_properties(
1662 std::vector< std::unique_ptr< GeoModelViewer< DIMENSION > > >&
1666 if( !geomodels.empty() )
1669 std::ostringstream oss;
1670 oss <<
"GeoModel" << DIMENSION <<
"D";
1671 ImGui::Text(
"%s", oss.str().c_str() );
1672 for(
auto i :
range( geomodels.size() ) )
1674 GeoModelViewer< DIMENSION >& viewer = *geomodels[i];
1675 ImGui::PushID(
id++ );
1676 if( ImGui::Checkbox(
1677 viewer.GM_.name().c_str(), &viewer.is_visible_ ) )
1679 current_viewer_ = i;
1680 current_viewer_type_ = viewer.type();
1681 update_region_of_interest();
1683 ImGui::SameLine( ImGui::GetWindowWidth() - 30 );
1684 if( ImGui::Button(
"X" ) )
1686 geomodels.erase( geomodels.begin() + i );
1687 if( current_viewer_type_ == viewer.type()
1688 && current_viewer_ >= i )
1692 if( geomodels.empty() )
1703 void RINGMeshApplication::draw_viewer_properties()
1705 GEO::Application::draw_viewer_properties();
1708 draw_geomodel_viewer_properties( geomodels2d_,
id );
1709 draw_geomodel_viewer_properties( geomodels3d_,
id );
1711 if( !meshes_.empty() )
1714 ImGui::Text(
"Mesh" );
1715 for(
auto i :
range( meshes_.size() ) )
1717 MeshViewer& viewer = *meshes_[i];
1718 ImGui::PushID(
id++ );
1719 if( ImGui::Checkbox(
1720 viewer.name_.c_str(), &viewer.is_visible_ ) )
1722 current_viewer_ = i;
1723 current_viewer_type_ = ViewerType::MESH;
1724 update_region_of_interest();
1726 ImGui::SameLine( ImGui::GetWindowWidth() - 30 );
1727 if( ImGui::Button(
"X" ) )
1729 meshes_.erase( meshes_.begin() + i );
1730 if( current_viewer_type_ == ViewerType::MESH
1731 && current_viewer_ >= i )
1735 if( meshes_.empty() )
1746 void RINGMeshApplication::draw_object_properties()
1748 if( current_viewer_ == NO_ID )
1750 switch( current_viewer_type_ )
1752 case ViewerType::GEOMODEL2D:
1754 geomodels2d_[current_viewer_]->draw_object_properties();
1756 case ViewerType::GEOMODEL3D:
1758 geomodels3d_[current_viewer_]->draw_object_properties();
1760 case ViewerType::MESH:
1762 meshes_[current_viewer_]->draw_object_properties();
1769 ColorTable RINGMeshApplication::color_table_ = create_color_table();
Abstract base class for GeoModelMeshEntity.
void RINGMESH_API print_header_information()
const vecn< DIMENSION > & vertex(index_t vertex_index) const
Coordinates of the vertex_index.
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
bool is_line(const MeshEntityType &type) const
index_t nb_boundaries() const
const gmme_id & boundary_gmme(index_t x) const
Entity_type_template type() const
static void div(const std::string &title)
bool geomodel_load(GeoModel< DIMENSION > &geomodel, const std::string &filename)
bool is_surface(const MeshEntityType &type) const
void add_point(const vecn< DIMENSION > &p)
bool is_corner(const MeshEntityType &type) const
static void out(const std::string &feature, const Args &... args)
static GEO::Logger * instance()
const gmme_id & child_gmme(index_t x) const
const vecn< DIMENSION > & min() const
index_t RINGMESH_API find_geomodel_dimension(const std::string &filename)
#define ringmesh_assert(x)
index_t nb_children() const
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
This template is a specialization of a gme_id to the GeoModelGeologicalEntity.
Classes to build GeoModel from various inputs.
A GeoModelEntity of type LINE.
void RINGMESH_API configure_ringmesh()
This template is a specialization of a gme_id to the GeoModelMeshEntity.
index_t nb_vertices() const
#define ringmesh_assert_not_reached