~mht/surcut

9e36f62052a0cfe23df508c5a47a00a5f9bbab06 — Martin Hafskjold Thoresen 4 years ago 2811359
Format and comment.

I don't think the way we've attempted here is any good, though I'm sure
there's something wrong with the impl as well, since only 2/3 vertices
is supposed to move.
2 files changed, 31 insertions(+), 34 deletions(-)

M arap-mold.h
M main.cpp
M arap-mold.h => arap-mold.h +2 -2
@@ 96,13 96,13 @@ bool precomputation(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const in
void iter(const Args &, const Eigen::MatrixXd &bc, Data &data, int num_tets, Eigen::MatrixXi &,
          Eigen::MatrixXd &U);


enum Moldable {
  YES,
  NO,
  CROSSING,
};

Moldable is_moldable(Eigen::Vector3d &remove_dir, std::vector<bool> &is_point_above, Eigen::MatrixXi &faces, int face, Eigen::Vector3d normal, double *out_dot);
Moldable is_moldable(Eigen::Vector3d &remove_dir, std::vector<bool> &is_point_above,
                     Eigen::MatrixXi &faces, int face, Eigen::Vector3d normal, double *out_dot);

} // namespace arap

M main.cpp => main.cpp +29 -32
@@ 31,12 31,12 @@ Eigen::MatrixXd N;
Eigen::MatrixXd colors;

// Tetrahedralized data
Eigen::MatrixXd TV;                 // Vertices
Eigen::MatrixXi TT;                 // Tets
Eigen::MatrixXi TF;                 // Triangles
Eigen::MatrixXi TF2T;               // Face to tets mapping
Eigen::MatrixXi TT2F;               // Tet to faces mapping
Eigen::MatrixXi TNeigh;             // Neighbor tets for each tet
Eigen::MatrixXd TV;     // Vertices
Eigen::MatrixXi TT;     // Tets
Eigen::MatrixXi TF;     // Triangles
Eigen::MatrixXi TF2T;   // Face to tets mapping
Eigen::MatrixXi TT2F;   // Tet to faces mapping
Eigen::MatrixXi TNeigh; // Neighbor tets for each tet

// Indices of the fixed vertices in TV.
Eigen::VectorXi boundary(BOUNDARY_SIZE);


@@ 293,9 293,7 @@ void ensure_moldability() {
  igl::per_face_normals(U, TF, normals);

  std::vector<bool> is_point_above(U.rows());
  auto above_plane = [&](Eigen::Vector3d v) {
    return (v - plane_p).dot(plane_n) >= 0.0;
  };
  auto above_plane = [&](Eigen::Vector3d v) { return (v - plane_p).dot(plane_n) >= 0.0; };
  for (int i = 0; i < U.rows(); i++) {
    is_point_above[i] = above_plane(U.row(i));
  }


@@ 304,18 302,20 @@ void ensure_moldability() {
    double x = dir.dot(U.row(TF(f, 0)));
    double y = dir.dot(U.row(TF(f, 1)));
    double z = dir.dot(U.row(TF(f, 2)));
    if (x >= y && x >= z)
    if (y <= x && z <= x)
      return 0;
    if (y >= x && y >= z)
    if (x <= y && z <= y)
      return 1;
    if (z >= x && z >= y)
    if (x <= z && y <= z)
      return 2;
    std::cerr << dir << std::endl << std::endl;
    std::cerr << U.row(TF(f, 0)) << std::endl << std::endl;
    std::cerr << U.row(TF(f, 1)) << std::endl << std::endl;
    std::cerr << U.row(TF(f, 2)) << std::endl << std::endl;

    fprintf(stderr, "%lf %lf %lf\n", x, y, z);
    { /* XXX(debug) */
      std::cerr << dir << std::endl << std::endl;
      std::cerr << U.row(TF(f, 0)) << std::endl << std::endl;
      std::cerr << U.row(TF(f, 1)) << std::endl << std::endl;
      std::cerr << U.row(TF(f, 2)) << std::endl << std::endl;
      fprintf(stderr, "%lf %lf %lf\n", x, y, z);
    }
    assert(false && "This is impossible");
    return -1;
  };


@@ 337,7 337,7 @@ void ensure_moldability() {
    auto normal = normals.row(i);
    Eigen::Vector3d removal_dir(plane_n);
    auto moldable = arap::is_moldable(removal_dir, is_point_above, TF, i, normal, NULL);
    if (moldable != arap::YES) {
    if (moldable == arap::NO) {
      indices.push_back(i);
    }
  }


@@ 352,13 352,12 @@ void ensure_moldability() {
    Eigen::Vector3d removal_dir(plane_n);
    auto moldable = arap::is_moldable(removal_dir, is_point_above, TF, face, normal, NULL);
    // XXX(todo): how to handle crossing faces?
    if (moldable != arap::NO) continue;
    if (moldable != arap::NO)
      continue;
    auto drag_dir = (normal - plane_n.dot(normal) * plane_n).normalized();

    // XXX(debug)
    {
    { /* XXX(debug): NaN check */
      if (drag_dir[0] != drag_dir[0]) {
        /* NaN checks*/
        std::cerr << drag_dir << std::endl;
        std::cerr << normal << std::endl;
        std::cerr << plane_n << std::endl;


@@ 398,7 397,6 @@ void ensure_moldability() {
    }

    // XXX(todo): check neighboring faces of these vertices and add to `indices` as needed.
    
  }
}



@@ 436,15 434,14 @@ int main(int argc, char *argv[]) {

  boundary << 0, 1, 2, 3; // 19, 22, 121, 122, 221, 224, 321, 326;

//   Dbg(V);
//   Dbg(F);
//   Dbg(TV);
//   Dbg(TT);
//   Dbg(TF);
//   Dbg(TT2F);
//   Dbg(TF2T);
//   Dbg(TNeigh);

  //   Dbg(V);
  //   Dbg(F);
  //   Dbg(TV);
  //   Dbg(TT);
  //   Dbg(TF);
  //   Dbg(TT2F);
  //   Dbg(TF2T);
  //   Dbg(TNeigh);

  arap_data.mht_triangles = TF;
  arap_data.mht_tf2t = TF2T;