Browse Source

tmp commit

cflin
cflin 2 years ago
parent
commit
a716c37ebe
  1. 50
      src/viewer/UISimState.hpp
  2. 73
      src/viewer/UIStaticSimState.cpp
  3. 22
      src/viewer/UIStaticSimState.h

50
src/viewer/UISimState.hpp

@ -15,7 +15,9 @@
// WARNING: Use an anonymous namespace when including gif.h to avoid duplicate // WARNING: Use an anonymous namespace when including gif.h to avoid duplicate
// symbols. // symbols.
namespace { namespace {
#include <gif.h> #include <gif.h>
} }
#include "SimState.hpp" #include "SimState.hpp"
@ -28,11 +30,15 @@ class UISimState : public igl::opengl::glfw::imgui::ImGuiMenu {
public: public:
UISimState(); UISimState();
virtual ~UISimState() override {} virtual ~UISimState() override {}
enum PlayerState { Playing = 0, Paused, TotalPlayerStatus }; enum PlayerState {
Playing = 0, Paused, TotalPlayerStatus
};
virtual void init(igl::opengl::glfw::Viewer *_viewer) override; virtual void init(igl::opengl::glfw::Viewer *_viewer) override;
virtual void draw_menu() override; virtual void draw_menu() override;
// virtual bool mouse_down(int button, int modifier) override; // virtual bool mouse_down(int button, int modifier) override;
// virtual bool key_pressed(unsigned int key, int modifiers) override; // virtual bool key_pressed(unsigned int key, int modifiers) override;
@ -41,59 +47,59 @@ public:
get_data(const std::string &data) const; get_data(const std::string &data) const;
virtual void launch(const std::string &inital_scene); virtual void launch(const std::string &inital_scene);
virtual void load_scene(); virtual void load_scene();
virtual void redraw_scene(); virtual void redraw_scene();
virtual bool pre_draw_loop(); virtual bool pre_draw_loop();
virtual bool post_draw_loop(); virtual bool post_draw_loop();
bool custom_key_pressed(unsigned int unicode_key, int modifiers); bool custom_key_pressed(unsigned int unicode_key, int modifiers);
bool load(std::string scene_filename) override bool load(std::string scene_filename) override {
{
if (scene_filename != "" && m_state.load_scene(scene_filename)) { if (scene_filename != "" && m_state.load_scene(scene_filename)) {
load_scene(); load_scene();
return true; return true;
} }
return false; return false;
} }
bool save(std::string scene_filename) override
{ bool save(std::string scene_filename) override {
return m_state.save_simulation(scene_filename); return m_state.save_simulation(scene_filename);
} }
bool save_obj_sequence(const std::string& dir_name) bool save_obj_sequence(const std::string &dir_name) {
{
bool success = m_state.save_obj_sequence(dir_name); bool success = m_state.save_obj_sequence(dir_name);
m_state.problem_ptr->state( m_state.problem_ptr->state(
m_state.state_sequence[m_state.m_num_simulation_steps]); m_state.state_sequence[m_state.m_num_simulation_steps]);
return success; return success;
} }
bool save_gltf(const std::string& filename) bool save_gltf(const std::string &filename) {
{
return m_state.save_gltf(filename); return m_state.save_gltf(filename);
} }
void get_window_dimensions(int& width, int& height) const void get_window_dimensions(int &width, int &height) const {
{
width = m_viewer.core().viewport[2] - m_viewer.core().viewport[0]; width = m_viewer.core().viewport[2] - m_viewer.core().viewport[0];
height = m_viewer.core().viewport[3] - m_viewer.core().viewport[1]; height = m_viewer.core().viewport[3] - m_viewer.core().viewport[1];
} }
void save_screenshot(const std::string &filename); void save_screenshot(const std::string &filename);
void start_recording(const std::string &filename); void start_recording(const std::string &filename);
void end_recording(); void end_recording();
void reload() void reload() {
{
m_reloading_scene = true; m_reloading_scene = true;
m_state.reload_scene(); m_state.reload_scene();
load_scene(); load_scene();
m_reloading_scene = false; m_reloading_scene = false;
} }
void simulation_step() void simulation_step() {
{
igl::Timer timer; igl::Timer timer;
timer.start(); timer.start();
m_state.simulation_step(); m_state.simulation_step();
@ -103,8 +109,7 @@ public:
redraw_scene(); redraw_scene();
} }
void log_simulation_time() void log_simulation_time() {
{
spdlog::info("total_simulation_time={:g}s", m_simulation_time); spdlog::info("total_simulation_time={:g}s", m_simulation_time);
} }
@ -121,10 +126,13 @@ public:
bool m_show_vertex_data; bool m_show_vertex_data;
protected: protected:
void draw_io(); virtual void draw_io();
void draw_simulation_player();
void draw_settings(); virtual void draw_simulation_player();
void draw_legends();
virtual void draw_settings();
virtual void draw_legends();
private: private:
std::shared_ptr<igl::opengl::MeshData> mesh_data; std::shared_ptr<igl::opengl::MeshData> mesh_data;

73
src/viewer/UIStaticSimState.cpp

@ -6,5 +6,78 @@
namespace ipc { namespace ipc {
namespace rigid { 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<Target>(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 } // ipc
} // rigid } // rigid

22
src/viewer/UIStaticSimState.h

@ -22,12 +22,20 @@
#include "path_config.h" #include "path_config.h"
#include "../../static_sim/StaticSim.h" #include "../../static_sim/StaticSim.h"
#include "ColorbarPlugin.h" #include "ColorbarPlugin.h"
namespace ipc { namespace ipc {
namespace rigid { namespace rigid {
struct GUICtrl { struct GUICtrl {
bool is_modified = true;
bool mesh_visible = true; bool mesh_visible = true;
bool single_color = false; bool single_color = false;
ssim::SimTargetOption::Target target_to_evaluate = ssim::SimTargetOption::U_NORM; ssim::SimTargetOption::Target target_to_evaluate = ssim::SimTargetOption::U_NORM;
void set_target(ssim::SimTargetOption::Target target_to_set) {
target_to_evaluate = target_to_set;
is_modified = true;
}
}; };
class UIStaticSimState : public UISimState { class UIStaticSimState : public UISimState {
@ -118,7 +126,7 @@ namespace ipc {
// void load_scene(); // void load_scene();
void redraw_scene() { void redraw_scene() override {
ssim::Model model = sp_StaticSim_->get_mesh(); ssim::Model model = sp_StaticSim_->get_mesh();
const Eigen::MatrixXd &V = model.V; const Eigen::MatrixXd &V = model.V;
const Eigen::MatrixXi &F = model.F; const Eigen::MatrixXi &F = model.F;
@ -148,7 +156,10 @@ namespace ipc {
} }
bool pre_draw_loop() { bool pre_draw_loop() {
if (gui_ctrl_.is_modified) {
redraw_scene(); redraw_scene();
gui_ctrl_.is_modified = false;
}
return false; return false;
} }
@ -157,10 +168,19 @@ namespace ipc {
} }
// void draw_menu() override{
//
// }
protected:
void draw_settings();
private: private:
std::shared_ptr<ssim::StaticSim> sp_StaticSim_; std::shared_ptr<ssim::StaticSim> sp_StaticSim_;
GUICtrl gui_ctrl_; GUICtrl gui_ctrl_;
// ColorbarPlugin colorbar_plugin_; // ColorbarPlugin colorbar_plugin_;
}; };
} // ipc } // ipc

Loading…
Cancel
Save