1 (defun split-by-char (char string
)
2 "Returns a list of substrings of string
3 divided by ONE character CHAR each.
4 Note: Two consecutive CHAR will be seen as
5 if there were an empty string between them."
6 (declare (character char
)
8 (loop for i
= 0 then
(1+ j
)
9 as j
= (position char string
:start i
)
10 collect
(subseq string i j
)
14 (split-by-char #\x
"12x124x42")
16 (defun parse-raw-filename (fn)
17 "Parses a filename like
18 /home/martin/d0708/stacks/c-291x354x41x91_dx200_dz1000.raw and returns
19 291 354 41 and 91 as multiple values."
21 (values (or null fixnum
) fixnum fixnum fixnum
&optional
))
22 (let* ((p- (position #\- fn
:from-end t
))
23 (part (subseq fn
(1+ p-
)))
24 (p_ (position #\_ part
))
25 (sizes (subseq part
0 p_
))
26 (numlist (split-by-char #\x sizes
)))
27 (unless (eq 4 (length numlist
))
28 (error "didn't read 4 dimensions as expected."))
29 (destructuring-bind (x y z time
)
30 (mapcar #'read-from-string numlist
)
31 (values x y z time
))))
35 (parse-raw-filename "/home/martin/d0708/stacks/c-291x354x41x91_dx200_dz1000.raw")
37 (defun read-raw-stack-video-frame (fn time
)
40 (values (simple-array (unsigned-byte 8) 3) &optional
))
41 (multiple-value-bind (x y z maxtime
)
42 (parse-raw-filename fn
)
43 (unless (< time maxtime
)
44 (error "requested time ~d is to big (must be <~d!)" time maxtime
))
45 (let* ((vol (make-array (list z y x
)
46 :element-type
'(unsigned-byte 8)))
47 (vol1 (sb-ext:array-storage-vector vol
)))
48 (with-open-file (s fn
:direction
:input
49 :element-type
'(unsigned-byte 8))
50 (file-position s
(* x y z time
))
51 (read-sequence vol1 s
))
55 (let* ((fn "/home/martin/d0708/stacks/c-291x354x41x91_dx200_dz1000_2.raw")
56 (ao (decimate-xy-ub8 5
57 (read-raw-stack-video-frame fn
0))))
58 (destructuring-bind (z y x
)
61 (o (loop for radius from
1 upto
10 collect
62 (let* ((oval (draw-sphere-ub8 (* 1d0 radius
) z y x
))
63 (volume (count-non-zero-ub8 oval
)))
65 (ft3 (convert3-ub8/cdf-complex oval
)))))))
66 (let* ((ao (decimate-xy-ub8 5
67 (read-raw-stack-video-frame fn timestep
)))
68 (a (convert3-ub8/cdf-complex ao
))
71 (destructuring-bind (radius volume oval
)
73 (let* ((dir (format nil
"/home/martin/tmp/o~d" radius
))
74 (conv (fftshift3 (ift3 (.
* ka oval
))))
75 (conv-df (convert3-cdf/df-realpart conv
)))
77 (normalize-ub8-df/ub8-realpart conv-df
))
78 (with-open-file (s (format nil
"~a/maxima" dir
)
81 (loop for el in
(find-maxima3-df conv-df
) do
82 (destructuring-bind (height pos
)
84 (format s
"~f ~d ~a~%"
88 (map 'vec-i
#'(lambda (x) (floor x
2)) pos
)