Normand Briere
2019-09-18 f9325048496d7cdbcad233f8a6b84c88e79adcc2
BoundaryRep.java
....@@ -7,7 +7,8 @@
77
88 class BoundaryRep implements java.io.Serializable
99 {
10
- static final long serialVersionUID = -4852664309425035321L;
10
+ static final long serialVersionUID = // VERY old 2008 -5762968998168738314L;
11
+ -4852664309425035321L;
1112
1213 transient int displaylist = 0;
1314
....@@ -161,6 +162,7 @@
161162 || FaceCount() != other.FaceCount()
162163 || !(indices == null ^ other.indices != null)) // july 2014
163164 {
165
+ // The meshes have different structures.
164166 //new Exception().printStackTrace();
165167 trimmed = other.trimmed;
166168 stripified = other.stripified;
....@@ -172,16 +174,16 @@
172174 bufV = other.bufV;
173175 bufF = other.bufF;
174176
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);
177
+ positions = (float[]) Grafreed.clone(other.positions);
178
+ normals = (float[]) Grafreed.clone(other.normals);
179
+ colors = (float[]) Grafreed.clone(other.colors);
180
+ uvmap = (float[]) Grafreed.clone(other.uvmap);
181
+ triangles = (int[]) Grafreed.clone(other.triangles);
180182
181
- indices = (int[]) GrafreeD.clone(other.indices);
183
+ indices = (int[]) Grafreed.clone(other.indices);
182184
183
- vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GrafreeD.clone(other.faces);
185
+ vertices = (Vector<Vertex>) Grafreed.clone(other.vertices);
186
+ faces = (Vector<Face>) Grafreed.clone(other.faces);
185187 }
186188 else
187189 {
....@@ -239,9 +241,16 @@
239241 }
240242 }
241243
242
- Support[] InitConnections(BoundaryRep other)
244
+ transient Support[] cachesupports = null;
245
+
246
+ Support[] InitConnections()
243247 {
244
- int n = other.startvertices.length-1;
248
+ if (cachesupports != null)
249
+ {
250
+ return cachesupports;
251
+ }
252
+
253
+ int n = this.startvertices.length-1;
245254
246255 Support[] supports = new Support[n];
247256
....@@ -253,38 +262,60 @@
253262
254263 for (int object=1; object<=n; object++)
255264 {
256
- int start = other.startvertices[object-1];
257
- int end = other.startvertices[object];
265
+ int start = this.startvertices[object-1];
266
+ int end = this.startvertices[object];
258267
259268 if (start == end)
260269 continue; // ??
261270
271
+ /**
272
+ Vertex v2 = vertextemp;
273
+ v2.x = averagepoints[object*3];
274
+ v2.y = averagepoints[object*3+1];
275
+ v2.z = averagepoints[object*3+2];
276
+
277
+ //v2.set(GetVertex(this.startvertices[subsupport]));
278
+
279
+ // projected point
280
+ Vertex v3 = vertextemp2;
281
+ //GetVertex(this.startvertices[subsupport]);
282
+ v3.x = extremepoints[object*3];
283
+ v3.y = extremepoints[object*3+1];
284
+ v3.z = extremepoints[object*3+2];
285
+
286
+ vect3.set(v3); // "X" axis apex
287
+ vect3.sub(v2); // origin (center)
288
+ vect3.normalize();
289
+ /**/
290
+
262291 int linkcount = 0;
263292
264293 int objectinlist = -1;
294
+
295
+ Support subsupport = supports[object-1];
265296
266297 for (int object2=1; object2<=n; object2++)
267298 {
268299 for (int i = start; i < end; i++)
269300 {
270
- Vertex v = other.GetVertex(i);
301
+ Vertex v = this.GetVertex(i);
271302
272
- //
273
- if (other.Contains(v, object2))
303
+ // Check if v is close enough from any vertex of the given subobject.
304
+ if (this.Contains(v, object2))
274305 {
275
- if (linkcount == supports[object-1].links.length)
306
+ if (linkcount == subsupport.links.length)
276307 break;
277308
278309 if (object2 == object)
279310 objectinlist = linkcount;
280311
281
- supports[object-1].links[linkcount++] = object2;
312
+ subsupport.links[linkcount++] = object2;
282313 break;
283314 }
284315 }
285316 }
286317
287
- supports[object-1].links[linkcount] = -1;
318
+ subsupport.links[linkcount] = -1;
288319
289320 if (objectinlist == -1)
290321 assert(objectinlist != -1);
....@@ -293,9 +324,9 @@
293324 // assert(linkcount > 1);
294325
295326 // 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;
327
+ int first = subsupport.links[0];
328
+ subsupport.links[0] = subsupport.links[objectinlist];
329
+ subsupport.links[objectinlist] = first;
299330 }
300331
301332 for (int loop = 0; --loop>=0;)
....@@ -353,7 +384,7 @@
353384 supports = supports2;
354385 }
355386
356
- return supports;
387
+ return cachesupports = supports;
357388 }
358389
359390 double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k)
....@@ -500,7 +531,7 @@
500531 static Vertex vertextemp = new Vertex(true);
501532 static Vertex vertextemp2 = new Vertex(true);
502533
503
- static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07;
534
+ static double SEUIL = 0.025f; // 0.1 for rag doll; 0.07;
504535
505536 // Compute weight of point w/r to this
506537 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -598,7 +629,7 @@
598629 // ;
599630 //
600631
601
- supportsize = supportsizes[subsupport];
632
+ supportsize = supportminsize[subsupport];
602633
603634 double K = supportsize / distmax;
604635
....@@ -650,11 +681,13 @@
650681 // if (supportsize * fadefactor > 1)
651682 // return 1;
652683
653
- return supportsize * fadefactor;
684
+ return //supportsize *
685
+ supportsize * fadefactor;
654686 }
655687
656688 void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v)
657689 {
690
+ CameraPane.CreateSelectedPoint();
658691 CameraPane.selectedpoint.
659692 getAverage(cStatic.point1, true);
660693
....@@ -952,7 +985,7 @@
952985
953986 // sept 2017 SEUIL = 0.1; // aout 2013
954987
955
- supports = InitConnections(other);
988
+ supports = other.InitConnections();
956989
957990 other.supports = supports; // should be the other way around...
958991
....@@ -972,6 +1005,7 @@
9721005
9731006 v.closestsupport = -1;
9741007
1008
+ CameraPane.CreateSelectedPoint();
9751009 CameraPane.selectedpoint.
9761010 getAverage(cStatic.point1, true);
9771011
....@@ -1230,6 +1264,7 @@
12301264 for (int wi = v0.weights.length; --wi>=0;)
12311265 v[wi] = 0;
12321266
1267
+ CameraPane.CreateSelectedPoint();
12331268 CameraPane.selectedpoint.
12341269 getAverage(cStatic.point1, true);
12351270
....@@ -1367,6 +1402,7 @@
13671402 v0.x = v0.y = v0.z = 0;
13681403 v0.norm.x = v0.norm.y = v0.norm.z = 0;
13691404
1405
+ CameraPane.CreateSelectedPoint();
13701406 CameraPane.selectedpoint.
13711407 getAverage(cStatic.point1, true);
13721408
....@@ -1518,7 +1554,7 @@
15181554 InitFaceIndices();
15191555 }
15201556
1521
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1557
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15221558 //float[] v = new float[100];
15231559
15241560 for (int loops=1; --loops>=0;)
....@@ -1548,7 +1584,7 @@
15481584 InitFaceIndices();
15491585 }
15501586
1551
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1587
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15521588 //float[] v = new float[100];
15531589
15541590 for (int loops=10; --loops>=0;)
....@@ -1895,7 +1931,7 @@
18951931 return;
18961932 }
18971933
1898
- // System.exit(0);
1934
+ // System.exit(0);
18991935
19001936 cVector vect = new cVector();
19011937 cVector normal = new cVector();
....@@ -1966,7 +2002,10 @@
19662002 if (v.vertexlinks == null)
19672003 continue;
19682004
1969
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2005
+ // Warning: faster but dangerous
2006
+ if (v.weights != null && v.weights[j]
2007
+ == 0)
2008
+ //< 0.001 * v.totalweight)
19702009 {
19712010 //testweight += v.weights[j-1];
19722011 continue;
....@@ -2247,6 +2286,8 @@
22472286
22482287 transient int lastsoundtime;
22492288
2289
+ transient boolean once = false;
2290
+
22502291 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512292 {
22522293 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2343,11 @@
23022343
23032344 if (v.totalweight == 0)
23042345 {
2305
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2346
+ if (!once)
2347
+ {
2348
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2349
+ once = true;
2350
+ }
23062351 continue;
23072352 }
23082353
....@@ -2670,7 +2715,7 @@
26702715
26712716 if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722717 {
2673
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2718
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742719
26752720 lastsoundtime = Globals.framecount;
26762721 }
....@@ -3098,6 +3143,7 @@
30983143 //
30993144 // transient VertexCompare[] vertexcompare = null;
31003145
3146
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013147 boolean Contains(Vertex v0, int object)
31023148 {
31033149 int start = startvertices[object-1];
....@@ -3403,7 +3449,7 @@
34033449 k /= x*x + y*y;
34043450 }
34053451 else
3406
- GrafreeD.Assert(z == 1);
3452
+ Grafreed.Assert(z == 1);
34073453
34083454 if (k < 0)
34093455 k = 0;
....@@ -3696,6 +3742,114 @@
36963742 */
36973743 }
36983744
3745
+ void GenerateNormals2(boolean crease)
3746
+ {
3747
+ cVector tempVector = new cVector();
3748
+
3749
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3750
+//
3751
+//
3752
+// for (int i=0; i<this.VertexCount(); i++)
3753
+// {
3754
+// Vertex v = this.GetVertex(i);
3755
+//
3756
+// tempVector.set(v);
3757
+//
3758
+// cVector n = tableBase.get(tempVector.ToFloat());
3759
+//
3760
+// if (n != null)
3761
+// {
3762
+// continue;
3763
+// }
3764
+//
3765
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3766
+// }
3767
+
3768
+ BoundaryRep tempSupport = this.support;
3769
+
3770
+ this.support = null;
3771
+
3772
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3773
+
3774
+ this.support = tempSupport;
3775
+
3776
+ //tempRep.Unstripify();
3777
+
3778
+ tempRep.GenerateNormals(crease);
3779
+
3780
+ boolean keepnormal = Vertex.normalmode;
3781
+ boolean epsequal = Grafreed.epsequal;
3782
+
3783
+ Vertex.normalmode = false;
3784
+ Grafreed.epsequal = false; // A bit strange
3785
+
3786
+ // No need to have a match for vertex counts.
3787
+
3788
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3789
+
3790
+ for (int i=0; i<tempRep.VertexCount(); i++)
3791
+ {
3792
+ Vertex v = tempRep.GetVertex(i);
3793
+
3794
+ cVector n = table.get(tempVector.ToFloat());
3795
+
3796
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3797
+ {
3798
+ //continue;
3799
+ }
3800
+
3801
+ tempVector.set(v);
3802
+
3803
+ //cVector nBase = tableBase.get(tempVector);
3804
+
3805
+ //if (v.norm.dot(nBase) < 0.9)
3806
+ //{
3807
+ // continue;
3808
+ //}
3809
+
3810
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3811
+ {
3812
+ //continue;
3813
+ }
3814
+
3815
+ if (n != null)
3816
+ {
3817
+// if (n.dot(v.norm) < 0)
3818
+// n.sub(v.norm);
3819
+// else
3820
+// n.add(v.norm);
3821
+//
3822
+// n.normalize();
3823
+ continue;
3824
+ }
3825
+
3826
+ table.put(new cVector(tempVector), new cVector(v.norm));
3827
+ }
3828
+
3829
+ for (int i=0; i<this.VertexCount(); i++)
3830
+ {
3831
+ Vertex v = this.GetVertex(i);
3832
+
3833
+ tempVector.set(v);
3834
+
3835
+ cVector n = table.get(tempVector.ToFloat());
3836
+
3837
+ //if (n.dot(v.norm) < 0)
3838
+ if (n == null)
3839
+ continue;
3840
+
3841
+ if (v.norm == null)
3842
+ v.norm = new cVector();
3843
+
3844
+ LA.vecCopy(n, v.norm);
3845
+
3846
+ this.SetVertex(v, i);
3847
+ }
3848
+
3849
+ Grafreed.epsequal = epsequal;
3850
+ Vertex.normalmode = keepnormal;
3851
+ }
3852
+
36993853 void GenerateNormals(boolean crease)
37003854 {
37013855 boolean wastrim = trimmed;
....@@ -3712,6 +3866,28 @@
37123866 }
37133867
37143868 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3869
+ }
3870
+
3871
+ void GenerateNormalsMesh()
3872
+ {
3873
+ if (stripified)
3874
+ {
3875
+ Unstripify();
3876
+ }
3877
+
3878
+ if (trimmed)
3879
+ {
3880
+ normals = null;
3881
+ }
3882
+ else
3883
+ {
3884
+ for (int i=VertexCount(); --i>=0;)
3885
+ {
3886
+ Vertex v = GetVertex(i);
3887
+
3888
+ v.norm = null;
3889
+ }
3890
+ }
37153891 }
37163892
37173893 void GenNormalsJME()
....@@ -3836,7 +4012,7 @@
38364012 NormalGenerator ng;
38374013
38384014 if (crease)
3839
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4015
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
38404016 else
38414017 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
38424018
....@@ -3854,8 +4030,6 @@
38544030 //System.out.println("NEW = " + positions.length);
38554031 uvmap = new float[ta.getVertexCount() * 2];
38564032
3857
- colors = new float[ta.getVertexCount()]; // * 3];
3858
-
38594033 ta.getCoordinates(0, positions);
38604034 ta.getNormals(0, normals);
38614035 // ta.getColors(0, colors);
....@@ -3863,12 +4037,24 @@
38634037
38644038 System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";");
38654039
4040
+ colors = null;
4041
+// colors = new float[ta.getVertexCount()]; // * 3];
4042
+//
4043
+// for (int i=colors.length; --i>=0;)
4044
+// {
4045
+// colors[i] = 1;
4046
+// }
4047
+
38664048 triangles = new int[ta.getVertexCount()];
38674049
38684050 for (int i = 0; i < triangles.length; i++)
38694051 {
38704052 triangles[i] = i;
38714053 }
4054
+
4055
+// Untrim();
4056
+ if (!trimmed)
4057
+ MergeNormals();
38724058 }
38734059 }
38744060
....@@ -3896,17 +4082,18 @@
38964082 positions = new float[3 * ga.getVertexCount()];
38974083 normals = new float[3 * ga.getVertexCount()];
38984084 uvmap = new float[2 * ga.getVertexCount()];
3899
- colors = new float[1 * ga.getVertexCount()];
39004085
39014086 tsa.getCoordinates(0, positions);
39024087 tsa.getNormals(0, normals);
39034088 tsa.getTextureCoordinates(0, 0, uvmap);
39044089 // tsa.getColors(0, colors);
3905
-
3906
- for (int i=colors.length; --i>=0;)
3907
- {
3908
- colors[i] = 1;
3909
- }
4090
+
4091
+ colors = null;
4092
+// colors = new float[1 * ga.getVertexCount()];
4093
+// for (int i=colors.length; --i>=0;)
4094
+// {
4095
+// colors[i] = 1;
4096
+// }
39104097
39114098 int stripcount = tsa.getNumStrips();
39124099 triangles = new int[stripcount];
....@@ -3915,6 +4102,7 @@
39154102 stripified = true;
39164103 } catch (ClassCastException e)
39174104 {
4105
+ // ??? aug 2019
39184106 TriangleArray ta = (TriangleArray) ga;
39194107
39204108 positions = new float[3 * ga.getVertexCount()];
....@@ -3929,6 +4117,10 @@
39294117 triangles = new int[1];
39304118 triangles[0] = 3;
39314119 }
4120
+
4121
+ //Untrim();
4122
+ if (!trimmed)
4123
+ MergeNormals();
39324124 }
39334125
39344126 /*
....@@ -3978,6 +4170,42 @@
39784170 }
39794171
39804172 Vertex.normalmode = false;
4173
+ }
4174
+
4175
+ void MergeNormals()
4176
+ {
4177
+ assert(!trimmed);
4178
+
4179
+ boolean smooth = Grafreed.smoothmode;
4180
+ boolean link = Grafreed.linkUV;
4181
+ Grafreed.smoothmode = true;
4182
+ Grafreed.linkUV = true;
4183
+
4184
+ System.out.println("#Vertex = " + VertexCount());
4185
+ System.out.println("#Face = " + FaceCount());
4186
+
4187
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4188
+
4189
+ for (int i = 0; i < VertexCount(); i++)
4190
+ {
4191
+ Vertex v = GetVertex(i);
4192
+
4193
+ if (!table.contains(v))
4194
+ {
4195
+ table.add(v);
4196
+ }
4197
+ }
4198
+
4199
+ Grafreed.smoothmode = smooth;
4200
+ Grafreed.linkUV = link;
4201
+
4202
+// for (int i = 0; i < VertexCount(); i++)
4203
+// {
4204
+// Vertex v = GetVertex(i);
4205
+//
4206
+// table.add(v);
4207
+// }
4208
+
39814209 }
39824210
39834211 static cVector temp1 = new cVector();
....@@ -4752,16 +4980,25 @@
47524980 {
47534981 i3 = positions.length-3;
47544982 i2 = uvmap.length - 2;
4755
- new Exception().printStackTrace();
4983
+ //new Exception().printStackTrace();
47564984 }
47574985
47584986 v./*pos.*/x = positions[i3];
47594987 v./*pos.*/y = positions[i3 + 1];
47604988 v./*pos.*/z = positions[i3 + 2];
47614989
4762
- v.norm.x = normals[i3];
4763
- v.norm.y = normals[i3 + 1];
4764
- v.norm.z = normals[i3 + 2];
4990
+ if (normals == null)
4991
+ {
4992
+ v.norm.x = 0;
4993
+ v.norm.y = 0;
4994
+ v.norm.z = 0;
4995
+ }
4996
+ else
4997
+ {
4998
+ v.norm.x = normals[i3];
4999
+ v.norm.y = normals[i3 + 1];
5000
+ v.norm.z = normals[i3 + 2];
5001
+ }
47655002
47665003 v.s = uvmap[i2];
47675004 v.t = uvmap[i2 + 1];
....@@ -5476,17 +5713,27 @@
54765713
54775714 transient int nbbadfaces; // ?? = 1000000;
54785715
5479
- int ChooseTriangle()
5716
+ /*
5717
+ */
5718
+ int ChooseTriangle(boolean firstEquilateral)
54805719 {
54815720 int chosen = -1;
54825721
54835722 double minweight = 1E10;
54845723
5724
+ int step = 8; // ?
5725
+
5726
+ if (firstEquilateral)
5727
+ step = 1;
5728
+
54855729 nbbadfaces = 0;
5486
- for (int i=0; i<faces.size(); i+=8)
5730
+ for (int i=0; i<faces.size(); i+=step)
54875731 // for (int i=faces.size(); (i-=8)>=0;)
54885732 {
54895733 Face face = (Face) faces.get(i);
5734
+
5735
+ if (face.used)
5736
+ continue;
54905737
54915738 if (!Valid(face))
54925739 {
....@@ -5496,6 +5743,15 @@
54965743
54975744 if (Boundary(face))
54985745 continue;
5746
+
5747
+// if (Boundary(face.p))
5748
+// continue;
5749
+//
5750
+// if (Boundary(face.q))
5751
+// continue;
5752
+//
5753
+// if (Boundary(face.r))
5754
+// continue;
54995755
55005756 if (!ValidValence(face))
55015757 continue;
....@@ -5508,22 +5764,55 @@
55085764 //?? if (face.weight < 0)
55095765 // continue;
55105766
5511
- double K = 1; // 0.01; // .25;
5512
-
5513
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5514
-
5515
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5516
-
5517
- if (minweight > weight)
5767
+ if (firstEquilateral)
55185768 {
5519
- minweight = weight;
5769
+ if (OneFaceUsed(links.get(face.p)))
5770
+ continue;
5771
+
5772
+ if (OneFaceUsed(links.get(face.q)))
5773
+ continue;
5774
+
5775
+ if (OneFaceUsed(links.get(face.r)))
5776
+ continue;
5777
+
55205778 chosen = i;
5521
- if (minweight == 0)
5522
- break;
5779
+ break;
5780
+ }
5781
+ else
5782
+ {
5783
+ double K = 1; // 0.01; // .25;
5784
+
5785
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5786
+
5787
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5788
+
5789
+ if (minweight > weight)
5790
+ {
5791
+ minweight = weight;
5792
+ chosen = i;
5793
+ if (minweight == 0)
5794
+ break;
5795
+ }
55235796 }
55245797 }
55255798
55265799 return chosen;
5800
+ }
5801
+
5802
+ private boolean OneFaceUsed(Vector<Face> faces)
5803
+ {
5804
+ if (faces.size() != 6)
5805
+ return true;
5806
+
5807
+ for (int i=0; i<6; i+=1)
5808
+ {
5809
+ if (faces.get(i).used)
5810
+ {
5811
+ return true;
5812
+ }
5813
+ }
5814
+
5815
+ return false;
55275816 }
55285817
55295818 static boolean remove3valence = true;
....@@ -5559,7 +5848,7 @@
55595848 }
55605849 else
55615850 {
5562
- assert(links.size() == vertices.size());
5851
+ // TODO Grafreed.Assert(links.size() == vertices.size());
55635852
55645853 links.setSize(vertices.size());
55655854 for (int i=vertices.size(); --i>=0;)
....@@ -5567,6 +5856,7 @@
55675856 // linkstouched[i] = false;
55685857 if (links.get(i) == null) // ??
55695858 {
5859
+ new Exception().printStackTrace();
55705860 links.set(i, new Vector(8));
55715861 // linkstouched[i] = true;
55725862 }
....@@ -5577,6 +5867,8 @@
55775867 }
55785868 }
55795869
5870
+ boolean once = false;
5871
+
55805872 for (int i=faces.size(); --i>=0;)
55815873 {
55825874 Face face = (Face) faces.get(i);
....@@ -5588,6 +5880,9 @@
55885880 //if (linkstouched[face.r])
55895881 links.get(face.r).add(face);
55905882
5883
+ if (face.used)
5884
+ once = true;
5885
+
55915886 face.good = 1;
55925887 face.boundary = -1;
55935888 }
....@@ -6953,6 +7248,10 @@
69537248 return (face.boundary = 1) == 1;
69547249 }
69557250
7251
+ // June 2019
7252
+ if (true)
7253
+ return (face.boundary = 0) == 1;
7254
+
69567255 // reverse triangle test
69577256 q1.set(p);
69587257 q2.set(q);
....@@ -7402,7 +7701,7 @@
74027701 //InitWeights();
74037702 }
74047703
7405
- int chosen = ChooseTriangle(); // Best is slow and not really better
7704
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
74067705
74077706 if (chosen == -1)
74087707 {
....@@ -7416,7 +7715,7 @@
74167715 //remove3valence = false;
74177716 // InitWeights();
74187717
7419
- chosen = ChooseTriangle();
7718
+ chosen = ChooseTriangle(true);
74207719 }
74217720 }
74227721
....@@ -7692,7 +7991,7 @@
76927991
76937992 // boolean lock;
76947993
7695
- void SplitInTwo(boolean reduction34, boolean onlyone)
7994
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76967995 {
76977996 if (stripified)
76987997 {
....@@ -7729,12 +8028,12 @@
77298028 {
77308029 System.err.println("EXCEPTION CAUGHT");
77318030 e.printStackTrace();
7732
- return;
8031
+ return false;
77338032 } catch (Error e)
77348033 {
77358034 System.err.println("ERROR CAUGHT");
77368035 e.printStackTrace();
7737
- return;
8036
+ return false;
77388037 }
77398038
77408039 System.out.println("# faces = " + faces.size());
....@@ -7744,6 +8043,7 @@
77448043 {
77458044 Face face = (Face) faces.get(i);
77468045
8046
+ face.used = false;
77478047 face.nbiterations = 1;
77488048 face.weight = -1;
77498049 face.boundary = -1;
....@@ -7795,6 +8095,11 @@
77958095 nbbadfaces = faces.size();
77968096 //remove3valence = true;
77978097
8098
+ int count = 2;
8099
+
8100
+ if (onlyone)
8101
+ count = 1;
8102
+
77988103 firstpass = true;
77998104
78008105 int n = faces.size();
....@@ -7810,8 +8115,9 @@
78108115 System.out.print('.');
78118116 }
78128117 System.out.println();
8118
+ boolean atleastone = false;
78138119 int i = 0;
7814
- while (reduction34 || faces.size() > n/2)
8120
+ while (true) // reduction34 || faces.size() > n/2)
78158121 {
78168122 if (i++%100 == 0)
78178123 {
....@@ -7833,6 +8139,8 @@
78338139 {
78348140 if (!RemoveOneTriangle())
78358141 break;
8142
+
8143
+ atleastone = true;
78368144 }
78378145 // if (iterationcount == 0)
78388146 // break;
....@@ -7843,8 +8151,8 @@
78438151 break;
78448152 }
78458153 firstpass = false;
7846
- if (onlyone)
7847
- break; // one triangle only
8154
+// if (--count<0 && !reduction34)
8155
+// break; // one triangle only
78488156 }
78498157
78508158 InitLinks(false); // for further display
....@@ -7860,6 +8168,8 @@
78608168 Trim(true,false,false,false,false);
78618169
78628170 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8171
+
8172
+ return atleastone;
78638173 }
78648174
78658175 void UpdateIndices(Face face, Face minface)
....@@ -7872,18 +8182,21 @@
78728182 face.p = minface.p;
78738183 //if (leafweights)
78748184 face.good = 0; // false;
8185
+ face.used = true;
78758186 }
78768187 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
78778188 {
78788189 face.q = minface.p;
78798190 //if (leafweights)
78808191 face.good = 0; // false;
8192
+ face.used = true;
78818193 }
78828194 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
78838195 {
78848196 face.r = minface.p;
78858197 //if (leafweights)
78868198 face.good = 0; // false;
8199
+ face.used = true;
78878200 }
78888201
78898202 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7943,50 +8256,50 @@
79438256 if (v == 2)
79448257 vert = minface.r;
79458258 // Face face = (Face) faces.get(i);
7946
- Vector<Face> vertfaces = links.get(vert);
7947
- for (int i=vertfaces.size(); --i>=0;)
7948
- {
7949
- Face face = (Face) vertfaces.get(i);
7950
-
7951
- // if (face.weight == 10000)
7952
- // continue;
7953
-
7954
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7955
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7956
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8259
+ Vector<Face> vertfaces = links.get(vert);
8260
+ for (int i=vertfaces.size(); --i>=0;)
79578261 {
7958
- if (!leafweights)
8262
+ Face face = (Face) vertfaces.get(i);
8263
+
8264
+ // if (face.weight == 10000)
8265
+ // continue;
8266
+
8267
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8268
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8269
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
79598270 {
7960
-// if(minfaceweight <= 0)
7961
-// assert(minfaceweight > 0);
7962
-//
7963
-// //FaceWeight(face);
7964
-// if(face.weight < 0)
7965
-// assert(face.weight >= 0);
7966
-
7967
- face.weight += minfaceweight;
7968
-
7969
-// if (face.weight >= 10000)
7970
-// assert(face.weight < 10000);
8271
+ if (!leafweights)
8272
+ {
8273
+ // if(minfaceweight <= 0)
8274
+ // assert(minfaceweight > 0);
8275
+ //
8276
+ // //FaceWeight(face);
8277
+ // if(face.weight < 0)
8278
+ // assert(face.weight >= 0);
8279
+
8280
+ face.weight += minfaceweight;
8281
+
8282
+ // if (face.weight >= 10000)
8283
+ // assert(face.weight < 10000);
8284
+ }
8285
+ else
8286
+ face.weight = -1;
8287
+
8288
+ face.nbiterations += 1;
8289
+ face.boundary = -1;
8290
+
8291
+ Vertex p = (Vertex)vertices.get(face.p);
8292
+ Vertex q = (Vertex)vertices.get(face.q);
8293
+ Vertex r = (Vertex)vertices.get(face.r);
8294
+
8295
+ p.boundary = -1;
8296
+ q.boundary = -1;
8297
+ r.boundary = -1;
79718298 }
79728299 else
7973
- face.weight = -1;
7974
-
7975
- face.nbiterations += 1;
7976
- face.boundary = -1;
7977
-
7978
- Vertex p = (Vertex)vertices.get(face.p);
7979
- Vertex q = (Vertex)vertices.get(face.q);
7980
- Vertex r = (Vertex)vertices.get(face.r);
7981
-
7982
- p.boundary = -1;
7983
- q.boundary = -1;
7984
- r.boundary = -1;
8300
+ assert(false);
79858301 }
7986
- else
7987
- assert(false);
79888302 }
7989
- }
79908303
79918304 // TouchVertex(minface.p);
79928305 // TouchVertex(minface.q);
....@@ -8187,6 +8500,7 @@
81878500 for (int i=vertfaces.size(); --i>=0;)
81888501 {
81898502 Face face = (Face) vertfaces.get(i);
8503
+ face.used = true;
81908504 face.good = 0; // false;
81918505 if (leafweights)
81928506 face.weight = -1;
....@@ -8233,7 +8547,7 @@
82338547 if (!trimmed)
82348548 return;
82358549
8236
- GrafreeD.linkUV = false;
8550
+ Grafreed.linkUV = false;
82378551
82388552 try
82398553 {
....@@ -8465,7 +8779,8 @@
84658779 int[] startvertices;
84668780 float[] averagepoints;
84678781 float[] extremepoints;
8468
- float[] supportsizes; // distance of closest point
8782
+ float[] supportminsize; // distance of closest point
8783
+ float[] supportmaxsize; // distance of fartest point
84698784
84708785 transient Hashtable vertextable;
84718786 /*transient*/ private Vertex[] verticesCopy;