18 changed files with 130296 additions and 181 deletions
@ -1,4 +1,6 @@ |
|||||
cmake-*/ |
cmake-*/ |
||||
.idea/ |
.idea/ |
||||
stl/ |
output/ |
||||
|
*.und/ |
||||
|
path_config.h |
||||
engine.json |
engine.json |
||||
|
File diff suppressed because it is too large
@ -0,0 +1,3 @@ |
|||||
|
# replace the absolute path to the local directory with a relative one |
||||
|
set(LOCAL_DIR_PATH ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "PATH TO LOCAL DIR") |
||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/engine.json.in ${CMAKE_CURRENT_SOURCE_DIR}/engine.json @ONLY) |
@ -0,0 +1 @@ |
|||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/path_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/path_config.h @ONLY) |
@ -0,0 +1,7 @@ |
|||||
|
#ifndef PATH_CONFIG_H_IN |
||||
|
#define PATH_CONFIG_H_IN |
||||
|
|
||||
|
#cmakedefine CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@" |
||||
|
|
||||
|
#endif |
||||
|
|
@ -0,0 +1,10 @@ |
|||||
|
//
|
||||
|
// Created by cflin on 4/7/23.
|
||||
|
//
|
||||
|
|
||||
|
#include "UIStaticSimState.h" |
||||
|
|
||||
|
namespace ipc { |
||||
|
namespace rigid { |
||||
|
} // ipc
|
||||
|
} // rigid
|
@ -0,0 +1,169 @@ |
|||||
|
//
|
||||
|
// Created by cflin on 4/7/23.
|
||||
|
//
|
||||
|
|
||||
|
#ifndef RIGIDIPC_UISTATICSIMSTATE_H |
||||
|
#define RIGIDIPC_UISTATICSIMSTATE_H |
||||
|
|
||||
|
#include <memory> // shared_ptr |
||||
|
|
||||
|
#include <spdlog/spdlog.h> |
||||
|
|
||||
|
#include <igl/Timer.h> |
||||
|
#include <igl/opengl/glfw/Viewer.h> |
||||
|
#include <igl/opengl/glfw/imgui/ImGuiMenu.h> |
||||
|
#include <igl/png/render_to_png.h> |
||||
|
#include <igl/png/writePNG.h> |
||||
|
#include <igl/jet.h> |
||||
|
#include <viewer/igl_viewer_ext.hpp> |
||||
|
|
||||
|
#include "UISimState.hpp" |
||||
|
#include "path_config.h" |
||||
|
#include "../../static_sim/StaticSim.h" |
||||
|
|
||||
|
namespace ipc { |
||||
|
namespace rigid { |
||||
|
struct GUICtrl { |
||||
|
bool mesh_visible = true; |
||||
|
bool single_color = false; |
||||
|
}; |
||||
|
|
||||
|
class UIStaticSimState : public UISimState { |
||||
|
typedef igl::opengl::glfw::imgui::ImGuiMenu Super; |
||||
|
public: |
||||
|
UIStaticSimState(std::shared_ptr<ssim::StaticSim> sp_StaticSim) : UISimState(),sp_StaticSim_(sp_StaticSim),display_target(ssim::SimTargetOption::U_NORM) { |
||||
|
// set gui_ctrl_;
|
||||
|
gui_ctrl_.single_color = true; |
||||
|
gui_ctrl_.mesh_visible = true; |
||||
|
} |
||||
|
|
||||
|
virtual ~UIStaticSimState() override {} |
||||
|
|
||||
|
virtual void init(igl::opengl::glfw::Viewer *_viewer) override { |
||||
|
Super::init(_viewer); |
||||
|
ImGuiIO &io = ImGui::GetIO(); |
||||
|
io.Fonts->Clear(); |
||||
|
io.Fonts->AddFontFromFileTTF( |
||||
|
CMAKE_SOURCE_DIR "/src/viewer/Arial Unicode MS.TTF", |
||||
|
14.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull()); |
||||
|
|
||||
|
viewer->data().clear(); |
||||
|
load_scene(); |
||||
|
} |
||||
|
|
||||
|
// virtual void draw_menu() override;
|
||||
|
void load_scene() { |
||||
|
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(display_target); |
||||
|
|
||||
|
// plot
|
||||
|
viewer->data().set_mesh(V, F); |
||||
|
// colormap
|
||||
|
Eigen::MatrixXd C; |
||||
|
igl::jet(Target, true, C); |
||||
|
viewer->data().set_colors(C); |
||||
|
|
||||
|
|
||||
|
m_has_scene = true; |
||||
|
|
||||
|
int dim = V.cols(); |
||||
|
m_viewer.core().trackball_angle.setIdentity(); |
||||
|
m_viewer.core().set_rotation_type( |
||||
|
dim == 2 ? igl::opengl::ViewerCore::ROTATION_TYPE_NO_ROTATION |
||||
|
: igl::opengl::ViewerCore:: |
||||
|
ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP); |
||||
|
m_viewer.core().orthographic = dim == 2; |
||||
|
m_viewer.core().lighting_factor = 0.0; // dim == 2 ? 0.0 : 1.0;
|
||||
|
// mesh_data->data().set_face_based(true);
|
||||
|
assert(dim == 3.0); |
||||
|
m_viewer.core().align_camera_center( |
||||
|
V, F); |
||||
|
|
||||
|
// Default colors
|
||||
|
m_viewer.core().background_color << 0.9f, 0.9f, 0.9f, 0.4f; |
||||
|
// background_color << 0.3f, 0.3f, 0.5f, 1.0f;
|
||||
|
|
||||
|
// Camera parameters
|
||||
|
m_viewer.core().camera_zoom = 1.0f; |
||||
|
m_viewer.core().camera_translation << 0, 0, 0; |
||||
|
} |
||||
|
|
||||
|
void launch(const std::string &inital_scene) override { |
||||
|
m_viewer.plugins.push_back(this); |
||||
|
m_viewer.core().set_rotation_type( |
||||
|
igl::opengl::ViewerCore::ROTATION_TYPE_NO_ROTATION); |
||||
|
m_viewer.core().orthographic = true; |
||||
|
m_viewer.core().is_animating = true; |
||||
|
m_viewer.core().lighting_factor = 0.0; |
||||
|
m_viewer.core().animation_max_fps = 120.0; |
||||
|
// this->inital_scene = inital_scene;
|
||||
|
m_viewer.callback_pre_draw = [&](igl::opengl::glfw::Viewer &) { |
||||
|
return pre_draw_loop(); |
||||
|
}; |
||||
|
m_viewer.callback_post_draw = [&](igl::opengl::glfw::Viewer &) { |
||||
|
return post_draw_loop(); |
||||
|
}; |
||||
|
m_viewer.callback_key_pressed = [&](igl::opengl::glfw::Viewer &, |
||||
|
unsigned int unicode_key, |
||||
|
int modifiers) { |
||||
|
return custom_key_pressed(unicode_key, modifiers); |
||||
|
}; |
||||
|
m_viewer.launch( |
||||
|
/*resizable=*/true, /*fullscreen=*/false, |
||||
|
/*name=*/"静力学仿真"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// void load_scene();
|
||||
|
|
||||
|
void redraw_scene() { |
||||
|
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(display_target); |
||||
|
|
||||
|
// plot
|
||||
|
viewer->data().set_mesh(V, F); |
||||
|
|
||||
|
if (!gui_ctrl_.mesh_visible) { |
||||
|
viewer->data().show_overlay = false; |
||||
|
viewer->data().show_lines = false; |
||||
|
} |
||||
|
|
||||
|
if (!gui_ctrl_.single_color) { |
||||
|
// colormap
|
||||
|
Eigen::MatrixXd C; |
||||
|
igl::jet(Target, true, C); |
||||
|
viewer->data().set_colors(C); |
||||
|
} else { |
||||
|
// single color
|
||||
|
viewer->data().set_colors(Eigen::RowVector3d(1, 0, 0)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool pre_draw_loop() { |
||||
|
redraw_scene(); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
bool post_draw_loop() { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private: |
||||
|
std::shared_ptr<ssim::StaticSim> sp_StaticSim_; |
||||
|
ssim::SimTargetOption::Target display_target; |
||||
|
GUICtrl gui_ctrl_; |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
} // ipc
|
||||
|
} // rigid
|
||||
|
|
||||
|
#endif //RIGIDIPC_UISTATICSIMSTATE_H
|
@ -0,0 +1,16 @@ |
|||||
|
# Static Simulation Project |
||||
|
add_library(StaticSim STATIC StaticSim.cpp) |
||||
|
# eigen |
||||
|
target_link_libraries(StaticSim PUBLIC Eigen3::Eigen) |
||||
|
|
||||
|
# igl |
||||
|
include(libigl) |
||||
|
target_link_libraries(StaticSim PUBLIC |
||||
|
igl::core |
||||
|
igl::predicates |
||||
|
) |
||||
|
target_link_libraries(StaticSim PUBLIC spdlog::spdlog) |
||||
|
|
||||
|
|
||||
|
# IPC link static simulation |
||||
|
target_link_libraries(rigid_ipc_sim PUBLIC StaticSim) |
@ -0,0 +1,46 @@ |
|||||
|
//
|
||||
|
// Created by cflin on 4/7/23.
|
||||
|
//
|
||||
|
|
||||
|
#ifndef RIGIDIPC_SIMTARGETOPTION_H |
||||
|
#define RIGIDIPC_SIMTARGETOPTION_H |
||||
|
|
||||
|
namespace ssim { |
||||
|
|
||||
|
class SimTargetOption { |
||||
|
public: |
||||
|
static const int NUM_TARGETS = 10; |
||||
|
enum Target{ |
||||
|
U_NORM = 0,S_NORM, S_X, S_Y, S_Z |
||||
|
}; |
||||
|
|
||||
|
SimTargetOption(int init_state=0) : state(init_state) {} |
||||
|
|
||||
|
void set_option(int option) { |
||||
|
state |= (1 << option); |
||||
|
} |
||||
|
|
||||
|
void unset_option(int option) { |
||||
|
state &= ~(1 << option); |
||||
|
} |
||||
|
|
||||
|
bool is_option_set(int option) const { |
||||
|
return state & (1 << option); |
||||
|
} |
||||
|
|
||||
|
void clear() { |
||||
|
state = 0; |
||||
|
} |
||||
|
|
||||
|
void set() { |
||||
|
state = INT_MAX; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
int state; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} // ssim
|
||||
|
|
||||
|
#endif //RIGIDIPC_SIMTARGETOPTION_H
|
@ -0,0 +1,8 @@ |
|||||
|
//
|
||||
|
// Created by cflin on 4/7/23.
|
||||
|
//
|
||||
|
|
||||
|
#include "StaticSim.h" |
||||
|
|
||||
|
namespace ssim { |
||||
|
} // ssim
|
@ -0,0 +1,107 @@ |
|||||
|
//
|
||||
|
// Created by cflin on 4/7/23.
|
||||
|
//
|
||||
|
|
||||
|
#ifndef RIGIDIPC_STATICSIM_H |
||||
|
#define RIGIDIPC_STATICSIM_H |
||||
|
|
||||
|
#include <igl/readOBJ.h> |
||||
|
#include <Eigen/Dense> |
||||
|
#include <spdlog/spdlog.h> |
||||
|
#include "SimTargetOption.h" |
||||
|
namespace ssim { |
||||
|
struct Model { |
||||
|
Eigen::MatrixX3d V; |
||||
|
Eigen::MatrixX3i F; |
||||
|
|
||||
|
Model() = default; |
||||
|
|
||||
|
Model(const Eigen::MatrixX3d &V, const Eigen::MatrixX3i &F) : V(V), F(F) {} |
||||
|
int NumVertex() const{ |
||||
|
return V.rows(); |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
class StaticSim { |
||||
|
using MeshModel = Model; |
||||
|
using StlModel = Model; |
||||
|
public: |
||||
|
|
||||
|
StaticSim(const SimTargetOption &option,const std::string & obj_path){ |
||||
|
igl::readOBJ(obj_path,mesh_.V,mesh_.F); |
||||
|
// set option
|
||||
|
option_=option; |
||||
|
map_target_to_evaluated_.resize(option_.NUM_TARGETS); |
||||
|
for (int i = 0; i < option_.NUM_TARGETS; ++i) { |
||||
|
if(option_.is_option_set(i)) |
||||
|
MapAppendTarget(i); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
StaticSim(const StlModel &stl, const SimTargetOption &option) : stl_(stl), option_(option) { |
||||
|
map_target_to_evaluated_.resize(option_.NUM_TARGETS); |
||||
|
// TODO: boundary condition && solve
|
||||
|
|
||||
|
for (int i = 0; i < option_.NUM_TARGETS; ++i) { |
||||
|
MapAppendTarget(i); |
||||
|
} |
||||
|
// ...
|
||||
|
} |
||||
|
|
||||
|
Eigen::MatrixXd EvaluateTarget(SimTargetOption::Target target) { |
||||
|
if (!option_.is_option_set(target)) { |
||||
|
// new target, update option_ and map_
|
||||
|
MapAppendTarget(target); |
||||
|
option_.set_option(target); |
||||
|
} |
||||
|
return map_target_to_evaluated_[target]; |
||||
|
} |
||||
|
|
||||
|
void set_stl(const std::string &stl_path) { |
||||
|
// TODO read stl file
|
||||
|
} |
||||
|
|
||||
|
Model get_mesh() const { |
||||
|
return mesh_; |
||||
|
} |
||||
|
|
||||
|
Model get_stl() const { |
||||
|
return stl_; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
MeshModel mesh_; |
||||
|
StlModel stl_; |
||||
|
SimTargetOption option_; |
||||
|
std::vector<Eigen::MatrixXd> map_target_to_evaluated_; |
||||
|
|
||||
|
|
||||
|
Eigen::MatrixXd EvaluateUNorm() const { |
||||
|
// TODO
|
||||
|
return (Eigen::VectorXd::Random(mesh_.NumVertex()).array() + 1.0) * 50; |
||||
|
} |
||||
|
|
||||
|
Eigen::MatrixXd EvaluateSNorm() const { |
||||
|
// TODO
|
||||
|
return (Eigen::VectorXd::Random(mesh_.NumVertex()).array() + 1.0) * 50; |
||||
|
} |
||||
|
|
||||
|
void MapAppendTarget(int target) { |
||||
|
switch (target) { |
||||
|
case SimTargetOption::U_NORM: |
||||
|
map_target_to_evaluated_[target] = EvaluateUNorm(); |
||||
|
break; |
||||
|
case SimTargetOption::S_NORM: |
||||
|
map_target_to_evaluated_[target] = EvaluateSNorm(); |
||||
|
break; |
||||
|
default: |
||||
|
spdlog::warn("Wrong target {:d} !(TODO)", target); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
}; |
||||
|
|
||||
|
} // ssim
|
||||
|
|
||||
|
#endif //RIGIDIPC_STATICSIM_H
|
Loading…
Reference in new issue