Normand Briere
2019-06-11 5e6a6f3319f0c4c687fe71952ac9ecc17792b83a
BoundaryRep.java
....@@ -161,6 +161,7 @@
161161 || FaceCount() != other.FaceCount()
162162 || !(indices == null ^ other.indices != null)) // july 2014
163163 {
164
+ // The meshes have different structures.
164165 //new Exception().printStackTrace();
165166 trimmed = other.trimmed;
166167 stripified = other.stripified;
....@@ -172,16 +173,16 @@
172173 bufV = other.bufV;
173174 bufF = other.bufF;
174175
175
- positions = (float[]) GrafreeD.clone(other.positions);
176
- normals = (float[]) GrafreeD.clone(other.normals);
177
- colors = (float[]) GrafreeD.clone(other.colors);
178
- uvmap = (float[]) GrafreeD.clone(other.uvmap);
179
- triangles = (int[]) GrafreeD.clone(other.triangles);
176
+ positions = (float[]) Grafreed.clone(other.positions);
177
+ normals = (float[]) Grafreed.clone(other.normals);
178
+ colors = (float[]) Grafreed.clone(other.colors);
179
+ uvmap = (float[]) Grafreed.clone(other.uvmap);
180
+ triangles = (int[]) Grafreed.clone(other.triangles);
180181
181
- indices = (int[]) GrafreeD.clone(other.indices);
182
+ indices = (int[]) Grafreed.clone(other.indices);
182183
183
- vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GrafreeD.clone(other.faces);
184
+ vertices = (Vector<Vertex>) Grafreed.clone(other.vertices);
185
+ faces = (Vector<Face>) Grafreed.clone(other.faces);
185186 }
186187 else
187188 {
....@@ -239,9 +240,16 @@
239240 }
240241 }
241242
242
- Support[] InitConnections(BoundaryRep other)
243
+ transient Support[] cachesupports = null;
244
+
245
+ Support[] InitConnections()
243246 {
244
- int n = other.startvertices.length-1;
247
+ if (cachesupports != null)
248
+ {
249
+ return cachesupports;
250
+ }
251
+
252
+ int n = this.startvertices.length-1;
245253
246254 Support[] supports = new Support[n];
247255
....@@ -253,38 +261,60 @@
253261
254262 for (int object=1; object<=n; object++)
255263 {
256
- int start = other.startvertices[object-1];
257
- int end = other.startvertices[object];
264
+ int start = this.startvertices[object-1];
265
+ int end = this.startvertices[object];
258266
259267 if (start == end)
260268 continue; // ??
261269
270
+ /**
271
+ Vertex v2 = vertextemp;
272
+ v2.x = averagepoints[object*3];
273
+ v2.y = averagepoints[object*3+1];
274
+ v2.z = averagepoints[object*3+2];
275
+
276
+ //v2.set(GetVertex(this.startvertices[subsupport]));
277
+
278
+ // projected point
279
+ Vertex v3 = vertextemp2;
280
+ //GetVertex(this.startvertices[subsupport]);
281
+ v3.x = extremepoints[object*3];
282
+ v3.y = extremepoints[object*3+1];
283
+ v3.z = extremepoints[object*3+2];
284
+
285
+ vect3.set(v3); // "X" axis apex
286
+ vect3.sub(v2); // origin (center)
287
+ vect3.normalize();
288
+ /**/
289
+
262290 int linkcount = 0;
263291
264292 int objectinlist = -1;
293
+
294
+ Support subsupport = supports[object-1];
265295
266296 for (int object2=1; object2<=n; object2++)
267297 {
268298 for (int i = start; i < end; i++)
269299 {
270
- Vertex v = other.GetVertex(i);
300
+ Vertex v = this.GetVertex(i);
271301
272
- //
273
- if (other.Contains(v, object2))
302
+ // Check if v is close enough from any vertex of the given subobject.
303
+ if (this.Contains(v, object2))
274304 {
275
- if (linkcount == supports[object-1].links.length)
305
+ if (linkcount == subsupport.links.length)
276306 break;
277307
278308 if (object2 == object)
279309 objectinlist = linkcount;
280310
281
- supports[object-1].links[linkcount++] = object2;
311
+ subsupport.links[linkcount++] = object2;
282312 break;
283313 }
284314 }
285315 }
286316
287
- supports[object-1].links[linkcount] = -1;
317
+ subsupport.links[linkcount] = -1;
288318
289319 if (objectinlist == -1)
290320 assert(objectinlist != -1);
....@@ -293,9 +323,9 @@
293323 // assert(linkcount > 1);
294324
295325 // show main support as blue
296
- int first = supports[object-1].links[0];
297
- supports[object-1].links[0] = supports[object-1].links[objectinlist];
298
- supports[object-1].links[objectinlist] = first;
326
+ int first = subsupport.links[0];
327
+ subsupport.links[0] = subsupport.links[objectinlist];
328
+ subsupport.links[objectinlist] = first;
299329 }
300330
301331 for (int loop = 0; --loop>=0;)
....@@ -353,7 +383,7 @@
353383 supports = supports2;
354384 }
355385
356
- return supports;
386
+ return cachesupports = supports;
357387 }
358388
359389 double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k)
....@@ -500,7 +530,7 @@
500530 static Vertex vertextemp = new Vertex(true);
501531 static Vertex vertextemp2 = new Vertex(true);
502532
503
- static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07;
533
+ static double SEUIL = 0.05f; // 0.1 for rag doll; 0.07;
504534
505535 // Compute weight of point w/r to this
506536 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -598,7 +628,7 @@
598628 // ;
599629 //
600630
601
- supportsize = supportsizes[subsupport];
631
+ supportsize = supportminsize[subsupport];
602632
603633 double K = supportsize / distmax;
604634
....@@ -650,7 +680,8 @@
650680 // if (supportsize * fadefactor > 1)
651681 // return 1;
652682
653
- return supportsize * fadefactor;
683
+ return //supportsize *
684
+ supportsize * fadefactor;
654685 }
655686
656687 void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v)
....@@ -952,7 +983,7 @@
952983
953984 // sept 2017 SEUIL = 0.1; // aout 2013
954985
955
- supports = InitConnections(other);
986
+ supports = other.InitConnections();
956987
957988 other.supports = supports; // should be the other way around...
958989
....@@ -1518,7 +1549,7 @@
15181549 InitFaceIndices();
15191550 }
15201551
1521
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1552
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15221553 //float[] v = new float[100];
15231554
15241555 for (int loops=1; --loops>=0;)
....@@ -1548,7 +1579,7 @@
15481579 InitFaceIndices();
15491580 }
15501581
1551
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1582
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15521583 //float[] v = new float[100];
15531584
15541585 for (int loops=10; --loops>=0;)
....@@ -1895,7 +1926,7 @@
18951926 return;
18961927 }
18971928
1898
- // System.exit(0);
1929
+ // System.exit(0);
18991930
19001931 cVector vect = new cVector();
19011932 cVector normal = new cVector();
....@@ -1966,7 +1997,7 @@
19661997 if (v.vertexlinks == null)
19671998 continue;
19681999
1969
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2000
+ if (v.weights != null && v.weights[j] < 0.001 * v.totalweight) // == 0)
19702001 {
19712002 //testweight += v.weights[j-1];
19722003 continue;
....@@ -2247,6 +2278,8 @@
22472278
22482279 transient int lastsoundtime;
22492280
2281
+ transient boolean once = false;
2282
+
22502283 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512284 {
22522285 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2335,11 @@
23022335
23032336 if (v.totalweight == 0)
23042337 {
2305
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2338
+ if (!once)
2339
+ {
2340
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2341
+ once = true;
2342
+ }
23062343 continue;
23072344 }
23082345
....@@ -2670,7 +2707,7 @@
26702707
26712708 if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722709 {
2673
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2710
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742711
26752712 lastsoundtime = Globals.framecount;
26762713 }
....@@ -3098,6 +3135,7 @@
30983135 //
30993136 // transient VertexCompare[] vertexcompare = null;
31003137
3138
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013139 boolean Contains(Vertex v0, int object)
31023140 {
31033141 int start = startvertices[object-1];
....@@ -3155,7 +3193,27 @@
31553193 */
31563194 }
31573195
3158
- void GenUV()
3196
+ void UnfoldUV()
3197
+ {
3198
+ for (int i = 0; i < VertexCount(); i++)
3199
+ {
3200
+ Vertex v = GetVertex(i);
3201
+
3202
+ v.x = v.s;
3203
+ v.y = v.t;
3204
+ v.z = 0;
3205
+
3206
+ v.norm.x = 0;
3207
+ v.norm.y = 0;
3208
+ v.norm.z = 1;
3209
+
3210
+ SetVertex(v, i);
3211
+ }
3212
+ }
3213
+
3214
+ float power = 2;
3215
+
3216
+ void GenUV() // float power)
31593217 {
31603218 Trim();
31613219
....@@ -3219,6 +3277,125 @@
32193277 y -= 0.5;
32203278 z -= 0.5;
32213279
3280
+ double ax = Math.abs(x);
3281
+ double ay = Math.abs(y);
3282
+ double max = ax;
3283
+ if (max < ay)
3284
+ {
3285
+ max = ay;
3286
+ }
3287
+
3288
+ if (max == 0)
3289
+ {
3290
+ uvmap[i2] = 0.5f;
3291
+ uvmap[i2+1] = 0.5f;
3292
+ continue;
3293
+ }
3294
+
3295
+ x /= max;
3296
+ y /= max;
3297
+
3298
+ double angle = Math.acos(Math.abs(z*2));
3299
+
3300
+ double k = angle / Math.PI * 2;
3301
+
3302
+ assert(k >= 0);
3303
+
3304
+ // k == 0 => uv = 0 (center)
3305
+ // k == 1 => uv = -1,1 (border)
3306
+
3307
+ if (i == 0)
3308
+ System.out.println("power = " + power);
3309
+
3310
+ double length1 = (ax+ay)/max;
3311
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3312
+
3313
+ double t = k;
3314
+
3315
+ t = Math.pow(t, 3);
3316
+
3317
+ // Interpolate between k/length2 (center) and k (border)
3318
+ if (length2 > 0)
3319
+ k *= (1 - t) / length2 + t;
3320
+
3321
+ double u = k*x;
3322
+ double v = k*y;
3323
+
3324
+ u /= 2;
3325
+ v /= 2;
3326
+ u += 0.5;
3327
+ v += 0.5;
3328
+
3329
+ uvmap[i2] = (float) u;
3330
+ uvmap[i2+1] = (float) v;
3331
+ }
3332
+ }
3333
+
3334
+ void GenUVold(float power)
3335
+ {
3336
+ Trim();
3337
+
3338
+ cVector boxcenter = null;
3339
+ cVector minima, maxima;
3340
+ minima = new cVector();
3341
+ maxima = new cVector();
3342
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3343
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3344
+ for (int i = 0; i < VertexCount(); i++)
3345
+ {
3346
+ Vertex v = GetVertex(i);
3347
+
3348
+ if (minima.x > v.x)
3349
+ {
3350
+ minima.x = v.x;
3351
+ }
3352
+ if (minima.y > v.y)
3353
+ {
3354
+ minima.y = v.y;
3355
+ }
3356
+ if (minima.z > v.z)
3357
+ {
3358
+ minima.z = v.z;
3359
+ }
3360
+
3361
+ if (maxima.x < v.x)
3362
+ {
3363
+ maxima.x = v.x;
3364
+ }
3365
+ if (maxima.y < v.y)
3366
+ {
3367
+ maxima.y = v.y;
3368
+ }
3369
+ if (maxima.z < v.z)
3370
+ {
3371
+ maxima.z = v.z;
3372
+ }
3373
+ }
3374
+
3375
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3376
+ int i2 = 0, i3 = 0;
3377
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3378
+ {
3379
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3380
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3381
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3382
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3383
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3384
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3385
+ // box UV
3386
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3387
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3388
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3389
+
3390
+ // [-1/2, 1/2]
3391
+ x /= maxima.x - minima.x;
3392
+ y /= maxima.y - minima.y;
3393
+ z /= maxima.z - minima.z;
3394
+
3395
+ x -= 0.5;
3396
+ y -= 0.5;
3397
+ z -= 0.5;
3398
+
32223399 // x *= 2;
32233400 // y *= 2;
32243401 // z *= 2;
....@@ -3245,6 +3422,15 @@
32453422
32463423 z = Math.cos(angle/2);
32473424
3425
+ assert(z >= 0);
3426
+ assert(z <= 1);
3427
+
3428
+ /**/
3429
+ //z = Math.pow(z, power); //1.08f);
3430
+
3431
+ if (i == 0)
3432
+ System.out.println("power = " + power);
3433
+
32483434 // sqrt(k2*x2 + k2*z2 + y2) = length
32493435 // k2*x2 + k2*z2 = length2 - y2
32503436 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3255,7 +3441,7 @@
32553441 k /= x*x + y*y;
32563442 }
32573443 else
3258
- GrafreeD.Assert(z == 1);
3444
+ Grafreed.Assert(z == 1);
32593445
32603446 if (k < 0)
32613447 k = 0;
....@@ -3264,6 +3450,7 @@
32643450
32653451 x *= k;
32663452 y *= k;
3453
+ /**/
32673454
32683455 double max = Math.abs(x);
32693456 if (max < Math.abs(y))
....@@ -3276,10 +3463,15 @@
32763463 }
32773464
32783465 // max = Math.sqrt(max*2)/2;
3466
+// double x2 = Math.pow(Math.abs(x), 1/power);
3467
+// double y2 = Math.pow(Math.abs(y), 1/power);
3468
+// double z2 = Math.pow(Math.abs(z), 1/power);
3469
+// max = Math.pow(x2 + y2 + z2, power);
32793470
32803471 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3472
+ //assert(max > 0);
3473
+ assert(max >= 0);
3474
+
32833475 x /= max;
32843476 y /= max;
32853477 z /= max;
....@@ -3542,6 +3734,111 @@
35423734 */
35433735 }
35443736
3737
+ void GenerateNormals2(boolean crease)
3738
+ {
3739
+ cVector tempVector = new cVector();
3740
+
3741
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3742
+//
3743
+//
3744
+// for (int i=0; i<this.VertexCount(); i++)
3745
+// {
3746
+// Vertex v = this.GetVertex(i);
3747
+//
3748
+// tempVector.set(v);
3749
+//
3750
+// cVector n = tableBase.get(tempVector.ToFloat());
3751
+//
3752
+// if (n != null)
3753
+// {
3754
+// continue;
3755
+// }
3756
+//
3757
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3758
+// }
3759
+
3760
+ BoundaryRep tempSupport = this.support;
3761
+
3762
+ this.support = null;
3763
+
3764
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3765
+
3766
+ this.support = tempSupport;
3767
+
3768
+ //tempRep.Unstripify();
3769
+
3770
+ tempRep.GenerateNormals2(crease);
3771
+
3772
+ boolean keepnormal = Vertex.normalmode;
3773
+ boolean epsequal = Grafreed.epsequal;
3774
+
3775
+ Vertex.normalmode = false;
3776
+ Grafreed.epsequal = false; // A bit strange
3777
+
3778
+ // No need to have a match for vertex counts.
3779
+
3780
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3781
+
3782
+ for (int i=0; i<tempRep.VertexCount(); i++)
3783
+ {
3784
+ Vertex v = tempRep.GetVertex(i);
3785
+
3786
+ cVector n = table.get(tempVector.ToFloat());
3787
+
3788
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3789
+ {
3790
+ //continue;
3791
+ }
3792
+
3793
+ tempVector.set(v);
3794
+
3795
+ //cVector nBase = tableBase.get(tempVector);
3796
+
3797
+ //if (v.norm.dot(nBase) < 0.9)
3798
+ //{
3799
+ // continue;
3800
+ //}
3801
+
3802
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3803
+ {
3804
+ //continue;
3805
+ }
3806
+
3807
+ if (n != null)
3808
+ {
3809
+// if (n.dot(v.norm) < 0)
3810
+// n.sub(v.norm);
3811
+// else
3812
+// n.add(v.norm);
3813
+//
3814
+// n.normalize();
3815
+ continue;
3816
+ }
3817
+
3818
+ table.put(new cVector(tempVector), new cVector(v.norm));
3819
+ }
3820
+
3821
+ for (int i=0; i<this.VertexCount(); i++)
3822
+ {
3823
+ Vertex v = this.GetVertex(i);
3824
+
3825
+ tempVector.set(v);
3826
+
3827
+ cVector n = table.get(tempVector.ToFloat());
3828
+
3829
+ //if (n.dot(v.norm) < 0)
3830
+ if (n == null)
3831
+ continue;
3832
+
3833
+ LA.vecCopy(n, v.norm);
3834
+
3835
+ this.SetVertex(v, i);
3836
+ }
3837
+
3838
+ Grafreed.epsequal = epsequal;
3839
+ Vertex.normalmode = keepnormal;
3840
+ }
3841
+
35453842 void GenerateNormals(boolean crease)
35463843 {
35473844 boolean wastrim = trimmed;
....@@ -3715,6 +4012,9 @@
37154012 {
37164013 triangles[i] = i;
37174014 }
4015
+
4016
+ Untrim();
4017
+ MergeNormals();
37184018 }
37194019 }
37204020
....@@ -3748,6 +4048,11 @@
37484048 tsa.getNormals(0, normals);
37494049 tsa.getTextureCoordinates(0, 0, uvmap);
37504050 // tsa.getColors(0, colors);
4051
+
4052
+ for (int i=colors.length; --i>=0;)
4053
+ {
4054
+ colors[i] = 1;
4055
+ }
37514056
37524057 int stripcount = tsa.getNumStrips();
37534058 triangles = new int[stripcount];
....@@ -3770,6 +4075,9 @@
37704075 triangles = new int[1];
37714076 triangles[0] = 3;
37724077 }
4078
+
4079
+ Untrim();
4080
+ MergeNormals();
37734081 }
37744082
37754083 /*
....@@ -3819,6 +4127,40 @@
38194127 }
38204128
38214129 Vertex.normalmode = false;
4130
+ }
4131
+
4132
+ void MergeNormals()
4133
+ {
4134
+ boolean smooth = Grafreed.smoothmode;
4135
+ boolean link = Grafreed.linkUV;
4136
+ Grafreed.smoothmode = true;
4137
+ Grafreed.linkUV = true;
4138
+
4139
+ System.out.println("#Vertex = " + VertexCount());
4140
+ System.out.println("#Face = " + FaceCount());
4141
+
4142
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4143
+
4144
+ for (int i = 0; i < VertexCount(); i++)
4145
+ {
4146
+ Vertex v = GetVertex(i);
4147
+
4148
+ if (!table.contains(v))
4149
+ {
4150
+ table.add(v);
4151
+ }
4152
+ }
4153
+
4154
+ Grafreed.smoothmode = smooth;
4155
+ Grafreed.linkUV = link;
4156
+
4157
+// for (int i = 0; i < VertexCount(); i++)
4158
+// {
4159
+// Vertex v = GetVertex(i);
4160
+//
4161
+// table.add(v);
4162
+// }
4163
+
38224164 }
38234165
38244166 static cVector temp1 = new cVector();
....@@ -4593,7 +4935,7 @@
45934935 {
45944936 i3 = positions.length-3;
45954937 i2 = uvmap.length - 2;
4596
- new Exception().printStackTrace();
4938
+ //new Exception().printStackTrace();
45974939 }
45984940
45994941 v./*pos.*/x = positions[i3];
....@@ -5317,17 +5659,27 @@
53175659
53185660 transient int nbbadfaces; // ?? = 1000000;
53195661
5320
- int ChooseTriangle()
5662
+ /*
5663
+ */
5664
+ int ChooseTriangle(boolean firstEquilateral)
53215665 {
53225666 int chosen = -1;
53235667
53245668 double minweight = 1E10;
53255669
5670
+ int step = 8; // ?
5671
+
5672
+ if (firstEquilateral)
5673
+ step = 1;
5674
+
53265675 nbbadfaces = 0;
5327
- for (int i=0; i<faces.size(); i+=8)
5676
+ for (int i=0; i<faces.size(); i+=step)
53285677 // for (int i=faces.size(); (i-=8)>=0;)
53295678 {
53305679 Face face = (Face) faces.get(i);
5680
+
5681
+ if (face.used)
5682
+ continue;
53315683
53325684 if (!Valid(face))
53335685 {
....@@ -5337,6 +5689,15 @@
53375689
53385690 if (Boundary(face))
53395691 continue;
5692
+
5693
+// if (Boundary(face.p))
5694
+// continue;
5695
+//
5696
+// if (Boundary(face.q))
5697
+// continue;
5698
+//
5699
+// if (Boundary(face.r))
5700
+// continue;
53405701
53415702 if (!ValidValence(face))
53425703 continue;
....@@ -5349,22 +5710,55 @@
53495710 //?? if (face.weight < 0)
53505711 // continue;
53515712
5352
- double K = 1; // 0.01; // .25;
5353
-
5354
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5355
-
5356
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5357
-
5358
- if (minweight > weight)
5713
+ if (firstEquilateral)
53595714 {
5360
- minweight = weight;
5715
+ if (OneFaceUsed(links.get(face.p)))
5716
+ continue;
5717
+
5718
+ if (OneFaceUsed(links.get(face.q)))
5719
+ continue;
5720
+
5721
+ if (OneFaceUsed(links.get(face.r)))
5722
+ continue;
5723
+
53615724 chosen = i;
5362
- if (minweight == 0)
5363
- break;
5725
+ break;
5726
+ }
5727
+ else
5728
+ {
5729
+ double K = 1; // 0.01; // .25;
5730
+
5731
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5732
+
5733
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5734
+
5735
+ if (minweight > weight)
5736
+ {
5737
+ minweight = weight;
5738
+ chosen = i;
5739
+ if (minweight == 0)
5740
+ break;
5741
+ }
53645742 }
53655743 }
53665744
53675745 return chosen;
5746
+ }
5747
+
5748
+ private boolean OneFaceUsed(Vector<Face> faces)
5749
+ {
5750
+ if (faces.size() != 6)
5751
+ return true;
5752
+
5753
+ for (int i=0; i<6; i+=1)
5754
+ {
5755
+ if (faces.get(i).used)
5756
+ {
5757
+ return true;
5758
+ }
5759
+ }
5760
+
5761
+ return false;
53685762 }
53695763
53705764 static boolean remove3valence = true;
....@@ -5400,7 +5794,7 @@
54005794 }
54015795 else
54025796 {
5403
- assert(links.size() == vertices.size());
5797
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54045798
54055799 links.setSize(vertices.size());
54065800 for (int i=vertices.size(); --i>=0;)
....@@ -5408,6 +5802,7 @@
54085802 // linkstouched[i] = false;
54095803 if (links.get(i) == null) // ??
54105804 {
5805
+ new Exception().printStackTrace();
54115806 links.set(i, new Vector(8));
54125807 // linkstouched[i] = true;
54135808 }
....@@ -5418,6 +5813,8 @@
54185813 }
54195814 }
54205815
5816
+ boolean once = false;
5817
+
54215818 for (int i=faces.size(); --i>=0;)
54225819 {
54235820 Face face = (Face) faces.get(i);
....@@ -5429,6 +5826,9 @@
54295826 //if (linkstouched[face.r])
54305827 links.get(face.r).add(face);
54315828
5829
+ if (face.used)
5830
+ once = true;
5831
+
54325832 face.good = 1;
54335833 face.boundary = -1;
54345834 }
....@@ -6200,6 +6600,7 @@
62006600
62016601 void InitWeights()
62026602 {
6603
+ new Exception().printStackTrace();
62036604 System.exit(0);
62046605 int n = 0;
62056606 int b = 0;
....@@ -6793,6 +7194,10 @@
67937194 return (face.boundary = 1) == 1;
67947195 }
67957196
7197
+ // June 2019
7198
+ if (true)
7199
+ return (face.boundary = 0) == 1;
7200
+
67967201 // reverse triangle test
67977202 q1.set(p);
67987203 q2.set(q);
....@@ -7242,7 +7647,7 @@
72427647 //InitWeights();
72437648 }
72447649
7245
- int chosen = ChooseTriangle(); // Best is slow and not really better
7650
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
72467651
72477652 if (chosen == -1)
72487653 {
....@@ -7256,7 +7661,7 @@
72567661 //remove3valence = false;
72577662 // InitWeights();
72587663
7259
- chosen = ChooseTriangle();
7664
+ chosen = ChooseTriangle(true);
72607665 }
72617666 }
72627667
....@@ -7532,7 +7937,7 @@
75327937
75337938 // boolean lock;
75347939
7535
- void SplitInTwo(boolean reduction34, boolean onlyone)
7940
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
75367941 {
75377942 if (stripified)
75387943 {
....@@ -7569,12 +7974,12 @@
75697974 {
75707975 System.err.println("EXCEPTION CAUGHT");
75717976 e.printStackTrace();
7572
- return;
7977
+ return false;
75737978 } catch (Error e)
75747979 {
75757980 System.err.println("ERROR CAUGHT");
75767981 e.printStackTrace();
7577
- return;
7982
+ return false;
75787983 }
75797984
75807985 System.out.println("# faces = " + faces.size());
....@@ -7584,6 +7989,7 @@
75847989 {
75857990 Face face = (Face) faces.get(i);
75867991
7992
+ face.used = false;
75877993 face.nbiterations = 1;
75887994 face.weight = -1;
75897995 face.boundary = -1;
....@@ -7635,6 +8041,11 @@
76358041 nbbadfaces = faces.size();
76368042 //remove3valence = true;
76378043
8044
+ int count = 2;
8045
+
8046
+ if (onlyone)
8047
+ count = 1;
8048
+
76388049 firstpass = true;
76398050
76408051 int n = faces.size();
....@@ -7650,8 +8061,9 @@
76508061 System.out.print('.');
76518062 }
76528063 System.out.println();
8064
+ boolean atleastone = false;
76538065 int i = 0;
7654
- while (reduction34 || faces.size() > n/2)
8066
+ while (true) // reduction34 || faces.size() > n/2)
76558067 {
76568068 if (i++%100 == 0)
76578069 {
....@@ -7673,6 +8085,8 @@
76738085 {
76748086 if (!RemoveOneTriangle())
76758087 break;
8088
+
8089
+ atleastone = true;
76768090 }
76778091 // if (iterationcount == 0)
76788092 // break;
....@@ -7683,8 +8097,8 @@
76838097 break;
76848098 }
76858099 firstpass = false;
7686
- if (onlyone)
7687
- break; // one triangle only
8100
+// if (--count<0 && !reduction34)
8101
+// break; // one triangle only
76888102 }
76898103
76908104 InitLinks(false); // for further display
....@@ -7700,6 +8114,8 @@
77008114 Trim(true,false,false,false,false);
77018115
77028116 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8117
+
8118
+ return atleastone;
77038119 }
77048120
77058121 void UpdateIndices(Face face, Face minface)
....@@ -7712,18 +8128,21 @@
77128128 face.p = minface.p;
77138129 //if (leafweights)
77148130 face.good = 0; // false;
8131
+ face.used = true;
77158132 }
77168133 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77178134 {
77188135 face.q = minface.p;
77198136 //if (leafweights)
77208137 face.good = 0; // false;
8138
+ face.used = true;
77218139 }
77228140 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77238141 {
77248142 face.r = minface.p;
77258143 //if (leafweights)
77268144 face.good = 0; // false;
8145
+ face.used = true;
77278146 }
77288147
77298148 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7783,50 +8202,50 @@
77838202 if (v == 2)
77848203 vert = minface.r;
77858204 // Face face = (Face) faces.get(i);
7786
- Vector<Face> vertfaces = links.get(vert);
7787
- for (int i=vertfaces.size(); --i>=0;)
7788
- {
7789
- Face face = (Face) vertfaces.get(i);
7790
-
7791
- // if (face.weight == 10000)
7792
- // continue;
7793
-
7794
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7795
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7796
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8205
+ Vector<Face> vertfaces = links.get(vert);
8206
+ for (int i=vertfaces.size(); --i>=0;)
77978207 {
7798
- if (!leafweights)
8208
+ Face face = (Face) vertfaces.get(i);
8209
+
8210
+ // if (face.weight == 10000)
8211
+ // continue;
8212
+
8213
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8214
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8215
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
77998216 {
7800
-// if(minfaceweight <= 0)
7801
-// assert(minfaceweight > 0);
7802
-//
7803
-// //FaceWeight(face);
7804
-// if(face.weight < 0)
7805
-// assert(face.weight >= 0);
7806
-
7807
- face.weight += minfaceweight;
7808
-
7809
-// if (face.weight >= 10000)
7810
-// assert(face.weight < 10000);
8217
+ if (!leafweights)
8218
+ {
8219
+ // if(minfaceweight <= 0)
8220
+ // assert(minfaceweight > 0);
8221
+ //
8222
+ // //FaceWeight(face);
8223
+ // if(face.weight < 0)
8224
+ // assert(face.weight >= 0);
8225
+
8226
+ face.weight += minfaceweight;
8227
+
8228
+ // if (face.weight >= 10000)
8229
+ // assert(face.weight < 10000);
8230
+ }
8231
+ else
8232
+ face.weight = -1;
8233
+
8234
+ face.nbiterations += 1;
8235
+ face.boundary = -1;
8236
+
8237
+ Vertex p = (Vertex)vertices.get(face.p);
8238
+ Vertex q = (Vertex)vertices.get(face.q);
8239
+ Vertex r = (Vertex)vertices.get(face.r);
8240
+
8241
+ p.boundary = -1;
8242
+ q.boundary = -1;
8243
+ r.boundary = -1;
78118244 }
78128245 else
7813
- face.weight = -1;
7814
-
7815
- face.nbiterations += 1;
7816
- face.boundary = -1;
7817
-
7818
- Vertex p = (Vertex)vertices.get(face.p);
7819
- Vertex q = (Vertex)vertices.get(face.q);
7820
- Vertex r = (Vertex)vertices.get(face.r);
7821
-
7822
- p.boundary = -1;
7823
- q.boundary = -1;
7824
- r.boundary = -1;
8246
+ assert(false);
78258247 }
7826
- else
7827
- assert(false);
78288248 }
7829
- }
78308249
78318250 // TouchVertex(minface.p);
78328251 // TouchVertex(minface.q);
....@@ -8027,6 +8446,7 @@
80278446 for (int i=vertfaces.size(); --i>=0;)
80288447 {
80298448 Face face = (Face) vertfaces.get(i);
8449
+ face.used = true;
80308450 face.good = 0; // false;
80318451 if (leafweights)
80328452 face.weight = -1;
....@@ -8073,7 +8493,7 @@
80738493 if (!trimmed)
80748494 return;
80758495
8076
- GrafreeD.linkUV = false;
8496
+ Grafreed.linkUV = false;
80778497
80788498 try
80798499 {
....@@ -8305,7 +8725,8 @@
83058725 int[] startvertices;
83068726 float[] averagepoints;
83078727 float[] extremepoints;
8308
- float[] supportsizes; // distance of closest point
8728
+ float[] supportminsize; // distance of closest point
8729
+ float[] supportmaxsize; // distance of fartest point
83098730
83108731 transient Hashtable vertextable;
83118732 /*transient*/ private Vertex[] verticesCopy;