diff options
author | over0219 <over0219@umn.edu> | 2020-06-23 03:00:36 +0300 |
---|---|---|
committer | over0219 <over0219@umn.edu> | 2020-06-23 03:00:36 +0300 |
commit | 88ab1c138dcb370829ae0362ad6ee8a462d8a6ca (patch) | |
tree | f8a1f130be9bd564141e720114e31aef4839e748 | |
parent | 50e2c479cc22d0efd1d744720df64311d8fefb80 (diff) |
more interface changes
-rw-r--r-- | extern/softbody/src/admmpd_collision.cpp | 8 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_collision.h | 23 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_solver.cpp | 26 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_solver.h | 18 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_types.h | 26 | ||||
-rw-r--r-- | intern/softbody/admmpd_api.cpp | 56 | ||||
-rw-r--r-- | intern/softbody/admmpd_api.h | 2 |
7 files changed, 85 insertions, 74 deletions
diff --git a/extern/softbody/src/admmpd_collision.cpp b/extern/softbody/src/admmpd_collision.cpp index 02a197c4138..54bca95729e 100644 --- a/extern/softbody/src/admmpd_collision.cpp +++ b/extern/softbody/src/admmpd_collision.cpp @@ -50,10 +50,10 @@ void EmbeddedMeshCollision::set_obstacles( obs_tree.init(obs_aabbs); } // end add obstacle - + /* void EmbeddedMeshCollision::detect(const Eigen::MatrixXd *x0, const Eigen::MatrixXd *x1) { - /* + // First, update the positions of the embedded vertex // and perform collision detection against obstacles int n_ev = emb_V0.rows(); @@ -93,9 +93,9 @@ void EmbeddedMeshCollision::detect(const Eigen::MatrixXd *x0, const Eigen::Matri // Only bother with self collision if it // is not colliding with an obstacle. // This is only useful for discrete tests. -*/ -} // end emb collision detect +} // end emb collision detect +*/ /* void FloorCollider::detect(const Eigen::MatrixXd *x) { diff --git a/extern/softbody/src/admmpd_collision.h b/extern/softbody/src/admmpd_collision.h index 5126d1a6958..2996249158e 100644 --- a/extern/softbody/src/admmpd_collision.h +++ b/extern/softbody/src/admmpd_collision.h @@ -4,10 +4,8 @@ #ifndef ADMMPD_COLLISION_H_ #define ADMMPD_COLLISION_H_ -#include <Eigen/Sparse> -#include <Eigen/Geometry> -#include <vector> #include "admmpd_bvh.h" +#include "admmpd_types.h" namespace admmpd { @@ -62,16 +60,23 @@ public: const int *faces, int nf); - // Unlike set_obstacles, the pointers - void set_embedded( - const Eigen::MatrixXd *emb_barys, - const Eigen::VectorXi *vtx_to_tet, - const Eigen::MatrixXi *tets){} + // Updates the tetmesh BVH for self collisions + // TODO + void update_bvh( + const EmbeddedMeshData *mesh, + const Eigen::MatrixXd *x0, + const Eigen::MatrixXd *x1) + { (void)(mesh); (void)(x0); (void)(x1); } // Given a list of deformable vertices (the lattice) // perform collision detection of the surface mesh against // obstacles and possibly self. - void detect(const Eigen::MatrixXd *x0, const Eigen::MatrixXd *x1); + void detect( + const EmbeddedMeshData *mesh, + const Eigen::MatrixXd *x0, + const Eigen::MatrixXd *x1){ + + } void jacobian( const Eigen::MatrixXd *x, diff --git a/extern/softbody/src/admmpd_solver.cpp b/extern/softbody/src/admmpd_solver.cpp index da766d43cc1..17bd8c7d008 100644 --- a/extern/softbody/src/admmpd_solver.cpp +++ b/extern/softbody/src/admmpd_solver.cpp @@ -21,14 +21,14 @@ template <typename T> using RowSparseMatrix = SparseMatrix<T,RowMajor>; typedef struct ThreadData { const Options *options; - Data *data; + SolverData *data; } ThreadData; bool Solver::init( const Eigen::MatrixXd &V, const Eigen::MatrixXi &T, const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -49,7 +49,7 @@ bool Solver::init( int Solver::solve( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -89,7 +89,7 @@ int Solver::solve( void Solver::init_solve( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -138,7 +138,7 @@ static void parallel_zu_update( void Solver::solve_local_step( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -152,7 +152,7 @@ void Solver::solve_local_step( void Solver::update_constraints( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -195,7 +195,7 @@ void Solver::update_constraints( } // end update constraints typedef struct LinSolveThreadData { - Data *data; + SolverData *data; MatrixXd *ls_x; MatrixXd *ls_b; } LinSolveThreadData; @@ -211,7 +211,7 @@ static void parallel_lin_solve( void Solver::solve_conjugate_gradients( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -230,7 +230,7 @@ void Solver::solve_conjugate_gradients( // Solve Ax = b in parallel auto solve_Ax_b = []( - Data *data_, + SolverData *data_, MatrixXd *x_, MatrixXd *b_) { @@ -267,7 +267,7 @@ void Solver::solve_conjugate_gradients( }; // Update CGData - admmpd::Data::CGData *cgdata = &data->cgdata; + admmpd::SolverData::CGData *cgdata = &data->cgdata; double eps = options->min_res; cgdata->b = data->b; if (cgdata->r.rows() != nx) @@ -316,7 +316,7 @@ void Solver::solve_conjugate_gradients( bool Solver::compute_matrices( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -392,7 +392,7 @@ bool Solver::compute_matrices( void Solver::compute_masses( const Options *options, - Data *data) + SolverData *data) { BLI_assert(data != NULL); BLI_assert(options != NULL); @@ -432,7 +432,7 @@ void Solver::compute_masses( void Solver::append_energies( const Options *options, - Data *data, + SolverData *data, std::vector<Triplet<double> > &D_triplets) { BLI_assert(data != NULL); diff --git a/extern/softbody/src/admmpd_solver.h b/extern/softbody/src/admmpd_solver.h index 229411ae340..d26da293bc8 100644 --- a/extern/softbody/src/admmpd_solver.h +++ b/extern/softbody/src/admmpd_solver.h @@ -17,45 +17,45 @@ public: const Eigen::MatrixXd &V, // vertices const Eigen::MatrixXi &T, // tets const Options *options, - Data *data); + SolverData *data); // Solve a single time step. // Returns number of iterations. int solve( const Options *options, - Data *data); + SolverData *data); protected: void update_constraints( const Options *options, - Data *data); + SolverData *data); void init_solve( const Options *options, - Data *data); + SolverData *data); void solve_local_step( const Options *options, - Data *data); + SolverData *data); // Global step with CG: // 1/2||Ax-b||^2 + k/2||Kx-l||^2 void solve_conjugate_gradients( const Options *options, - Data *data); + SolverData *data); bool compute_matrices( const Options *options, - Data *data); + SolverData *data); void compute_masses( const Options *options, - Data *data); + SolverData *data); void append_energies( const Options *options, - Data *data, + SolverData *data, std::vector<Eigen::Triplet<double> > &D_triplets); }; // class ADMMPD_solver diff --git a/extern/softbody/src/admmpd_types.h b/extern/softbody/src/admmpd_types.h index 48f3121f721..925072b282f 100644 --- a/extern/softbody/src/admmpd_types.h +++ b/extern/softbody/src/admmpd_types.h @@ -36,9 +36,23 @@ struct Options { {} }; -struct Data { +struct TetMesh { + Eigen::MatrixXd x_rest; // verts at rest + Eigen::MatrixXi faces; // surface elements, m x 3 + Eigen::MatrixXi tets; // internal elements, m x 4 +}; // type 0 + +struct EmbeddedMeshData { // i.e. the lattice + Eigen::MatrixXd x_rest; // embedded verts at rest + Eigen::MatrixXi faces; // embedded faces + Eigen::MatrixXi tets; // lattice elements, m x 4 + Eigen::VectorXi vtx_to_tet; // what tet vtx is embedded in, p x 1 + Eigen::MatrixXd barys; // barycoords of the embedding, p x 4 +}; // type 1 + +struct SolverData { // Set from input - Eigen::MatrixXi tets; // elements t x 4 + Eigen::MatrixXi tets; // elements t x 4, copy from mesh Eigen::MatrixXd x; // vertices, n x 3 Eigen::MatrixXd v; // velocity, n x 3 // Set in compute_matrices: @@ -71,14 +85,6 @@ struct Data { std::vector<double> weights; // per-energy weights }; -struct EmbeddedMeshData { // i.e. the lattice - Eigen::MatrixXd x_rest; // embedded verts at rest - Eigen::MatrixXi faces; // embedded faces - Eigen::MatrixXi tets; // lattice elements, m x 4 - Eigen::VectorXi vtx_to_tet; // what tet vtx is embedded in, p x 1 - Eigen::MatrixXd barys; // barycoords of the embedding, p x 4 -}; - } // namespace admmpd #endif // ADMMPD_TYPES_H_ diff --git a/intern/softbody/admmpd_api.cpp b/intern/softbody/admmpd_api.cpp index 56971ed4262..203ec9bf9c6 100644 --- a/intern/softbody/admmpd_api.cpp +++ b/intern/softbody/admmpd_api.cpp @@ -38,7 +38,7 @@ struct ADMMPDInternalData { admmpd::Options *options; - admmpd::Data *data; + admmpd::SolverData *data; admmpd::EmbeddedMeshData *embmesh; int in_totverts; // number of input verts }; @@ -50,18 +50,18 @@ void admmpd_dealloc(ADMMPDInterfaceData *iface) iface->totverts = 0; // output vertices - if (iface->data) + if (iface->idata) { - if(iface->data->options) - delete iface->data->options; - if(iface->data->data) - delete iface->data->data; - if(iface->data->embmesh) - delete iface->data->embmesh; - delete iface->data; + if(iface->idata->options) + delete iface->idata->options; + if(iface->idata->data) + delete iface->idata->data; + if(iface->idata->embmesh) + delete iface->idata->embmesh; + delete iface->idata; } - iface->data = NULL; + iface->idata = NULL; } static int admmpd_init_with_tetgen( @@ -133,11 +133,11 @@ static int admmpd_init_with_lattice( } iface->totverts = 0; - bool success = admmpd::EmbeddedMesh().generate(in_V,in_F,iface->data->embmesh,V); + bool success = admmpd::EmbeddedMesh().generate(in_V,in_F,iface->idata->embmesh,V); if (success) { iface->totverts = V->rows(); - *T = iface->data->embmesh->tets; + *T = iface->idata->embmesh->tets; return 1; } @@ -157,12 +157,12 @@ int admmpd_init(ADMMPDInterfaceData *iface, float *in_verts, unsigned int *in_fa admmpd_dealloc(iface); // Generate solver data - iface->data = new ADMMPDInternalData(); - iface->data->options = new admmpd::Options(); - admmpd::Options *options = iface->data->options; - iface->data->data = new admmpd::Data(); - admmpd::Data *data = iface->data->data; - iface->data->embmesh = new admmpd::EmbeddedMeshData(); + iface->idata = new ADMMPDInternalData(); + iface->idata->options = new admmpd::Options(); + admmpd::Options *options = iface->idata->options; + iface->idata->data = new admmpd::SolverData(); + admmpd::SolverData *data = iface->idata->data; + iface->idata->embmesh = new admmpd::EmbeddedMeshData(); // Generate tets and vertices Eigen::MatrixXd V; @@ -214,8 +214,8 @@ void admmpd_copy_from_bodypoint(ADMMPDInterfaceData *iface, const BodyPoint *pts const BodyPoint *pt = &pts[i]; for(int j=0; j<3; ++j) { - iface->data->data->x(i,j)=pt->pos[j]; - iface->data->data->v(i,j)=pt->vec[j]; + iface->idata->data->x(i,j)=pt->pos[j]; + iface->idata->data->v(i,j)=pt->vec[j]; } } } @@ -233,8 +233,8 @@ void admmpd_copy_to_bodypoint_and_object(ADMMPDInterfaceData *iface, BodyPoint * BodyPoint *pt = &pts[i]; for(int j=0; j<3; ++j) { - pt->pos[j] = iface->data->data->x(i,j); - pt->vec[j] = iface->data->data->v(i,j); + pt->pos[j] = iface->idata->data->x(i,j); + pt->vec[j] = iface->idata->data->v(i,j); } } @@ -242,9 +242,9 @@ void admmpd_copy_to_bodypoint_and_object(ADMMPDInterfaceData *iface, BodyPoint * // n vertices of the tet mesh are the input surface mesh. if (vertexCos != NULL && iface->init_mode==0 && i<iface->mesh_totverts) { - vertexCos[i][0] = iface->data->data->x(i,0); - vertexCos[i][1] = iface->data->data->x(i,1); - vertexCos[i][2] = iface->data->data->x(i,2); + vertexCos[i][0] = iface->idata->data->x(i,0); + vertexCos[i][1] = iface->idata->data->x(i,1); + vertexCos[i][2] = iface->idata->data->x(i,2); } } // end loop all verts @@ -256,7 +256,7 @@ void admmpd_copy_to_bodypoint_and_object(ADMMPDInterfaceData *iface, BodyPoint * { Eigen::Vector3d xi = admmpd::EmbeddedMesh().get_mapped_vertex( - iface->data->embmesh, &iface->data->data->x, i); + iface->idata->embmesh, &iface->idata->data->x, i); vertexCos[i][0] = xi[0]; vertexCos[i][1] = xi[1]; vertexCos[i][2] = xi[2]; @@ -271,12 +271,12 @@ void admmpd_solve(ADMMPDInterfaceData *iface) if (iface == NULL) return; - if (iface->data == NULL || iface->data->options == NULL || iface->data->data == NULL) + if (iface->idata == NULL || iface->idata->options == NULL || iface->idata->data == NULL) return; try { - admmpd::Solver().solve(iface->data->options,iface->data->data); + admmpd::Solver().solve(iface->idata->options,iface->idata->data); } catch(const std::exception &e) { diff --git a/intern/softbody/admmpd_api.h b/intern/softbody/admmpd_api.h index e08e527b0e1..bd4ff9a3a1f 100644 --- a/intern/softbody/admmpd_api.h +++ b/intern/softbody/admmpd_api.h @@ -38,7 +38,7 @@ typedef struct ADMMPDInterfaceData { int mesh_totfaces; // number of surface mesh faces (input) int init_mode; // 0=tetgen, 1=lattice // Solver data used internally - struct ADMMPDInternalData *data; + struct ADMMPDInternalData *idata; } ADMMPDInterfaceData; // SoftBody bodypoint (contains pos,vec) |