Code Monkey home page Code Monkey logo

laplacian-deformation's Introduction

laplacian deformation module

CLICK HERE FOR DEMO

This module implements laplacian surface editing. This technique allows you to deform the surface of a mesh, while still preserving the details of the surface. We implement this by minimizing the energy function (5) in the linked paper.

To run a minimal example do:

npm run minimal

To run a more advanced demo do:

npm run start

In our current API, we load the module as

require("laplacian-deformation").load(function(initModule,prepareDeform, doDeform, freeModule) {
// code that uses the API here.
}

The API consists of four methods. We describe them below.

initModule(mesh)

initializes the module for doing deformation on mesh. Must be called before any other methods in the API.

prepareDeform(handles, unconstrained)

Does precalculations necessary for performing deformation on a region of vertices of the mesh. Note that this is a slow operation that performs performs a cholesky decomposition!

  • handles vertices that can be freely manipulated and moved by the user of the library.

  • unconstrained these are vertices that are free, and are solved for in the laplacian deformation calculations.

Some images will serve to clarify the meaning of the above parameters.

In the image, handles is yellow, unconstrained is blue, and the gray region are vertices not affected by the deformation. Only yellow and blue vertices are affected by the deformation, so these are in the region of deformation. Note that the user is expected to specify boundary vertices that specify the end of the region of deformation. In the above image, these boundary vertices are the yellow vertices above the gray vertices, and these boundary vertices are part of the handles vertices. So their positions can be manipulated as well.

The user of the library deforms the mesh by setting the positions of the handles vertices by calling doDeform. One possible deformation can look like the below:

It is shown in minimal/minimal.js how this deformation was done.

deDeform(handlesPositions)

After calling prepareDeform(), we can use doDeform() to specify the positions of the handles vertices, and thus deform the mesh. The function returns the vertex coordinates of the deformed mesh. We can call this function as many times as we want after calling prepareDeform. In difference to prepareDeform, this is a very fast operation.

  • handlesPositions is simply an array of coordinates of the format [[x,y,z], [x,y,z], ...]. The first coordinate sets the positions of the handle handles[0], and so on.

laplacian-deformation's People

Contributors

erkaman avatar mikolalysenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laplacian-deformation's Issues

the finger become bigger than before

image
image

Hello. I select right hand elbow to be the mainHandle, and I want to descend the the right arm, everything looks right except the right palm and hand, it looks bigger then before! is that normal? is that the mainHandle should be located in telos of body? do you have some advice to constraint it

In RSI mode, the decomposition of s.energyMatrixCholesky fails

Hi, thanks for sharing your code.

When I tested the C++ version of the code, the RSI mode did not work as expected.
I checked the source of the bug by replacing the sparse solve to Eigen::SparseLU and checked the value of s.energyMatrixCholesky.info(), because Eigen's SparseCholesky often ignores matrix decomposition failure. After the LU decomposition, the info() value was not Eigen::Success.

So if you seek to use the RSI mode, you might want to be careful.

I may have used the API in the wrong way, Here I attach a code I used.

// V : (#V x 3) vertex positions
// F: (#F x 3) face vertex indices
// df: (n x 2) 2D deformation delta (dx,dy) values
// I: (n) indices for vertex indices of handle vertices
void deform_mesh_laplacian(const Eigen::MatrixXd &V,
                                    const Eigen::MatrixXi &F,
                                    const Eigen::MatrixXd &df,
                                    const Eigen::VectorXi &I,
                                    Eigen::MatrixXd &Vresult) {    
  using namespace original;                                             
  Eigen::MatrixXi FT = F.transpose();                                   
  Eigen::MatrixXd VT = V.transpose();                                      
  Eigen::VectorXi roi(VT.cols());       
  for (Eigen::Index i = 0; i < roi.size(); i++) {
    roi(i) = i;                       
  }                               
  prepareDeform(FT.data(), FT.cols(), VT.data(), VT.cols(), roi.data(),
                roi.size(), I.size(), true); // I want to put the values of I to specify which vertices to move, but it seems the handle is just (0~n)th vertices
  Eigen::MatrixXd posT_handles(3, I.size());
  for (Eigen::Index i = 0; i < I.size(); i++) {
    posT_handles(0, i) = VT(0, i) + df.transpose()(0, i);
    posT_handles(1, i) = VT(1, i) + df.transpose()(1, i);
    posT_handles(2, i) = VT(2, i);                                          
  }                                                                     
                                              
  Eigen::MatrixXd VT_result = VT;
  doDeform(posT_handles.data(), I.size(), VT_result.data());
  freeDeform();
  Vresult = VT_result.transpose();
}

energyMatrixCoeffs contains "nan"

Hi,

I'm doing a small test with Laplacian deformation with the API that you provided.

My mesh contains 25 regular points. The positions of the points are

for(int i = 0; i < 5; ++i) 
    {
        for(int j = 0; j < 5; ++j)
       {
            x = 0.1 * i;
            y = 0.1 * j;
            z = 0;
        }
    } 

I choose only one point within them as the handle. All the rest points are unconstrained.

After the methods doDeform(), I got much "nan" in the meshPositions. I found it is because that there is "nan" in the energyMatrixCoeffs.

could you please help me with this?

Thanks very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.