Browse Source

tmp commit

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

238
src/viewer/UISimState.hpp

@ -15,7 +15,9 @@
// WARNING: Use an anonymous namespace when including gif.h to avoid duplicate
// symbols.
namespace {
#include <gif.h>
}
#include "SimState.hpp"
@ -23,129 +25,135 @@ namespace {
namespace ipc::rigid {
class UISimState : public igl::opengl::glfw::imgui::ImGuiMenu {
typedef igl::opengl::glfw::imgui::ImGuiMenu Super;
class UISimState : public igl::opengl::glfw::imgui::ImGuiMenu {
typedef igl::opengl::glfw::imgui::ImGuiMenu Super;
public:
UISimState();
virtual ~UISimState() override {}
enum PlayerState {
Playing = 0, Paused, TotalPlayerStatus
};
virtual void init(igl::opengl::glfw::Viewer *_viewer) override;
virtual void draw_menu() override;
// virtual bool mouse_down(int button, int modifier) override;
// virtual bool key_pressed(unsigned int key, int modifiers) override;
std::shared_ptr<igl::opengl::ViewerDataExt>
get_data(const std::string &data) const;
virtual void launch(const std::string &inital_scene);
virtual void load_scene();
public:
UISimState();
virtual ~UISimState() override {}
virtual void redraw_scene();
enum PlayerState { Playing = 0, Paused, TotalPlayerStatus };
virtual bool pre_draw_loop();
virtual void init(igl::opengl::glfw::Viewer* _viewer) override;
virtual void draw_menu() override;
// virtual bool mouse_down(int button, int modifier) override;
// virtual bool key_pressed(unsigned int key, int modifiers) override;
virtual bool post_draw_loop();
std::shared_ptr<igl::opengl::ViewerDataExt>
get_data(const std::string& data) const;
bool custom_key_pressed(unsigned int unicode_key, int modifiers);
virtual void launch(const std::string& inital_scene);
virtual void load_scene();
virtual void redraw_scene();
virtual bool pre_draw_loop();
virtual bool post_draw_loop();
bool load(std::string scene_filename) override {
if (scene_filename != "" && m_state.load_scene(scene_filename)) {
load_scene();
return true;
}
return false;
}
bool save(std::string scene_filename) override {
return m_state.save_simulation(scene_filename);
}
bool save_obj_sequence(const std::string &dir_name) {
bool success = m_state.save_obj_sequence(dir_name);
m_state.problem_ptr->state(
m_state.state_sequence[m_state.m_num_simulation_steps]);
return success;
}
bool save_gltf(const std::string &filename) {
return m_state.save_gltf(filename);
}
void get_window_dimensions(int &width, int &height) const {
width = m_viewer.core().viewport[2] - m_viewer.core().viewport[0];
height = m_viewer.core().viewport[3] - m_viewer.core().viewport[1];
}
bool custom_key_pressed(unsigned int unicode_key, int modifiers);
void save_screenshot(const std::string &filename);
bool load(std::string scene_filename) override
{
if (scene_filename != "" && m_state.load_scene(scene_filename)) {
void start_recording(const std::string &filename);
void end_recording();
void reload() {
m_reloading_scene = true;
m_state.reload_scene();
load_scene();
return true;
m_reloading_scene = false;
}
return false;
}
bool save(std::string scene_filename) override
{
return m_state.save_simulation(scene_filename);
}
bool save_obj_sequence(const std::string& dir_name)
{
bool success = m_state.save_obj_sequence(dir_name);
m_state.problem_ptr->state(
m_state.state_sequence[m_state.m_num_simulation_steps]);
return success;
}
bool save_gltf(const std::string& filename)
{
return m_state.save_gltf(filename);
}
void get_window_dimensions(int& width, int& height) const
{
width = m_viewer.core().viewport[2] - m_viewer.core().viewport[0];
height = m_viewer.core().viewport[3] - m_viewer.core().viewport[1];
}
void save_screenshot(const std::string& filename);
void start_recording(const std::string& filename);
void end_recording();
void reload()
{
m_reloading_scene = true;
m_state.reload_scene();
load_scene();
m_reloading_scene = false;
}
void simulation_step()
{
igl::Timer timer;
timer.start();
m_state.simulation_step();
timer.stop();
m_simulation_time += timer.getElapsedTime();
m_state.save_simulation_step();
redraw_scene();
}
void log_simulation_time()
{
spdlog::info("total_simulation_time={:g}s", m_simulation_time);
}
igl::opengl::glfw::Viewer m_viewer;
SimState m_state;
PlayerState m_player_state;
bool replaying = false;
bool m_has_scene;
bool m_bkp_had_collision;
bool m_bkp_has_intersections;
bool m_bkp_optimization_failed;
double m_interval_time; ///< @brief time within the interval
bool m_show_vertex_data;
protected:
void draw_io();
void draw_simulation_player();
void draw_settings();
void draw_legends();
private:
std::shared_ptr<igl::opengl::MeshData> mesh_data;
std::shared_ptr<igl::opengl::VectorFieldData> velocity_data;
std::shared_ptr<igl::opengl::CoMData> com_data;
std::vector<
std::pair<std::string, std::shared_ptr<igl::opengl::ViewerDataExt>>>
datas_;
bool m_reloading_scene;
GifWriter m_gif_writer;
uint32_t m_gif_delay = 1; //*10ms
double m_gif_scale = 0.5;
bool m_is_gif_recording = false;
bool m_scene_changed;
double m_simulation_time;
std::string inital_scene;
};
void simulation_step() {
igl::Timer timer;
timer.start();
m_state.simulation_step();
timer.stop();
m_simulation_time += timer.getElapsedTime();
m_state.save_simulation_step();
redraw_scene();
}
void log_simulation_time() {
spdlog::info("total_simulation_time={:g}s", m_simulation_time);
}
igl::opengl::glfw::Viewer m_viewer;
SimState m_state;
PlayerState m_player_state;
bool replaying = false;
bool m_has_scene;
bool m_bkp_had_collision;
bool m_bkp_has_intersections;
bool m_bkp_optimization_failed;
double m_interval_time; ///< @brief time within the interval
bool m_show_vertex_data;
protected:
virtual void draw_io();
virtual void draw_simulation_player();
virtual void draw_settings();
virtual void draw_legends();
private:
std::shared_ptr<igl::opengl::MeshData> mesh_data;
std::shared_ptr<igl::opengl::VectorFieldData> velocity_data;
std::shared_ptr<igl::opengl::CoMData> com_data;
std::vector<
std::pair<std::string, std::shared_ptr<igl::opengl::ViewerDataExt>>>
datas_;
bool m_reloading_scene;
GifWriter m_gif_writer;
uint32_t m_gif_delay = 1; //*10ms
double m_gif_scale = 0.5;
bool m_is_gif_recording = false;
bool m_scene_changed;
double m_simulation_time;
std::string inital_scene;
};
} // namespace ipc::rigid

73
src/viewer/UIStaticSimState.cpp

@ -6,5 +6,78 @@
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<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
} // rigid

24
src/viewer/UIStaticSimState.h

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

Loading…
Cancel
Save