Normand Briere
2019-09-02 21ac57b36a9e3b909853c7d64ac29b7ad72490a3
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,11 +680,13 @@
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)
657688 {
689
+ CameraPane.CreateSelectedPoint();
658690 CameraPane.selectedpoint.
659691 getAverage(cStatic.point1, true);
660692
....@@ -952,7 +984,7 @@
952984
953985 // sept 2017 SEUIL = 0.1; // aout 2013
954986
955
- supports = InitConnections(other);
987
+ supports = other.InitConnections();
956988
957989 other.supports = supports; // should be the other way around...
958990
....@@ -972,6 +1004,7 @@
9721004
9731005 v.closestsupport = -1;
9741006
1007
+ CameraPane.CreateSelectedPoint();
9751008 CameraPane.selectedpoint.
9761009 getAverage(cStatic.point1, true);
9771010
....@@ -1230,6 +1263,7 @@
12301263 for (int wi = v0.weights.length; --wi>=0;)
12311264 v[wi] = 0;
12321265
1266
+ CameraPane.CreateSelectedPoint();
12331267 CameraPane.selectedpoint.
12341268 getAverage(cStatic.point1, true);
12351269
....@@ -1367,6 +1401,7 @@
13671401 v0.x = v0.y = v0.z = 0;
13681402 v0.norm.x = v0.norm.y = v0.norm.z = 0;
13691403
1404
+ CameraPane.CreateSelectedPoint();
13701405 CameraPane.selectedpoint.
13711406 getAverage(cStatic.point1, true);
13721407
....@@ -1518,7 +1553,7 @@
15181553 InitFaceIndices();
15191554 }
15201555
1521
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1556
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15221557 //float[] v = new float[100];
15231558
15241559 for (int loops=1; --loops>=0;)
....@@ -1548,7 +1583,7 @@
15481583 InitFaceIndices();
15491584 }
15501585
1551
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1586
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15521587 //float[] v = new float[100];
15531588
15541589 for (int loops=10; --loops>=0;)
....@@ -1895,7 +1930,7 @@
18951930 return;
18961931 }
18971932
1898
- // System.exit(0);
1933
+ // System.exit(0);
18991934
19001935 cVector vect = new cVector();
19011936 cVector normal = new cVector();
....@@ -1966,7 +2001,10 @@
19662001 if (v.vertexlinks == null)
19672002 continue;
19682003
1969
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2004
+ // Warning: faster but dangerous
2005
+ if (v.weights != null && v.weights[j]
2006
+ // == 0)
2007
+ < 0.0001 * v.totalweight)
19702008 {
19712009 //testweight += v.weights[j-1];
19722010 continue;
....@@ -2247,6 +2285,8 @@
22472285
22482286 transient int lastsoundtime;
22492287
2288
+ transient boolean once = false;
2289
+
22502290 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512291 {
22522292 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2342,11 @@
23022342
23032343 if (v.totalweight == 0)
23042344 {
2305
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2345
+ if (!once)
2346
+ {
2347
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2348
+ once = true;
2349
+ }
23062350 continue;
23072351 }
23082352
....@@ -2670,7 +2714,7 @@
26702714
26712715 if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722716 {
2673
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2717
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742718
26752719 lastsoundtime = Globals.framecount;
26762720 }
....@@ -3098,6 +3142,7 @@
30983142 //
30993143 // transient VertexCompare[] vertexcompare = null;
31003144
3145
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013146 boolean Contains(Vertex v0, int object)
31023147 {
31033148 int start = startvertices[object-1];
....@@ -3247,12 +3292,21 @@
32473292 max = ay;
32483293 }
32493294
3295
+ if (max == 0)
3296
+ {
3297
+ uvmap[i2] = 0.5f;
3298
+ uvmap[i2+1] = 0.5f;
3299
+ continue;
3300
+ }
3301
+
32503302 x /= max;
32513303 y /= max;
32523304
32533305 double angle = Math.acos(Math.abs(z*2));
32543306
32553307 double k = angle / Math.PI * 2;
3308
+
3309
+ assert(k >= 0);
32563310
32573311 // k == 0 => uv = 0 (center)
32583312 // k == 1 => uv = -1,1 (border)
....@@ -3268,7 +3322,8 @@
32683322 t = Math.pow(t, 3);
32693323
32703324 // Interpolate between k/length2 (center) and k (border)
3271
- k = k / length2 * (1 - t) + k * t;
3325
+ if (length2 > 0)
3326
+ k *= (1 - t) / length2 + t;
32723327
32733328 double u = k*x;
32743329 double v = k*y;
....@@ -3393,7 +3448,7 @@
33933448 k /= x*x + y*y;
33943449 }
33953450 else
3396
- GrafreeD.Assert(z == 1);
3451
+ Grafreed.Assert(z == 1);
33973452
33983453 if (k < 0)
33993454 k = 0;
....@@ -3686,6 +3741,111 @@
36863741 */
36873742 }
36883743
3744
+ void GenerateNormals2(boolean crease)
3745
+ {
3746
+ cVector tempVector = new cVector();
3747
+
3748
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3749
+//
3750
+//
3751
+// for (int i=0; i<this.VertexCount(); i++)
3752
+// {
3753
+// Vertex v = this.GetVertex(i);
3754
+//
3755
+// tempVector.set(v);
3756
+//
3757
+// cVector n = tableBase.get(tempVector.ToFloat());
3758
+//
3759
+// if (n != null)
3760
+// {
3761
+// continue;
3762
+// }
3763
+//
3764
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3765
+// }
3766
+
3767
+ BoundaryRep tempSupport = this.support;
3768
+
3769
+ this.support = null;
3770
+
3771
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3772
+
3773
+ this.support = tempSupport;
3774
+
3775
+ //tempRep.Unstripify();
3776
+
3777
+ tempRep.GenerateNormals2(crease);
3778
+
3779
+ boolean keepnormal = Vertex.normalmode;
3780
+ boolean epsequal = Grafreed.epsequal;
3781
+
3782
+ Vertex.normalmode = false;
3783
+ Grafreed.epsequal = false; // A bit strange
3784
+
3785
+ // No need to have a match for vertex counts.
3786
+
3787
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3788
+
3789
+ for (int i=0; i<tempRep.VertexCount(); i++)
3790
+ {
3791
+ Vertex v = tempRep.GetVertex(i);
3792
+
3793
+ cVector n = table.get(tempVector.ToFloat());
3794
+
3795
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3796
+ {
3797
+ //continue;
3798
+ }
3799
+
3800
+ tempVector.set(v);
3801
+
3802
+ //cVector nBase = tableBase.get(tempVector);
3803
+
3804
+ //if (v.norm.dot(nBase) < 0.9)
3805
+ //{
3806
+ // continue;
3807
+ //}
3808
+
3809
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3810
+ {
3811
+ //continue;
3812
+ }
3813
+
3814
+ if (n != null)
3815
+ {
3816
+// if (n.dot(v.norm) < 0)
3817
+// n.sub(v.norm);
3818
+// else
3819
+// n.add(v.norm);
3820
+//
3821
+// n.normalize();
3822
+ continue;
3823
+ }
3824
+
3825
+ table.put(new cVector(tempVector), new cVector(v.norm));
3826
+ }
3827
+
3828
+ for (int i=0; i<this.VertexCount(); i++)
3829
+ {
3830
+ Vertex v = this.GetVertex(i);
3831
+
3832
+ tempVector.set(v);
3833
+
3834
+ cVector n = table.get(tempVector.ToFloat());
3835
+
3836
+ //if (n.dot(v.norm) < 0)
3837
+ if (n == null)
3838
+ continue;
3839
+
3840
+ LA.vecCopy(n, v.norm);
3841
+
3842
+ this.SetVertex(v, i);
3843
+ }
3844
+
3845
+ Grafreed.epsequal = epsequal;
3846
+ Vertex.normalmode = keepnormal;
3847
+ }
3848
+
36893849 void GenerateNormals(boolean crease)
36903850 {
36913851 boolean wastrim = trimmed;
....@@ -3702,6 +3862,28 @@
37023862 }
37033863
37043864 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3865
+ }
3866
+
3867
+ void GenerateNormalsMesh()
3868
+ {
3869
+ if (stripified)
3870
+ {
3871
+ Unstripify();
3872
+ }
3873
+
3874
+ if (trimmed)
3875
+ {
3876
+ normals = null;
3877
+ }
3878
+ else
3879
+ {
3880
+ for (int i=VertexCount(); --i>=0;)
3881
+ {
3882
+ Vertex v = GetVertex(i);
3883
+
3884
+ v.norm = null;
3885
+ }
3886
+ }
37053887 }
37063888
37073889 void GenNormalsJME()
....@@ -3826,7 +4008,7 @@
38264008 NormalGenerator ng;
38274009
38284010 if (crease)
3829
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4011
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
38304012 else
38314013 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
38324014
....@@ -3844,8 +4026,6 @@
38444026 //System.out.println("NEW = " + positions.length);
38454027 uvmap = new float[ta.getVertexCount() * 2];
38464028
3847
- colors = new float[ta.getVertexCount()]; // * 3];
3848
-
38494029 ta.getCoordinates(0, positions);
38504030 ta.getNormals(0, normals);
38514031 // ta.getColors(0, colors);
....@@ -3853,12 +4033,24 @@
38534033
38544034 System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";");
38554035
4036
+ colors = null;
4037
+// colors = new float[ta.getVertexCount()]; // * 3];
4038
+//
4039
+// for (int i=colors.length; --i>=0;)
4040
+// {
4041
+// colors[i] = 1;
4042
+// }
4043
+
38564044 triangles = new int[ta.getVertexCount()];
38574045
38584046 for (int i = 0; i < triangles.length; i++)
38594047 {
38604048 triangles[i] = i;
38614049 }
4050
+
4051
+// Untrim();
4052
+ if (!trimmed)
4053
+ MergeNormals();
38624054 }
38634055 }
38644056
....@@ -3886,12 +4078,18 @@
38864078 positions = new float[3 * ga.getVertexCount()];
38874079 normals = new float[3 * ga.getVertexCount()];
38884080 uvmap = new float[2 * ga.getVertexCount()];
3889
- colors = new float[1 * ga.getVertexCount()];
38904081
38914082 tsa.getCoordinates(0, positions);
38924083 tsa.getNormals(0, normals);
38934084 tsa.getTextureCoordinates(0, 0, uvmap);
38944085 // tsa.getColors(0, colors);
4086
+
4087
+ colors = null;
4088
+// colors = new float[1 * ga.getVertexCount()];
4089
+// for (int i=colors.length; --i>=0;)
4090
+// {
4091
+// colors[i] = 1;
4092
+// }
38954093
38964094 int stripcount = tsa.getNumStrips();
38974095 triangles = new int[stripcount];
....@@ -3900,6 +4098,7 @@
39004098 stripified = true;
39014099 } catch (ClassCastException e)
39024100 {
4101
+ // ??? aug 2019
39034102 TriangleArray ta = (TriangleArray) ga;
39044103
39054104 positions = new float[3 * ga.getVertexCount()];
....@@ -3914,6 +4113,10 @@
39144113 triangles = new int[1];
39154114 triangles[0] = 3;
39164115 }
4116
+
4117
+ //Untrim();
4118
+ if (!trimmed)
4119
+ MergeNormals();
39174120 }
39184121
39194122 /*
....@@ -3963,6 +4166,42 @@
39634166 }
39644167
39654168 Vertex.normalmode = false;
4169
+ }
4170
+
4171
+ void MergeNormals()
4172
+ {
4173
+ assert(!trimmed);
4174
+
4175
+ boolean smooth = Grafreed.smoothmode;
4176
+ boolean link = Grafreed.linkUV;
4177
+ Grafreed.smoothmode = true;
4178
+ Grafreed.linkUV = true;
4179
+
4180
+ System.out.println("#Vertex = " + VertexCount());
4181
+ System.out.println("#Face = " + FaceCount());
4182
+
4183
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4184
+
4185
+ for (int i = 0; i < VertexCount(); i++)
4186
+ {
4187
+ Vertex v = GetVertex(i);
4188
+
4189
+ if (!table.contains(v))
4190
+ {
4191
+ table.add(v);
4192
+ }
4193
+ }
4194
+
4195
+ Grafreed.smoothmode = smooth;
4196
+ Grafreed.linkUV = link;
4197
+
4198
+// for (int i = 0; i < VertexCount(); i++)
4199
+// {
4200
+// Vertex v = GetVertex(i);
4201
+//
4202
+// table.add(v);
4203
+// }
4204
+
39664205 }
39674206
39684207 static cVector temp1 = new cVector();
....@@ -4737,16 +4976,25 @@
47374976 {
47384977 i3 = positions.length-3;
47394978 i2 = uvmap.length - 2;
4740
- new Exception().printStackTrace();
4979
+ //new Exception().printStackTrace();
47414980 }
47424981
47434982 v./*pos.*/x = positions[i3];
47444983 v./*pos.*/y = positions[i3 + 1];
47454984 v./*pos.*/z = positions[i3 + 2];
47464985
4747
- v.norm.x = normals[i3];
4748
- v.norm.y = normals[i3 + 1];
4749
- v.norm.z = normals[i3 + 2];
4986
+ if (normals == null)
4987
+ {
4988
+ v.norm.x = 0;
4989
+ v.norm.y = 0;
4990
+ v.norm.z = 0;
4991
+ }
4992
+ else
4993
+ {
4994
+ v.norm.x = normals[i3];
4995
+ v.norm.y = normals[i3 + 1];
4996
+ v.norm.z = normals[i3 + 2];
4997
+ }
47504998
47514999 v.s = uvmap[i2];
47525000 v.t = uvmap[i2 + 1];
....@@ -5461,17 +5709,27 @@
54615709
54625710 transient int nbbadfaces; // ?? = 1000000;
54635711
5464
- int ChooseTriangle()
5712
+ /*
5713
+ */
5714
+ int ChooseTriangle(boolean firstEquilateral)
54655715 {
54665716 int chosen = -1;
54675717
54685718 double minweight = 1E10;
54695719
5720
+ int step = 8; // ?
5721
+
5722
+ if (firstEquilateral)
5723
+ step = 1;
5724
+
54705725 nbbadfaces = 0;
5471
- for (int i=0; i<faces.size(); i+=8)
5726
+ for (int i=0; i<faces.size(); i+=step)
54725727 // for (int i=faces.size(); (i-=8)>=0;)
54735728 {
54745729 Face face = (Face) faces.get(i);
5730
+
5731
+ if (face.used)
5732
+ continue;
54755733
54765734 if (!Valid(face))
54775735 {
....@@ -5481,6 +5739,15 @@
54815739
54825740 if (Boundary(face))
54835741 continue;
5742
+
5743
+// if (Boundary(face.p))
5744
+// continue;
5745
+//
5746
+// if (Boundary(face.q))
5747
+// continue;
5748
+//
5749
+// if (Boundary(face.r))
5750
+// continue;
54845751
54855752 if (!ValidValence(face))
54865753 continue;
....@@ -5493,22 +5760,55 @@
54935760 //?? if (face.weight < 0)
54945761 // continue;
54955762
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)
5763
+ if (firstEquilateral)
55035764 {
5504
- minweight = weight;
5765
+ if (OneFaceUsed(links.get(face.p)))
5766
+ continue;
5767
+
5768
+ if (OneFaceUsed(links.get(face.q)))
5769
+ continue;
5770
+
5771
+ if (OneFaceUsed(links.get(face.r)))
5772
+ continue;
5773
+
55055774 chosen = i;
5506
- if (minweight == 0)
5507
- break;
5775
+ break;
5776
+ }
5777
+ else
5778
+ {
5779
+ double K = 1; // 0.01; // .25;
5780
+
5781
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5782
+
5783
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5784
+
5785
+ if (minweight > weight)
5786
+ {
5787
+ minweight = weight;
5788
+ chosen = i;
5789
+ if (minweight == 0)
5790
+ break;
5791
+ }
55085792 }
55095793 }
55105794
55115795 return chosen;
5796
+ }
5797
+
5798
+ private boolean OneFaceUsed(Vector<Face> faces)
5799
+ {
5800
+ if (faces.size() != 6)
5801
+ return true;
5802
+
5803
+ for (int i=0; i<6; i+=1)
5804
+ {
5805
+ if (faces.get(i).used)
5806
+ {
5807
+ return true;
5808
+ }
5809
+ }
5810
+
5811
+ return false;
55125812 }
55135813
55145814 static boolean remove3valence = true;
....@@ -5544,7 +5844,7 @@
55445844 }
55455845 else
55465846 {
5547
- assert(links.size() == vertices.size());
5847
+ // TODO Grafreed.Assert(links.size() == vertices.size());
55485848
55495849 links.setSize(vertices.size());
55505850 for (int i=vertices.size(); --i>=0;)
....@@ -5552,6 +5852,7 @@
55525852 // linkstouched[i] = false;
55535853 if (links.get(i) == null) // ??
55545854 {
5855
+ new Exception().printStackTrace();
55555856 links.set(i, new Vector(8));
55565857 // linkstouched[i] = true;
55575858 }
....@@ -5562,6 +5863,8 @@
55625863 }
55635864 }
55645865
5866
+ boolean once = false;
5867
+
55655868 for (int i=faces.size(); --i>=0;)
55665869 {
55675870 Face face = (Face) faces.get(i);
....@@ -5573,6 +5876,9 @@
55735876 //if (linkstouched[face.r])
55745877 links.get(face.r).add(face);
55755878
5879
+ if (face.used)
5880
+ once = true;
5881
+
55765882 face.good = 1;
55775883 face.boundary = -1;
55785884 }
....@@ -6344,6 +6650,7 @@
63446650
63456651 void InitWeights()
63466652 {
6653
+ new Exception().printStackTrace();
63476654 System.exit(0);
63486655 int n = 0;
63496656 int b = 0;
....@@ -6937,6 +7244,10 @@
69377244 return (face.boundary = 1) == 1;
69387245 }
69397246
7247
+ // June 2019
7248
+ if (true)
7249
+ return (face.boundary = 0) == 1;
7250
+
69407251 // reverse triangle test
69417252 q1.set(p);
69427253 q2.set(q);
....@@ -7386,7 +7697,7 @@
73867697 //InitWeights();
73877698 }
73887699
7389
- int chosen = ChooseTriangle(); // Best is slow and not really better
7700
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73907701
73917702 if (chosen == -1)
73927703 {
....@@ -7400,7 +7711,7 @@
74007711 //remove3valence = false;
74017712 // InitWeights();
74027713
7403
- chosen = ChooseTriangle();
7714
+ chosen = ChooseTriangle(true);
74047715 }
74057716 }
74067717
....@@ -7676,7 +7987,7 @@
76767987
76777988 // boolean lock;
76787989
7679
- void SplitInTwo(boolean reduction34, boolean onlyone)
7990
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76807991 {
76817992 if (stripified)
76827993 {
....@@ -7713,12 +8024,12 @@
77138024 {
77148025 System.err.println("EXCEPTION CAUGHT");
77158026 e.printStackTrace();
7716
- return;
8027
+ return false;
77178028 } catch (Error e)
77188029 {
77198030 System.err.println("ERROR CAUGHT");
77208031 e.printStackTrace();
7721
- return;
8032
+ return false;
77228033 }
77238034
77248035 System.out.println("# faces = " + faces.size());
....@@ -7728,6 +8039,7 @@
77288039 {
77298040 Face face = (Face) faces.get(i);
77308041
8042
+ face.used = false;
77318043 face.nbiterations = 1;
77328044 face.weight = -1;
77338045 face.boundary = -1;
....@@ -7779,6 +8091,11 @@
77798091 nbbadfaces = faces.size();
77808092 //remove3valence = true;
77818093
8094
+ int count = 2;
8095
+
8096
+ if (onlyone)
8097
+ count = 1;
8098
+
77828099 firstpass = true;
77838100
77848101 int n = faces.size();
....@@ -7794,8 +8111,9 @@
77948111 System.out.print('.');
77958112 }
77968113 System.out.println();
8114
+ boolean atleastone = false;
77978115 int i = 0;
7798
- while (reduction34 || faces.size() > n/2)
8116
+ while (true) // reduction34 || faces.size() > n/2)
77998117 {
78008118 if (i++%100 == 0)
78018119 {
....@@ -7817,6 +8135,8 @@
78178135 {
78188136 if (!RemoveOneTriangle())
78198137 break;
8138
+
8139
+ atleastone = true;
78208140 }
78218141 // if (iterationcount == 0)
78228142 // break;
....@@ -7827,8 +8147,8 @@
78278147 break;
78288148 }
78298149 firstpass = false;
7830
- if (onlyone)
7831
- break; // one triangle only
8150
+// if (--count<0 && !reduction34)
8151
+// break; // one triangle only
78328152 }
78338153
78348154 InitLinks(false); // for further display
....@@ -7844,6 +8164,8 @@
78448164 Trim(true,false,false,false,false);
78458165
78468166 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8167
+
8168
+ return atleastone;
78478169 }
78488170
78498171 void UpdateIndices(Face face, Face minface)
....@@ -7856,18 +8178,21 @@
78568178 face.p = minface.p;
78578179 //if (leafweights)
78588180 face.good = 0; // false;
8181
+ face.used = true;
78598182 }
78608183 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
78618184 {
78628185 face.q = minface.p;
78638186 //if (leafweights)
78648187 face.good = 0; // false;
8188
+ face.used = true;
78658189 }
78668190 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
78678191 {
78688192 face.r = minface.p;
78698193 //if (leafweights)
78708194 face.good = 0; // false;
8195
+ face.used = true;
78718196 }
78728197
78738198 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7927,50 +8252,50 @@
79278252 if (v == 2)
79288253 vert = minface.r;
79298254 // 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)
8255
+ Vector<Face> vertfaces = links.get(vert);
8256
+ for (int i=vertfaces.size(); --i>=0;)
79418257 {
7942
- if (!leafweights)
8258
+ Face face = (Face) vertfaces.get(i);
8259
+
8260
+ // if (face.weight == 10000)
8261
+ // continue;
8262
+
8263
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8264
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8265
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
79438266 {
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);
8267
+ if (!leafweights)
8268
+ {
8269
+ // if(minfaceweight <= 0)
8270
+ // assert(minfaceweight > 0);
8271
+ //
8272
+ // //FaceWeight(face);
8273
+ // if(face.weight < 0)
8274
+ // assert(face.weight >= 0);
8275
+
8276
+ face.weight += minfaceweight;
8277
+
8278
+ // if (face.weight >= 10000)
8279
+ // assert(face.weight < 10000);
8280
+ }
8281
+ else
8282
+ face.weight = -1;
8283
+
8284
+ face.nbiterations += 1;
8285
+ face.boundary = -1;
8286
+
8287
+ Vertex p = (Vertex)vertices.get(face.p);
8288
+ Vertex q = (Vertex)vertices.get(face.q);
8289
+ Vertex r = (Vertex)vertices.get(face.r);
8290
+
8291
+ p.boundary = -1;
8292
+ q.boundary = -1;
8293
+ r.boundary = -1;
79558294 }
79568295 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;
8296
+ assert(false);
79698297 }
7970
- else
7971
- assert(false);
79728298 }
7973
- }
79748299
79758300 // TouchVertex(minface.p);
79768301 // TouchVertex(minface.q);
....@@ -8171,6 +8496,7 @@
81718496 for (int i=vertfaces.size(); --i>=0;)
81728497 {
81738498 Face face = (Face) vertfaces.get(i);
8499
+ face.used = true;
81748500 face.good = 0; // false;
81758501 if (leafweights)
81768502 face.weight = -1;
....@@ -8217,7 +8543,7 @@
82178543 if (!trimmed)
82188544 return;
82198545
8220
- GrafreeD.linkUV = false;
8546
+ Grafreed.linkUV = false;
82218547
82228548 try
82238549 {
....@@ -8449,7 +8775,8 @@
84498775 int[] startvertices;
84508776 float[] averagepoints;
84518777 float[] extremepoints;
8452
- float[] supportsizes; // distance of closest point
8778
+ float[] supportminsize; // distance of closest point
8779
+ float[] supportmaxsize; // distance of fartest point
84538780
84548781 transient Hashtable vertextable;
84558782 /*transient*/ private Vertex[] verticesCopy;