You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

107 lines
2.9 KiB

//
// 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