Normand Briere
2019-07-24 ebd16116fc612bf14e2469ba27dd7ee54918eabb
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,8 @@
19661997 if (v.vertexlinks == null)
19671998 continue;
19681999
1969
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2000
+ // Warning: faster but dangerous
2001
+ if (v.weights != null && v.weights[j] == 0) // < 0.001 * v.totalweight)
19702002 {
19712003 //testweight += v.weights[j-1];
19722004 continue;
....@@ -2247,6 +2279,8 @@
22472279
22482280 transient int lastsoundtime;
22492281
2282
+ transient boolean once = false;
2283
+
22502284 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512285 {
22522286 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2336,11 @@
23022336
23032337 if (v.totalweight == 0)
23042338 {
2305
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2339
+ if (!once)
2340
+ {
2341
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2342
+ once = true;
2343
+ }
23062344 continue;
23072345 }
23082346
....@@ -2670,7 +2708,7 @@
26702708
26712709 if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722710 {
2673
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2711
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742712
26752713 lastsoundtime = Globals.framecount;
26762714 }
....@@ -3098,6 +3136,7 @@
30983136 //
30993137 // transient VertexCompare[] vertexcompare = null;
31003138
3139
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013140 boolean Contains(Vertex v0, int object)
31023141 {
31033142 int start = startvertices[object-1];
....@@ -3247,12 +3286,21 @@
32473286 max = ay;
32483287 }
32493288
3289
+ if (max == 0)
3290
+ {
3291
+ uvmap[i2] = 0.5f;
3292
+ uvmap[i2+1] = 0.5f;
3293
+ continue;
3294
+ }
3295
+
32503296 x /= max;
32513297 y /= max;
32523298
32533299 double angle = Math.acos(Math.abs(z*2));
32543300
32553301 double k = angle / Math.PI * 2;
3302
+
3303
+ assert(k >= 0);
32563304
32573305 // k == 0 => uv = 0 (center)
32583306 // k == 1 => uv = -1,1 (border)
....@@ -3268,7 +3316,8 @@
32683316 t = Math.pow(t, 3);
32693317
32703318 // Interpolate between k/length2 (center) and k (border)
3271
- k = k / length2 * (1 - t) + k * t;
3319
+ if (length2 > 0)
3320
+ k *= (1 - t) / length2 + t;
32723321
32733322 double u = k*x;
32743323 double v = k*y;
....@@ -3393,7 +3442,7 @@
33933442 k /= x*x + y*y;
33943443 }
33953444 else
3396
- GrafreeD.Assert(z == 1);
3445
+ Grafreed.Assert(z == 1);
33973446
33983447 if (k < 0)
33993448 k = 0;
....@@ -3686,6 +3735,111 @@
36863735 */
36873736 }
36883737
3738
+ void GenerateNormals2(boolean crease)
3739
+ {
3740
+ cVector tempVector = new cVector();
3741
+
3742
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3743
+//
3744
+//
3745
+// for (int i=0; i<this.VertexCount(); i++)
3746
+// {
3747
+// Vertex v = this.GetVertex(i);
3748
+//
3749
+// tempVector.set(v);
3750
+//
3751
+// cVector n = tableBase.get(tempVector.ToFloat());
3752
+//
3753
+// if (n != null)
3754
+// {
3755
+// continue;
3756
+// }
3757
+//
3758
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3759
+// }
3760
+
3761
+ BoundaryRep tempSupport = this.support;
3762
+
3763
+ this.support = null;
3764
+
3765
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3766
+
3767
+ this.support = tempSupport;
3768
+
3769
+ //tempRep.Unstripify();
3770
+
3771
+ tempRep.GenerateNormals2(crease);
3772
+
3773
+ boolean keepnormal = Vertex.normalmode;
3774
+ boolean epsequal = Grafreed.epsequal;
3775
+
3776
+ Vertex.normalmode = false;
3777
+ Grafreed.epsequal = false; // A bit strange
3778
+
3779
+ // No need to have a match for vertex counts.
3780
+
3781
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3782
+
3783
+ for (int i=0; i<tempRep.VertexCount(); i++)
3784
+ {
3785
+ Vertex v = tempRep.GetVertex(i);
3786
+
3787
+ cVector n = table.get(tempVector.ToFloat());
3788
+
3789
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3790
+ {
3791
+ //continue;
3792
+ }
3793
+
3794
+ tempVector.set(v);
3795
+
3796
+ //cVector nBase = tableBase.get(tempVector);
3797
+
3798
+ //if (v.norm.dot(nBase) < 0.9)
3799
+ //{
3800
+ // continue;
3801
+ //}
3802
+
3803
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3804
+ {
3805
+ //continue;
3806
+ }
3807
+
3808
+ if (n != null)
3809
+ {
3810
+// if (n.dot(v.norm) < 0)
3811
+// n.sub(v.norm);
3812
+// else
3813
+// n.add(v.norm);
3814
+//
3815
+// n.normalize();
3816
+ continue;
3817
+ }
3818
+
3819
+ table.put(new cVector(tempVector), new cVector(v.norm));
3820
+ }
3821
+
3822
+ for (int i=0; i<this.VertexCount(); i++)
3823
+ {
3824
+ Vertex v = this.GetVertex(i);
3825
+
3826
+ tempVector.set(v);
3827
+
3828
+ cVector n = table.get(tempVector.ToFloat());
3829
+
3830
+ //if (n.dot(v.norm) < 0)
3831
+ if (n == null)
3832
+ continue;
3833
+
3834
+ LA.vecCopy(n, v.norm);
3835
+
3836
+ this.SetVertex(v, i);
3837
+ }
3838
+
3839
+ Grafreed.epsequal = epsequal;
3840
+ Vertex.normalmode = keepnormal;
3841
+ }
3842
+
36893843 void GenerateNormals(boolean crease)
36903844 {
36913845 boolean wastrim = trimmed;
....@@ -3702,6 +3856,28 @@
37023856 }
37033857
37043858 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3859
+ }
3860
+
3861
+ void GenerateNormalsMesh()
3862
+ {
3863
+ if (stripified)
3864
+ {
3865
+ Unstripify();
3866
+ }
3867
+
3868
+ if (trimmed)
3869
+ {
3870
+ normals = null;
3871
+ }
3872
+ else
3873
+ {
3874
+ for (int i=VertexCount(); --i>=0;)
3875
+ {
3876
+ Vertex v = GetVertex(i);
3877
+
3878
+ v.norm = null;
3879
+ }
3880
+ }
37053881 }
37063882
37073883 void GenNormalsJME()
....@@ -3826,7 +4002,7 @@
38264002 NormalGenerator ng;
38274003
38284004 if (crease)
3829
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4005
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
38304006 else
38314007 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
38324008
....@@ -3859,6 +4035,10 @@
38594035 {
38604036 triangles[i] = i;
38614037 }
4038
+
4039
+// Untrim();
4040
+ if (!trimmed)
4041
+ MergeNormals();
38624042 }
38634043 }
38644044
....@@ -3892,6 +4072,11 @@
38924072 tsa.getNormals(0, normals);
38934073 tsa.getTextureCoordinates(0, 0, uvmap);
38944074 // tsa.getColors(0, colors);
4075
+
4076
+ for (int i=colors.length; --i>=0;)
4077
+ {
4078
+ colors[i] = 1;
4079
+ }
38954080
38964081 int stripcount = tsa.getNumStrips();
38974082 triangles = new int[stripcount];
....@@ -3914,6 +4099,10 @@
39144099 triangles = new int[1];
39154100 triangles[0] = 3;
39164101 }
4102
+
4103
+ //Untrim();
4104
+ if (!trimmed)
4105
+ MergeNormals();
39174106 }
39184107
39194108 /*
....@@ -3963,6 +4152,42 @@
39634152 }
39644153
39654154 Vertex.normalmode = false;
4155
+ }
4156
+
4157
+ void MergeNormals()
4158
+ {
4159
+ assert(!trimmed);
4160
+
4161
+ boolean smooth = Grafreed.smoothmode;
4162
+ boolean link = Grafreed.linkUV;
4163
+ Grafreed.smoothmode = true;
4164
+ Grafreed.linkUV = true;
4165
+
4166
+ System.out.println("#Vertex = " + VertexCount());
4167
+ System.out.println("#Face = " + FaceCount());
4168
+
4169
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4170
+
4171
+ for (int i = 0; i < VertexCount(); i++)
4172
+ {
4173
+ Vertex v = GetVertex(i);
4174
+
4175
+ if (!table.contains(v))
4176
+ {
4177
+ table.add(v);
4178
+ }
4179
+ }
4180
+
4181
+ Grafreed.smoothmode = smooth;
4182
+ Grafreed.linkUV = link;
4183
+
4184
+// for (int i = 0; i < VertexCount(); i++)
4185
+// {
4186
+// Vertex v = GetVertex(i);
4187
+//
4188
+// table.add(v);
4189
+// }
4190
+
39664191 }
39674192
39684193 static cVector temp1 = new cVector();
....@@ -4737,16 +4962,25 @@
47374962 {
47384963 i3 = positions.length-3;
47394964 i2 = uvmap.length - 2;
4740
- new Exception().printStackTrace();
4965
+ //new Exception().printStackTrace();
47414966 }
47424967
47434968 v./*pos.*/x = positions[i3];
47444969 v./*pos.*/y = positions[i3 + 1];
47454970 v./*pos.*/z = positions[i3 + 2];
47464971
4747
- v.norm.x = normals[i3];
4748
- v.norm.y = normals[i3 + 1];
4749
- v.norm.z = normals[i3 + 2];
4972
+ if (normals == null)
4973
+ {
4974
+ v.norm.x = 0;
4975
+ v.norm.y = 0;
4976
+ v.norm.z = 0;
4977
+ }
4978
+ else
4979
+ {
4980
+ v.norm.x = normals[i3];
4981
+ v.norm.y = normals[i3 + 1];
4982
+ v.norm.z = normals[i3 + 2];
4983
+ }
47504984
47514985 v.s = uvmap[i2];
47524986 v.t = uvmap[i2 + 1];
....@@ -5461,17 +5695,27 @@
54615695
54625696 transient int nbbadfaces; // ?? = 1000000;
54635697
5464
- int ChooseTriangle()
5698
+ /*
5699
+ */
5700
+ int ChooseTriangle(boolean firstEquilateral)
54655701 {
54665702 int chosen = -1;
54675703
54685704 double minweight = 1E10;
54695705
5706
+ int step = 8; // ?
5707
+
5708
+ if (firstEquilateral)
5709
+ step = 1;
5710
+
54705711 nbbadfaces = 0;
5471
- for (int i=0; i<faces.size(); i+=8)
5712
+ for (int i=0; i<faces.size(); i+=step)
54725713 // for (int i=faces.size(); (i-=8)>=0;)
54735714 {
54745715 Face face = (Face) faces.get(i);
5716
+
5717
+ if (face.used)
5718
+ continue;
54755719
54765720 if (!Valid(face))
54775721 {
....@@ -5481,6 +5725,15 @@
54815725
54825726 if (Boundary(face))
54835727 continue;
5728
+
5729
+// if (Boundary(face.p))
5730
+// continue;
5731
+//
5732
+// if (Boundary(face.q))
5733
+// continue;
5734
+//
5735
+// if (Boundary(face.r))
5736
+// continue;
54845737
54855738 if (!ValidValence(face))
54865739 continue;
....@@ -5493,22 +5746,55 @@
54935746 //?? if (face.weight < 0)
54945747 // continue;
54955748
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)
5749
+ if (firstEquilateral)
55035750 {
5504
- minweight = weight;
5751
+ if (OneFaceUsed(links.get(face.p)))
5752
+ continue;
5753
+
5754
+ if (OneFaceUsed(links.get(face.q)))
5755
+ continue;
5756
+
5757
+ if (OneFaceUsed(links.get(face.r)))
5758
+ continue;
5759
+
55055760 chosen = i;
5506
- if (minweight == 0)
5507
- break;
5761
+ break;
5762
+ }
5763
+ else
5764
+ {
5765
+ double K = 1; // 0.01; // .25;
5766
+
5767
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5768
+
5769
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5770
+
5771
+ if (minweight > weight)
5772
+ {
5773
+ minweight = weight;
5774
+ chosen = i;
5775
+ if (minweight == 0)
5776
+ break;
5777
+ }
55085778 }
55095779 }
55105780
55115781 return chosen;
5782
+ }
5783
+
5784
+ private boolean OneFaceUsed(Vector<Face> faces)
5785
+ {
5786
+ if (faces.size() != 6)
5787
+ return true;
5788
+
5789
+ for (int i=0; i<6; i+=1)
5790
+ {
5791
+ if (faces.get(i).used)
5792
+ {
5793
+ return true;
5794
+ }
5795
+ }
5796
+
5797
+ return false;
55125798 }
55135799
55145800 static boolean remove3valence = true;
....@@ -5544,7 +5830,7 @@
55445830 }
55455831 else
55465832 {
5547
- assert(links.size() == vertices.size());
5833
+ // TODO Grafreed.Assert(links.size() == vertices.size());
55485834
55495835 links.setSize(vertices.size());
55505836 for (int i=vertices.size(); --i>=0;)
....@@ -5552,6 +5838,7 @@
55525838 // linkstouched[i] = false;
55535839 if (links.get(i) == null) // ??
55545840 {
5841
+ new Exception().printStackTrace();
55555842 links.set(i, new Vector(8));
55565843 // linkstouched[i] = true;
55575844 }
....@@ -5562,6 +5849,8 @@
55625849 }
55635850 }
55645851
5852
+ boolean once = false;
5853
+
55655854 for (int i=faces.size(); --i>=0;)
55665855 {
55675856 Face face = (Face) faces.get(i);
....@@ -5573,6 +5862,9 @@
55735862 //if (linkstouched[face.r])
55745863 links.get(face.r).add(face);
55755864
5865
+ if (face.used)
5866
+ once = true;
5867
+
55765868 face.good = 1;
55775869 face.boundary = -1;
55785870 }
....@@ -6344,6 +6636,7 @@
63446636
63456637 void InitWeights()
63466638 {
6639
+ new Exception().printStackTrace();
63476640 System.exit(0);
63486641 int n = 0;
63496642 int b = 0;
....@@ -6937,6 +7230,10 @@
69377230 return (face.boundary = 1) == 1;
69387231 }
69397232
7233
+ // June 2019
7234
+ if (true)
7235
+ return (face.boundary = 0) == 1;
7236
+
69407237 // reverse triangle test
69417238 q1.set(p);
69427239 q2.set(q);
....@@ -7386,7 +7683,7 @@
73867683 //InitWeights();
73877684 }
73887685
7389
- int chosen = ChooseTriangle(); // Best is slow and not really better
7686
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73907687
73917688 if (chosen == -1)
73927689 {
....@@ -7400,7 +7697,7 @@
74007697 //remove3valence = false;
74017698 // InitWeights();
74027699
7403
- chosen = ChooseTriangle();
7700
+ chosen = ChooseTriangle(true);
74047701 }
74057702 }
74067703
....@@ -7676,7 +7973,7 @@
76767973
76777974 // boolean lock;
76787975
7679
- void SplitInTwo(boolean reduction34, boolean onlyone)
7976
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76807977 {
76817978 if (stripified)
76827979 {
....@@ -7713,12 +8010,12 @@
77138010 {
77148011 System.err.println("EXCEPTION CAUGHT");
77158012 e.printStackTrace();
7716
- return;
8013
+ return false;
77178014 } catch (Error e)
77188015 {
77198016 System.err.println("ERROR CAUGHT");
77208017 e.printStackTrace();
7721
- return;
8018
+ return false;
77228019 }
77238020
77248021 System.out.println("# faces = " + faces.size());
....@@ -7728,6 +8025,7 @@
77288025 {
77298026 Face face = (Face) faces.get(i);
77308027
8028
+ face.used = false;
77318029 face.nbiterations = 1;
77328030 face.weight = -1;
77338031 face.boundary = -1;
....@@ -7779,6 +8077,11 @@
77798077 nbbadfaces = faces.size();
77808078 //remove3valence = true;
77818079
8080
+ int count = 2;
8081
+
8082
+ if (onlyone)
8083
+ count = 1;
8084
+
77828085 firstpass = true;
77838086
77848087 int n = faces.size();
....@@ -7794,8 +8097,9 @@
77948097 System.out.print('.');
77958098 }
77968099 System.out.println();
8100
+ boolean atleastone = false;
77978101 int i = 0;
7798
- while (reduction34 || faces.size() > n/2)
8102
+ while (true) // reduction34 || faces.size() > n/2)
77998103 {
78008104 if (i++%100 == 0)
78018105 {
....@@ -7817,6 +8121,8 @@
78178121 {
78188122 if (!RemoveOneTriangle())
78198123 break;
8124
+
8125
+ atleastone = true;
78208126 }
78218127 // if (iterationcount == 0)
78228128 // break;
....@@ -7827,8 +8133,8 @@
78278133 break;
78288134 }
78298135 firstpass = false;
7830
- if (onlyone)
7831
- break; // one triangle only
8136
+// if (--count<0 && !reduction34)
8137
+// break; // one triangle only
78328138 }
78338139
78348140 InitLinks(false); // for further display
....@@ -7844,6 +8150,8 @@
78448150 Trim(true,false,false,false,false);
78458151
78468152 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8153
+
8154
+ return atleastone;
78478155 }
78488156
78498157 void UpdateIndices(Face face, Face minface)
....@@ -7856,18 +8164,21 @@
78568164 face.p = minface.p;
78578165 //if (leafweights)
78588166 face.good = 0; // false;
8167
+ face.used = true;
78598168 }
78608169 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
78618170 {
78628171 face.q = minface.p;
78638172 //if (leafweights)
78648173 face.good = 0; // false;
8174
+ face.used = true;
78658175 }
78668176 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
78678177 {
78688178 face.r = minface.p;
78698179 //if (leafweights)
78708180 face.good = 0; // false;
8181
+ face.used = true;
78718182 }
78728183
78738184 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7927,50 +8238,50 @@
79278238 if (v == 2)
79288239 vert = minface.r;
79298240 // 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)
8241
+ Vector<Face> vertfaces = links.get(vert);
8242
+ for (int i=vertfaces.size(); --i>=0;)
79418243 {
7942
- if (!leafweights)
8244
+ Face face = (Face) vertfaces.get(i);
8245
+
8246
+ // if (face.weight == 10000)
8247
+ // continue;
8248
+
8249
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8250
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8251
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
79438252 {
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);
8253
+ if (!leafweights)
8254
+ {
8255
+ // if(minfaceweight <= 0)
8256
+ // assert(minfaceweight > 0);
8257
+ //
8258
+ // //FaceWeight(face);
8259
+ // if(face.weight < 0)
8260
+ // assert(face.weight >= 0);
8261
+
8262
+ face.weight += minfaceweight;
8263
+
8264
+ // if (face.weight >= 10000)
8265
+ // assert(face.weight < 10000);
8266
+ }
8267
+ else
8268
+ face.weight = -1;
8269
+
8270
+ face.nbiterations += 1;
8271
+ face.boundary = -1;
8272
+
8273
+ Vertex p = (Vertex)vertices.get(face.p);
8274
+ Vertex q = (Vertex)vertices.get(face.q);
8275
+ Vertex r = (Vertex)vertices.get(face.r);
8276
+
8277
+ p.boundary = -1;
8278
+ q.boundary = -1;
8279
+ r.boundary = -1;
79558280 }
79568281 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;
8282
+ assert(false);
79698283 }
7970
- else
7971
- assert(false);
79728284 }
7973
- }
79748285
79758286 // TouchVertex(minface.p);
79768287 // TouchVertex(minface.q);
....@@ -8171,6 +8482,7 @@
81718482 for (int i=vertfaces.size(); --i>=0;)
81728483 {
81738484 Face face = (Face) vertfaces.get(i);
8485
+ face.used = true;
81748486 face.good = 0; // false;
81758487 if (leafweights)
81768488 face.weight = -1;
....@@ -8217,7 +8529,7 @@
82178529 if (!trimmed)
82188530 return;
82198531
8220
- GrafreeD.linkUV = false;
8532
+ Grafreed.linkUV = false;
82218533
82228534 try
82238535 {
....@@ -8449,7 +8761,8 @@
84498761 int[] startvertices;
84508762 float[] averagepoints;
84518763 float[] extremepoints;
8452
- float[] supportsizes; // distance of closest point
8764
+ float[] supportminsize; // distance of closest point
8765
+ float[] supportmaxsize; // distance of fartest point
84538766
84548767 transient Hashtable vertextable;
84558768 /*transient*/ private Vertex[] verticesCopy;