File indexing completed on 2026-04-10 07:49:32
0001
0002 """
0003 CSGOptiXRenderTest.py
0004 =======================
0005
0006 Selects slice rectangles from isect arrays::
0007
0008 epsilon:CSGOptiX blyth$ i tests/CSGOptiXRenderTest.py
0009 a : (1080, 1920, 4, 4) : /tmp/blyth/opticks/GeoChain_Darwin/GeneralSphereDEV/CSGOptiXRenderTest/cvd0/50001/ALL/top_i0_/cxr_geochain_GeneralSphereDEV_ALL_isect.npy
0010 b : (3, 3, 4, 4) : select the central portion of the image array
0011
0012
0013 Note that the first dimension is the smaller vertical 1080 one (in landscape aspect).
0014 Selecting vertical strip 3 pixels wide and 21 pixels high in the middle of the frame::
0015
0016 epsilon:CSGOptiX blyth$ DYDX=10,1 i tests/CSGOptiXRenderTest.py
0017 a : (1080, 1920, 4, 4) : /tmp/blyth/opticks/GeoChain_Darwin/GeneralSphereDEV/CSGOptiXRenderTest/cvd0/50001/ALL/top_i0_/cxr_geochain_GeneralSphereDEV_ALL_isect.npy
0018 b : (21, 3, 4, 4) : select the central portion of the image array
0019
0020
0021 Selecting 3x3 square in middle, happens to make an "H"::
0022
0023 DYDX=1,1 i tests/CSGOptiXRenderTest.py
0024 DYDX=4,4 i tests/CSGOptiXRenderTest.py
0025
0026 """
0027
0028 import numpy as np
0029 import platform
0030 import matplotlib.pyplot as plt
0031 from opticks.ana.eget import efloat_, efloatlist_, eint_, eintlist_
0032
0033 def isectpath():
0034 geochain_suffix = "_Darwin" if platform.system() == "Darwin" else ""
0035 geom = os.environ.get("GEOM", "GeneralSphereDEV")
0036 cvdver = os.environ.get("CVDVER", "cvd0/50001" )
0037 fmt = "/tmp/$USER/opticks/GeoChain%(geochain_suffix)s/%(geom)s/CSGOptiXRenderTest/%(cvdver)s/ALL/top_i0_/cxr_geochain_%(geom)s_ALL_isect.npy" % locals()
0038 path = os.path.expandvars(fmt)
0039 return path
0040
0041 def outpath_(dy, dx):
0042 outdir = os.path.expandvars("/tmp/$USER/opticks/CSGOptiX/CSGOptiXRenderTest")
0043 if not os.path.isdir(outdir):
0044 os.makedirs(outdir)
0045 pass
0046 outname = "dy_%d_dx_%d.npy" % ( dy, dx )
0047 outpath = os.path.join(outdir, outname)
0048 return outpath
0049
0050
0051 if __name__ == '__main__':
0052
0053 path = isectpath()
0054 a = np.load(path)
0055
0056 fmt = " %3s : %20s : %s "
0057 print(fmt % ( "a", str(a.shape), path ))
0058
0059 assert len(a.shape) == 4
0060 ny, nx, ni, nj = a.shape
0061 assert ni == 4
0062 assert nj == 4
0063
0064 dy,dx = eintlist_("DYDX", "1,1")
0065
0066 mid_y, mid_x = ny//2, nx//2
0067 ys = slice(mid_y-dy, mid_y+dy+1)
0068 xs = slice(mid_x-dx, mid_x+dx+1)
0069
0070 b = a[ys,xs]
0071
0072 outpath = outpath_(dy, dx)
0073 np.save(outpath, b )
0074 print(fmt % ( "b", str(b.shape), outpath ))
0075
0076
0077 a_result = a[:,:,0,:3]
0078 b_result = b[:,:,0,:3]
0079
0080 fig, axs = plt.subplots(2)
0081 axs[0].imshow( a_result )
0082 axs[1].imshow( b_result )
0083 fig.show()
0084
0085