diff -urN rt_v23/Makefile rt_v24/Makefile --- rt_v23/Makefile 2018-04-16 21:00:00.000000000 +0900 +++ rt_v24/Makefile 2018-04-18 21:11:56.000000000 +0900 @@ -1,6 +1,6 @@ CC = gcc CFLAGS += -Wall -OBJS = sock.o cross.o ax.o vecs.o line.o v.o mt.o +OBJS = sock.o cross.o lstx.o ax.o cylx.o fcx.o vecs.o line.o v.o mt.o all: sock diff -urN rt_v23/cg.py rt_v24/cg.py --- rt_v23/cg.py 2018-04-12 21:29:06.000000000 +0900 +++ rt_v24/cg.py 2018-04-18 21:11:56.000000000 +0900 @@ -21,9 +21,18 @@ ut.if_not_set(d, k, v) ut.dic_set( d, k, lstx.opt( d.get(k) ) ) +def if_not_set_idx(d, k): + if k in d: + v = d.get(k) + if type(v) != int: + d[k] = img.get_idx(v) + def m_setup(d, m): # 'fn' in d + if_not_set_idx( m, 'fn' ) + if_not_set_idx( m, 'fn_r' ) + if_not_set_opt( m, 'wh2xyz', [ ax.fn_map( m.get('fn') ) ] ) if 'xyz2t' not in m: diff -urN rt_v23/cross.c rt_v24/cross.c --- rt_v23/cross.c 2018-04-14 09:02:21.000000000 +0900 +++ rt_v24/cross.c 2018-04-18 21:11:56.000000000 +0900 @@ -1,36 +1,31 @@ #include "cross.h" int -plane_z0(struct line *l, double *rt) +plane_z0(struct cross_ret *ret) { double vz, pz, t; - vz = l->v[2]; + vz = ret->l.v[2]; if(vz == 0){ return 0; } - pz = l->p[2]; + pz = ret->l.p[2]; t = -pz / vz; if(t <= 0){ return 0; } - *rt = t; + ret->t = t; return 1; } int -plane_z0_xy_cond(struct line *l, - int (*xy_cond_f)(double x, double y), - double *rt) +plane_z0_xy_cond(int (*xy_cond_f)(double x, double y), struct cross_ret *ret) { - double t, p[3]; - - if( !plane_z0(l, rt) ){ + if( !plane_z0(ret) ){ return 0; } - t = *rt; - line_on_line_p(l, t, p); - return xy_cond_f( p[0], p[1] ); + line_on_line_p(&ret->l, ret->t, ret->p); + return xy_cond_f( ret->p[0], ret->p[1] ); } int @@ -40,9 +35,9 @@ } int -square(struct line *l, double *rt) +square(struct cross_ret *ret) { - return plane_z0_xy_cond(l, square_xy, rt); + return plane_z0_xy_cond(square_xy, ret); } int @@ -52,9 +47,9 @@ } int -circle(struct line *l, double *rt) +circle(struct cross_ret *ret) { - return plane_z0_xy_cond(l, circle_xy, rt); + return plane_z0_xy_cond(circle_xy, ret); } int @@ -64,14 +59,15 @@ } int -triangle(struct line *l, double *rt) +triangle(struct cross_ret *ret) { - return plane_z0_xy_cond(l, triangle_xy, rt); + return plane_z0_xy_cond(triangle_xy, ret); } int -ball(struct line *l, double *rt, int eq_d) +ball(int eq_d, struct cross_ret *ret) { + struct line *l = &ret->l; double a, b, c, ts[2], tmp[2]; int n, i, tmp_n; @@ -102,17 +98,18 @@ if(n == 0){ return 0; } - *rt = (n == 2 && ts[0] > ts[1]) ? ts[1] : ts[0]; + ret->t = (n == 2 && ts[0] > ts[1]) ? ts[1] : ts[0]; + line_on_line_p(l, ret->t, ret->p); return 1; } int -pipe_side(struct line *l, double *rt, int eq_d) +pipe_side(int eq_d, struct cross_ret *ret) { + struct line *l = &ret->l; double px, py, vx, vy; double a, b, c, ts[2], tmp[2]; int n, i, tmp_n; - double p[3]; px = l->p[0]; py = l->p[1]; @@ -153,9 +150,9 @@ } for(i=0; ip); + if( fabs(ret->p[2]) < 1 ){ + ret->t = ts[i]; return 1; } } @@ -163,12 +160,12 @@ } int -cone_side(struct line *l, double *rt, int eq_d) +cone_side(int eq_d, struct cross_ret *ret) { + struct line *l = &ret->l; double px, py, pz, vx, vy, vz; double a, b, c, ts[2], tmp[2]; int n, i, tmp_n; - double p[3]; px = l->p[0]; py = l->p[1]; @@ -211,9 +208,9 @@ } for(i=0; ip); + if( 0p[2] && ret->p[2]<1 ){ + ret->t = ts[i]; return 1; } } @@ -221,10 +218,8 @@ } int -cross_cross(int kind_idx, struct ax *l2g, int eq_d, struct line *l_g, double *rt) +cross_cross(int kind_idx, struct ax *l2g, int eq_d, struct line *l_g, struct cross_ret *ret) { - struct line l; - switch(kind_idx){ case KIND_SQUARE: case KIND_CIRCLE: @@ -236,25 +231,68 @@ break; } - ax_tr_line(l2g, G2L, l_g, &l); + ax_tr_line(l2g, G2L, l_g, &ret->l); switch(kind_idx){ case KIND_SQUARE: - return square(&l, rt); + return square(ret); case KIND_CIRCLE: - return circle(&l, rt); + return circle(ret); case KIND_TRIANGLE: - return triangle(&l, rt); + return triangle(ret); case KIND_BALL: - return ball(&l, rt, eq_d); + return ball(eq_d, ret); case KIND_PIPE_SIDE: - return pipe_side(&l, rt, eq_d); + return pipe_side(eq_d, ret); case KIND_CONE_SIDE: - return cone_side(&l, rt, eq_d); + return cone_side(eq_d, ret); default: break; } return 0; } +void +cross_nv(int kind_idx, struct ax *l2g, struct line *l_g, struct cross_ret *ret) +{ + double nv[3]; + struct line l_nv; + + switch(kind_idx){ + case KIND_SQUARE: + case KIND_CIRCLE: + case KIND_TRIANGLE: + v_set(nv, v_z1); + break; + case KIND_BALL: + unit(ret->p, nv); + break; + case KIND_PIPE_SIDE: + v_set(nv, ret->p); + nv[2] = 0; + unit(nv, nv); + break; + case KIND_CONE_SIDE: + v_set(nv, ret->p); + nv[2]= 0; + if(dot(nv, nv) == 0){ + v_set(nv, v_z1); + }else{ + unit(nv, nv); + nv[2] = 1; + unit(nv, nv); + } + break; + default: + break; + } + + line_new(&l_nv, ret->p, nv); + ax_tr_line(l2g, L2G, &l_nv, &ret->l_nv_g); + + unit(ret->l_nv_g.v, ret->nv); + unit(l_g->v, ret->eyev); + ret->ang_nv_eyev = dot( ret->nv, ret->eyev ); +} + /* EOF */ diff -urN rt_v23/cross.h rt_v24/cross.h --- rt_v23/cross.h 2018-04-14 08:51:49.000000000 +0900 +++ rt_v24/cross.h 2018-04-18 21:11:56.000000000 +0900 @@ -4,20 +4,28 @@ #include "mt.h" #include "ax.h" -int plane_z0(struct line *l, double *rt); -int plane_z0_xy_cond(struct line *l, - int (*xy_cond_f)(double x, double y), - double *rt); +struct cross_ret{ + double t; + struct line l; + double p[3]; + struct line l_nv_g; + double nv[3]; + double eyev[3]; + double ang_nv_eyev; +}; + +int plane_z0(struct cross_ret *ret); +int plane_z0_xy_cond(int (*xy_cond_f)(double x, double y), struct cross_ret *ret); int square_xy(double x, double y); -int square(struct line *l, double *rt); +int square(struct cross_ret *ret); int circle_xy(double x, double y); -int circle(struct line *l, double *rt); +int circle(struct cross_ret *ret); int triangle_xy(double x, double y); -int triangle(struct line *l, double *rt); +int triangle(struct cross_ret *ret); -int ball(struct line *l, double *rt, int eq_d); -int pipe_side(struct line *l, double *rt, int eq_d); -int cone_side(struct line *l, double *rt, int eq_d); +int ball(int eq_d, struct cross_ret *ret); +int pipe_side(int eq_d, struct cross_ret *ret); +int cone_side(int eq_d, struct cross_ret *ret); #define KIND_SQUARE 0 #define KIND_CIRCLE 1 @@ -26,6 +34,7 @@ #define KIND_PIPE_SIDE 4 #define KIND_CONE_SIDE 5 -int cross_cross(int kind_idx, struct ax *l2g, int eq_d, struct line *l_g, double *rt); +int cross_cross(int kind_idx, struct ax *l2g, int eq_d, struct line *l_g, struct cross_ret *ret); +void cross_nv(int kind_idx, struct ax *l2g, struct line *l_g, struct cross_ret *ret); #endif diff -urN rt_v23/cross.py rt_v24/cross.py --- rt_v23/cross.py 2018-04-12 11:50:22.000000000 +0900 +++ rt_v24/cross.py 2018-04-18 21:11:56.000000000 +0900 @@ -256,6 +256,10 @@ l2g = d.get('l2g') #crs['l_nv_g'] = l_nv_g = lstx.tr( l2g, 'l2g', l_nv ) crs['l_nv_g'] = l_nv_g = lstx.tr_line( l2g, 'l2g', l_nv ) - crs['p_g'] = l_nv_g.p - crs['nv_g'] = l_nv_g.v + + crs['nv'] = nv = v.unit(l_nv_g.v) + l_g = crs.get('l_g') + crs['eyev'] = eyev = v.unit(l_g.v) + crs['ang_nv_eyev'] = np.dot( nv, eyev ) + # EOF diff -urN rt_v23/cylx.c rt_v24/cylx.c --- rt_v23/cylx.c 1970-01-01 09:00:00.000000000 +0900 +++ rt_v24/cylx.c 2018-04-17 21:55:25.000000000 +0900 @@ -0,0 +1,63 @@ +#include "cylx.h" + +void +cylx_new(struct cylx *cx, double r, int rev) +{ + cx->r = r; + cx->rev = rev; +} + +void +cylx_l2g(struct cylx *cx, double *p, double *rp) +{ + double rad = p[0] / cx->r; + double r = p[2]; + rp[0] = r * cos(rad); + rp[1] = r * sin(rad); + rp[2] = p[1]; +} + +void +cylx_g2l(struct cylx *cx, double *p, double *rp) +{ + double rad = atan2( p[1], p[0] ); + double tmp[3] = { p[0], p[1], 0 }; + rp[0] = cx->r * rad; + rp[1] = p[2]; + rp[2] = len1(tmp); +} + +int +cylx_dval(struct cylx *cx, int d) +{ + return cx->rev ? 1-d : d; +} + +void +cylx_tr_p(struct cylx *cx, int d, double *p, double *rp) +{ + if( cylx_dval(cx, d) == L2G ){ + cylx_l2g(cx, p, rp); + }else{ + cylx_g2l(cx, p, rp); + } +} + +static void +func(double *p, double *rp, void *arg) +{ + void **pp = (void **)arg; + struct cylx *cx = pp[0]; + int d = *(int *)( pp[1] ); + + cylx_tr_p(cx, d, p, rp); +} + +void +cylx_tr_line(struct cylx *cx, int d, struct line *l, struct line *rl) +{ + void *arg[2] = { cx, &d }; + line_tr_by_func(l, rl, func, arg); +} + +/* EOF */ diff -urN rt_v23/cylx.h rt_v24/cylx.h --- rt_v23/cylx.h 1970-01-01 09:00:00.000000000 +0900 +++ rt_v24/cylx.h 2018-04-17 21:55:25.000000000 +0900 @@ -0,0 +1,19 @@ +#ifndef __CYLX_H__ +#define __CYLX_H__ 1 + +#include "vecs.h" +#include "line.h" + +struct cylx{ + double r; + int rev; +}; + +void cylx_new(struct cylx *cx, double r, int rev); +void cylx_l2g(struct cylx *cx, double *p, double *rp); +void cylx_g2l(struct cylx *cx, double *p, double *rp); +int cylx_dval(struct cylx *cx, int d); +void cylx_tr_p(struct cylx *cx, int d, double *p, double *rp); +void cylx_tr_line(struct cylx *cx, int d, struct line *l, struct line *rl); + +#endif diff -urN rt_v23/cylx.py rt_v24/cylx.py --- rt_v23/cylx.py 2018-04-06 15:33:42.000000000 +0900 +++ rt_v24/cylx.py 2018-04-18 21:11:56.000000000 +0900 @@ -10,12 +10,13 @@ e = ut.Empty() e.typ = 'cylx' e.r = r + e.rev = rev def l2g(p): (x, y, z) = p rad = x/e.r r = z - return mt.arr( [ r*math.cos(r), r*math.sin(r), y ] ) + return mt.arr( [ r*math.cos(rad), r*math.sin(rad), y ] ) def g2l(p): (x, y, z) = p @@ -36,7 +37,5 @@ return f(d, targ) e.tr = tr - e.rev = lambda : new(e.r, not rev) - return e # EOF diff -urN rt_v23/fcx.c rt_v24/fcx.c --- rt_v23/fcx.c 1970-01-01 09:00:00.000000000 +0900 +++ rt_v24/fcx.c 2018-04-17 21:55:25.000000000 +0900 @@ -0,0 +1,72 @@ +#include "fcx.h" + +void +fcx_new(struct fcx *fx, double dz, int rev) +{ + fx->dz = dz; + fx->rev = rev; +} + +int +fcx_l2g(struct fcx *fx, double *p, double *rp) +{ + double z = p[2]; + + if(fx->dz == 0){ + return 0; + } + rp[0] = p[0]*z/fx->dz; + rp[1] = p[1]*z/fx->dz; + rp[2] = z; + return 1; +} + +int +fcx_g2l(struct fcx *fx, double *p, double *rp) +{ + double z = p[2]; + + if(z == 0){ + return 0; + } + + rp[0] = p[0]*fx->dz/z; + rp[1] = p[1]*fx->dz/z; + rp[2] = z; + return 1; +} + +int +fcx_dval(struct fcx *fx, int d) +{ + return fx->rev ? 1-d : d; +} + +void +fcx_tr_p(struct fcx *fx, int d, double *p, double *rp) +{ + if( fcx_dval(fx, d) == L2G ){ + fcx_l2g(fx, p, rp); + }else{ + fcx_g2l(fx, p, rp); + } +} + +static void +func(double *p, double *rp, void *arg) +{ + void **pp = (void **)arg; + struct fcx *fx = pp[0]; + int d = *(int *)( pp[1] ); + + fcx_tr_p(fx, d, p, rp); +} + +void +fcx_tr_line(struct fcx *fx, int d, struct line *l, struct line *rl) +{ + void *arg[2] = { fx, &d }; + line_tr_by_func(l, rl, func, arg); +} + +/* EOF */ diff -urN rt_v23/fcx.h rt_v24/fcx.h --- rt_v23/fcx.h 1970-01-01 09:00:00.000000000 +0900 +++ rt_v24/fcx.h 2018-04-17 21:55:25.000000000 +0900 @@ -0,0 +1,19 @@ +#ifndef __FCX_H__ +#define __FCX_H__ 1 + +#include "vecs.h" +#include "line.h" + +struct fcx{ + double dz; + int rev; +}; + +void fcx_new(struct fcx *fx, double dz, int rev); +int fcx_l2g(struct fcx *fx, double *p, double *rp); +int fcx_g2l(struct fcx *fx, double *p, double *rp); +int fcx_dval(struct fcx *fx, int d); +void fcx_tr_p(struct fcx *fx, int d, double *p, double *rp); +void fcx_tr_line(struct fcx *fx, int d, struct line *l, struct line *rl); + +#endif diff -urN rt_v23/fcx.py rt_v24/fcx.py --- rt_v23/fcx.py 2018-04-06 15:33:48.000000000 +0900 +++ rt_v24/fcx.py 2018-04-18 21:11:56.000000000 +0900 @@ -5,12 +5,13 @@ import v import line -def new(dz): +def new(dz, rev=False): # dz != 0 e = ut.Empty() e.typ = 'fcx' e.dz = dz + e.rev = rev def l2g(p): (x, y, z) = p @@ -33,7 +34,5 @@ return f(d, targ) e.tr = tr - rev = lambda : new(e.r, not rev) - return e # EOF diff -urN rt_v23/img.py rt_v24/img.py --- rt_v23/img.py 2018-04-16 21:00:00.000000000 +0900 +++ rt_v24/img.py 2018-04-18 21:11:56.000000000 +0900 @@ -109,18 +109,29 @@ videos = new_videos() +fns = [] + +def get_idx(fn): + if fn not in fns: + fns.append(fn) + return fns.index(fn) + +to_fn = lambda x: fns[x] if x in range( len(fns) ) else x + def fn_typ(fn): # 'v': video, 'i': image vs = [ 'mp4', 'avi', 'mov', 'gif' ] vs = sum( map( lambda s: [ s, s.upper() ], vs ) , [] ) for s in vs: - if fn.endswith('.' + s): + if to_fn(fn).endswith('.' + s): return 'v' return 'i' -wh = lambda fn: ( videos if fn_typ(fn) == 'v' else imgs ).wh(fn) +wh_ = lambda fn: ( videos if fn_typ(fn) == 'v' else imgs ).wh(fn) +wh = lambda fn: wh_( to_fn(fn) ) def col(fn, sec, x, y, def_col=[128,128,128], rep=None): + fn = to_fn(fn) if fn_typ(fn) == 'v': return videos.col(fn, sec, x, y, def_col, rep) return imgs.col(fn, x, y, def_col, rep) @@ -193,7 +204,7 @@ def imgs_to_video(img_name, video_name, fps, zm): cmd = 'ls {}[0-9]*.jpg'.format(img_name) - lst = ut.cmd_exec(cmd).strip().split('\n') + lst = ut.cmd_exec(cmd).decode().strip().split('\n') (w, h) = imgs.wh(lst[0]) codec = 'H264' diff -urN rt_v23/line.c rt_v24/line.c --- rt_v23/line.c 2018-04-13 20:24:38.000000000 +0900 +++ rt_v24/line.c 2018-04-17 21:56:00.000000000 +0900 @@ -22,13 +22,13 @@ } void -line_tr_by_func(struct line *l, void (*f)(double *s, double *d), struct line *rl) +line_tr_by_func(struct line *l, struct line *rl, void (*f)(double *s, double *d, void *arg), void *arg) { double p[3], tmp[3], tmp2[3], v[3]; - f(l->p, p); + f(l->p, p, arg); v_add(l->p, l->v, tmp); - f(tmp, tmp2); + f(tmp, tmp2, arg); v_sub(tmp2, l->p, v); line_new(rl, p, v); } diff -urN rt_v23/line.h rt_v24/line.h --- rt_v23/line.h 2018-04-13 20:24:38.000000000 +0900 +++ rt_v24/line.h 2018-04-17 21:56:00.000000000 +0900 @@ -11,6 +11,7 @@ void line_new(struct line *l, double *p, double *v); void line_on_line_p(struct line *l, double t, double *rp); +void line_tr_by_func(struct line *l, struct line *rl, void (*f)(double *s, double *d, void *arg), void *arg); int is_plane_side(struct line *l, double *p); int cross_plane_line(struct line *plane, struct line *other_line, double *rp); diff -urN rt_v23/lstx.c rt_v24/lstx.c --- rt_v23/lstx.c 1970-01-01 09:00:00.000000000 +0900 +++ rt_v24/lstx.c 2018-04-18 21:11:56.000000000 +0900 @@ -0,0 +1,58 @@ +#include "lstx.h" + +void +lstx_tr_p_one(struct lstx *lx, int d, double *p, double *rp) +{ + switch(lx->typ){ + case TYP_AX: + ax_tr_p(&lx->ax, d, p, rp); + break; + case TYP_CX: + cylx_tr_p(&lx->cx, d, p, rp); + break; + case TYP_FX: + fcx_tr_p(&lx->fx, d, p, rp); + break; + default: + break; + } +} + +void +lstx_tr_p(struct lstx *lx, int n, int d, double *p, double *rp) +{ + int i, j; + double p_[3]; + + if(n == 1){ + lstx_tr_p_one(lx, d, p, rp); + return; + } + + v_set(rp, p); + for(i=0; i= 0 ){ + cross_nv( data[idx].ki, &data[idx].l2g, &l_g, &ret ); + } + bp = sbuf; - n = 4; + n = sz_int; memcpy(bp, &idx, n); bp += n; - n = 8; - memcpy(bp, &t, n); + + n = sizeof(ret); + memcpy(bp, &ret, n); bp += n; + n = sizeof(sbuf); fwrite(sbuf, 1, n, stdout); fflush(stdout); diff -urN rt_v23/sock.py rt_v24/sock.py --- rt_v23/sock.py 2018-04-13 22:07:57.000000000 +0900 +++ rt_v24/sock.py 2018-04-18 21:42:28.000000000 +0900 @@ -7,6 +7,8 @@ import socket import six import ut +import mt +import v import line import vecs import ax @@ -19,9 +21,41 @@ pack_i4 = lambda i: struct.pack('=i', i) pack_np64 = lambda np64_arr: np64_arr.tobytes() if six.PY3 else bytes( np.getbuffer(np64_arr) ) +pack_f8 = lambda d: pack_np64(d) +pack_p = lambda p: pack_np64(p) +pack_line = lambda l: pack_p(l.p) + pack_p(l.v) +pack_vs = lambda vs: pack_np64(vs.v3) +pack_ax = lambda ax: pack_p(ax.p) + pack_vs(ax.vs) +pack_cx = lambda cx: pack_f8(cx.r) + pack_i4(cx.rev) +pack_fx = lambda fx: pack_f8(fx.dz) + pack_i4(fx,rev) unpack_i4 = lambda s: ( struct.unpack_from('=i', s)[0], s[4:] ) unpack_np64 = lambda s, n: ( np.frombuffer( s[:8*n], dtype=np.float64 ), s[8*n:] ) +def unpack_f8(s): + (a, s) = unpack_np64(s, 1) + return (a[0], s) +unpack_p = lambda s: unpack_np64(s, 3) +def unpack_line(s): + (p, s) = unpack_p(s) + (v, s) = unpack_p(s) + return ( line.new(p, v), s ) +def unpack_vs(s): + (v3, s) = unpack_np64(s, 3*3) + return ( vecs.new( v3.reshape(3,3) ), s ) +def unpack_ax(s): + (p, s) = unpack_p(s) + (vs, s) = unpack_vs(s) + return ( ax.new(p, vs), s ) +def unpack_cx(s): + (r, s) = unpack_f8(s) + (rev, s) = unpack_i4(s) + return ( cylx.new(r, rev), s ) +def unpack_fx(s): + (dz, s) = unpack_f8(s) + (rev, s) = unpack_i4(s) + return ( fcx.new(dz, rev), s ) + +usz = 4 + 8 + 8*3*2 + 8*3 + 8*3*2 + 8*3 + 8*3 + 8 def new_client(): e = ut.Empty() @@ -45,22 +79,36 @@ s = b'a' s += pack_i4(i) s += pack_i4( kinds.index(kind) ) - s += pack_np64(ax.p) - s += pack_np64(ax.vs.v3) + s += pack_ax(ax) send_recv(s, 0) e.add = add def cross(l_g, prev_idx=-1): s = b'x' - s += pack_np64(l_g.p) - s += pack_np64(l_g.v) + s += pack_line(l_g) s += pack_i4(prev_idx) - s = send_recv(s, 4+8) + s = send_recv(s, usz) - (i, s) = unpack_i4(s) - (t, s) = unpack_np64(s, 1) - return ( i, t[0] ) + (idx, s) = unpack_i4(s) + (t, s) = unpack_f8(s) + (l, s) = unpack_line(s) + (p, s) = unpack_p(s) + (l_nv_g, s) = unpack_line(s) + (nv, s) = unpack_p(s) + (eyev, s) = unpack_p(s) + (ang_nv_eyev, s) = unpack_f8(s) + + return { + 'idx': idx, + 't': t, + 'l': l, + 'p': p, + 'l_nv_g': l_nv_g, + 'nv': nv, + 'eyev': eyev, + 'ang_nv_eyev': ang_nv_eyev, + } e.cross = cross return e @@ -104,26 +152,23 @@ s = recv( 4 + 4 + 8*3 + 8*3*3 ) (i, s) = unpack_i4(s) (ki, s) = unpack_i4(s) - (p, s) = unpack_np64(s, 3) - (v3, s) = unpack_np64(s, 3*3) + (ax, s) = unpack_ax(s) d = e.data[i] d['kind'] = kinds[ki] - d['l2g'] = [ ax.new( p, vecs.new( v3.reshape(3,3) ) ) ] + d['l2g'] = [ ax ] e.in_ = [] e.out = [] def cross_(): - s = recv(8*3 + 8*3 + 4) + s = recv(8*3*2 + 4) if e.in_: send( e.in_.pop(0) ) return - (p, s) = unpack_np64(s, 3) - (v, s) = unpack_np64(s, 3) + (l_g, s) = unpack_line(s) (prev_idx, s) = unpack_i4(s) - l_g = line.new(p, v) lst = [] for (i, d) in enumerate(e.data): @@ -134,13 +179,33 @@ continue crs['idx'] = i lst.append(crs) - idx = -1 - t = np.float64(0) + + crs = { + 'idx': -1, + 't': np.float64(0), + 'l': line.new(mt.zero, v.zero), + 'p': mt.zero, + 'l_nv_g': line.new(mt.zero, v.zero), + 'nv': v.zero, + 'eyev': v.zero, + 'ang_nv_eyev': np.float64(0), + } if lst: crs = min( lst, key=lambda crs: crs.get('t') ) - idx = crs.get('idx') - t = crs.get('t') - s = pack_i4(idx) + pack_np64(t) + cross.nv(crs) + + infs = [ + ('idx', pack_i4), + ('t', pack_f8), + ('l', pack_line), + ('p', pack_p), + ('l_nv_g', pack_line), + ('nv', pack_p), + ('eyev', pack_p), + ('ang_nv_eyev', pack_f8), + ] + s = b''.join( ut.map_up_lst( lambda k, f: f( crs.get(k) ), infs ) ) + send(s) e.out.append(s) @@ -158,7 +223,6 @@ return with open(e.fn, 'rb') as f: s = f.read() - usz = 4+8 e.in_ = [] while s: e.in_.append( s[:usz] )