Normand Briere
2019-06-16 372b7fd481a476cd659713a4a01bf28bf6760cbe
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];
....@@ -3247,12 +3285,21 @@
32473285 max = ay;
32483286 }
32493287
3288
+ if (max == 0)
3289
+ {
3290
+ uvmap[i2] = 0.5f;
3291
+ uvmap[i2+1] = 0.5f;
3292
+ continue;
3293
+ }
3294
+
32503295 x /= max;
32513296 y /= max;
32523297
32533298 double angle = Math.acos(Math.abs(z*2));
32543299
32553300 double k = angle / Math.PI * 2;
3301
+
3302
+ assert(k >= 0);
32563303
32573304 // k == 0 => uv = 0 (center)
32583305 // k == 1 => uv = -1,1 (border)
....@@ -3268,7 +3315,8 @@
32683315 t = Math.pow(t, 3);
32693316
32703317 // Interpolate between k/length2 (center) and k (border)
3271
- k = k / length2 * (1 - t) + k * t;
3318
+ if (length2 > 0)
3319
+ k *= (1 - t) / length2 + t;
32723320
32733321 double u = k*x;
32743322 double v = k*y;
....@@ -3393,7 +3441,7 @@
33933441 k /= x*x + y*y;
33943442 }
33953443 else
3396
- GrafreeD.Assert(z == 1);
3444
+ Grafreed.Assert(z == 1);
33973445
33983446 if (k < 0)
33993447 k = 0;
....@@ -3686,6 +3734,111 @@
36863734 */
36873735 }
36883736
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
+
36893842 void GenerateNormals(boolean crease)
36903843 {
36913844 boolean wastrim = trimmed;
....@@ -3702,6 +3855,28 @@
37023855 }
37033856
37043857 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3858
+ }
3859
+
3860
+ void GenerateNormalsMesh()
3861
+ {
3862
+ if (stripified)
3863
+ {
3864
+ Unstripify();
3865
+ }
3866
+
3867
+ if (trimmed)
3868
+ {
3869
+ normals = null;
3870
+ }
3871
+ else
3872
+ {
3873
+ for (int i=VertexCount(); --i>=0;)
3874
+ {
3875
+ Vertex v = GetVertex(i);
3876
+
3877
+ v.norm = null;
3878
+ }
3879
+ }
37053880 }
37063881
37073882 void GenNormalsJME()
....@@ -3859,6 +4034,10 @@
38594034 {
38604035 triangles[i] = i;
38614036 }
4037
+
4038
+// Untrim();
4039
+ if (!trimmed)
4040
+ MergeNormals();
38624041 }
38634042 }
38644043
....@@ -3892,6 +4071,11 @@
38924071 tsa.getNormals(0, normals);
38934072 tsa.getTextureCoordinates(0, 0, uvmap);
38944073 // tsa.getColors(0, colors);
4074
+
4075
+ for (int i=colors.length; --i>=0;)
4076
+ {
4077
+ colors[i] = 1;
4078
+ }
38954079
38964080 int stripcount = tsa.getNumStrips();
38974081 triangles = new int[stripcount];
....@@ -3914,6 +4098,10 @@
39144098 triangles = new int[1];
39154099 triangles[0] = 3;
39164100 }
4101
+
4102
+ //Untrim();
4103
+ if (!trimmed)
4104
+ MergeNormals();
39174105 }
39184106
39194107 /*
....@@ -3963,6 +4151,40 @@
39634151 }
39644152
39654153 Vertex.normalmode = false;
4154
+ }
4155
+
4156
+ void MergeNormals()
4157
+ {
4158
+ boolean smooth = Grafreed.smoothmode;
4159
+ boolean link = Grafreed.linkUV;
4160
+ Grafreed.smoothmode = true;
4161
+ Grafreed.linkUV = true;
4162
+
4163
+ System.out.println("#Vertex = " + VertexCount());
4164
+ System.out.println("#Face = " + FaceCount());
4165
+
4166
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4167
+
4168
+ for (int i = 0; i < VertexCount(); i++)
4169
+ {
4170
+ Vertex v = GetVertex(i);
4171
+
4172
+ if (!table.contains(v))
4173
+ {
4174
+ table.add(v);
4175
+ }
4176
+ }
4177
+
4178
+ Grafreed.smoothmode = smooth;
4179
+ Grafreed.linkUV = link;
4180
+
4181
+// for (int i = 0; i < VertexCount(); i++)
4182
+// {
4183
+// Vertex v = GetVertex(i);
4184
+//
4185
+// table.add(v);
4186
+// }
4187
+
39664188 }
39674189
39684190 static cVector temp1 = new cVector();
....@@ -4737,16 +4959,25 @@
47374959 {
47384960 i3 = positions.length-3;
47394961 i2 = uvmap.length - 2;
4740
- new Exception().printStackTrace();
4962
+ //new Exception().printStackTrace();
47414963 }
47424964
47434965 v./*pos.*/x = positions[i3];
47444966 v./*pos.*/y = positions[i3 + 1];
47454967 v./*pos.*/z = positions[i3 + 2];
47464968
4747
- v.norm.x = normals[i3];
4748
- v.norm.y = normals[i3 + 1];
4749
- v.norm.z = normals[i3 + 2];
4969
+ if (normals == null)
4970
+ {
4971
+ v.norm.x = 0;
4972
+ v.norm.y = 0;
4973
+ v.norm.z = 0;
4974
+ }
4975
+ else
4976
+ {
4977
+ v.norm.x = normals[i3];
4978
+ v.norm.y = normals[i3 + 1];
4979
+ v.norm.z = normals[i3 + 2];
4980
+ }
47504981
47514982 v.s = uvmap[i2];
47524983 v.t = uvmap[i2 + 1];
....@@ -5461,17 +5692,27 @@
54615692
54625693 transient int nbbadfaces; // ?? = 1000000;
54635694
5464
- int ChooseTriangle()
5695
+ /*
5696
+ */
5697
+ int ChooseTriangle(boolean firstEquilateral)
54655698 {
54665699 int chosen = -1;
54675700
54685701 double minweight = 1E10;
54695702
5703
+ int step = 8; // ?
5704
+
5705
+ if (firstEquilateral)
5706
+ step = 1;
5707
+
54705708 nbbadfaces = 0;
5471
- for (int i=0; i<faces.size(); i+=8)
5709
+ for (int i=0; i<faces.size(); i+=step)
54725710 // for (int i=faces.size(); (i-=8)>=0;)
54735711 {
54745712 Face face = (Face) faces.get(i);
5713
+
5714
+ if (face.used)
5715
+ continue;
54755716
54765717 if (!Valid(face))
54775718 {
....@@ -5481,6 +5722,15 @@
54815722
54825723 if (Boundary(face))
54835724 continue;
5725
+
5726
+// if (Boundary(face.p))
5727
+// continue;
5728
+//
5729
+// if (Boundary(face.q))
5730
+// continue;
5731
+//
5732
+// if (Boundary(face.r))
5733
+// continue;
54845734
54855735 if (!ValidValence(face))
54865736 continue;
....@@ -5493,22 +5743,55 @@
54935743 //?? if (face.weight < 0)
54945744 // continue;
54955745
5496
- double K = 1; // 0.01; // .25;
5497
-
5498
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5499
-
5500
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5501
-
5502
- if (minweight > weight)
5746
+ if (firstEquilateral)
55035747 {
5504
- minweight = weight;
5748
+ if (OneFaceUsed(links.get(face.p)))
5749
+ continue;
5750
+
5751
+ if (OneFaceUsed(links.get(face.q)))
5752
+ continue;
5753
+
5754
+ if (OneFaceUsed(links.get(face.r)))
5755
+ continue;
5756
+
55055757 chosen = i;
5506
- if (minweight == 0)
5507
- break;
5758
+ break;
5759
+ }
5760
+ else
5761
+ {
5762
+ double K = 1; // 0.01; // .25;
5763
+
5764
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5765
+
5766
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5767
+
5768
+ if (minweight > weight)
5769
+ {
5770
+ minweight = weight;
5771
+ chosen = i;
5772
+ if (minweight == 0)
5773
+ break;
5774
+ }
55085775 }
55095776 }
55105777
55115778 return chosen;
5779
+ }
5780
+
5781
+ private boolean OneFaceUsed(Vector<Face> faces)
5782
+ {
5783
+ if (faces.size() != 6)
5784
+ return true;
5785
+
5786
+ for (int i=0; i<6; i+=1)
5787
+ {
5788
+ if (faces.get(i).used)
5789
+ {
5790
+ return true;
5791
+ }
5792
+ }
5793
+
5794
+ return false;
55125795 }
55135796
55145797 static boolean remove3valence = true;
....@@ -5544,7 +5827,7 @@
55445827 }
55455828 else
55465829 {
5547
- assert(links.size() == vertices.size());
5830
+ // TODO Grafreed.Assert(links.size() == vertices.size());
55485831
55495832 links.setSize(vertices.size());
55505833 for (int i=vertices.size(); --i>=0;)
....@@ -5552,6 +5835,7 @@
55525835 // linkstouched[i] = false;
55535836 if (links.get(i) == null) // ??
55545837 {
5838
+ new Exception().printStackTrace();
55555839 links.set(i, new Vector(8));
55565840 // linkstouched[i] = true;
55575841 }
....@@ -5562,6 +5846,8 @@
55625846 }
55635847 }
55645848
5849
+ boolean once = false;
5850
+
55655851 for (int i=faces.size(); --i>=0;)
55665852 {
55675853 Face face = (Face) faces.get(i);
....@@ -5573,6 +5859,9 @@
55735859 //if (linkstouched[face.r])
55745860 links.get(face.r).add(face);
55755861
5862
+ if (face.used)
5863
+ once = true;
5864
+
55765865 face.good = 1;
55775866 face.boundary = -1;
55785867 }
....@@ -6344,6 +6633,7 @@
63446633
63456634 void InitWeights()
63466635 {
6636
+ new Exception().printStackTrace();
63476637 System.exit(0);
63486638 int n = 0;
63496639 int b = 0;
....@@ -6937,6 +7227,10 @@
69377227 return (face.boundary = 1) == 1;
69387228 }
69397229
7230
+ // June 2019
7231
+ if (true)
7232
+ return (face.boundary = 0) == 1;
7233
+
69407234 // reverse triangle test
69417235 q1.set(p);
69427236 q2.set(q);
....@@ -7386,7 +7680,7 @@
73867680 //InitWeights();
73877681 }
73887682
7389
- int chosen = ChooseTriangle(); // Best is slow and not really better
7683
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73907684
73917685 if (chosen == -1)
73927686 {
....@@ -7400,7 +7694,7 @@
74007694 //remove3valence = false;
74017695 // InitWeights();
74027696
7403
- chosen = ChooseTriangle();
7697
+ chosen = ChooseTriangle(true);
74047698 }
74057699 }
74067700
....@@ -7676,7 +7970,7 @@
76767970
76777971 // boolean lock;
76787972
7679
- void SplitInTwo(boolean reduction34, boolean onlyone)
7973
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76807974 {
76817975 if (stripified)
76827976 {
....@@ -7713,12 +8007,12 @@
77138007 {
77148008 System.err.println("EXCEPTION CAUGHT");
77158009 e.printStackTrace();
7716
- return;
8010
+ return false;
77178011 } catch (Error e)
77188012 {
77198013 System.err.println("ERROR CAUGHT");
77208014 e.printStackTrace();
7721
- return;
8015
+ return false;
77228016 }
77238017
77248018 System.out.println("# faces = " + faces.size());
....@@ -7728,6 +8022,7 @@
77288022 {
77298023 Face face = (Face) faces.get(i);
77308024
8025
+ face.used = false;
77318026 face.nbiterations = 1;
77328027 face.weight = -1;
77338028 face.boundary = -1;
....@@ -7779,6 +8074,11 @@
77798074 nbbadfaces = faces.size();
77808075 //remove3valence = true;
77818076
8077
+ int count = 2;
8078
+
8079
+ if (onlyone)
8080
+ count = 1;
8081
+
77828082 firstpass = true;
77838083
77848084 int n = faces.size();
....@@ -7794,8 +8094,9 @@
77948094 System.out.print('.');
77958095 }
77968096 System.out.println();
8097
+ boolean atleastone = false;
77978098 int i = 0;
7798
- while (reduction34 || faces.size() > n/2)
8099
+ while (true) // reduction34 || faces.size() > n/2)
77998100 {
78008101 if (i++%100 == 0)
78018102 {
....@@ -7817,6 +8118,8 @@
78178118 {
78188119 if (!RemoveOneTriangle())
78198120 break;
8121
+
8122
+ atleastone = true;
78208123 }
78218124 // if (iterationcount == 0)
78228125 // break;
....@@ -7827,8 +8130,8 @@
78278130 break;
78288131 }
78298132 firstpass = false;
7830
- if (onlyone)
7831
- break; // one triangle only
8133
+// if (--count<0 && !reduction34)
8134
+// break; // one triangle only
78328135 }
78338136
78348137 InitLinks(false); // for further display
....@@ -7844,6 +8147,8 @@
78448147 Trim(true,false,false,false,false);
78458148
78468149 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8150
+
8151
+ return atleastone;
78478152 }
78488153
78498154 void UpdateIndices(Face face, Face minface)
....@@ -7856,18 +8161,21 @@
78568161 face.p = minface.p;
78578162 //if (leafweights)
78588163 face.good = 0; // false;
8164
+ face.used = true;
78598165 }
78608166 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
78618167 {
78628168 face.q = minface.p;
78638169 //if (leafweights)
78648170 face.good = 0; // false;
8171
+ face.used = true;
78658172 }
78668173 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
78678174 {
78688175 face.r = minface.p;
78698176 //if (leafweights)
78708177 face.good = 0; // false;
8178
+ face.used = true;
78718179 }
78728180
78738181 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7927,50 +8235,50 @@
79278235 if (v == 2)
79288236 vert = minface.r;
79298237 // Face face = (Face) faces.get(i);
7930
- Vector<Face> vertfaces = links.get(vert);
7931
- for (int i=vertfaces.size(); --i>=0;)
7932
- {
7933
- Face face = (Face) vertfaces.get(i);
7934
-
7935
- // if (face.weight == 10000)
7936
- // continue;
7937
-
7938
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7939
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7940
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8238
+ Vector<Face> vertfaces = links.get(vert);
8239
+ for (int i=vertfaces.size(); --i>=0;)
79418240 {
7942
- if (!leafweights)
8241
+ Face face = (Face) vertfaces.get(i);
8242
+
8243
+ // if (face.weight == 10000)
8244
+ // continue;
8245
+
8246
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8247
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8248
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
79438249 {
7944
-// if(minfaceweight <= 0)
7945
-// assert(minfaceweight > 0);
7946
-//
7947
-// //FaceWeight(face);
7948
-// if(face.weight < 0)
7949
-// assert(face.weight >= 0);
7950
-
7951
- face.weight += minfaceweight;
7952
-
7953
-// if (face.weight >= 10000)
7954
-// assert(face.weight < 10000);
8250
+ if (!leafweights)
8251
+ {
8252
+ // if(minfaceweight <= 0)
8253
+ // assert(minfaceweight > 0);
8254
+ //
8255
+ // //FaceWeight(face);
8256
+ // if(face.weight < 0)
8257
+ // assert(face.weight >= 0);
8258
+
8259
+ face.weight += minfaceweight;
8260
+
8261
+ // if (face.weight >= 10000)
8262
+ // assert(face.weight < 10000);
8263
+ }
8264
+ else
8265
+ face.weight = -1;
8266
+
8267
+ face.nbiterations += 1;
8268
+ face.boundary = -1;
8269
+
8270
+ Vertex p = (Vertex)vertices.get(face.p);
8271
+ Vertex q = (Vertex)vertices.get(face.q);
8272
+ Vertex r = (Vertex)vertices.get(face.r);
8273
+
8274
+ p.boundary = -1;
8275
+ q.boundary = -1;
8276
+ r.boundary = -1;
79558277 }
79568278 else
7957
- face.weight = -1;
7958
-
7959
- face.nbiterations += 1;
7960
- face.boundary = -1;
7961
-
7962
- Vertex p = (Vertex)vertices.get(face.p);
7963
- Vertex q = (Vertex)vertices.get(face.q);
7964
- Vertex r = (Vertex)vertices.get(face.r);
7965
-
7966
- p.boundary = -1;
7967
- q.boundary = -1;
7968
- r.boundary = -1;
8279
+ assert(false);
79698280 }
7970
- else
7971
- assert(false);
79728281 }
7973
- }
79748282
79758283 // TouchVertex(minface.p);
79768284 // TouchVertex(minface.q);
....@@ -8171,6 +8479,7 @@
81718479 for (int i=vertfaces.size(); --i>=0;)
81728480 {
81738481 Face face = (Face) vertfaces.get(i);
8482
+ face.used = true;
81748483 face.good = 0; // false;
81758484 if (leafweights)
81768485 face.weight = -1;
....@@ -8217,7 +8526,7 @@
82178526 if (!trimmed)
82188527 return;
82198528
8220
- GrafreeD.linkUV = false;
8529
+ Grafreed.linkUV = false;
82218530
82228531 try
82238532 {
....@@ -8449,7 +8758,8 @@
84498758 int[] startvertices;
84508759 float[] averagepoints;
84518760 float[] extremepoints;
8452
- float[] supportsizes; // distance of closest point
8761
+ float[] supportminsize; // distance of closest point
8762
+ float[] supportmaxsize; // distance of fartest point
84538763
84548764 transient Hashtable vertextable;
84558765 /*transient*/ private Vertex[] verticesCopy;