GeometryCollective / boundary-first-flattening

MIT License
768 stars 96 forks source link

Flattening not succedeed after implementing eigen equivalent of cholmod routines #26

Closed lukkio88 closed 5 years ago

lukkio88 commented 6 years ago

Hi, there's some issue with my wrappers and I'd like to know if I've implemented corretly the Eigen equivalent of some of the cholmod routines, the documentation doesn't say much.

For example you've implemented:

inline cholmod_sparse* add(cholmod_sparse *A, cholmod_sparse *B, double alpha[2], double beta[2])
{
    // C = alpha*A + beta*B
    return cholmod_l_add(A, B, alpha, beta, 1, 1, common);
}

My eigen equivalent, which actually I'm not sure anymore, is:


inline SpMat* add(SpMat *A, SpMat *B, double alpha[2], double beta[2])
{
    // C = alpha*A + beta*B
    SpMat & refA = *A;
    SpMat & refB = *B;

    return new SpMat(alpha[0]*refA + beta[0]*refB);
}

Where SpMat is defined as:

using SpMat = Eigen::SparseMatrix<double>;

Is my conversion correct? There're similar function throught in SparseMatrix.inl I guess the interpretation of the inputs must be the same.

But I've not clear why you have alpha,beta as vectors with two entries.

What I'm currently getting is something like:

screenshot from 2018-10-12 11-55-08

While originally is supposed to generate:

screenshot from 2018-10-12 12-30-26

lukkio88 commented 6 years ago

By the way, the client app I'm using is:

#include <Bff.h>
#include <MeshIO.h>
#include <iostream>

int main(int argc, char** argv) {

    if(argc != 3) {
        std::cout << "Usage : UnitTestDewrinkling <input-filename>.obj <output-filename>.obj" << std::endl;
        return 1;
    }

    std::string input_filename = argv[1];
    std::string output_filename = argv[2];

    Mesh test_mesh;

    std::cout << "Loading mesh from " << input_filename << "..." << std::endl;

    if(!test_mesh.read(input_filename))
        std::cout << "Reading problems!" << std::endl;

    std::cout << "Initializing flattening module..." << std::endl;

    BFF flattening_module(test_mesh);
    EigenDenseMatrix boundaryData(flattening_module.data->bN);

    std::cout << "Flattening (generating uv)" << std::endl;

    flattening_module.flatten(boundaryData,true);

    std::cout << "Flattening done, now storing into " << output_filename << "..." << std::endl;

    test_mesh.write(output_filename,false,false);

    std::cout << "Output stored!" << std::endl;

    return 0;

}

Maybe there's some other setting I'm before starting the flattening. For example I noticed you have something like:

        // flatten
        if (type == BoundaryType::automatic) {
            removeVertexHandles();
            DenseMatrix u(bff->data->bN);
            bff->flatten(u, true);
            performPCA();
            update();

        } 

In your Viewer.cpp, maybe I need to call removeVertexHandles and PerformPCA somehow?

lukkio88 commented 6 years ago

And one more question... I'm not 100% sure, but why is the image of the checkboard like shifted (from your original tool)?

rohan-sawhney commented 6 years ago

You can probably just get rid of the alpha and beta (this is cholmod specific) and return "refA + refB". It seems like your client app is alright, there is no need to call/implement "removeVertexHandles" and "performPCA" - these are called for visualization purposes.

lukkio88 commented 6 years ago

There was an issue with my initialization function in my Dense/Sparse classes now I'm getting the following outputs (normalized and not normalized) screenshot from 2018-10-12 13-46-40

screenshot from 2018-10-12 13-48-54

The second picture is quite close to what your tool provides (not the same though, this might be actually Eigen at this point). However I don't understand why the texture mapping doesn't align the texture with the orientation of the mesh.

lukkio88 commented 6 years ago

I've accidentally closed the issue... sorry...

rohan-sawhney commented 6 years ago

You'll have to translate, rotate and/or scale either the texture image or the uvs to get them to align the way you want them to. The "Show UV Tex Param" option in Meshlab lets you see the current alignment.

lukkio88 commented 6 years ago

So despite not being aligned, you would say the parameterization is still correct.

rohan-sawhney commented 6 years ago

Its difficult for me to say, I'd print out the uvs from the BFF tool and your implementation and see the error between them to check if your implementation is correct.

lukkio88 commented 6 years ago

I was more referring, in general. The UV look different to me, so there might still be something to sorted out.

lukkio88 commented 6 years ago

You can probably just get rid of the alpha and beta (this is cholmod specific) and return "refA + refB". It seems like your client app is alright, there is no need to call/implement "removeVertexHandles" and "performPCA" - these are called for visualization purposes.

I don't think I can get rid of the two constants, since you use them in your overload of the operator -

rohan-sawhney commented 6 years ago

Right, but you can just get rid of the "add" function and directly return "A + B" and "A - B" in the appropriate operators.

lukkio88 commented 6 years ago

Fair point.

lukkio88 commented 6 years ago

Hi again, Is there some special setting you do in your cholesky factorization? If you compare my output against yours you can see the top right corner distorted (in mine). Is there maybe some special setting I should be aware of?

I have the feeling the Eigen solver has stability issues, but I might be complete wrong.

rohan-sawhney commented 6 years ago

In my experience, Cholmod is a more stable solver than Eigen. Eigen has wrappers around multiple external solvers such as Cholmod (see here: http://eigen.tuxfamily.org/dox/group__TopicSparseSystems.html), it might be worth giving them a try to see if the results improve (and to make sure the problem is solver related).