1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
|
package com.sun.opengl.impl.nurbs;
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/**
* Class working with curves and surfaces
* @author Tomas Hrasky
*
*/
class Subdivider {
/**
* Cull type
*/
public static final int CULL_TRIVIAL_REJECT = 0;
/**
* Cull type
*/
public static final int CULL_ACCEPT = 1;
/**
* Maximum trimming arcs
*/
private static final int MAXARCS = 10;
/**
* Linked list of Quilts
*/
Quilt qlist;
/**
* Object holding rendering honts information
*/
private Renderhints renderhints;
/**
* Backend object
*/
private Backend backend;
/**
* Number of subdivisions
*/
private int subdivisions;
/**
* U step when using domain distance sampling
*/
private float domain_distance_u_rate;
/**
* Use domain distance sampling
*/
private int is_domain_distance_sampling;
/**
* Initial class holding trimming arcs
*/
private Bin initialbin;
/**
* Not used
*/
private boolean showDegenerate;
/**
* Is triming arc type bezier arc
*/
private boolean isArcTypeBezier;
/**
* Breakpoints in v direction
*/
private Flist tpbrkpts;
/**
* Breakpoints in u direction
*/
private Flist spbrkpts;
/**
* Unused
*/
private int s_index;
/**
* Head of linked list of trimming arcs
*/
private Arc pjarc;
/**
* Class tesselating trimming arcs
*/
private ArcTesselator arctesselator;
/**
* Unused
*/
private int t_index;
/**
* Breakpoints
*/
private Flist smbrkpts;
/**
* Not used
*/
private float[] stepsizes;
/**
* Domain distance in V direction
*/
private float domain_distance_v_rate;
/**
* Initializes quilt list
*/
public void beginQuilts() {
// DONE
qlist = null;
renderhints = new Renderhints();
backend = new Backend();
initialbin = new Bin();
arctesselator = new ArcTesselator();
}
/**
* Adds quilt to linked list
* @param quilt added quilt
*/
public void addQuilt(Quilt quilt) {
// DONE
if (qlist == null)
qlist = quilt;
else {
quilt.next = qlist;
qlist = quilt;
}
}
/**
* Empty method
*/
public void endQuilts() {
// DONE
}
/**
* Draws a surface
*/
public void drawSurfaces() {
renderhints.init();
if (qlist == null) {
// System.out.println("qlist is null");
return;
}
for (Quilt q = qlist; q != null; q = q.next) {
if (q.isCulled() == CULL_TRIVIAL_REJECT) {
freejarcs(initialbin);
return;
}
}
float[] from = new float[2];
float[] to = new float[2];
spbrkpts = new Flist();
tpbrkpts = new Flist();
qlist.getRange(from, to, spbrkpts, tpbrkpts);
boolean optimize = (is_domain_distance_sampling > 0 && (renderhints.display_method != NurbsConsts.N_OUTLINE_PATCH));
// TODO decide whether to optimize (when there is gluNurbsProperty implemented)
optimize = true;
if (!initialbin.isnonempty()) {
if (!optimize) {
makeBorderTrim(from, to);
}
} else {
float[] rate = new float[2];
qlist.findRates(spbrkpts, tpbrkpts, rate);
// System.out.println("subdivider.drawsurfaces decompose");
}
backend.bgnsurf(renderhints.wiretris, renderhints.wirequads);
// TODO partition test
if (!initialbin.isnonempty() && optimize) {
int i, j;
int num_u_steps;
int num_v_steps;
for (i = spbrkpts.start; i < spbrkpts.end - 1; i++) {
for (j = tpbrkpts.start; j < tpbrkpts.end - 1; j++) {
float[] pta = new float[2];
float[] ptb = new float[2];
pta[0] = spbrkpts.pts[i];
ptb[0] = spbrkpts.pts[i + 1];
pta[1] = tpbrkpts.pts[j];
ptb[1] = tpbrkpts.pts[j + 1];
qlist.downloadAll(pta, ptb, backend);
num_u_steps = (int) (domain_distance_u_rate * (ptb[0] - pta[0]));
num_v_steps = (int) (domain_distance_v_rate * (ptb[1] - pta[1]));
if (num_u_steps <= 0)
num_u_steps = 1;
if (num_v_steps <= 0)
num_v_steps = 1;
backend.surfgrid(pta[0], ptb[0], num_u_steps, ptb[1],
pta[1], num_v_steps);
backend.surfmesh(0, 0, num_u_steps, num_v_steps);
}
}
} else
subdivideInS(initialbin);
backend.endsurf();
}
/**
* Empty method
* @param initialbin2
*/
private void freejarcs(Bin initialbin2) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.freejarcs");
}
/**
* Subdivide in U direction
* @param source Trimming arcs source
*/
private void subdivideInS(Bin source) {
// DONE
if (renderhints.display_method == NurbsConsts.N_OUTLINE_PARAM) {
outline(source);
freejarcs(source);
} else {
setArcTypeBezier();
setNonDegenerate();
splitInS(source, spbrkpts.start, spbrkpts.end);
}
}
/**
* Split in U direction
* @param source Trimming arcs source
* @param start breakpoints start
* @param end breakpoints end
*/
private void splitInS(Bin source, int start, int end) {
// DONE
if (source.isnonempty()) {
if (start != end) {
int i = start + (end - start) / 2;
Bin left = new Bin();
Bin right = new Bin();
split(source, left, right, 0, spbrkpts.pts[i]);
splitInS(left, start, i);
splitInS(right, i + 1, end);
} else {
if (start == spbrkpts.start || start == spbrkpts.end) {
freejarcs(source);
} else if (renderhints.display_method == NurbsConsts.N_OUTLINE_PARAM_S) {
outline(source);
freejarcs(source);
} else {
setArcTypeBezier();
setNonDegenerate();
s_index = start;
splitInT(source, tpbrkpts.start, tpbrkpts.end);
}
}
} else{
// System.out.println("Source is empty - subdivider.splitins");
}
}
/**
* Split in V direction
* @param source
* @param start
* @param end
*/
private void splitInT(Bin source, int start, int end) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.splitint");
if (source.isnonempty()) {
if (start != end) {
int i = start + (end - start) / 2;
Bin left = new Bin();
Bin right = new Bin();
split(source, left, right, 1, tpbrkpts.pts[i + 1]);
splitInT(left, start, i);
splitInT(right, i + 1, end);
} else {
if (start == tpbrkpts.start || start == tpbrkpts.end) {
freejarcs(source);
} else if (renderhints.display_method == NurbsConsts.N_OUTLINE_PARAM_ST) {
outline(source);
freejarcs(source);
} else {
t_index = start;
setArcTypeBezier();
setDegenerate();
float[] pta = new float[2];
float[] ptb = new float[2];
pta[0] = spbrkpts.pts[s_index - 1];
pta[1] = tpbrkpts.pts[t_index - 1];
ptb[0] = spbrkpts.pts[s_index];
ptb[1] = tpbrkpts.pts[t_index];
qlist.downloadAll(pta, ptb, backend);
Patchlist patchlist = new Patchlist(qlist, pta, ptb);
samplingSplit(source, patchlist,
renderhints.maxsubdivisions, 0);
setNonDegenerate();
setArcTypeBezier();
}
}
}
}
/**
* Sample
* @param source
* @param patchlist
* @param subdivisions
* @param param
*/
private void samplingSplit(Bin source, Patchlist patchlist,
int subdivisions, int param) {
// DONE
if (!source.isnonempty())
return;
if (patchlist.cullCheck() == CULL_TRIVIAL_REJECT) {
freejarcs(source);
return;
}
patchlist.getstepsize();
if (renderhints.display_method == NurbsConsts.N_OUTLINE_PATCH) {
tesselation(source, patchlist);
outline(source);
freejarcs(source);
return;
}
tesselation(source, patchlist);
if (patchlist.needsSamplingSubdivision() && subdivisions > 0) {
if (!patchlist.needsSubdivision(0)) {
param = 1;
} else if (patchlist.needsSubdivision(1))
param = 0;
else
param = 1 - param;
Bin left = new Bin();
Bin right = new Bin();
float mid = (float) ((patchlist.pspec[param].range[0] + patchlist.pspec[param].range[1]) * .5);
split(source, left, right, param, mid);
Patchlist subpatchlist = new Patchlist(patchlist, param, mid);
samplingSplit(left, subpatchlist, subdivisions - 1, param);
samplingSplit(right, subpatchlist, subdivisions - 1, param);
} else {
setArcTypePwl();
setDegenerate();
nonSamplingSplit(source, patchlist, subdivisions, param);
setDegenerate();
setArcTypeBezier();
}
}
/**
* Not used
* @param source
* @param patchlist
* @param subdivisions
* @param param
*/
private void nonSamplingSplit(Bin source, Patchlist patchlist,
int subdivisions, int param) {
// DONE
if (patchlist.needsNonSamplingSubdivision() && subdivisions > 0) {
param = 1 - param;
Bin left = new Bin();
Bin right = new Bin();
float mid = (float) ((patchlist.pspec[param].range[0] + patchlist.pspec[param].range[1]) * .5);
split(source, left, right, param, mid);
Patchlist subpatchlist = new Patchlist(patchlist, param, mid);
if (left.isnonempty()) {
if (subpatchlist.cullCheck() == CULL_TRIVIAL_REJECT)
freejarcs(left);
else
nonSamplingSplit(left, subpatchlist, subdivisions - 1,
param);
}
if (right.isnonempty()) {
if (patchlist.cullCheck() == CULL_TRIVIAL_REJECT)
freejarcs(right);
else
nonSamplingSplit(right, subpatchlist, subdivisions - 1,
param);
}
} else {
patchlist.bbox();
backend.patch(patchlist.pspec[0].range[0],
patchlist.pspec[0].range[1], patchlist.pspec[1].range[0],
patchlist.pspec[1].range[1]);
if (renderhints.display_method == NurbsConsts.N_OUTLINE_SUBDIV) {
outline(source);
freejarcs(source);
} else {
setArcTypePwl();
setDegenerate();
findIrregularS(source);
monosplitInS(source, smbrkpts.start, smbrkpts.end);
}
}
}
/**
* Not used
* @param source
* @param start
* @param end
*/
private void monosplitInS(Bin source, int start, int end) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.monosplitins");
}
/**
* Not used
* @param source
*/
private void findIrregularS(Bin source) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.findIrregularS");
}
/**
* Not used
*/
private void setArcTypePwl() {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.setarctypepwl");
}
/**
* Not used
* @param source
* @param patchlist
*/
private void tesselation(Bin source, Patchlist patchlist) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.tesselation");
}
/**
* Not used
*/
private void setDegenerate() {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.setdegenerate");
}
/**
* Not used
* @param bin
* @param left
* @param right
* @param param
* @param value
*/
private void split(Bin bin, Bin left, Bin right, int param, float value) {
// DONE
Bin intersections = new Bin();
Bin unknown = new Bin();
partition(bin, left, intersections, right, unknown, param, value);
int count = intersections.numarcs();
// TODO jumpbuffer ??
if (count % 2 == 0) {
Arc[] arclist = new Arc[MAXARCS];
CArrayOfArcs list;
if (count >= MAXARCS) {
list = new CArrayOfArcs(new Arc[count]);
} else {
list = new CArrayOfArcs(arclist);
}
CArrayOfArcs last, lptr;
Arc jarc;
for (last = new CArrayOfArcs(list); (jarc = intersections
.removearc()) != null; last.pp())
last.set(jarc);
if (param == 0) {// sort into incrasing t order
ArcSdirSorter sorter = new ArcSdirSorter(this);
sorter.qsort(list, count);
for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last
.getPointer(); lptr.raisePointerBy(2))
check_s(lptr.get(), lptr.getRelative(1));
for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last
.getPointer(); lptr.raisePointerBy(2))
join_s(left, right, lptr.get(), lptr.getRelative(1));
for (lptr = new CArrayOfArcs(list); lptr.getPointer() != last
.getPointer(); lptr.pp()) {
if (lptr.get().head()[0] <= value
&& lptr.get().tail()[0] <= value)
left.addarc(lptr.get());
else
right.addarc(lptr.get());
}
} else {// sort into decreasing s order
ArcTdirSorter sorter = new ArcTdirSorter(this);
sorter.qsort(list, count);
for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last
.getPointer(); lptr.raisePointerBy(2))
check_t(lptr.get(), lptr.getRelative(1));
for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last
.getPointer(); lptr.raisePointerBy(2))
join_t(left, right, lptr.get(), lptr.getRelative(1));
for (lptr = new CArrayOfArcs(list); lptr.getPointer() != last
.getPointer(); lptr.raisePointerBy(2)) {
if (lptr.get().head()[0] <= value
&& lptr.get().tail()[0] <= value)
left.addarc(lptr.get());
else
right.addarc(lptr.get());
}
}
unknown.adopt();
}
}
/**
* Not used
* @param left
* @param right
* @param arc
* @param relative
*/
private void join_t(Bin left, Bin right, Arc arc, Arc relative) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.join_t");
}
/**
* Not used
* @param arc
* @param relative
*/
private void check_t(Arc arc, Arc relative) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.check_t");
}
/**
* Not used
* @param left
* @param right
* @param jarc1
* @param jarc2
*/
private void join_s(Bin left, Bin right, Arc jarc1, Arc jarc2) {
// DONE
if (!jarc1.getitail())
jarc1 = jarc1.next;
if (!jarc2.getitail())
jarc2 = jarc2.next;
float s = jarc1.tail()[0];
float t1 = jarc1.tail()[1];
float t2 = jarc2.tail()[1];
if (t1 == t2) {
simplelink(jarc1, jarc2);
} else {
Arc newright = new Arc(Arc.ARC_RIGHT);
Arc newleft = new Arc(Arc.ARC_LEFT);
if (isBezierArcType()) {
arctesselator.bezier(newright, s, s, t1, t2);
arctesselator.bezier(newleft, s, s, t2, t1);
} else {
arctesselator.pwl_right(newright, s, t1, t2, stepsizes[0]);
arctesselator.pwl_left(newright, s, t2, t1, stepsizes[2]);
}
link(jarc1, jarc2, newright, newleft);
left.addarc(newright);
right.addarc(newleft);
}
}
/**
* Not used
* @param jarc1
* @param jarc2
* @param newright
* @param newleft
*/
private void link(Arc jarc1, Arc jarc2, Arc newright, Arc newleft) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.link");
}
/**
* Not used
* @return true
*/
private boolean isBezierArcType() {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.isbezierarc");
return true;
}
/**
* Not used
* @param jarc1
* @param jarc2
*/
private void simplelink(Arc jarc1, Arc jarc2) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.simplelink");
}
/**
* Not used
* @param arc
* @param relative
*/
private void check_s(Arc arc, Arc relative) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.check_s");
}
/**
* Not used
* @param bin
* @param left
* @param intersections
* @param right
* @param unknown
* @param param
* @param value
*/
private void partition(Bin bin, Bin left, Bin intersections, Bin right,
Bin unknown, int param, float value) {
Bin headonleft = new Bin();
Bin headonright = new Bin();
Bin tailonleft = new Bin();
Bin tailonright = new Bin();
for (Arc jarc = bin.removearc(); jarc != null; jarc = bin.removearc()) {
float tdiff = jarc.tail()[param] - value;
float hdiff = jarc.head()[param] - value;
if (tdiff > 0) {
if (hdiff > 0) {
right.addarc(jarc);
} else if (hdiff == 0) {
tailonright.addarc(jarc);
} else {
Arc jtemp;
switch (arc_split(jarc, param, value, 0)) {
case 2:
tailonright.addarc(jarc);
headonleft.addarc(jarc.next);
break;
// TODO rest cases
default:
System.out
.println("TODO subdivider.partition rest cases");
break;
}
}
} else if (tdiff == 0) {
if (hdiff > 0) {
headonright.addarc(jarc);
} else if (hdiff == 0) {
unknown.addarc(jarc);
} else {
headonright.addarc(jarc);
}
} else {
if (hdiff > 0) {
// TODO rest
// System.out.println("TODO subdivider.partition rest of else");
} else if (hdiff == 0) {
tailonleft.addarc(jarc);
} else {
left.addarc(jarc);
}
}
}
if (param == 0) {
classify_headonleft_s(headonleft, intersections, left, value);
classify_tailonleft_s(tailonleft, intersections, left, value);
classify_headonright_s(headonright, intersections, right, value);
classify_tailonright_s(tailonright, intersections, right, value);
} else {
classify_headonleft_t(headonleft, intersections, left, value);
classify_tailonleft_t(tailonleft, intersections, left, value);
classify_headonright_t(headonright, intersections, right, value);
classify_tailonright_t(tailonright, intersections, right, value);
}
}
/**
* Not used
* @param tailonright
* @param intersections
* @param right
* @param value
*/
private void classify_tailonright_t(Bin tailonright, Bin intersections,
Bin right, float value) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.classify_tailonright_t");
}
/**
* Not used
* @param bin
* @param in
* @param out
* @param val
*/
private void classify_tailonleft_s(Bin bin, Bin in, Bin out, float val) {
// DONE
Arc j;
while ((j = bin.removearc()) != null) {
j.clearitail();
float diff = j.next.head()[0] - val;
if (diff > 0) {
in.addarc(j);
} else if (diff < 0) {
if (ccwTurn_sl(j, j.next))
out.addarc(j);
else
in.addarc(j);
} else {
if (j.next.tail()[1] > j.next.head()[1])
in.addarc(j);
else
out.addarc(j);
}
}
}
/**
* Not used
* @param bin
* @param in
* @param out
* @param val
*/
private void classify_headonright_s(Bin bin, Bin in, Bin out, float val) {
// DONE
Arc j;
while ((j = bin.removearc()) != null) {
j.setitail();
float diff = j.prev.tail()[0] - val;
if (diff > 0) {
if (ccwTurn_sr(j.prev, j))
out.addarc(j);
else
in.addarc(j);
} else if (diff < 0) {
out.addarc(j);
} else {
if (j.prev.tail()[1] > j.prev.head()[1])
out.addarc(j);
else
in.addarc(j);
}
}
}
/**
* Not used
* @param prev
* @param j
* @return false
*/
private boolean ccwTurn_sr(Arc prev, Arc j) {
// TODO Auto-generated method stub
// System.out.println("TODO ccwTurn_sr");
return false;
}
/**
* Not used
* @param headonright
* @param intersections
* @param right
* @param value
*/
private void classify_headonright_t(Bin headonright, Bin intersections,
Bin right, float value) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.classify_headonright_t");
}
/**
* Not used
* @param tailonleft
* @param intersections
* @param left
* @param value
*/
private void classify_tailonleft_t(Bin tailonleft, Bin intersections,
Bin left, float value) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.classify_tailonleft_t");
}
/**
* Not used
* @param bin
* @param in
* @param out
* @param val
*/
private void classify_headonleft_t(Bin bin, Bin in, Bin out, float val) {
// DONE
Arc j;
while ((j = bin.removearc()) != null) {
j.setitail();
float diff = j.prev.tail()[1] - val;
if (diff > 0) {
out.addarc(j);
} else if (diff < 0) {
if (ccwTurn_tl(j.prev, j))
out.addarc(j);
else
in.addarc(j);
} else {
if (j.prev.tail()[0] > j.prev.head()[0])
out.addarc(j);
else
in.addarc(j);
}
}
}
/**
* Not used
* @param prev
* @param j
* @return false
*/
private boolean ccwTurn_tl(Arc prev, Arc j) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.ccwTurn_tl");
return false;
}
/**
* Not used
* @param bin
* @param in
* @param out
* @param val
*/
private void classify_tailonright_s(Bin bin, Bin in, Bin out, float val) {
// DONE
Arc j;
while ((j = bin.removearc()) != null) {
j.clearitail();
float diff = j.next.head()[0] - val;
if (diff > 0) {
if (ccwTurn_sr(j, j.next))
out.addarc(j);
else
in.addarc(j);
} else if (diff < 0) {
in.addarc(j);
} else {
if (j.next.tail()[1] > j.next.head()[1])
out.addarc(j);
else
in.addarc(j);
}
}
}
/**
* Not used
* @param bin
* @param in
* @param out
* @param val
*/
private void classify_headonleft_s(Bin bin, Bin in, Bin out, float val) {
// DONE
Arc j;
while ((j = bin.removearc()) != null) {
j.setitail();
float diff = j.prev.tail()[0] - val;
if (diff > 0) {
out.addarc(j);
} else if (diff < 0) {
if (ccwTurn_sl(j.prev, j))
out.addarc(j);
else
in.addarc(j);
} else {
if (j.prev.tail()[1] > j.prev.head()[1])
in.addarc(j);
else
out.addarc(j);
}
}
}
/**
* Not used
* @param prev
* @param j
* @return false
*/
private boolean ccwTurn_sl(Arc prev, Arc j) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.ccwTurn_sl");
return false;
}
/**
* Not used
* @param jarc
* @param param
* @param value
* @param i
* @return 0
*/
private int arc_split(Arc jarc, int param, float value, int i) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.arc_split");
return 0;
}
/**
* Not used
*/
private void setNonDegenerate() {
// DONE
this.showDegenerate = false;
}
/**
* sets trimming arc default type to bezier
*/
private void setArcTypeBezier() {
// DONE
isArcTypeBezier = true;
}
/**
* Not used
* @param source
*/
private void outline(Bin source) {
// TODO Auto-generated method stub
// System.out.println("TODO subdivider.outline");
}
/**
* Makes default trim along surface borders
* @param from range beginnings
* @param to range ends
*/
private void makeBorderTrim(float[] from, float[] to) {
// DONE
float smin = from[0];
float smax = to[0];
float tmin = from[1];
float tmax = to[1];
pjarc = null;
Arc jarc = null;
jarc = new Arc(Arc.ARC_BOTTOM);
arctesselator.bezier(jarc, smin, smax, tmin, tmin);
initialbin.addarc(jarc);
pjarc = jarc.append(pjarc);
jarc = new Arc(Arc.ARC_RIGHT);
arctesselator.bezier(jarc, smax, smax, tmin, tmax);
initialbin.addarc(jarc);
pjarc = jarc.append(pjarc);
jarc = new Arc(Arc.ARC_TOP);
arctesselator.bezier(jarc, smax, smin, tmax, tmax);
initialbin.addarc(jarc);
pjarc = jarc.append(pjarc);
jarc = new Arc(Arc.ARC_LEFT);
arctesselator.bezier(jarc, smin, smin, tmax, tmin);
initialbin.addarc(jarc);
jarc = jarc.append(pjarc);
// assert (jarc.check() == true);
}
/**
* Draws NURBS curve
*/
public void drawCurves() {
// DONE
float[] from = new float[1];
float[] to = new float[1];
Flist bpts = new Flist();
qlist.getRange(from, to, bpts);
renderhints.init();
backend.bgncurv();
for (int i = bpts.start; i < bpts.end - 1; i++) {
float[] pta = new float[1];
float[] ptb = new float[1];
pta[0] = bpts.pts[i];
ptb[0] = bpts.pts[i + 1];
qlist.downloadAll(pta, ptb, backend);
Curvelist curvelist = new Curvelist(qlist, pta, ptb);
samplingSplit(curvelist, renderhints.maxsubdivisions);
}
backend.endcurv();
}
/**
* Samples a curve in case of need, or sends curve to backend
* @param curvelist list of curves
* @param maxsubdivisions maximum number of subdivisions
*/
private void samplingSplit(Curvelist curvelist, int maxsubdivisions) {
if (curvelist.cullCheck() == CULL_TRIVIAL_REJECT)
return;
curvelist.getstepsize();
if (curvelist.needsSamplingSubdivision() && (subdivisions > 0)) {
// TODO kód
// System.out.println("TODO subdivider-needsSamplingSubdivision");
} else {
int nu = (int) (1 + curvelist.range[2] / curvelist.stepsize);
backend.curvgrid(curvelist.range[0], curvelist.range[1], nu);
backend.curvmesh(0, nu);
}
}
/**
* Sets new domain_distance_u_rate value
* @param d new domain_distance_u_rate value
*/
public void set_domain_distance_u_rate(double d) {
// DONE
domain_distance_u_rate = (float) d;
}
/**
* Sets new domain_distance_v_rate value
* @param d new domain_distance_v_rate value
*/
public void set_domain_distance_v_rate(double d) {
// DONE
domain_distance_v_rate = (float) d;
}
/**
* Sets new is_domain_distance_sampling value
* @param i new is_domain_distance_sampling value
*/
public void set_is_domain_distance_sampling(int i) {
// DONE
this.is_domain_distance_sampling = i;
}
}
|