3

I am currently using libigl to manipulate/deform a simple (2D) square by manipulating its corners (cf. initial state below):

enter image description here

After imposing displacement u(1,1) to the bottom-left corner and updating non-corner vertices locations using biharmonic deformation I end up with the following state (inspired from Biharmonic deformation tutorial ):

enter image description here

Problems are:

  • triangles are not uniformly distributed
  • The deformation has altered the sides which are no longer straight lines

An ideal solution would then be something close to the image below, without having to manage each boundary vertice:

enter image description here

Questions are:

  • Which king of deformation method should I use to achieve such result?
  • Is libigl the right tool for such operations?

NOTE: full implementation is:

#include <iostream>
#include <Eigen/Core>
#include <igl/colon.h>
#include <igl/harmonic.h>
#include <igl/viewer/Viewer.h>
#include <igl/triangle/triangulate.h>
#include "tutorial_shared_path.h"

using namespace Eigen;
using namespace std;

double step = 0.1;
// Input polygon
MatrixXd V; // corners location
MatrixXi E; // boundary edges
MatrixXd H; // 2D positions of points contained in holes of the triangulation

// Triangulated interior
MatrixXd D_bc; // displacements / corner
MatrixXd V2; // all vertexes location
MatrixXd U; // deformed vertexes
MatrixXi F2;
Eigen::VectorXi b; // index of corner vertices
int selected = 0; // index of currently selected corner

void update(igl::viewer::Viewer &viewer) {
  cout << "D_bc " <<endl
       << D_bc <<endl;
  // compute displacements
  MatrixXd D;
  igl::harmonic(V2,F2,b,D_bc,2.,D);
  // compute solution as init state + displacements
  U = V2+D;
  viewer.data.set_vertices(U);

  // display current selection
  Eigen::MatrixXd points(1,3);
  points << V(selected, 0) + D_bc(selected, 0), V(selected, 1) + D_bc(selected, 1), 0;
  viewer.data.set_points(points,Eigen::RowVector3d(1,0,0));
}

bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) {
  switch((int)key)
  {
    case 32: // space
      selected = (selected + 1) % 4;
      break;
    case 6: // right
      D_bc(selected, 0) += step;
      break;
    case 7: // left
      D_bc(selected, 0) -= step;
      break;
    case 8: // down
      D_bc(selected, 1) -= step;
      break;
    case 9: // top
      D_bc(selected, 1) += step;
      break;
    default:
      return false;
  }
  update(viewer);
  return true;
}

int main(int argc, char *argv[])
{
  // Create the boundary of a square
  V.resize(4,2);
  V << -1,-1, 1,-1, 1,1, -1,1;
  E.resize(4,2);
  E << 0,1, 1,2, 2,3, 3,0;
  H.resize(0,2);
  // Triangulate the interior
  igl::triangle::triangulate(V,E,H,"a0.01q",V2,F2);

  igl::colon<int>(0,V.rows()-1,b);

  // Plot the generated mesh
  igl::viewer::Viewer viewer;
  viewer.data.set_mesh(V2,F2);

  // set initial displacements / solution
  D_bc = MatrixXd::Zero(V.rows(), V.cols());
  U=V2;

  viewer.callback_key_down = &key_down;
  update(viewer);

  // display legend
  cout<<
    "Press [space] to switch point."<<endl<<
    "Use arrows to move current point."<<endl;

  viewer.launch();
}
nicolaspanel
  • 943
  • 11
  • 21
  • 1
    It looks to me that you are cropping instead of deforming. I think you could achieve this by calculating the new rect of the square, and iterating over the vertices, modifying their positions if they are on the "wrong side" of the rect. I don't think that there is a deformation pre-made for what you want, however it shouldn't be difficult to implement using libigl (Or another tool) – Javier Feb 27 '17 at 20:07
  • Doubling down on @Javier's comment, is the goal to have a "new mesh" or a deformation of the original mesh? If you just want a new mesh, then I'd focus on deforming the boundary and triangulating the new boundary. If you want to deform the original mesh, it seems like you might want to look at "generalized barycentric coordinates". In particular "harmonic coordinates" (incidentally implemented in libigl). – Alec Jacobson Mar 15 '17 at 23:22

0 Answers0