libigl / libigl

Simple MPL-2.0-licensed C++ geometry processing library.
http://libigl.github.io/libigl/
GNU General Public License v3.0
4.59k stars 1.14k forks source link

505_MIQ tutorial generates poor results for a simple model #36

Closed RogersDoug closed 9 years ago

RogersDoug commented 9 years ago

I have a simple model that generates poor global texture parameterization in the tutorial sample 505_MIQ. It is obvious in the viewer. The texture coordinate area is zero or near zero for several triangles.

II have attached the model in OBJ format by adding ".jpg" to the extension. Under the front left leg, you can see the distortion. You will need to change readOFF to readOBJ, but that should be the only change required.

cow mtl cow obj

http://www.inf.ethz.ch/personal/dpanozzo/libigl_tutorial/505_MIQ/main.cpp

danielepanozzo commented 9 years ago

The links to the files are not working, could you please upload them again?

The example is very basic, if you want to get high quality results you should make sure that: 1) The model has enough triangles, and the quality of the triangles is high (no slivers) 2) You provide good directional constraints (usually they are extracted from curvature), in the example there is only one face constrained to random direction just for demonstration purposes.

Could you please confirm if the you can reproduce the images that you see in the tutorial? If it does this is probably not a bug, just a bad input.

RogersDoug commented 9 years ago

The links to the files are not working, could you please upload them again? Sure. I put them on DropBox:

https://dl.dropboxusercontent.com/u/85781814/cow.mtl https://dl.dropboxusercontent.com/u/85781814/cow.obj https://dl.dropboxusercontent.com/u/85781814/cow.jpg

My slightly modified version is here: https://dl.dropboxusercontent.com/u/85781814/flow.cpp

Let me know if you have trouble accessing them.

I believe the model has enough triangles, but I am not using the curvature as input. Most of the parameterization looks good, though.

usually they are extracted from curvature Do you have an example showing generating curvature and using that as input to the global parameterization?

The tutorials run correctly.

Thanks.

-Doug

RogersDoug commented 9 years ago

I added constraints with the code below. While the legs was improved, the parameterization was significantly worse on the left side. I used the curvatures from PD1 and PD2 (below) and they seem random on the left side.

https://dl.dropboxusercontent.com/u/85781814/cow_withConstriants.jpg

// All files: https://www.dropbox.com/sh/5azy2qe54weox42/AAAudOjrFzXTEbErHalrbRu7a?dl=0

if 0

// Contrain one face
VectorXi b(1);
b << 0;
MatrixXd bc(1, 3);
bc << 1, 0, 0;
// Create a smooth 4-RoSy field
VectorXd S;
igl::nrosy(V, F, b, bc, VectorXi(), VectorXd(), MatrixXd(), 4, 0.5, X1, S);

else

MatrixXd HN;
SparseMatrix<double> L, M, Minv;
igl::cotmatrix(V, F, L);
igl::massmatrix(V, F, igl::MASSMATRIX_TYPE_VORONOI, M);
igl::invert_diag(M, Minv);
// Laplace-Beltrami of position
HN = -Minv_(L_V);
// Extract magnitude as mean curvature
VectorXd H = HN.rowwise().norm();
// Compute curvature directions via quadric fitting
MatrixXd PD1, PD2;
VectorXd PV1, PV2;
igl::principal_curvature(V, F, PD1, PD2, PV1, PV2);
// mean curvature
H = 0.5*(PV1 + PV2);

int n = PD1.rows();
VectorXi b(n);
for (int i = 0; i < n; i++)
{
    b[i] = i;
}

// Create a smooth 4-RoSy field
VectorXd S;
igl::nrosy(V, F, b, PD1, VectorXi(), VectorXd(), MatrixXd(), 4, 0.5, X1, S);

// I also tried PD2, but there was no difference

endif

danielepanozzo commented 9 years ago

The mesh is way too coarse and the element quality is bad, it is not surprising that you get some distortion. The way you are specifying constraint is also not good, please take a look at the original mixed integer paper for a better way of specifying "sparse" constraints. You cannot provide dense constraints, they should be sparse.

The MIQ algorithm is complex and very hard to use as black box: what I think is happening in your example is that you have two close singularities and the grid size is too large. If this is the case the mixed-integer roundings will destroy a large part of the parametrization. It will probably get much better if you subdivide the mesh 1-2 times and if you increase the resolution of the quad mesh ("gradient" parameter).

This example is only meant to demonstrate the MIQ pipeline: if you want to control it and get high-quality quandrangulations you need to tune the parameters and possibly add a UI to specify the alignment constraints. These things are not in the tutorial yet, since they require a lot of engineering and they are not very interesting from a geometry processing point of view.

I close the issue for now since this does not look like a bug in libigl, feel free to contact me by email if you need some extra support on quadrangulation in general.

RogersDoug commented 9 years ago

Ok. It was a test model only. I am trying to understand how to use it in practice and what the issues are.

please take a look at the original mixed integer paper for a better way of specifying "sparse" constraints

In this paper?: http://www-sop.inria.fr/members/David.Bommes/publications/miq.pdf I can do that, but I had hoped that this had be coded already to save some time. There is not an example in libigl? You have a lot of great code here :)

I close the issue for now since this does not look like a bug in libigl, feel free to contact me by email if you need some extra support on quadrangulation in general.

I am using the texture coordinates directly, not using this as an input to quadragulation. Most of the time, the texture coordinates are usable, albeit after some processing.

Oh, by the way. This is really good work. Well done and thank you for the project and your support.

RogersDoug commented 9 years ago

Subdividing the model did indeed fix the issue. I'm not sure why the principal curvature was incorrect, though.

danielepanozzo commented 9 years ago

Yes that is the paper, the section for the constraints is Section 3. We do not have code for that part since it is problem specific and it requires a bit of UI to properly specify the constraints. To get rid of the distortion in certain areas, a good trick is to remove all the constraints there and let nrosy do the smoothing.