-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathISurfaceCreator.java
More file actions
1523 lines (1317 loc) · 54.7 KB
/
ISurfaceCreator.java
File metadata and controls
1523 lines (1317 loc) · 54.7 KB
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
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/
package igeo;
import java.util.ArrayList;
/**
class with collection of static methods to create various type of surface.
@author Satoru Sugihara
*/
public class ISurfaceCreator{
/** state variable of a server to store surfaces created in the methods in this class */
public static IServerI server = null;
/** set a server to store surfaces created in the methods in this class */
public static void server(IServerI s){ server=s; }
public static IServerI server(){ return server; }
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
double[] uknots, double[] vknots,
double ustart, double uend, double vstart, double vend){
return new ISurface(server,cpts,udegree,vdegree,uknots,vknots,ustart,uend,vstart,vend);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
double[] uknots, double[] vknots){
return new ISurface(server,cpts,udegree,vdegree,uknots,vknots);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree){
return new ISurface(server,cpts,udegree,vdegree);
}
public static ISurface surface(IVecI[][] cpts){ return new ISurface(server,cpts); }
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
boolean closeU, boolean closeV){
return new ISurface(server,cpts,udegree,vdegree,closeU,closeV);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
boolean closeU, double[] vk){
return new ISurface(server,cpts,udegree,vdegree,closeU,vk);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
double[] uk, boolean closeV){
return new ISurface(server,cpts,udegree,vdegree,uk,closeV);
}
public static ISurface surface(IVecI[][] cpts, boolean closeU, boolean closeV){
return new ISurface(server,cpts,closeU,closeV);
}
public static ISurface surface(IVecI pt1, IVecI pt2, IVecI pt3, IVecI pt4){
return new ISurface(server,pt1,pt2,pt3,pt4);
}
public static ISurface surface(IVecI pt1, IVecI pt2, IVecI pt3){
return new ISurface(server,pt1,pt2,pt3);
}
public static ISurface surface(double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3,
double x4, double y4, double z4){
return new ISurface(server,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4);
}
public static ISurface surface(double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3){
return new ISurface(server,x1,y1,z1,x2,y2,z2,x3,y3,z3);
}
public static ISurface surface(double[][][] xyzValues){
return new ISurface(server, xyzValues);
}
public static ISurface surface(double[][][] xyzValues, int udeg, int vdeg){
return new ISurface(server, xyzValues, udeg, vdeg);
}
public static ISurface surface(double[][][] xyzValues, boolean closeU, boolean closeV){
return new ISurface(server, xyzValues, closeU, closeV);
}
public static ISurface surface(double[][][] xyzValues, int udeg, int vdeg, boolean closeU, boolean closeV){
return new ISurface(server, xyzValues, udeg, vdeg, closeU, closeV);
}
public static ISurface surface(ISurfaceI srf){ return new ISurface(server, srf); }
// planar surface with trim
public static ISurface surface(ICurveI trimCurve){ return new ISurface(server, trimCurve); }
public static ISurface surface(ICurveI trimCurve, ICurveI[] innerTrimCurves){
return new ISurface(server, trimCurve, innerTrimCurves);
}
public static ISurface surface(ICurveI trimCurve, ICurveI innerTrimCurve){
return new ISurface(server, trimCurve, innerTrimCurve);
}
public static ISurface surface(ICurveI[] trimCurves){ return new ISurface(server, trimCurves); }
public static ISurface surface(IVecI[] trimCrvPts){ return new ISurface(server, trimCrvPts); }
public static ISurface surface(IVecI[] trimCrvPts, int trimCrvDeg){ return new ISurface(server, trimCrvPts, trimCrvDeg); }
public static ISurface surface(IVecI[] trimCrvPts, int trimCrvDeg, double[] trimCrvKnots){ return new ISurface(server, trimCrvPts, trimCrvDeg, trimCrvKnots); }
/**
box
*/
public static IBox box(double x, double y, double z, double size){
return new IBox(x,y,z,size);
}
public static IBox box(double x, double y, double z, double width, double height, double depth){
return new IBox(x,y,z,width,height,depth);
}
public static IBox box(IVecI origin, double size){ return new IBox(origin,size); }
public static IBox box(IVecI origin, double width, double height, double depth){
return new IBox(origin,width,height,depth);
}
public static IBox box(IVecI origin, IVecI xvec, IVecI yvec, IVecI zvec){
return new IBox(origin,xvec,yvec,zvec);
}
public static IBox box(IVecI pt1, IVecI pt2, IVecI pt3, IVecI pt4,
IVecI pt5, IVecI pt6, IVecI pt7, IVecI pt8 ){
return new IBox(pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8);
}
public static IBox box(IVecI[][][] corners){ return new IBox(corners); }
/**
sphere
*/
public static ISphere sphere(double x, double y, double z, double radius){
return new ISphere(server, x, y, z, radius);
}
public static ISphere sphere(IVecI center, double radius){
return new ISphere(server, center, radius);
}
public static ISphere sphere(IVecI center, IDoubleI radius){
return new ISphere(server, center, radius);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, double radius){
return new ICylinder(server, pt1, pt2, radius);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, IDoubleI radius){
return new ICylinder(server, pt1, pt2, radius);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, double radius1, double radius2){
return new ICylinder(server, pt1, pt2, radius1, radius2);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, IDoubleI radius1, IDoubleI radius2){
return new ICylinder(server, pt1, pt2, radius1, radius2);
}
public static ICylinder cone(IVecI pt1, IVecI pt2, double radius){
return new ICylinder(server, pt1, pt2, radius, 0);
}
public static ICylinder cone(IVecI pt1, IVecI pt2, IDoubleI radius){
return new ICylinder(server, pt1, pt2, radius, new IDouble(0));
}
public static ISurface plane(IVecI corner, double xwidth, double yheight){
return plane(corner, new IVec(xwidth,0,0), new IVec(0,yheight,0));
}
public static ISurface plane(IVecI corner, IVecI widthVec, IVecI heightVec){
return new ISurface(server, corner, corner.dup().add(widthVec),
corner.dup().add(widthVec).add(heightVec),
corner.dup().add(heightVec));
}
/** one directional extrusion */
public static ISurface extrude(IVecI[] profile, double extrudeDepth){
return extrude(profile,1,false,IVec.averageNormal(profile).len(extrudeDepth));
}
public static ISurface extrude(IVecI[] profile, IDoubleI extrudeDepth){
return extrude(profile,1,false,new IVecR(IVec.averageNormal(profile)).len(extrudeDepth));
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double extrudeDepth){
return extrude(profile,profileDeg,false,IVec.averageNormal(profile).len(extrudeDepth));
}
public static ISurface extrude(IVecI[] profile, int profileDeg, IDoubleI extrudeDepth){
return extrude(profile,profileDeg,false,new IVecR(IVec.averageNormal(profile)).len(extrudeDepth));
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile, double extrudeDepth){
return extrude(profile,profileDeg,closeProfile,IVec.averageNormal(profile).len(extrudeDepth));
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile, IDoubleI extrudeDepth){
return extrude(profile,profileDeg,closeProfile,new IVecR(IVec.averageNormal(profile)).len(extrudeDepth));
}
public static ISurface extrude(IVecI[] profile, IVecI extrudeDir){
return extrude(profile,1,false,extrudeDir);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, IVecI extrudeDir){
return extrude(profile,profileDeg,false,extrudeDir);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile, IVecI extrudeDir){
IVecI[] profPts = null;
double[] profKnots = null;
if(closeProfile){
profPts = INurbsGeo.createClosedCP(profile, profileDeg);
profKnots = INurbsGeo.createClosedKnots(profileDeg, profPts.length);
}
else{
profPts = profile;
profKnots = INurbsGeo.createKnots(profileDeg, profPts.length);
}
return extrude(profPts, profileDeg, profKnots, extrudeDir);
/*
IVecI[][] cpts = new IVecI[2][profPts.length];
for(int i=0; i<profPts.length; i++){
cpts[0][i] = profPts[i];
cpts[1][i] = profPts[i].dup().add(extrudeDir);
}
if(closeProfile)
return new ISurface(cpts, 1, profileDeg, INurbsGeo.createKnots(1,2), profKnots,
0.0, 1.0, 0.0, 1.0);
return new ISurface(cpts, 1, profileDeg);
*/
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI extrudeDir){
IVecI[][] cpts = new IVecI[2][profile.length];
for(int i=0; i<profile.length; i++){
cpts[0][i] = profile[i];
cpts[1][i] = profile[i].dup().add(extrudeDir);
}
return new ISurface(server, cpts, 1, profileDeg, INurbsGeo.createKnots(1,2), profileKnots,
0.0, 1.0, 0.0, 1.0);
}
public static ISurface extrude(IVecI[] profile, ICurve rail){
return extrude(profile,1,false,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, ICurve rail){
return extrude(profile,profileDeg,false,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile,
ICurve rail){
IVecI[] profPts = null;
double[] profKnots = null;
if(closeProfile){
profPts = INurbsGeo.createClosedCP(profile, profileDeg);
profKnots = INurbsGeo.createClosedKnots(profileDeg, profPts.length);
}
else{
profPts = profile;
profKnots = INurbsGeo.createKnots(profileDeg, profPts.length);
}
return extrude(profPts,profileDeg,profKnots,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double[] profileKnots,
ICurve rail){
return extrude(profile,profileDeg,profileKnots,rail.cps(),rail.deg(),rail.knots());
}
public static ISurface extrude(ICurveI profile, IVecI extrudeDir){
IVecI[][] cpts = new IVecI[2][profile.num()];
for(int i=0; i<profile.num(); i++){
cpts[0][i] = profile.cp(i);
cpts[1][i] = profile.cp(i).dup().add(extrudeDir);
}
return new ISurface(server, cpts, 1, profile.deg(), INurbsGeo.createKnots(1,2), profile.knots(),
0., 1., 0., 1.); // to have knots not normalized, it needs to put 0.0 and 1.0
}
public static ISurface extrude(ICurveI profile, double extrudeDepth){
return extrude(profile, IVec.averageNormal(profile.cps()).len(extrudeDepth));
}
public static ISurface extrude(ICurveI profile, IDoubleI extrudeDepth){
return extrude(profile, IVec.averageNormal(profile.cps()).len(extrudeDepth));
}
/** extrusion along path (profile control points are copied parallely) */
public static ISurface extrude(IVecI[] profile, IVecI[] rail){
return extrude(profile,1,false,rail,1,false);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, IVecI[] rail, int railDeg){
return extrude(profile,profileDeg,false,rail,railDeg,false);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI[] rail, int railDeg, boolean closeRail){
IVecI[] profPts = null;
double[] profKnots = null;
if(closeProfile){
profPts = INurbsGeo.createClosedCP(profile, profileDeg);
profKnots = INurbsGeo.createClosedKnots(profileDeg, profPts.length);
}
else{
profPts = profile;
profKnots = INurbsGeo.createKnots(profileDeg,profPts.length);
}
IVecI[] railPts = null;
double[] railKnots = null;
if(closeRail){
railPts = INurbsGeo.createClosedCP(rail, railDeg);
railKnots = INurbsGeo.createClosedKnots(railDeg, railPts.length);
}
else{
railPts = rail;
railKnots = INurbsGeo.createKnots(railDeg,railPts.length);
}
return extrude(profPts, profileDeg, profKnots, railPts, railDeg, railKnots);
/*
IVecI[][] cpts = new IVec[railPts.length][profPts.length];
for(int i=0; i<railPts.length; i++){
for(int j=0; j<profPts.length; j++){
cpts[i][j] = railPts[i].dup().add(profPts[j]).sub(profOrig);
}
}
if(closeProfile || closeRail){
if(profKnots==null) profKnots = INurbsGeo.createKnots(profileDeg,profPts.length);
if(railKnots==null) railKnots = INurbsGeo.createKnots(railDeg,railPts.length);
return new ISurface(cpts,railDeg,profileDeg,railKnots,profKnots,0.0,1.0,0.0,1.0);
}
return new ISurface(server, cpts,railDeg,profileDeg);
*/
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI[] rail, int railDeg, double[] railKnots){
IVecI profOrig = profile[0];
IVecI[][] cpts = new IVec[rail.length][profile.length];
for(int i=0; i<rail.length; i++){
for(int j=0; j<profile.length; j++){
cpts[i][j] = rail[i].dup().add(profile[j]).sub(profOrig);
}
}
return new ISurface(server,cpts,railDeg,profileDeg,railKnots,profileKnots,0.0,1.0,0.0,1.0);
// to have knots not normalized, it needs to put 0.0 and 1.0
}
public static ISurface extrude(ICurveI profile, ICurveI rail){
return extrude(profile.cps(), profile.deg(), profile.knots(),
rail.cps(), rail.deg(), rail.knots());
/*
IVecI profOrig = profile.cp(0);
IVecI[][] cpts = new IVecI[rail.num()][profile.num()];
for(int i=0; i<rail.num(); i++){
for(int j=0; j<profile.num(); j++){
cpts[i][j] = rail.cp(i).dup().add(profile.cp(j)).sub(profOrig);
}
}
return new ISurface(cpts, rail.deg(), profile.deg(),rail.knots(),profile.knots(),
0., 1., 0., 1.); // to have knots not normalized, it needs to put 0.0 and 1.0
*/
}
/** sweep (profile is redirected perpendicular to rail and centered(actually just on bisector of control points)) */
public static ISurface sweep(IVecI[] profile, IVecI[] rail){
return sweep(profile,1,false,null,null,rail,1,false);
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, IVecI[] rail){
return sweep(profile,1,false,profileCenter,null,rail,1,false);
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, IVecI profileDir, IVecI[] rail){
return sweep(profile,1,false,profileCenter,profileDir,rail,1,false);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, IVecI[] rail, int railDeg){
return sweep(profile,profileDeg,false,null,null,rail,railDeg,false);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, IVecI profileCenter,
IVecI[] rail, int railDeg){
return sweep(profile,profileDeg,false,profileCenter,null,rail,railDeg,false);
}
public static ISurface sweep(IVecI[] profile, int profileDeg,
IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg){
return sweep(profile,profileDeg,false,profileCenter,profileDir,rail,railDeg,false);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI[] rail, int railDeg, boolean closeRail){
return sweep(profile,profileDeg, closeProfile, null, null, rail, railDeg, closeRail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter,
IVecI[] rail, int railDeg, boolean closeRail){
return sweep(profile,profileDeg,closeProfile,profileCenter,null,rail,railDeg,closeRail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg, boolean closeRail){
IVecI[] profPts = null;
double[] profKnots = null;
if(closeProfile){
profPts = INurbsGeo.createClosedCP(profile, profileDeg);
profKnots = INurbsGeo.createClosedKnots(profileDeg, profPts.length);
}
else{
profPts = profile;
profKnots = INurbsGeo.createKnots(profileDeg,profPts.length);
}
IVecI[] railPts = null;
double[] railKnots = null;
if(closeRail){
railPts = INurbsGeo.createClosedCP(rail, railDeg);
railKnots = INurbsGeo.createClosedKnots(railDeg, railPts.length);
}
else{
railPts = rail;
railKnots = INurbsGeo.createKnots(railDeg,railPts.length);
}
return sweep(profPts, profileDeg, profKnots, profileCenter, profileDir,
railPts, railDeg, railKnots);
}
public static ISurface sweep(IVecI[] profile, ICurveI rail){
return sweep(profile, 1, null, null, rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, ICurveI rail){
return sweep(profile, 1, null, profileCenter, rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, IVecI profileDir,
ICurveI rail){
return sweep(profile, 1, null, profileCenter, profileDir, rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, int profileDeg, ICurveI rail){
return sweep(profile, profileDeg, null, null, rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, int profileDeg, IVecI profileCenter,
ICurveI rail){
return sweep(profile, profileDeg, null, profileCenter, rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, int profileDeg,
IVecI profileCenter, IVecI profileDir, ICurveI rail){
return sweep(profile, profileDeg, null, profileCenter, profileDir,
rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile, ICurveI rail){
return sweep(profile,profileDeg,closeProfile,null,null,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter, ICurveI rail){
return sweep(profile,profileDeg,closeProfile,profileCenter,null,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter, IVecI profileDir, ICurveI rail){
IVecI[] profPts = null;
double[] profKnots = null;
if(closeProfile){
profPts = INurbsGeo.createClosedCP(profile, profileDeg);
profKnots = INurbsGeo.createClosedKnots(profileDeg, profPts.length);
}
else{
profPts = profile;
profKnots = INurbsGeo.createKnots(profileDeg,profPts.length);
}
return sweep(profPts, profileDeg, profKnots, profileCenter, profileDir,
rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(ICurveI profile, IVecI[] rail){
return sweep(profile.cps(), profile.deg(), profile.knots(), null,
rail, 1, null);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI[] rail){
return sweep(profile.cps(), profile.deg(), profile.knots(), profileCenter,
rail, 1, null);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI profileDir,
IVecI[] rail){
return sweep(profile.cps(), profile.deg(), profile.knots(),
profileCenter, profileDir, rail, 1, null);
}
public static ISurface sweep(ICurveI profile, IVecI[] rail, int railDeg){
return sweep(profile.cps(), profile.deg(), profile.knots(), null,
rail, railDeg, null);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI[] rail,int railDeg){
return sweep(profile.cps(), profile.deg(), profile.knots(), profileCenter,
rail, railDeg, null);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI profileDir,
IVecI[] rail,int railDeg){
return sweep(profile.cps(), profile.deg(), profile.knots(),
profileCenter, profileDir, rail, railDeg, null);
}
public static ISurface sweep(ICurveI profile, IVecI[] rail, int railDeg, boolean closeRail){
return sweep(profile, null, null, rail, railDeg, closeRail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter,
IVecI[] rail, int railDeg, boolean closeRail){
return sweep(profile,profileCenter,null,rail,railDeg,closeRail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg, boolean closeRail){
IVecI[] railPts = null;
double[] railKnots = null;
if(closeRail){
railPts = INurbsGeo.createClosedCP(rail, railDeg);
railKnots = INurbsGeo.createClosedKnots(railDeg, railPts.length);
}
else{
railPts = rail;
railKnots = INurbsGeo.createKnots(railDeg,railPts.length);
}
return sweep(profile.cps(), profile.deg(), profile.knots(),
profileCenter, profileDir, railPts, railDeg, railKnots);
}
public static ISurface sweep(ICurveI profile, ICurveI rail){
return sweep(profile.cps(), profile.deg(), profile.knots(),
rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, ICurveI rail){
return sweep(profile.cps(), profile.deg(), profile.knots(), profileCenter, null,
rail.cps(), rail.deg(), rail.knots());
}
/**
sweep.
@param profileCenter point on profile to be located at the points of rail
@param profileDir direction on profile to be aligned with the normal of rail
*/
public static ISurface sweep(ICurveI profile,
IVecI profileCenter,
IVecI profileDir,
ICurveI rail){
return sweep(profile.cps(), profile.deg(), profile.knots(),
profileCenter, profileDir,
rail.cps(), rail.deg(), rail.knots());
}
public static ISurface sweep(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI[] rail, int railDeg, double[] railKnots){
return sweep(profile, profileDeg, profileKnots, null, rail,railDeg,railKnots);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI profileCenter,
IVecI[] rail, int railDeg, double[] railKnots){
return sweep(profile,profileDeg,profileKnots,profileCenter,null,
rail,railDeg,railKnots);
}
/**
sweep.
@param profileCenter point on profile to be located at the points of rail
@param profileDir direction on profile to be aligned with the normal of rail
*/
public static ISurface sweep(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg, double[] railKnots){
IVecI[][] cpts = sweepPoints(profile,profileDeg,profileCenter,profileDir,rail,railDeg);
if(profileKnots==null) profileKnots = INurbsGeo.createKnots(profileDeg,profile.length);
if(railKnots==null) railKnots = INurbsGeo.createKnots(railDeg,rail.length);
return new ISurface(server, cpts, railDeg, profileDeg, railKnots, profileKnots,
0.0, 1.0, 0.0, 1.0);
}
/**
control points for sweep.
@param profileCenter point on profile to be located at the points of rail
@param profileDir direction on profile to be aligned with the normal of rail
*/
public static IVecI[][] sweepPoints(IVecI[] profile, int profileDeg, IVecI profileCenter,
IVecI profileDir, IVecI[] rail, int railDeg){
if(profile==null || profile.length<=1){
IOut.err("profile is null or number of array is too less");
return null;
}
if(rail==null || rail.length<=1){
IOut.err("rail is null or number of array is too less");
return null;
}
IVec profileNormal = IVec.averageNormal(profile);
if(profileCenter==null) profileCenter = getCenter(profile,profileDeg);
else{ profileCenter = profileCenter.dup(); } // profileCenter changes
boolean railClosed=isClosed(rail,railDeg);
IVec railNormal = null;
if(profileDir!=null){ railNormal = IVec.averageNormal(rail); }
IVecI[] ppts = duplicatePoints(profile);
IVecI[][] cpts = new IVecI[rail.length][];
for(int i=0; i<rail.length; i++){
IVecI dir = null;
if(i==0){ // start point
if(!railClosed && i<rail.length-1) dir = rail[i+1].dif(rail[i]);
else if(railClosed && rail.length-railDeg>0){
dir = rail[rail.length-railDeg].dif(rail[rail.length-railDeg-1]);
}
// auto adjust profileNormal to the first rail direction
if(profileNormal.dot(dir) < 0){ profileNormal.neg(); } // added 20130525
IVecI[] ppts2 = orient(ppts, profileCenter, profileNormal, profileDir,
rail[i], dir, railNormal);
if(railClosed){
if(i<rail.length-1){ dir = rail[i+1].dif(rail[i]); }
ppts2 = orientAndBisect(ppts, profileCenter, profileNormal, profileDir,
rail[i], dir, railNormal);
}
cpts[i] = ppts2;
}
else if(railClosed && i >= rail.length-railDeg){
cpts[i] = duplicatePoints(cpts[i - (rail.length-railDeg)]);
}
else if(i==rail.length-1){ // last rail point (not railClosed)
// direction is already set in the previous orientAndBisector
orient(ppts, profileCenter, rail[i]);
cpts[i] = ppts;
}
else{
if(i<rail.length-1) dir = rail[i+1].dif(rail[i]);
else dir = rail[i].dif(rail[i-1]);
IVecI[] bsct = orientAndBisect(ppts, profileCenter, profileNormal, profileDir,
rail[i], dir, railNormal);
cpts[i] = bsct;
}
}
return cpts;
}
/****************
* subroutines for sweep
****************/
public static IVecI[] duplicatePoints(IVecI[] pts){
IVecI[] pts2 = new IVecI[pts.length];
for(int i=0; i<pts.length; i++){ pts2[i] = pts[i].dup(); }
return pts2;
}
public static IVecI[] duplicatePoints(IVecI[] pts, double weight){
IVecI[] pts2 = new IVecI[pts.length];
for(int i=0; i<pts.length; i++){
double w = 1.0;
if(pts[i] instanceof IVec4I){ w = ((IVec4I)pts[i]).w(); }
pts2[i] = pts[i].to4d(w*weight);
}
return pts2;
}
/**
only moving profile points form profCenter to railPt. points are not duplicated.
*/
public static IVecI[] orient(IVecI[] profile, IVecI profCenter, IVecI railPt){
IVec diff = railPt.get().dif(profCenter);
for(IVecI p:profile) p.add(diff);
profCenter.set(railPt);
return profile;
}
public static IVecI[] orient(IVecI[] profile,
IVecI profCenter, IVecI profNml,
IVecI railPt, IVecI railDir){
return orient(profile,profCenter,profNml,null,railPt,railDir,null);
}
/**
Orienting profile points by matching profCenter with railPt, profNml with railDir,
profDir with railNml.
*/
public static IVecI[] orient(IVecI[] profile,
IVecI profCenter, IVecI profNml, IVecI profDir,
IVecI railPt, IVecI railDir, IVecI railNml){
IVec axis = null;
double angle = 0;
if(railDir!=null){
if(!profNml.get().isParallel(railDir)){
axis = profNml.get().cross(railDir);
angle = profNml.angle(railDir,axis);
}
else if(profNml.get().dot(railDir) < 0){ // parallel but opposite // added 20130525
profNml.neg();
}
}
for(IVecI p:profile){
p.sub(profCenter);
if(axis!=null) p.rot(axis,angle);
//p.add(railPt);
}
if(axis!=null) profNml.rot(axis,angle);
if(profDir!=null){
if(axis!=null) profDir.rot(axis,angle);
if(railNml!=null && !profDir.get().isParallel(railNml)){
if(profDir.get().dot(railNml) < 0){ // added 20130525
angle = profDir.angle(railNml, railDir.get().dup().neg());
}
else{
angle = profDir.angle(railNml, railDir);
}
for(IVecI p:profile) p.rot(railDir,angle);
profDir.rot(railDir,angle);
}
}
for(IVecI p:profile) p.add(railPt);
profCenter.set(railPt);
// multiply weight
if(railPt instanceof IVec4I) return duplicatePoints(profile, ((IVec4I)railPt).w());
return duplicatePoints(profile);
}
public static IVecI[] orientAndBisect(IVecI[] profile, IVecI profCenter, IVecI profNml,
IVecI railPt, IVecI railDir){
return orientAndBisect(profile,profCenter,profNml,null,railPt,railDir,null);
}
public static IVecI[] orientAndBisect(IVecI[] profile,
IVecI profCenter, IVecI profNml, IVecI profDir,
IVecI railPt, IVecI railDir, IVecI railNml){
IVec axis = null;
double angle = 0;
if(railDir!=null){
if(!profNml.get().isParallel(railDir)){
axis = profNml.get().cross(railDir);
angle = profNml.angle(railDir,axis);
//parallel = angle < IConfig.angleTolerance;
}
else if(profNml.get().dot(railDir) < 0){ // parallel but opposite // added 20130525
profNml.neg(); // ok?? test it.
}
}
for(IVecI p:profile) p.sub(profCenter);
double bangle = angle/2;
IVec bisectDir = null;
if(axis!=null){
for(IVecI p:profile){
//p.sub(profCenter);
//if(!parallel)
p.rot(axis,angle);
//p.add(railPt);
}
bisectDir = profNml.get().cross(axis);
//if(!parallel)
bisectDir.rot(axis,bangle);
profNml.rot(axis,angle);
if(profDir!=null) profDir.rot(axis,angle);
}
if(profDir!=null && railNml!=null && !profDir.get().isParallel(railNml)){
if(profDir.get().dot(railNml) < 0){ // added 20130525
angle = profDir.angle(railNml, railDir.get().dup().neg());
}
else{
angle = profDir.angle(railNml, railDir);
}
for(IVecI p:profile) p.rot(railDir,angle);
profDir.rot(railDir,angle);
}
IVecI[] bsct = null;
// multiply weight
if(railPt instanceof IVec4I) bsct = duplicatePoints(profile, ((IVec4I)railPt).w());
else bsct = duplicatePoints(profile);
if(axis != null){
for(IVecI b:bsct){
//b.sub(profCenter);
//if(!parallel){
//b.rot(axis,bangle);
b.rot(axis,-bangle);
// scale 1d
if(Math.abs(bangle-Math.PI/2)>=IConfig.angleTolerance){
double scale = 1.0/Math.abs(Math.cos(bangle));
b.scale1d(bisectDir,scale);
}
//}
//b.add(railPt);
}
}
for(IVecI p:profile) p.add(railPt);
for(IVecI b:bsct) b.add(railPt);
profCenter.set(railPt);
return bsct;
}
public static boolean isClosed(IVecI[] profile, int profileDeg){
boolean closed=true;
for(int i=0; i<profileDeg && closed; i++){
if(!profile[i].eq(profile[profile.length-profileDeg+i])) closed=false;
}
return closed;
}
public static IVec getCenter(IVecI[] profile, int profileDeg){
boolean closed = isClosed(profile,profileDeg);
IVec center=new IVec();
int count=0;
for(int i=0; i<profile.length&&!closed || i<profile.length-profileDeg&&closed; i++){
center.add(profile[i]);
count++;
}
center.div(count);
return center;
}
/*********************
* pipe
*********************/
public static ISurface pipe(IVecI pt1, IVecI pt2, double radius){
return pipe(new IVecI[]{pt1, pt2}, 1, false, radius);
}
public static ISurface pipe(IVecI[] rail, double radius){
return pipe(rail, 1, false, radius);
}
public static ISurface pipe(IVecI[] rail, int railDeg, double radius){
return pipe(rail, railDeg, false, radius);
}
public static ISurface pipe(IVecI[] rail, int railDeg, boolean close, double radius){
IVecI[] railPts = null;
double[] railKnots = null;
if(close){
railPts = INurbsGeo.createClosedCP(rail, railDeg);
railKnots = INurbsGeo.createClosedKnots(railDeg, railPts.length);
}
else{
railPts = rail;
railKnots = INurbsGeo.createKnots(railDeg,railPts.length);
}
return pipe(railPts, railDeg, railKnots, radius);
}
public static ISurface pipe(ICurveI rail, double radius){
return pipe(rail.cps(),rail.deg(),rail.knots(),radius);
}
public static ISurface pipe(IVecI[] rail, int railDeg, double[] railKnots, double radius){
IVec nml = IVec.averageNormal(rail);
//IVec dir = rail[1].get().dif(rail[0]);
IVec dir = rail[0].get().dif(rail[1]);
IVec center = rail[0].get();
//IVec roll = dir.cross(n);
//if(dir.isParallel(nml)){
// IG.err("dir and nml is parallel!!");
//}
IVec[] profile = ICircleGeo.circleCP(center, dir, nml, radius);
int profDeg = ICircleGeo.circleDeg();
double[] profKnots = ICircleGeo.circleKnots();
return sweep(profile, profDeg, profKnots, center, nml, rail, railDeg, railKnots);
}
public static ISurface squarePipe(IVecI pt1, IVecI pt2, double size){
return rectPipe(new IVecI[]{ pt1, pt2 }, size, size);
}
/** square pipe with width dir specified */
public static ISurface squarePipe(IVecI pt1, IVecI pt2, IVecI widthDir, double size){
return rectPipe(pt1,pt2,widthDir,size,size);
}
public static ISurface squarePipe(IVecI[] rail, double size){
return rectPipe(rail, size, size);
}
public static ISurface squarePipe(IVecI[] rail, int deg, double size){
return rectPipe(rail, deg, size, size);
}
public static ISurface squarePipe(IVecI[] rail, int deg, boolean close, double size){
return rectPipe(rail,deg,close,size,size);
}
public static ISurface squarePipe(ICurveI rail, double size){ return rectPipe(rail,size,size); }
public static ISurface squarePipe(IVecI[] rail, int deg, double[] knots, double size){
return rectPipe(rail,deg,knots,size,size);
}
/*
public static ISurface rectPipe(IVecI[] rail, double size){
return rectPipe(rail, size, size);
}
public static ISurface rectPipe(IVecI[] rail, int deg, double size){ // ambiguous with rectPip(IVecI[],double,double)
return rectPipe(rail, deg, size, size);
}
public static ISurface rectPipe(IVecI[] rail, int deg, boolean close, double size){
return rectPipe(rail,deg,close,size,size);
}
public static ISurface rectPipe(ICurveI rail, double size){ return rectPipe(rail,size,size); }
public static ISurface rectPipe(IVecI[] rail, int deg, double[] knots, double size){
return rectPipe(rail,deg,knots,size,size);
}
*/
/**
@param width size in the direction of offset of rail
@param height size in the direction of normal of rail
*/
public static ISurface rectPipe(IVecI pt1, IVecI pt2, double width, double height){
return rectPipe(new IVecI[]{ pt1, pt2 }, 1, false, width, height);
}
/** rect pipe with width dir specified */
public static ISurface rectPipe(IVecI pt1, IVecI pt2, IVecI widthDir, double width, double height){
return rectPipe(pt1,pt2,widthDir,-width/2,width/2,-height/2,height/2);
}
public static ISurface rectPipe(IVecI pt1, IVecI pt2,
double left, double right, double bottom, double top){
return rectPipe(new IVecI[]{ pt1, pt2 }, 1, false, left, right, bottom, top);
}
public static ISurface rectPipe(IVecI[] rail, double width, double height){
return rectPipe(rail, 1, false, width, height);
}
public static ISurface rectPipe(IVecI[] rail, double left, double right, double bottom, double top){
return rectPipe(rail, 1, false, left, right, bottom, top);
}
public static ISurface rectPipe(IVecI[] rail, int deg, double width, double height){
return rectPipe(rail, deg, false, width, height);
}
public static ISurface rectPipe(IVecI[] rail, int deg,
double left, double right, double bottom, double top){
return rectPipe(rail, deg, false, left, right, bottom, top);
}
public static ISurface rectPipe(IVecI[] rail, int deg, boolean close, double width, double height){
return rectPipe(rail,deg,close,-width/2,width/2,-height/2,height/2);
/*
IVecI[] railPts = null;
double[] railKnots = null;
if(close){
railPts = INurbsGeo.createClosedCP(rail, deg);
railKnots = INurbsGeo.createClosedKnots(deg, railPts.length);
}
else{
railPts = rail;
railKnots = INurbsGeo.createKnots(deg,railPts.length);
}
return rectPipe(railPts, deg, railKnots, width, height);
*/