Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the ratio but output file don't change #2

Open
ahmedsaptan opened this issue Apr 7, 2020 · 5 comments
Open

Change the ratio but output file don't change #2

ahmedsaptan opened this issue Apr 7, 2020 · 5 comments

Comments

@ahmedsaptan
Copy link

I try to minimize file with 0.1 but it output the same file with 0.2 to 0.06

@neurolabusc
Copy link
Owner

Unable to replicate. Can you provide an example? Does your mesh have enough complexity to support the desired reduction granularity? The example below provides a complete demonstration of successful compression to both 0.2 and 0.06 ratios using the included bunny.obj image:

$git clone https://github.com/neurolabusc/Fast-Quadric-Mesh-Simplification-Pascal-.git
$cd Fast-Quadric-Mesh-Simplification-Pascal-/c_code/
$g++ Main.cpp -O3 -o simplify
$./simplify ../bunny.obj bunny02 0.2
Mesh Simplification (C)2014 by Sven Forstmann in 2014, MIT License (64-bit)
Input: 34834 vertices, 69664 triangles (target 13933)
iteration 0 - triangles 69664 threshold 2.187e-06
Output: 6967 vertices, 13930 triangles (0.199960 reduction; 0.0779 sec)
$./simplify ../bunny.obj bunny006  0.06
Mesh Simplification (C)2014 by Sven Forstmann in 2014, MIT License (64-bit)
Input: 34834 vertices, 69664 triangles (target 4180)
iteration 0 - triangles 69664 threshold 2.187e-06
iteration 5 - triangles 7572 threshold 0.00209715
Output: 2091 vertices, 4178 triangles (0.059974 reduction; 0.1101 sec)

@neurolabusc
Copy link
Owner

Here is an example using the Pascal code showing similar performance:

$git clone https://github.com/neurolabusc/Fast-Quadric-Mesh-Simplification-Pascal-.git
$cd Fast-Quadric-Mesh-Simplification-Pascal-
$fpc simplify
$./simplify bunny.obj bunny02 0.2
Mesh Simplification (C)2014 by Sven Forstmann, MIT License 64-bit
 simplify bunny.obj with ratio = 0.20, agressiveness = 3.00 and tol = 0.00000
 Input: 34834 vertices, 69664 triangles
 Output: 6968 vertices, 13932 triangles (0.200, 0.21sec)
  Creating file bunny02
$./simplify bunny.obj bunny006  0.06
Mesh Simplification (C)2014 by Sven Forstmann, MIT License 64-bit
 simplify bunny.obj with ratio = 0.06, agressiveness = 3.00 and tol = 0.00000
 Input: 34834 vertices, 69664 triangles
 Output: 2092 vertices, 4180 triangles (0.060, 0.21sec)
  Creating file bunny006

@ahmedsaptan
Copy link
Author

./simplify '/home/moman/test of ismile/Upper/P-003 Upper jaw - 13 - Model.obj' obj02 0.2
Mesh Simplification (C)2014 by Sven Forstmann in 2014, MIT License (64-bit)
Input: 613116 vertices, 1226220 triangles (target 245244)
iteration 0 - triangles 1226220 threshold 2.187e-06
iteration 5 - triangles 816590 threshold 0.00209715
iteration 10 - triangles 773134 threshold 0.0627485
iteration 15 - triangles 765398 threshold 0.61222
iteration 20 - triangles 762754 threshold 3.40483
iteration 25 - triangles 761252 threshold 13.4929
iteration 30 - triangles 760368 threshold 42.6184
iteration 35 - triangles 759778 threshold 114.416
iteration 40 - triangles 759426 threshold 271.819
iteration 45 - triangles 759216 threshold 587.068
iteration 50 - triangles 759042 threshold 1174.71
iteration 55 - triangles 758846 threshold 2207.98
iteration 60 - triangles 758648 threshold 3938.98
iteration 65 - triangles 758542 threshold 6722.99
iteration 70 - triangles 758470 threshold 11047.4
iteration 75 - triangles 758404 threshold 17565.6
iteration 80 - triangles 758352 threshold 27136.1
iteration 85 - triangles 758308 threshold 40867.6
iteration 90 - triangles 758276 threshold 60170.1
iteration 95 - triangles 758276 threshold 86812.6
Output: 378667 vertices, 757316 triangles (0.617602 reduction; 95.8634 sec)

@ahmedsaptan
Copy link
Author

./simplify '/home/moman/test of ismile/Upper/P-003 Upper jaw - 13 - Model.obj' obj0.06 0.06
Mesh Simplification (C)2014 by Sven Forstmann in 2014, MIT License (64-bit)
Input: 613116 vertices, 1226220 triangles (target 73573)
iteration 0 - triangles 1226220 threshold 2.187e-06
iteration 5 - triangles 816590 threshold 0.00209715
iteration 10 - triangles 773134 threshold 0.0627485
iteration 15 - triangles 765398 threshold 0.61222
iteration 20 - triangles 762754 threshold 3.40483
iteration 25 - triangles 761252 threshold 13.4929
iteration 30 - triangles 760368 threshold 42.6184
iteration 35 - triangles 759778 threshold 114.416
iteration 40 - triangles 759426 threshold 271.819
iteration 45 - triangles 759216 threshold 587.068
iteration 50 - triangles 759042 threshold 1174.71
iteration 55 - triangles 758846 threshold 2207.98
iteration 60 - triangles 758648 threshold 3938.98
iteration 65 - triangles 758542 threshold 6722.99
iteration 70 - triangles 758470 threshold 11047.4
iteration 75 - triangles 758404 threshold 17565.6
iteration 80 - triangles 758352 threshold 27136.1
iteration 85 - triangles 758308 threshold 40867.6
iteration 90 - triangles 758276 threshold 60170.1
iteration 95 - triangles 758276 threshold 86812.6
Output: 378667 vertices, 757316 triangles (0.617602 reduction; 94.3381 sec)

@neurolabusc
Copy link
Owner

I suspect that your mesh is not a manifold surface but has lots of holes/gaps/tears in it. This will make simplification difficult and high resolution images will illustrate these errrors in the original mesh:
tear

What tool created the upper jaw model? If you created this from a voxelwise imaging dataset, make sure to use a marching cubes method that does not create a lot of tiny gaps. For example Surfice has the Advanced/ConvertVoxelwiseVolumeToMesh menu item. The MeshLab CleaningAndRepairing/MergeCloseSurfaces might help. My biggest fear is if the software that created this did a poor job merging vertices it may also have done a poor job of ensuring consistent face normals.

In general, good simplification requires a well designed input image. So I fear you really want to go back to your mesh creation and make sure you are using a good algorithm. Here is an elegant implementation - just make sure to include a tiny tolerance for vertex location to handle rounding errrors.

As a Hail Mary, you could try compiling the Pascal version of this repository and set the tolerance to a value greater than 0.0.:

Mesh Simplification (C)2014 by Sven Forstmann, MIT License 64-bit
Usage: ./simplify <input> <output> <ratio> <agressiveness> <tolerance>
 Input: name of existing MZ3 or OBJ format mesh
 Output: name for decimated MZ3 or OBJ format mesh
 Ratio: (default = 0.2) for example 0.1 will decimate 90% of triangles
         A ratio of 1 is "lossless" (though beware of pole artifacts) 
         A ratio of 2 only removes repeated vertices
         A ratio of 3 only removes of replicated vertices and faces (slow)
         A ratio of 4 makes no change (file conversion only)
 Agressiveness: (default = 3.0) faster (9) or better decimation (1)
 Tolerance: (default = 0.0) vertices closer to each other than this distance will be merged

So the call might be:

./simplify '/home/moman/test of ismile/Upper/P-003 Upper jaw - 13 - Model.obj' obj0.06 0.06 3 0.01

If you like the result, you could port the Pascal code to C for the vertex merging (also referred to as vertex welding).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants