GeometryCollective / boundary-first-flattening

MIT License
768 stars 96 forks source link

Flattening generates mesh with indices = 0 #25

Closed lukkio88 closed 5 years ago

lukkio88 commented 6 years ago

Hi, as I mentioned I've been trying to integrate Eigen in your tool. I managed to do that, I run the tool as suggested, but the output is a mesh with same vertices as the original one + the new UV and but all the faces are set to 0.

My main looks like the following:

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

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

    std::ifstream ifs("./test_mesh.obj");
    std::stringstream ss_content;
    std::string content;
    std::istringstream iss_content;

    if(ifs) {
        std::cout << "Reading file!" << std::endl;
        ss_content << ifs.rdbuf();
        content = ss_content.str();
        iss_content = std::istringstream(content);
    }

    ifs.close();

    Mesh test_mesh;

    if(!MeshIO::read(iss_content,test_mesh))
        std::cout << "Reading problems!" << std::endl;

    BFF flattening_module(test_mesh);

    EigenDenseMatrix boundaryData(flattening_module.data->bN);

    std::cout << "flattening mesh" << std::endl;

    flattening_module.flatten(boundaryData,true);

    std::cout << "mesh flattened, now storing into a file" << std::endl;

    test_mesh.write("./output_test_mesh.obj", false, false);

    return 0;

}

The only code I changed are the linear algebra wrappers, but nothing has changed inside the Mesh BFF, BFFData and MeshIO, so I assume the manipulation of the indices should be the same as before.

I cannot explain why I'm getting something like the following for the faces:

Input:


mtllib plane.mtl
o Plane
v 15.000000 -15.000000 0.000000
v 15.000000 15.000000 0.000000
v -15.000000 15.000000 0.000000
v -15.000000  -15.000000 0.000000

vt 15.000000 0.000000
vt 15.000000 15.000000
vt 0.000000 15.000000
vt 0.000000 0.000000

usemtl Material
s off
f 1/1 2/2 3/3
f 1/1 3/3 4/4

Output:

v 15 -15 0
v 15 15 0
v -15 15 0
v -15 -15 0
vt 11.682 11.682
vt -11.682 11.682
vt 11.682 -11.682
vt -11.682 11.682
vt -11.682 -11.682
vt 11.682 -11.682
f 0/0 0/0 0/0
f 0/0 0/0 0/0

Any advice?

lukkio88 commented 6 years ago

Just done the following check:

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

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

    std::ifstream ifs("./test_mesh.obj");
    std::stringstream ss_content;
    std::string content;
    std::istringstream iss_content;

    if(ifs) {
        std::cout << "Reading file!" << std::endl;
        ss_content << ifs.rdbuf();
        content = ss_content.str();
        iss_content = std::istringstream(content);
    }

    ifs.close();

    Mesh test_mesh;

    if(!MeshIO::read(iss_content,test_mesh))
        std::cout << "Reading problems!" << std::endl;

    test_mesh.write("./output_test_mesh.obj", false, false);

    return 0;

}

And I get the same problem, so the processing has nothing to do with it.

lukkio88 commented 6 years ago

The output of your binaries is instead the following:

v 0.707107 -0.707107 0
v 0.707107 0.707107 0
v -0.707107 0.707107 0
v -0.707107 -0.707107 0
vt 1 2e-08
vt -1e-08 1
vt 1e-08 -1
vt -1e-08 1
vt -1 -2e-08
vt 1e-08 -1
f 1/3 2/1 3/2
f 1/6 3/4 4/5

Why are the coordinates scaled?

lukkio88 commented 6 years ago

Never mind it worked... I probably wasn't supposed to use the MeshIO class... by using the following

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

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

    Mesh test_mesh;

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

    BFF flattening_module(test_mesh);

    EigenDenseMatrix boundaryData(flattening_module.data->bN);

    std::cout << "flattening mesh" << std::endl;

    flattening_module.flatten(boundaryData,true);

    std::cout << "mesh flattened, now storing into a file" << std::endl;

    test_mesh.write("./output_test_mesh.obj",false,true);

    return 0;

}

I got the following output:


v 0.707107 -0.707107 0
v 0.707107 0.707107 0
v -0.707107 0.707107 0
v -0.707107 -0.707107 0
vt 0.853553 0.853553
vt 0.146447 0.853553
vt 0.853553 0.146447
vt 0.146447 0.853553
vt 0.146447 0.146447
vt 0.853553 0.146447
f 1/3 2/1 3/2
f 1/6 3/4 4/5

Which is the same as the one provided by your tool (with the rescaling enabled). But again, is there a reason why the coordinates are scaled?

rohan-sawhney commented 6 years ago

The mesh class "normalizes" the model, which it probably shouldn't do. I would comment out this line: https://github.com/GeometryCollective/boundary-first-flattening/blob/23d8448a817f5175ebffd79f233076444b3a8d5e/mesh/src/Mesh.cpp#L34

lukkio88 commented 6 years ago

Is this final normalization a mistake then?

rohan-sawhney commented 6 years ago

Yes, it won't be there in the next version.