Commit 3934ca0c by Martin Reinecke

### recursive algorithm

parent a141d66e
 ... ... @@ -21,7 +21,7 @@ if __name__ == "__main__": ends = np.random.random((2, n)) return starts, ends nlos = 1000 nlos = 100 starts, ends = make_random_los(nlos) R = ift.library.LOSResponse(s_space, starts=starts, ends=ends) ... ...
 ... ... @@ -9,94 +9,61 @@ from ..field import Field from .. import dobj def _dist_from_LOS(start, end, pos): start = start.reshape((-1,1)) end = end.reshape((-1,1)) dir = end-start dlen = np.sqrt(np.sum(dir*dir)) dir *= 1./dlen t1 = pos - start dotpr = np.sum(dir*t1,axis=0) t2 = start + dir*dotpr.reshape((1,-1)) d1 = pos-t2 d1 = np.sqrt(np.sum(d1*d1,axis=0)) d2 = np.sqrt(np.sum(t1*t1,axis=0)) d3 = pos-end d3 = np.sqrt(np.sum(d3*d3,axis=0)) return np.where(dotpr<0, d2, np.where(dotpr 0)-0.5)*1e12, -start[:, i]/dirx) d1 = np.where(dir == 0., ((start[:, i] < pmax)-0.5)*-1e12, (pmax-start[:, i])/dirx) (dmin, dmax) = (np.minimum(d0, d1), np.maximum(d0, d1)) dmin = dmin.max() dmax = dmax.min() dmin = np.maximum(0., dmin) dmax = np.minimum(1., dmax) dmax = np.maximum(dmin, dmax) # hack: move away from potential grid crossings dmin += 1e-7 dmax -= 1e-7 if dmin > dmax: # no intersection out[i] = (np.full(0, 0), np.full(0, 0.)) continue # determine coordinates of first cell crossing c_first = np.ceil(start[:, i]+dir*dmin) c_first = np.where(dir > 0., c_first, c_first-1.) c_first = (c_first-start[:, i])/dirx pos1 = np.asarray((start[:, i]+dmin*dir), dtype=np.int) pos1 = np.sum(pos1*inc) cdist = np.empty(0, dtype=np.float64) add = np.empty(0, dtype=np.int) for j in range(ndim): if dir[j] != 0: step = inc[j] if dir[j] > 0 else -inc[j] tmp = np.arange(start=c_first[j], stop=dmax, step=abs(1./dir[j])) cdist = np.append(cdist, tmp) add = np.append(add, np.full(len(tmp), step)) idx = np.argsort(cdist) cdist = cdist[idx] add = add[idx] cdist = np.append(np.full(1, dmin), cdist) cdist = np.append(cdist, np.full(1, dmax)) corfac = np.linalg.norm(dir*dist) cdist *= corfac wgt = np.diff(cdist) mdist = 0.5*(cdist[:-1]+cdist[1:]) add = np.append(pos1, add) add = np.cumsum(add) zone = set() for x in combo: zone.update(add+x) npix = np.prod(shp) zone = [z for z in zone if z>=0 and z
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!