-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrate.lisp
1067 lines (955 loc) · 34.2 KB
/
integrate.lisp
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
;;; -*- Package: PROJ -*-
;;;****************************************************************
;;;Patches for Nichael
;;;****************************************************************
(defmethod (:associated-window basic-projector) ()
window)
(defmethod (:dump-data-to-projector basic-projector) (OTHER-PROJECTOR)
(send OTHER-PROJECTOR :initialize-data MAX-NUMBER-POINTS)
(loop for INDEX below CURRENT-POINT-PNTR
do (send OTHER-PROJECTOR :load-one-point
(raw-x INDEX) (raw-y INDEX) (raw-z INDEX) (point-data INDEX))))
(defmethod (:draw-axis alternating-b&w-projector) (&optional PENDING?)
(let ((DRER (if PENDING? (pending-drawer) (displaying-drawer))))
(let ((LENG (* SCALE-FACTOR 10)))
(multiple-value-bind (ORIG-X ORIG-Y)
(multiple-value-call
SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point 0 0 0))
(multiple-value-bind (X-X X-Y)
(multiple-value-call
SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point LENG 0 0))
(send DRER :draw-axis-line ORIG-X ORIG-Y X-X X-Y))
(multiple-value-bind (Y-X Y-Y)
(multiple-value-call
SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point 0 LENG 0))
(send DRER :draw-axis-line ORIG-X ORIG-Y Y-X Y-Y))
(multiple-value-bind (Z-X Z-Y)
(multiple-value-call
SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point 0 0 LENG))
(send DRER :draw-axis-line ORIG-X ORIG-Y Z-X Z-Y)))))
)
(defmethod (:convert-world-coord-to-scr-coord alternating-b&w-projector)
(WORLD-X WORLD-Y WORLD-Z)
(declare (values SCR-X SCR-Y))
(multiple-value-call
SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point
(* scale-factor WORLD-X)
(* scale-factor WORLD-Y)
(* scale-factor WORLD-Z))))
(defmethod (:draw-axis-line b&w-array-drawer) (X0 Y0 X1 Y1)
(send WINDOW :draw-line X0 Y0 X1 Y1))
(defmethod (:prepare-for-immediate-point-plotting alternating-b&w-projector)
(NUM-POINTS LINE-MODE SCALE &rest ROTATION-COMMANDS)
(send SELF :initialize-data NUM-POINTS)
(send SELF :set-line-mode LINE-MODE)
(send SELF :set-scale-factor SCALE nil)
(setup-transformation-matrix ROTATION-COMMANDS)
(prepare-for-immediate-draw)
(send SELF :draw-axis))
;;;++This does not multiply the scale-factor like :convert-world-coord-to-scr-coord
(defmethod (:pos-to-screen basic-alternating-color-projector) (x y z)
(declare (values SCR-X SCR-Y))
(multiple-value-call SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point x y z)))
;;;So we need this guy
(defmethod (:conv-to-scale basic-alternating-color-projector) (x y z)
(declare (values sx sy sz))
(values
(/ x scale-factor)
(/ y scale-factor)
(/ z scale-factor)))
;;;++This does not multiply the scale-factor like :convert-world-coord-to-scr-coord
(defmethod (:pos-to-screen alternating-b&w-projector) (x y z)
(declare (values SCR-X SCR-Y))
(multiple-value-call SCREENER :blast-project-one-point
(send TRANSFORMER :blast-transform-one-point x y z)))
;;;So we need this guy
(defmethod (:conv-to-scale alternating-b&w-projector) (x y z)
(declare (values sx sy sz))
(values
(/ x scale-factor)
(/ y scale-factor)
(/ z scale-factor)))
;;;****************************************************************
(defvar *PROJECTOR-B&W-WINDOW* (tv:make-window 'tv:window
:blinker-p nil
:borders nil
:label nil
:save-bits t)
)
(defvar *PROJECTOR-COLOR-WINDOW*
(tv:make-window 'tv:window
:superior (color:find-color-screen :create-p t)
:blinker-p nil
:borders nil
:label nil)
)
(defvar *PROJECTOR-COLOR-WINDOW1*
(tv:make-window 'tv:window
:superior (color:find-color-screen :create-p t)
:blinker-p nil
:borders 2
:label nil)
)
(defvar *MULTICOLOR-PROJECTOR* (make-alternating-multiple-color-projector))
(send *MULTICOLOR-PROJECTOR* :setup-screen)
(send *MULTICOLOR-PROJECTOR* :set-default-alus)
(send *MULTICOLOR-PROJECTOR* :setup-window-info *PROJECTOR-COLOR-WINDOW*)
(defvar *MULTICOLOR-PROJECTOR1* (make-alternating-multiple-color-projector))
(send *MULTICOLOR-PROJECTOR1* :setup-screen)
(send *MULTICOLOR-PROJECTOR1* :set-default-alus)
(send *MULTICOLOR-PROJECTOR1* :setup-window-info *PROJECTOR-COLOR-WINDOW1*)
#+ignore
(setup-amcdd-colors
'(( 00. 0. 1023.)
(1023. 00. 00.)
(00. 1023. 0.)
( 0. 1023. 1023.) (1023. 1023. 0.)
(1023. 0. 1023.)
;( 0. 1023. 1023.)
( 307. 1023. 0.)
( 0. 1023. 0.)
( 0. 1023. 307.)
( 0. 1023. 614.)
( 0. 1023. 1023.)
( 0. 614. 1023.)
( 0. 307. 1023.)
( 614. 614. 1023.)
(1023. 1023. 1023.)))
(defvar *alternating-B&W-PROJECTOR* (make-b&w-alternating-projector))
(send *alternating-B&W-PROJECTOR* :setup-window-info *PROJECTOR-B&W-WINDOW*)
#||
(defvar *FAST-PROJECTOR* (make-instance 'fast-projector))
(defvar *FAST-PROJECTOR-B&W-WINDOW* (tv:make-window 'tv:window
:blinker-p nil
:borders nil
:label nil
:save-bits t
:width 512.
:height 512.)
)
(send *FAST-PROJECTOR* :setup-window-info *FAST-PROJECTOR-B&W-WINDOW*)
||#
(defvar p)
(defvar w)
(defvar p1)
(defvar w1)
;;(setq w *FAST-PROJECTOR-B&W-WINDOW*)
(setq w *PROJECTOR-COLOR-WINDOW* #+ignore *PROJECTOR-B&W-WINDOW*)
(setq p *MULTICOLOR-PROJECTOR* #+ignore *DRIVEN-COLOR-PROJECTOR*
#+ignore *DRIVEN-B&W-PROJECTOR*)
(setq p1 *MULTICOLOR-PROJECTOR1*)
(setq w1 *PROJECTOR-COLOR-WINDOW1*)
;(send p :driver-loop)
(DEFFLAVOR 3d-equation
((scale 1)
(conv (/ -180. pi))
(pinc 1)
(x-offset 1/2)
(y-offset 1/2)
(delta 0.1)
(rotx -45)
(roty -45)
(rotz -45))
()
(:conc-name nil)
:INITABLE-INSTANCE-VARIABLES :readable-instance-variables :writable-instance-variables)
(defmethod (offsets 3d-equation) (window)
(multiple-value-bind (x y) (send window :inside-size)
(values (* x x-offset) (* y y-offset))))
(defmethod (VERY-SIMPLE-INTEGRATE 3d-equation) (p w ix iy iz transient total int-color)
w
#+ignore
(send p :prepare-for-shuffle rtot :points 10)
(loop with x = ix
with y = iy
with z = iz
with angx and angy
with rinc = 0
for i from 0 below (+ transient total)
do (multiple-value-setq (ix iy iz)
(integration-step self delta x y z))
when (> i transient)
when (zerop (mod i pinc))
do (setq angx (atan (- iy y) (- iz z))) and
do (setq angy (atan (- ix x) (- iz z))) and
do (send p :add-and-plot-immediate ix iy iz int-color)
#+ignore
(send p :add-one-point-and-shuffle rinc ix iy iz t
:transx (- x) :transy (- y) :transz (- z)
;:rotx (+ (* conv angx) 0) :roty (+ (* conv angy) 0)
) and
do (incf rinc)
do (setq x ix y iy z iz)))
(defmethod (simple-integrate 3d-equation) (p w ix iy iz iter-inc transient
total int-color)
w conv
(loop with x = ix
with y = iy
with z = iz
with rinc = 0
for i from 0 below (+ transient total) by iter-inc
do (multiple-value-setq (ix iy iz)
(loop with a and b and c
for ixx in x and
for iyy in y and
for izz in z
do (multiple-value-setq (a b c)
(integration-step self delta ixx iyy izz))
collect a into xv
collect b into yv
collect c into zv
finally (return (values xv yv zv))))
when (> i transient)
when (zerop (mod i pinc))
do (loop for i from int-color
for xv in ix
for yv in iy
for zv in iz
do (send p :add-and-plot-immediate xv yv zv i)
#+IGNORE
(send p :add-and-plot-single-point rinc xv yv zv i)
) and
do (incf rinc iter-inc)
do (setq x ix y iy z iz)))
(DEFFLAVOR lorenz
((scale 15)
(delta .005)
(x-offset .3)
(y-offset .3)
(rotz 0)
(pinc 2)
(s 10.0)
(r 28.0)
(b 8/3))
(3d-equation)
(:conc-name nil)
:INITABLE-INSTANCE-VARIABLES :readable-instance-variables :writable-instance-variables)
(defmethod (integration-step lorenz) (delta x y z)
(values #x + delta*s*(y - x)
#y + delta*(r*x - y - x*z)
#z + delta*(x*y - b*z) ))
(DEFFLAVOR rossler
((scale 100)
(delta 0.01)
(x-offset 1/2)
(y-offset 1/2)
(pinc 5)
(rotz 0)
(a .398 #+ignore 3/8)
(b 2)
(c 4))
(3d-equation)
(:conc-name nil)
:INITABLE-INSTANCE-VARIABLES :readable-instance-variables :writable-instance-variables)
(defmethod (integration-step rossler) (delta x y z)
(values #x - delta*(y + z)
#y + delta*(x + a*y)
#z + delta*(b + z*(x - c)) ))
(DEFFLAVOR rossler-corkscrew
((scale 75)
(delta 0.01)
(x-offset .3)
(y-offset .3)
(pinc 5)
(rotz 0)
(a #+ignore .398 .55 #+ignore 3/8)
(b 2)
(c 4))
(rossler)
(:conc-name nil)
:INITABLE-INSTANCE-VARIABLES :readable-instance-variables :writable-instance-variables)
(DEFFLAVOR forced-pendulum
((scale 5)
(delta .1)
(a 0.5)
(b 0.1))
(3d-equation)
(:conc-name nil)
:INITABLE-INSTANCE-VARIABLES :readable-instance-variables :writable-instance-variables)
(defmethod (integration-step forced-pendulum) (delta x y z)
(values #x + delta*y
#y - delta*(a*a + b*cos(z))*sin(x)
#mod (z + delta,pi*2)))
(defun integrate (fcn)
(let* ((eqn (make-instance fcn))
(ix 1.0) (iy 1.0) (iz 1.0)
(rtot 10000)
(transient 0 #+ignore 15000)
(total (1+ (* rtot (pinc eqn))))
)
(send w :expose)
(multiple-value-bind (x-offset y-offset) (offsets eqn w)
(send p :set-scr-cent
:cent-x x-offset
:cent-y y-offset))
(send p :prepare-for-immediate-point-plotting
rtot '(:points 2) (scale eqn) :roty (roty eqn) :rotx (rotx eqn) :rotz (rotz eqn)
)
(very-simple-integrate eqn p w ix iy iz transient total 0)))
(defun integrate1 (fcn)
(let* ((eqn (make-instance fcn))
(ix '(1.0 1.001 1.002)) (iy '(1.0 1.001 1.002)) (iz '(1.0 1.001 1.002))
(iter-inc (length ix))
(rtot (* iter-inc 5000))
(transient (* iter-inc 000))
(total (1+ (* rtot (pinc eqn)))))
(send w :expose) (send w :clear-window)
(multiple-value-bind (x-offset y-offset) (offsets eqn w)
(send p :set-scr-cent
:cent-x x-offset
:cent-y y-offset))
(send p :prepare-for-immediate-point-plotting
rtot '(:points 2) (scale eqn) :roty (roty eqn) :rotx (rotx eqn) :rotz (rotz eqn)
)
(simple-integrate eqn p w ix iy iz iter-inc transient total 0)))
(defun intmouse (fcn &optional (over nil) (points 200))
(let* ((eqn (make-instance fcn))
(ix nil) (iy nil) (iz nil)
(iter-inc (length ix))
(rtot 10000 #+ignore (* iter-inc 5000))
(transient (* iter-inc 000))
(total (1+ (* rtot (pinc eqn)))))
(send w :expose)
(unless over
(send w :clear-window)
(multiple-value-bind (x-offset y-offset) (offsets eqn w)
(send p :set-scr-cent
:cent-x x-offset
:cent-y y-offset))
(send p :prepare-for-immediate-point-plotting
rtot '(:points 2) (scale eqn) :roty (roty eqn)
:rotx (rotx eqn) :rotz (rotz eqn)))
(loop
do (multiple-value-bind (x y z)
(mouse-specify-3d-point)
(setq ix nil) (setq iy nil) (setq iz nil)
(push x ix) (push y iy) (push z iz)
(setq iter-inc (length ix))
(setq rtot (* iter-inc points))
(setq total (1+ (* rtot (pinc eqn))))
(simple-integrate eqn p w ix iy iz
iter-inc transient total 4)))))
(defun intmouse1 (fcn &optional (over nil) (points 200))
(let* ((eqn (make-instance fcn))
(ix nil) (iy nil) (iz nil)
(iter-inc (length ix))
(rtot 10000 #+ignore (* iter-inc 5000))
(transient (* iter-inc 000))
(total (1+ (* rtot (pinc eqn)))))
(send w :expose)
(send w1 :expose)
(send w1 :clear-window)
(multiple-value-bind (x-offset y-offset) (offsets eqn w1)
(send p1 :set-scr-cent
:cent-x x-offset
:cent-y y-offset))
(send p1 :prepare-for-immediate-point-plotting
rtot '(:points 2) (scale eqn) :roty (+ (roty eqn) 0)
:rotx (rotx eqn) :rotz (+ (rotz eqn) 90))
(send p :dump-data-to-projector p1)
(send p1 :transform-project-and-draw nil
:roty (+ (roty eqn) 0) :rotx (rotx eqn) :rotz (+ (rotz eqn) 90))
;(send p1 :rotate-project-and-draw nil
(unless over
(send w :clear-window)
(multiple-value-bind (x-offset y-offset) (offsets eqn w)
(send p :set-scr-cent
:cent-x x-offset
:cent-y y-offset))
(send p :prepare-for-immediate-point-plotting
rtot '(:points 2) (scale eqn) :roty (roty eqn)
:rotx (rotx eqn) :rotz (rotz eqn)))
(loop
do (multiple-value-bind (x y z)
(mouse-specify-3d-point)
(setq ix nil) (setq iy nil) (setq iz nil)
(push x ix) (push y iy) (push z iz)
(setq iter-inc (length ix))
(setq rtot (* iter-inc points))
(setq total (1+ (* rtot (pinc eqn))))
(simple-integrate eqn p w ix iy iz
iter-inc transient total 4)
(simple-integrate eqn p1 w1 ix iy iz
iter-inc transient total 4)))))
(defun bar ()
(loop do
(loop for ang from 0 by 20 ;below 50
do (when (send *terminal-io* :listen) (return-from bar))
do (send *multicolor-projector* :transform-project-and-draw t
:rotz (* 0.3 ang) :roty (* 2 ang)))))
(defvar *AGB-DATA1* (with-open-file (STRM "CONGER:>Nichael>new-projector>agb-data-file.lisp") (read STRM)))
;;;
(defun fast-projector-agb-demo (&optional (DATA-LIST *AGB-DATA1*))
(send *FAST-PROJECTOR* :setup DATA-LIST
:window *FAST-PROJECTOR-B&W-WINDOW*
:scale-factor 10.0)
(loop (loop for Y-INDEX below 72
do (loop for X-INDEX below 72
do (send *FAST-PROJECTOR* :transform-and-draw
X-INDEX (mod (+ X-INDEX X-INDEX Y-INDEX) 72)))))
)
(defun integrate-fast (fcn)
(let* ((eqn (make-instance fcn))
(ix 1.0) (iy 1.0) (iz 1.0)
(rtot 10000)
(p *FAST-PROJECTOR*)
(w *FAST-PROJECTOR-B&W-WINDOW*)
(transient 0 #+ignore 15000)
(total (1+ (* rtot (pinc eqn))))
)
(send w :expose)
(multiple-value-bind (x-offset y-offset) (offsets eqn w)
(send p :set-scr-cent
:cent-x x-offset
:cent-y y-offset))
(send p :prepare-for-immediate-point-plotting
rtot '(:points 2) (scale eqn) :roty (roty eqn) :rotx (rotx eqn) :rotz (rotz eqn)
)
(very-simple-integrate eqn p w ix iy iz transient total 0)))
(defmethod (fast-INTEGRATE 3d-equation) (p w ix iy iz transient total int-color)
w
#+ignore
(send p :prepare-for-shuffle rtot :points 10)
(loop with x = ix
with y = iy
with z = iz
with angx and angy
with rinc = 0
for i from 0 below (+ transient total)
do (multiple-value-setq (ix iy iz)
(integration-step self delta x y z))
when (> i transient)
when (zerop (mod i pinc))
do (setq angx (atan (- iy y) (- iz z))) and
do (setq angy (atan (- ix x) (- iz z))) and
do (send p :add-and-plot-immediate ix iy iz int-color)
#+ignore
(send p :add-one-point-and-shuffle rinc ix iy iz t
:transx (- x) :transy (- y) :transz (- z)
;:rotx (+ (* conv angx) 0) :roty (+ (* conv angy) 0)
) and
do (incf rinc)
do (setq x ix y iy z iz)))
#+ignore
(fast-projector-agb-demo)
#||
(defmethod (:initialize-data basic-fast-projector) (NUMBER-OF-POINTS)
(send SELF :set-number-points NUMBER-OF-POINTS)
(setq CURRENT-POINT-PNTR 0))
(defmethod (:load-one-point basic-fast-projector) (XXX YYY ZZZ)
(cond ((< CURRENT-POINT-PNTR MAX-NUMBER-POINTS)
(load-one-data-point CURRENT-POINT-PNTR XXX YYY ZZZ)
(convert-raw-data-1 CURRENT-POINT-PNTR)
(incf CURRENT-POINT-PNTR))
(t
(beep))))
(defmethod (:setup-simple-draw simple-drawer-mixin)
(DATA-LIST &key WINDOW SCALE-FACTOR (X-OFFSET 0.) (Y-OFFSET 0.) (Z-OFFSET 0.))
(when WINDOW
(send SELF :setup-window-info WINDOW))
(send SELF :set-initial-offsets :xoff X-OFFSET :yoff Y-OFFSET :zoff Z-OFFSET)
(send SELF :load-point-list DATA-LIST)
(when SCALE-FACTOR
(send SELF :set-scale-factor SCALE-FACTOR))
(send SELF :setup-bit-array-parameters)
(setup-axis-values)
(when WINDOW
(send WINDOW :expose))
)
||#
(defun find-plane (p)
(sort (mapcar #'(lambda (data)
(multiple-value-bind (x0 y0)
(send p :pos-to-screen 0 0 0)
(multiple-value-bind (x y)
(send p :pos-to-screen (first data) (second data) (third data))
(setq x (- x x0))
(setq y (- y y0))
(list (sqrt (+ (* x x) (* y y))) (fourth data)))))
'((100 0 0 x) (0 100 0 y) (0 0 100 z))) #'> :key #'first))
;;;****************************************************************
;;; 3D mouse interaction
;;;****************************************************************
(DEFFLAVOR 3d-axis-blinker
((for-z nil)
(plane-offset 0)
(curr-x 0)
(curr-y 0)
(curr-z 0)
(x-scale 1.0)
(y-scale 1.0)
(z-scale 1.0)
(x-scale-offset 0)
(y-scale-offset 0)
(z-scale-offset 0)
(associated-blinkers nil)
(blink-following nil)
(projector nil))
(tv:MOUSE-BLINKER-MIXIN tv:CHARACTER-BLINKER)
:INITABLE-INSTANCE-VARIABLES :settable-instance-variables)
(defmethod (:pos-to-screen 3d-axis-blinker) (x y z)
(declare (values SCR-X SCR-Y))
(send projector :pos-to-screen x y z))
(defmethod (:position 3d-axis-blinker) ()
(values curr-x curr-y curr-z))
(defmethod (:draw-line 3d-axis-blinker) (from-x from-y to-x to-y
&optional (alu :draw) (draw-end-point t))
(let ((tv:currently-prepared-sheet tv:sheet)
(tv:screen tv:sheet))
(multiple-value-bind (from-x from-y to-x to-y)
(tv::clip-and-offset-line-internal tv:sheet from-x from-y to-x to-y)
(when
from-x
(tv:sheet-draw-line from-x from-y to-x to-y alu draw-end-point tv:sheet)))))
(defmethod (:draw-floating-axis 3d-axis-blinker) (x-off y-off)
(macrolet ((with-offsets (&body body)
`(multiple-value-bind (xp yp)
,@body
(values (- (+ x-off xp) x-org)
(- (+ y-off yp) y-org)))))
(multiple-value-bind (x-size y-size) (send tv:sheet :inside-size)
x-size y-size
(let ((LENG 10000))
(multiple-value-bind (x-org y-org)
(send self :pos-to-screen 0 0 0)
(multiple-value-bind (X-X X-Y)
(with-offsets (send self :pos-to-screen LENG 0 0))
(multiple-value-bind (X-Xp X-Yp)
(with-offsets (send self :pos-to-screen (- LENG) 0 0))
(send self :draw-line X-Xp X-Yp X-X X-Y tv:blinker-alu)))
(multiple-value-bind (Y-X Y-Y)
(with-offsets (send self :pos-to-screen 0 LENG 0))
(multiple-value-bind (Y-Xp Y-Yp)
(with-offsets (send self :pos-to-screen 0 (- LENG) 0))
(send self :draw-line Y-Xp Y-Yp Y-X Y-Y tv:blinker-alu)))
(multiple-value-bind (Z-X Z-Y)
(with-offsets (send self :pos-to-screen 0 0 LENG))
(multiple-value-bind (Z-Xp Z-Yp)
(with-offsets (send self :pos-to-screen 0 0 (- LENG)))
(send self :draw-line Z-Xp Z-Yp Z-X Z-Y tv:blinker-alu))))))))
(defmethod (:set-scaling 3d-axis-blinker) ()
(multiple-value-bind (x0 y0)
(send self :pos-to-screen 0 0 0)
x0 y0
(multiple-value-bind (xmax ymax)
(send tv:sheet :inside-size)
(multiple-value-bind (xcx ycx)
(send self :pos-to-screen xmax 0 0)
(multiple-value-bind (xcy ycy)
(send self :pos-to-screen 0 ymax 0)
(multiple-value-bind (xcz ycz)
(send self :pos-to-screen 0 0 xmax)
;(setq x-scale-offset 0 y-scale-offset 0 z-scale-offset 0)
(setq x-scale-offset (- xmax)
y-scale-offset (- ymax)
z-scale-offset (- xmax))
#+ignore
(setq x-scale 1 y-scale 1 z-scale 1)
(setq x-scale (/ xmax (* .5 (max xcx ycx)))
y-scale (/ ymax (* .5 (max xcy ycy)))
z-scale (/ xmax (* .5 (max xcz ycz ))))))))))
(DEFMETHOD (:compute-x-y-z 3d-axis-blinker) ()
(cond (blink-following
(values curr-x curr-y curr-z))
(for-z
(multiple-value-bind (x0 y0)
(send self :pos-to-screen 0 0 0)
(let ((xd plane-offset)
(yd (- y0 (+ (* y-scale tv:y-pos) y-scale-offset)))
(zd (- (+ (* z-scale tv:x-pos) z-scale-offset) x0)))
(values xd yd zd))))
(T (multiple-value-bind (x0 y0)
(send self :pos-to-screen 0 0 0)
(let ((xd (- (+ (* x-scale tv:x-pos) x-scale-offset) x0))
(yd (- y0 (+ (* y-scale tv:y-pos) y-scale-offset)))
(zd plane-offset))
(values xd yd zd))))))
(DEFMETHOD (:blink 3d-axis-blinker) ()
(multiple-value-bind (xd yd zd)
(send self :compute-x-y-z)
(multiple-value-bind (x y)
(send self :pos-to-screen xd yd zd)
(send self :draw-with-offset x y tv:index tv:font)
(send self :draw-floating-axis x y)
(setq curr-x xd curr-y yd curr-z zd))))
(defmethod (:blink 3d-axis-blinker :after) ()
(cond (for-z
(multiple-value-bind (xd yd zd)
(send self :compute-x-y-z)
(multiple-value-bind (x y)
(send self :pos-to-screen xd yd 0)
(send self :draw-with-offset x y (char-code #\Y) fonts:cptfontb))
(multiple-value-bind (x y)
(send self :pos-to-screen xd 0 zd)
(send self :draw-with-offset x y (char-code #\Z) fonts:cptfontb))))
(t
(multiple-value-bind (xd yd zd)
(send self :compute-x-y-z)
(multiple-value-bind (x y)
(send self :pos-to-screen xd 0 zd)
(send self :draw-with-offset x y (char-code #\X) fonts:cptfontb))
(multiple-value-bind (x y)
(send self :pos-to-screen 0 yd zd)
(send self :draw-with-offset x y (char-code #\Y) fonts:cptfontb))))))
(defwhopper (:blink 3d-axis-blinker) ()
(continue-whopper)
(dolist (bl associated-blinkers)
(send bl :set-3d-pos curr-x curr-y curr-z)
(send bl :blink)))
(defmethod (:set-3d-pos 3d-axis-blinker) (x y z)
(setq curr-x x curr-y y curr-z z))
(DEFMETHOD (:mark 3d-axis-blinker) ()
(multiple-value-bind (sx sy sz)
(send self :conv-to-scale)
(send projector :add-and-plot-immediate sx sy sz 14)))
(DEFMETHOD (:conv-to-scale 3d-axis-blinker) ()
(multiple-value-bind (x y z)
(send self :position)
(multiple-value-bind (sx sy sz)
(send projector :conv-to-scale x y z)
(values sx sy sz))))
(DEFMETHOD (:draw-with-offset 3d-axis-blinker) (x y font-index font)
(if (eq font tv:font)
(tv:sheet-draw-glyph font-index font (- x tv::X-OFFSET) (- y tv::Y-OFFSET)
tv:blinker-alu
tv:sheet)
(let ((x-off (let ((fit (zl:font-indexing-table font)))
(if fit (- (aref fit (1+ font-index)) (aref fit font-index))
(zl:font-raster-width font))))
(y-off (round (/ (zl:font-raster-height font)))))
(setq x-off (round (/ x-off 2)))
(tv:sheet-draw-glyph font-index font (- x x-off) (- y y-off)
tv:blinker-alu
tv:sheet))))
(defmethod (:go-to-3d 3d-axis-blinker) (x y z)
(multiple-value-bind (x y)
(send self :pos-to-screen x y z)
(TV:MOUSE-WARP x y )))
#+ignore
(defwhopper (:go-to-3d 3d-axis-blinker) (x y z)
(continue-whopper x y z)
(dolist (bl associated-blinkers)
(send bl :go-to-3d x y z)))
#+ignore
(defwhopper (:set-visibility 3d-axis-blinker) (val)
(continue-whopper val)
(dolist (bl associated-blinkers)
(send bl :set-visibility val)))
(defun mouse-specify-3d-point (&optional (plot? t) (sheet w) abortable)
(declare (special w p))
(send w :expose)
abortable
(multiple-value-bind (x y z)
(tv:mouse-set-sheet-then-call sheet 'mouse-specify-3d-point1 sheet #+ignore abortable)
(when plot? (send p :add-and-plot-immediate x y z 14))
(values x y z)))
#+ignore
(defun window-set-blinker (type window &optional x-off y-off (mouse tv::main-mouse))
(let ((bl (tv:mouse-get-blinker type window tv::main-mouse)))
(and x-off (send bl ':set-offsets x-off y-off))
(send bl ':set-cursorpos (- (tv:mouse-x mouse) (or x-off 0)
(tv:sheet-inside-left window))
(- (tv:mouse-y mouse) (or y-off 0)
(tv:sheet-inside-top window)))
(send bl ':set-visibility t)
(send bl ':track-mouse)
bl))
(defmethod (:initial-sets 3d-axis-blinker) (p)
(send self :set-visibility nil)
(send self :set-projector p)
(send self :set-curr-x 0)
(send self :set-curr-y 0)
(send self :set-curr-z 0)
(send self :set-plane-offset 0)
(send self :set-scaling))
(defmethod (:loop-sets 3d-axis-blinker) (set-for-z)
(multiple-value-bind (x y z) (send self :position)
y z
(send self :set-visibility nil)
(send self :set-for-z set-for-z)
(send self :set-visibility t)
(send self :go-to-3d x y z)))
(defmethod (:loop-end 3d-axis-blinker) (set-for-z p sheet)
(multiple-value-bind (x y z) (send self :position)
(multiple-value-bind (xp yp) (send p :pos-to-screen x y z)
(tv:prepare-sheet (sheet)
#+ignore
(send self :draw-with-offset Xp Yp (if set-for-z 118 100) fonts:mouse)))
;(send self :mark)
(send self :set-plane-offset (if set-for-z z x))))
; (tv:key-state #\space)
; (tv:wait-for-mouse-button-down "Select X-Y Shift for Z" nil nil mouse)
(defun mouse-specify-3d-point1 (&optional (sheet w)
&aux (mouse (tv:sheet-mouse sheet)))
(declare (special w p w1 p1))
(tv:with-this-mouse-and-buttons-grabbed (mouse)
(tv:MOUSE-SET-BLINKER :3d-axis 6 6)
(loop with bl = (tv:MOUSE-GET-BLINKER :3d-axis w MOUSE) and button and foo = 0
initially (send bl :initial-sets p)
until (and button (zl:bit-test 2 button))
when (not (zerop (mod foo 2)))
do (send bl :loop-sets t) and
do (setq button (tv:wait-for-mouse-button-down
"Select Y-Z Click for X" nil nil mouse)) and
do (incf foo) and
do (send bl :loop-end t p sheet)
else do (send bl :loop-sets nil) and
do (setq button (tv:wait-for-mouse-button-down
"Select X-Y. Click for Z. M to end." nil nil mouse)) and
do (incf foo) and
do (send bl :loop-end nil p sheet)
finally (return (send bl :conv-to-scale)))))
#+ignore
(defun mouse-specify-3d-point1 (&optional (sheet w)
&aux (mouse (tv:sheet-mouse sheet)))
(declare (special w p w1 p1))
(tv:with-this-mouse-and-buttons-grabbed (mouse)
(tv:MOUSE-SET-BLINKER :3d-axis 6 6)
(loop with bl = (tv:MOUSE-GET-BLINKER :3d-axis w MOUSE) and
bl2 = *other-blinker* and button and foo = 0
initially (send bl2 ':set-offsets 6 6)
initially (send bl :initial-sets p)
initially (send bl2 :initial-sets p1)
initially (send bl :set-associated-blinkers (list bl2))
until (and button (zl:bit-test 2 button))
when (not (zerop (mod foo 2)))
do (send bl :loop-sets t) and
do (send bl2 :loop-sets t) and
do (setq button (tv:wait-for-mouse-button-down
"Select Y-Z Click for X" nil nil mouse)) and
do (incf foo) and
do (send bl :loop-end t p sheet) and
do (send bl2 :loop-end t p1 sheet)
else do (send bl :loop-sets nil) and
do (send bl2 :loop-sets nil) and
do (setq button (tv:wait-for-mouse-button-down
"Select X-Y. Click for Z. M to end." nil nil mouse)) and
do (incf foo) and
do (send bl :loop-end nil p sheet) and
do (send bl2 :loop-end nil p1 sheet)
finally (return (send bl :conv-to-scale)))))
(tv:MOUSE-DEFINE-BLINKER-TYPE
':3d-axis
#'(lambda (screen)
(tv:make-blinker screen '3d-axis-blinker
:projector p
:for-z nil
:CHAR #\mouse:Maltese-Cross
:visibility nil)))
;#+ignore
(defvar *other-blinker*
(tv:make-blinker w1 '3d-axis-blinker
;:for-z nil
:blink-following t
:CHAR #\mouse:Maltese-Cross
:visibility nil))
#+ignore
(defun set-up-3d-blinker (w)
(let* ((screen (send w :superior))
(bls (SEND SCREEN ':MOUSE-BLINKERS))
bl)
(unless (setq bl (assoc :3d-axis bls))
(push (cons :3d-axis (setq bl (tv:make-blinker screen '3d-axis-blinker
;:for-z nil
:CHAR #\mouse:Maltese-Cross
:visibility nil)))
bls)
(SEND SCREEN ':SET-MOUSE-BLINKERS bls))
(TV:BLINKER-SET-SHEET bl SCREEN)
bl))
#||
;;;from lox:>rel-7-2>color>zoom.lisp
(defun zoom (&optional (zoomed-window (send w ':screen)) &aux (old-sheet tv:mouse-sheet))
"use the mouse to specify a rectangle, and pan&zoom to center it"
(when (eq self zoomed-window)
(send self ':set-pan-and-zoom 0 0 0 0))
(unwind-protect
(let* ((scr (send zoomed-window :screen))
(specify-window zoomed-window))
(tv:mouse-set-sheet specify-window)
(multiple-value-bind (left top right bottom)
(tv:mouse-specify-rectangle nil nil nil nil specify-window 0 0 t)
(when (and left top right bottom)
(let* ((zoomed-width (- right left))
(zoomed-height (- bottom top))
(x-ratio (// zoomed-width (float width)))
(y-ratio (// zoomed-height (float height)))
(cent-x ))
(setq left (floor (* left x-ratio))
top (floor (* top y-ratio))
right (floor (- zoomed-width (* x-ratio (- my-width right))))
bottom (floor (- zoomed-height (* y-ratio (- my-height bottom))))))
(send zoomed-window :set-scr-cent
:cent-x #+ignore 0 200
:cent-y #+ignore 0 200)
(send :set-scale-factor
(send self ':pan-and-zoom-from-rectangle left top right bottom t zoomed-window))
)))
(tv:mouse-set-sheet old-sheet))
)
(defun mouse-specify-3d-point1 (&optional (sheet mouse-sheet) abortable
&aux (mouse (sheet-mouse sheet)) button abort mx my)
(declare (special p))
(tv:with-this-mouse-and-buttons-grabbed (mouse)
(do () (nil)
(multiple-value-bind (x y)
(send p :pos-to-screen 0 0 0)
(TV:MOUSE-WARP x y ))
(tv:mouse-set-blinker-definition-internal mouse
':character 0 0
':on ':set-character #\mouse:Maltese-Cross)
(setf (tv:who-line-mouse-grabbed-documentation mouse)
(if abortable
"Position initial conditions. Middle aborts. Right is smart."
"Position initial conditions. Right is smart."))
#+ignore
(multiple-value-setq (button mx my)
(tv:wait-for-mouse-button-down "Button" nil nil mouse))
;; The first click determines the point in x-y plane
#+ignore
(and abortable (zl:bit-test 2 button) (return (setq abort t)))
(multiple-value (left1 top1)
(tv:mouse-specified-point sheet mx my (zl:bit-test 4 button) nil))
(tv:mouse-warp (+ left1 width) (+ top1 height) mouse)
(tv:mouse-set-blinker-definition-internal mouse
:box-tracking-corner-blinker 0 0 :on
:set-edges-and-moving-corner
left1 top1 (+ left1 width) (+ top1 height)
:lower-right)
(setf (tv:who-line-mouse-grabbed-documentation mouse)
(if abortable
"Position lower right corner of rectangle. Middle aborts. Right is smart."
"Position lower right corner of rectangle. Right is smart."))
;; The next click fixes the lower right corner.
(multiple-value (button mx my)
(tv:wait-for-mouse-button-down "Button" nil nil mouse))
(tv:mouse-standard-blinker nil mouse)
(setf (tv:who-line-mouse-grabbed-documentation mouse) nil)
(and abortable (zl:bit-test 2 button) (return (setq abort t)))
(multiple-value-bind (x y)
(tv:mouse-specified-point sheet (1+ mx) (1+ my) (zl:bit-test 4 button) t)
(setq width (- x left1)
height (- y top1)))
(cond ((and (plusp width) (plusp height))
(multiple-value-bind (xoff yoff)
(sheet-mouse-offsets sheet)
(setq left1 (- left1 xoff)
top1 (- top1 yoff)))
(if (or (< width minimum-width) (< height minimum-height)
(minusp left1) (minusp top1)
(> (+ left1 width) (sheet-width sheet))
(> (+ top1 height) (sheet-height sheet)))
(beep)
(return nil)))
(t (setq left1 (tv:sheet-inside-left sheet)
top1 (tv:sheet-inside-top sheet)
width (tv:sheet-inside-width sheet)
height (tv:sheet-inside-height sheet))
(return nil)))))
(unless abort
(values left1 top1 (+ left1 width) (+ top1 height))))
(defmethod (:TRACK-internal basic-slider) (draw-message erase-message &optional mouse-line
&aux old-type old-sheet old-x old-y
mouse-x mouse-y graph
left bottom right top)
(setq old-type tv:mouse-blinker-name
old-sheet tv:mouse-sheet
old-x tv:mouse-x
old-y tv:mouse-y
graph (first graphs))
(multiple-value (left bottom right top) (send self :bounds))
(unwind-protect
;; Usurp control of the mouse from the mouse process, you must do everything.
(TV:WITH-MOUSE-USURPED
(tv:mouse-set-sheet (send graph :stream))
(send tv:mouse-blinker :set-visibility nil)
(setq tv:who-line-mouse-grabbed-documentation (and mouse-line mouse-line))
(multiple-value-bind (sx sy)
(send graph :xy-to-mouse x y)
(TV:MOUSE-WARP sx sy))
(multiple-value (nil mouse-x mouse-y)
(tv:wait-for-mouse-button-up))
(do ((start-flag t nil) ;guarantee do body at least once
(buttons-newly-pushed 0))
((and (not start-flag) ( 0 buttons-newly-pushed))
(let ((button (tv:mouse-button-encode buttons-newly-pushed)))
(send self erase-message) ; !KRA below clobbers x and last-x!
(setq lastx x lasty y) ;remember as the "last point"
(values x y button)))
(unless start-flag ;erase the old
(send self erase-message))
(multiple-value (x y)
(send graph :mouse-to-xy mouse-x mouse-y))
(send self :constrain-position left bottom right top)
#+ignore