From 6cce25e7ca3d475d56420375485d9642ad37e093 Mon Sep 17 00:00:00 2001 From: cflin Date: Tue, 11 Apr 2023 15:36:20 +0800 Subject: [PATCH] gui with basic results --- .gitignore | 2 + CMakeLists.txt | 4 + sim-test/rigid-test/CMakeLists.txt | 9 + .../cube/{config.json => config.json.in} | 2 +- src/main.cpp | 5 +- src/viewer/UIMenu.cpp | 1 + src/viewer/UIStaticMenu.cpp | 379 ++++++++++++++++++ src/viewer/UIStaticSimState.cpp | 70 ---- src/viewer/UIStaticSimState.h | 50 ++- static_sim/CMakeLists.txt | 2 + static_sim/StaticSim.cpp | 10 +- 11 files changed, 441 insertions(+), 93 deletions(-) create mode 100644 sim-test/rigid-test/CMakeLists.txt rename sim-test/rigid-test/cube/{config.json => config.json.in} (75%) create mode 100644 src/viewer/UIStaticMenu.cpp diff --git a/.gitignore b/.gitignore index b99062c..40c5c80 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ build/ output/ *.und/ path_config.h +# json engine.json +sim-test/*/*/*.json diff --git a/CMakeLists.txt b/CMakeLists.txt index d8d40a4..2cedeb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,6 +292,7 @@ if (RIGID_IPC_WITH_OPENGL) src/viewer/UIMenu.cpp # Edit start src/viewer/UIStaticSimState.cpp + src/viewer/UIStaticMenu.cpp # Edit end ) endif () @@ -360,6 +361,9 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/MshIO) add_subdirectory(engine) add_subdirectory(static_sim) + +add_subdirectory(sim-test/rigid-test) + # IPC link static simulation target_link_libraries(rigid_ipc_sim PUBLIC StaticSim) diff --git a/sim-test/rigid-test/CMakeLists.txt b/sim-test/rigid-test/CMakeLists.txt new file mode 100644 index 0000000..4caf837 --- /dev/null +++ b/sim-test/rigid-test/CMakeLists.txt @@ -0,0 +1,9 @@ +# Replace the absolute path with a relative one for .json +# Note that changes are only valid in *.json.in file +file(GLOB model_dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") +foreach (model_dir IN LISTS model_dirs) + if (IS_DIRECTORY ${model_dir}) + set(LOCAL_DIR ${model_dir}) + configure_file(${model_dir}/config.json.in ${model_dir}/config.json @ONLY) + endif () +endforeach () \ No newline at end of file diff --git a/sim-test/rigid-test/cube/config.json b/sim-test/rigid-test/cube/config.json.in similarity index 75% rename from sim-test/rigid-test/cube/config.json rename to sim-test/rigid-test/cube/config.json.in index 6e15fd7..ad44445 100644 --- a/sim-test/rigid-test/cube/config.json +++ b/sim-test/rigid-test/cube/config.json.in @@ -1,6 +1,6 @@ { "material": [1e5, 0.3, 1e3], - "mshFilePath": "/home/cw/MyCode/designauto/da-cmd/cmd-quasistatic-simulation/assets/cube_9743.msh", + "mshFilePath": "@LOCAL_DIR@/cube_9743.msh", "DBC": [ { diff --git a/src/main.cpp b/src/main.cpp index 2360be2..c642e75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,12 +91,11 @@ int main(int argc, char* argv[]) #ifdef RIGID_IPC_WITH_OPENGL // UISimState ui; // ui.launch(scene_path); - // Static Simulation ssim::SimTargetOption option; option.set_option(option.U_NORM); - std::string obj_path=CMAKE_SOURCE_DIR "/assets/armadillo.obj"; - std::shared_ptr sp_StaticSim = std::make_shared(option,obj_path); + std::string json_path=CMAKE_SOURCE_DIR "/sim-test/rigid-test/cube/config.json"; + std::shared_ptr sp_StaticSim = std::make_shared(option,json_path); UIStaticSimState ui(sp_StaticSim); ui.launch(scene_path); diff --git a/src/viewer/UIMenu.cpp b/src/viewer/UIMenu.cpp index 67c3209..9a10eb3 100644 --- a/src/viewer/UIMenu.cpp +++ b/src/viewer/UIMenu.cpp @@ -43,6 +43,7 @@ void UISimState::draw_menu() // } draw_io(); + if (m_has_scene) { if (ImGui::CollapsingHeader( diff --git a/src/viewer/UIStaticMenu.cpp b/src/viewer/UIStaticMenu.cpp new file mode 100644 index 0000000..2095cac --- /dev/null +++ b/src/viewer/UIStaticMenu.cpp @@ -0,0 +1,379 @@ +#include "UIStaticSimState.h" +#include "imgui.h" + +#include + +#include +#include + +#include + +namespace ipc::rigid { + + void UIStaticSimState::draw_menu() { + // if (m_show_vertex_data) { + // draw_labels_window(); + // } + + float menu_width = 220.f * menu_scaling(); + static bool player_menu = true; + static bool settings_menu = true; + static bool collisions_menu = true; + + //-------------------------------------------------------------------------- + ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSizeConstraints( + ImVec2(menu_width, -1.0f), ImVec2(menu_width, -1.0f)); + bool _viewer_menu_visible = true; + + ImGui::Begin( + "控制菜单", &_viewer_menu_visible, + ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize); + ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.6f); + { + const char *level_strings[] = {"trace", "debug", "info", "warning", + "error", "critical", "off"}; + int log_level = spdlog::get_level(); + // if (ImGui::Combo( + // "log-level##logger", &log_level, level_strings, + // CCD_IM_ARRAYSIZE(level_strings))) { + // set_logger_level(static_cast(log_level)); + // } + + draw_io(); + if (gui_ctrl_.is_loaded_json) { + + if (ImGui::CollapsingHeader( + "运行", &player_menu, ImGuiTreeNodeFlags_DefaultOpen)) { + draw_simulation_player(); + } + if (gui_ctrl_.is_solved) { + ImGui::Spacing(); + if (ImGui::CollapsingHeader( + "结果", &settings_menu, ImGuiTreeNodeFlags_DefaultOpen)) + draw_settings(); + } + } + } + ImGui::PopItemWidth(); + ImGui::End(); + + //-------------------------------------------------------------------------- + if (m_has_scene) { + float legends_width = 270.f * menu_scaling(); + ImGui::SetNextWindowPos( + ImVec2(ImGui::GetIO().DisplaySize.x - legends_width, 0.0f), + ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSizeConstraints( + ImVec2(200.0f, 30.0f), ImVec2(legends_width, -1.0f)); + bool _colors_menu_visible = true; + + // ImGui::Begin( + // "Legend", &_colors_menu_visible, + // ImGuiWindowFlags_NoSavedSettings + // | ImGuiWindowFlags_AlwaysAutoResize); + // { + // draw_legends(); + // } + // ImGui::End(); + } + } // namespace ipc::rigid + + void UIStaticSimState::draw_io() { + if (ImGui::Button("加载文件##IO", ImVec2(-1, 0))) { + std::string fname = igl::file_dialog_open(); + if (fname != "") { + load(fname); + } + } + if (m_has_scene) { +// if (ImGui::Button("重新加载##IO", ImVec2(-1, 0))) { +// reload(); +// } + ImGui::BeginChild( + "##filename", + ImVec2( + ImGui::GetWindowContentRegionWidth() * 0.9f, + ImGui::GetFontSize() * 3), + false, ImGuiWindowFlags_HorizontalScrollbar); + { + ImGui::Text("%s", m_state.scene_file.c_str()); + ImGui::SetScrollHere(1.0f); + } + ImGui::EndChild(); + + // if (ImGui::Button("Save simulation", ImVec2(-1, 0))) { + // std::string fname = igl::file_dialog_save(); + // save(fname); + // } + + // if (ImGui::Button("Save OBJ sequence", ImVec2(-1, 0))) { + // std::string dir_name = igl::file_dialog_save(); + // if (dir_name != "") { + // save_obj_sequence(dir_name); + // } + // } + + // if (ImGui::Button("Save gltf", ImVec2(-1, 0))) { + // std::string filename = igl::file_dialog_save(); + // if (filename != "") { + // save_gltf(filename); + // } + // } + + // if (ImGui::Button("Save screenshot", ImVec2(-1, 0))) { + // std::string fname = igl::file_dialog_save(); + // save_screenshot(fname); + // } + // if (m_is_gif_recording) { + // if (ImGui::Button("End recording", ImVec2(-1, 0))) { + // end_recording(); + // } + // } else if (ImGui::Button("Start recording", ImVec2(-1, 0))) { + // std::string fname = igl::file_dialog_save(); + // start_recording(fname); + // } + } + } + + void UIStaticSimState::draw_simulation_player() { + int player_state = static_cast(m_player_state); + + if (ImGui::Button("开始计算")) { + sp_StaticSim_->simulation(); + + gui_ctrl_.is_modified = true; + gui_ctrl_.is_solved = true; + } +// ImGui::RadioButton("开始计算##SimPlayer", &player_state, PlayerState::Playing); +// ImGui::RadioButton("暂停##SimPlayer", &player_state, PlayerState::Paused); + + if (ImGui::CollapsingHeader( + "边界条件设置##SimPlayer", ImGuiTreeNodeFlags_DefaultOpen)) { + // -------------------------------------------------------------------- + ImGui::Checkbox("边界包围盒", &m_bkp_has_intersections); + + // ImGui::Checkbox("受力", &m_state.m_solve_collisions); + static float zoom = 50.0f; + static float zoom1 = 50.0f; + static float zoom2 = 50.0f; + ImGui::SliderFloat("x-受力", &zoom, -50, 50, "%.3f"); + ImGui::SliderFloat("y-受力", &zoom1, -50, 50, "%.3f"); + ImGui::SliderFloat("z-受力", &zoom2, -50, 50, "%.3f"); + } + + // ImGui::Checkbox("受力大小", &m_bkp_optimization_failed); + // ImGui::SameLine(); + // ImGui::HelpMarker("yes - stop playing if step optimization failed."); + + // ImGui::Checkbox("pause on collisions", &m_bkp_had_collision); + // ImGui::SameLine(); + // ImGui::HelpMarker("yes - stop playing if step had a collision."); + + // -------------------------------------------------------------------- + // if (ImGui::SliderInt( + // "step##Replay", &m_state.m_num_simulation_steps, 0, + // m_state.state_sequence.size() - 1)) { + // replaying = true; + // } + + // if (ImGui::Button("结果##SimPlayer", ImVec2(-1, 0))) { + // m_player_state = PlayerState::Playing; + // pre_draw_loop(); + // m_player_state = PlayerState::Paused; + // } + // -------------------------------------------------------------------- + if (ImGui::CollapsingHeader("材料设置", ImGuiTreeNodeFlags_DefaultOpen)) { + static float f0 = 0.001f; + static float f1 = 0.001f; + static float f2 = 0.001f; + ImGui::InputFloat("杨氏模量", &f0, 0.01f, 1.0f, "%.3f"); + ImGui::InputFloat("泊松比", &f1, 0.01f, 1.0f, "%.3f"); + ImGui::InputFloat("密度", &f2, 0.01f, 1.0f, "%.3f"); + } + if (ImGui::CollapsingHeader( + "其他设置", ImGuiTreeNodeFlags_DefaultOpen)) { + static float f3 = 0.01f; + ImGui::InputFloat("时间步", &f3, 0.01f, 1.0f, "%.2f"); + } + } + + void UIStaticSimState::draw_settings() { + // auto config = m_state.get_active_config(); + // ImGui::BeginChild( + // "##config", ImVec2(ImGui::GetWindowContentRegionWidth(), 20), false, + // ImGuiWindowFlags_HorizontalScrollbar); + // { + // ImGui::TreeNodeJson(config); + // } + // ImGui::EndChild(); + // if (ImGui::Button("应力##IO", ImVec2(-1, 0))) { + // std::string fname = igl::file_dialog_save(); + // if (fname != "") { + // load(fname); + // } + // } + // ImGui::Checkbox("柔顺度(compliance)", &compliance); + + char *desc = "121.88"; +// ImGui::Text("柔顺度(compliance)"); +// sp_StaticSim_->EvaluateTarget(ssim::SimTargetOption::COMPLIANCE)(0,0); + ImGui::TextWrapped("柔顺度 (compliance): %.3f", 12222.2); + if (ImGui::IsItemHovered()) { + // 显示工具的提示 + ImGui::BeginTooltip(); + // 使得文字的区域可以自己控制, + // 但是这里我感觉更推荐使用:TextWrapped接口,之后的部分有提到他们的区别 + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(desc); + ImGui::PopTextWrapPos(); + // 结束工具提示 + ImGui::EndTooltip(); + } + // Buttons +// std::string fname = igl::file_dialog_open(); +// if (fname != "") { +// load(fname); +// } +// { +// using Target=ssim::SimTargetOption::Target; +// int i_target_to_set; +// ImGui::RadioButton("位移范数",&i_target_to_set,Target::U_NORM); ImGui::SameLine(); +// ImGui::RadioButton("位移-X",&i_target_to_set,Target::UX); ImGui::SameLine(); +// ImGui::RadioButton("位移-Y",&i_target_to_set,Target::UY); ImGui::SameLine(); +// ImGui::RadioButton("位移-Z",&i_target_to_set,Target::UZ); +// gui_ctrl_.set_target(static_cast(i_target_to_set)); +// } + + + if (ImGui::Button("位移范数", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::U_NORM); + } + if (ImGui::Button("位移-X", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::UX); + } + if (ImGui::Button("位移-Y", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::UY); + } + if (ImGui::Button("位移-Z", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::UZ); + } + + if (ImGui::Button("应力范数", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::S_NORM); + } + if (ImGui::Button("冯氏应力", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::S_VON_Mises); + } + + if (ImGui::Button("应力-X", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::SX); + } + if (ImGui::Button("应力-Y", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::SY); + } + if (ImGui::Button("应力-Z", ImVec2(-1, 0))) { + gui_ctrl_.set_target(ssim::SimTargetOption::Target::SZ); + } + + } + +//void UIStaticSimState::draw_legends() +//{ +// static float second_col = 100; +// float slider_width = ImGui::GetWindowWidth() * 0.2f; +// for (auto& data : datas_) { +// const std::string& label = data.first; +// const auto& ptr = data.second; +// +// /// visibility checkbox +// bool tmp = ptr->visibility(); +// if (!ptr->is_com()) { +// if (ImGui::Checkbox(("##UI-" + label).c_str(), &tmp)) { +// ptr->visibility(tmp); +// } +// /// Color +// ImGui::SameLine(); +// if (ImGui::DoubleColorEdit3( +// (label + "##UI-color").c_str(), ptr->m_color)) { +// ptr->recolor(); +// } +// } else if (ImGui::Checkbox((label + "##UI-check").c_str(), &tmp)) { +// ptr->visibility(tmp); +// } +// +// /// other specific attributes +// if (ptr->is_mesh()) { +// ImGui::SameLine(second_col); +// if (ImGui::Checkbox( +// ("数据##UI-" + label).c_str(), &m_show_vertex_data)) { } +// ptr->show_vertex_data = m_show_vertex_data; +// ptr->update_vertex_data(); +// +// ImGui::SameLine(); +// ImGui::PushItemWidth(slider_width); +// { +// float point_size = ptr->data().point_size / pixel_ratio(); +// if (ImGui::SliderFloat( +// ("顶点##UI-scaling" + label).c_str(), &point_size, +// 0.00f, 10.0f, "%1.f")) { +// ptr->data().point_size = point_size * pixel_ratio(); +// } +// } +// ImGui::PopItemWidth(); +// +// } else if (ptr->is_scalar_field()) { +// ImGui::SameLine(); +// if (ImGui::Checkbox( +// ("log##UI-" + label).c_str(), &ptr->m_use_log_scale)) { +// ptr->recolor(); +// } +// ImGui::SameLine(); +// bool show_iso = ptr->data().show_overlay; +// if (ImGui::Checkbox(("isolines##UI-" + label).c_str(), &show_iso)) { +// ptr->data().show_overlay = show_iso; +// } +// ImGui::SameLine(); +// bool show_faces = ptr->data().show_faces; +// if (ImGui::Checkbox(("faces##UI-" + label).c_str(), &show_faces)) { +// ptr->data().show_faces = show_faces; +// } +// +// } // else if (ptr->is_vector_field()) { +// // ImGui::SameLine(second_col); +// // if (ImGui::Checkbox( +// // ("norm##UI-" + label).c_str(), &ptr->m_normalized)) { +// // ptr->recolor(); +// // } +// // ImGui::SameLine(); +// // ImGui::PushItemWidth(slider_width); +// // { +// // float aux = float(ptr->m_scaling); +// // if (ImGui::SliderFloat( +// // ("scale##UI-scaling" + label).c_str(), &aux, 0.00f, +// // 10.0f, "%1.f")) { +// // ptr->m_scaling = double(aux); +// // ptr->recolor(); +// // } +// // } +// // ImGui::PopItemWidth(); +// // } else if (ptr->is_com()) { +// // ImGui::SameLine(); +// // ImGui::PushItemWidth(ImGui::GetWindowWidth() - 150); +// // { +// // float aux = float(ptr->m_scaling); +// // if (ImGui::SliderFloat( +// // ("scale##UI-com-scaling" + label).c_str(), &aux, +// // 0.00f, 10.0f, "%1.1f", 1.0f)) { +// // ptr->m_scaling = double(aux); +// // ptr->recolor(); +// // } +// // } +// // ImGui::PopItemWidth(); +// // } +// } +//} + +} // namespace ipc::rigid diff --git a/src/viewer/UIStaticSimState.cpp b/src/viewer/UIStaticSimState.cpp index d69aadd..1f79bc7 100644 --- a/src/viewer/UIStaticSimState.cpp +++ b/src/viewer/UIStaticSimState.cpp @@ -7,77 +7,7 @@ namespace ipc { namespace rigid { - void UIStaticSimState::draw_settings() { - // auto config = m_state.get_active_config(); - // ImGui::BeginChild( - // "##config", ImVec2(ImGui::GetWindowContentRegionWidth(), 20), false, - // ImGuiWindowFlags_HorizontalScrollbar); - // { - // ImGui::TreeNodeJson(config); - // } - // ImGui::EndChild(); - // if (ImGui::Button("应力##IO", ImVec2(-1, 0))) { - // std::string fname = igl::file_dialog_save(); - // if (fname != "") { - // load(fname); - // } - // } - // ImGui::Checkbox("柔顺度(compliance)", &compliance); - char *desc = "121.88"; - ImGui::Text("柔顺度(compliance)"); - ImGui::TextWrapped("柔顺度 (compliance): %.3f",1258.9999); - if (ImGui::IsItemHovered()) { - // 显示工具的提示 - ImGui::BeginTooltip(); - // 使得文字的区域可以自己控制, - // 但是这里我感觉更推荐使用:TextWrapped接口,之后的部分有提到他们的区别 - ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); - ImGui::TextUnformatted(desc); - ImGui::PopTextWrapPos(); - // 结束工具提示 - ImGui::EndTooltip(); - } - // Buttons - if (ImGui::Button("应力##IO", ImVec2(-1, 0))) { -// std::string fname = igl::file_dialog_open(); -// if (fname != "") { -// load(fname); -// } - } - { - using Target=ssim::SimTargetOption::Target; - int i_target_to_set; - ImGui::RadioButton("位移范数",&i_target_to_set,Target::U_NORM); ImGui::SameLine(); - ImGui::RadioButton("位移-X",&i_target_to_set,Target::UX); ImGui::SameLine(); - ImGui::RadioButton("位移-Y",&i_target_to_set,Target::UY); ImGui::SameLine(); - ImGui::RadioButton("位移-Z",&i_target_to_set,Target::UZ); - gui_ctrl_.set_target(static_cast(i_target_to_set)); - } - - - if (ImGui::Button("位移范数")) { - gui_ctrl_.set_target(ssim::SimTargetOption::Target::U_NORM); - } - if (ImGui::Button("位移-X", ImVec2(-1, 0))) { - gui_ctrl_.set_target(ssim::SimTargetOption::Target::UX); - } - if (ImGui::Button("位移-Y", ImVec2(-1, 0))) { - gui_ctrl_.set_target(ssim::SimTargetOption::Target::UY); - } - if (ImGui::Button("位移-Z", ImVec2(-1, 0))) { - gui_ctrl_.set_target(ssim::SimTargetOption::Target::UY); - } - - if (ImGui::Button("应力范数", ImVec2(-1, 0))) { - gui_ctrl_.set_target(ssim::SimTargetOption::Target::S_NORM); - } - if (ImGui::Button("冯氏应力", ImVec2(-1, 0))) { - gui_ctrl_.set_target(ssim::SimTargetOption::Target::S_VON_Mises); - } - - - } } // ipc } // rigid \ No newline at end of file diff --git a/src/viewer/UIStaticSimState.h b/src/viewer/UIStaticSimState.h index f7c9417..4e71c54 100644 --- a/src/viewer/UIStaticSimState.h +++ b/src/viewer/UIStaticSimState.h @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include #include "UISimState.hpp" @@ -26,7 +29,10 @@ namespace ipc { namespace rigid { struct GUICtrl { - bool is_modified = true; + bool is_init = true; + bool is_modified = false; + bool is_solved = false; + bool is_loaded_json = false; bool mesh_visible = true; bool single_color = false; ssim::SimTargetOption::Target target_to_evaluate = ssim::SimTargetOption::U_NORM; @@ -55,24 +61,22 @@ namespace ipc { CMAKE_SOURCE_DIR "/src/viewer/Arial Unicode MS.TTF", 14.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull()); - viewer->data().clear(); - load_scene(); + // back_color + m_viewer.core().background_color << 0.9f, 0.9f, 0.9f, 0.4f; + } // virtual void draw_menu() override; void load_scene() { + viewer->data().clear(); + // get V, F ssim::Model model = sp_StaticSim_->get_mesh(); const Eigen::MatrixXd &V = model.V; const Eigen::MatrixXi &F = model.F; - Eigen::MatrixXd Target = sp_StaticSim_->EvaluateTarget(gui_ctrl_.target_to_evaluate); // plot viewer->data().set_mesh(V, F); - // colormap - Eigen::MatrixXd C; - igl::jet(Target, true, C); - viewer->data().set_colors(C); - +// viewer->data().set_colors(Eigen::Vector3d(0.5,0.5,1)); m_has_scene = true; @@ -156,6 +160,10 @@ namespace ipc { } bool pre_draw_loop() { + if (gui_ctrl_.is_loaded_json && !gui_ctrl_.is_solved && gui_ctrl_.is_init) { + load_scene(); + gui_ctrl_.is_init = false; + } if (gui_ctrl_.is_modified) { redraw_scene(); gui_ctrl_.is_modified = false; @@ -167,13 +175,27 @@ namespace ipc { return false; } - -// void draw_menu() override{ -// -// } + void draw_menu() override; protected: - void draw_settings(); + + + void draw_io() override; + + void draw_simulation_player() override; + + void draw_settings() override; + +// void draw_legends() override; + + void load(const std::string &json_path) { + ssim::SimTargetOption option; + option.set_option(option.U_NORM); + sp_StaticSim_ = std::make_shared(option, json_path); + gui_ctrl_.is_loaded_json = true; + } + + private: std::shared_ptr sp_StaticSim_; diff --git a/static_sim/CMakeLists.txt b/static_sim/CMakeLists.txt index eebc6dc..4c46a8a 100644 --- a/static_sim/CMakeLists.txt +++ b/static_sim/CMakeLists.txt @@ -11,6 +11,8 @@ add_library(StaticSim STATIC ${SRCFILES}) target_include_directories(StaticSim PUBLIC LinSysSolver) target_link_libraries(StaticSim PUBLIC mshio::mshio) +# json +target_link_libraries(StaticSim PUBLIC nlohmann::json) # eigen target_link_libraries(StaticSim PUBLIC Eigen3::Eigen) diff --git a/static_sim/StaticSim.cpp b/static_sim/StaticSim.cpp index 0952ad3..31a0385 100644 --- a/static_sim/StaticSim.cpp +++ b/static_sim/StaticSim.cpp @@ -58,14 +58,15 @@ namespace ssim { #endif linSysSolver->set_pattern(vNeighbor); linSysSolver->analyze_pattern(); - spdlog::info("mesh constructed"); spdlog::info("nodes number: {}, dofs number: {}, tets element number: {}", nN, nDof, nEle); + } void StaticSim::simulation() { int ENUM_SIZE = SimTargetOption::Target::ENUM_SIZE; + map_target_to_evaluated_.clear(); map_target_to_evaluated_.resize(ENUM_SIZE); // solve @@ -161,7 +162,6 @@ namespace ssim { F_surf(sfI, 1) = vI2SVI[SF(sfI, 1)]; F_surf(sfI, 2) = vI2SVI[SF(sfI, 2)]; } - // eDof eDof.resize(nEle); #ifdef USE_TBB @@ -171,6 +171,7 @@ namespace ssim { #endif { Eigen::VectorXi TT_I = TT.row(eI); + eDof[eI].resize(12); for (int i_ = 0; i_ < 4; ++i_) { eDof[eI](3 * i_) = TT_I(i_) * 3; eDof[eI](3 * i_ + 1) = TT_I(i_) * 3 + 1; @@ -180,7 +181,6 @@ namespace ssim { #ifdef USE_TBB ); #endif - // vNeighbor vNeighbor.resize(0); vNeighbor.resize(nN); @@ -329,7 +329,6 @@ namespace ssim { DBC_nI.conservativeResize(nDBC); // Utils::writeOBJ(outputPath + "DBCV.obj", TV(DBC_nI, Eigen::all), // Eigen::VectorXi::LinSpaced(nDBC, 0, nDBC-1)); - // NBC load.resize(0); load.setZero(nDof); @@ -352,7 +351,7 @@ namespace ssim { // Utils::writeOBJ(outputPath + "NBCV.obj", TV(NBC_nI, Eigen::all), // Eigen::VectorXi::LinSpaced(nNBC, 0, nNBC-1)); - spdlog::debug("#DBC nodes: {}, #NBC particles: {}", nDBC, nNBC); + spdlog::info("#DBC nodes: {}, #NBC particles: {}", nDBC, nNBC); // ensure (DBC intersect NBC) = (empty) for (int i_ = 0; i_ < DBC_nI.size(); ++i_) { @@ -468,6 +467,7 @@ namespace ssim { Eigen::MatrixXd StaticSim::EvaluateCompliance() const { Eigen::MatrixXd ret(1, 1); ret(0, 0) = compliance_; + return ret; } } // ssim \ No newline at end of file