# # You should have received a copy of the GNU General Public License along # with this program (LICENSE.txt). If not, see <http://www.gnu.org/licenses/> import sys sys.path.append(scriptdir + '..') from eidolon import ReprType, ImageSceneObject, extendImage from TestUtils import generateTimeSphereImages step = 0.1 dim = 50 # create an object and repr with a particular name images = generateTimeSphereImages(step, dim) obj = ImageSceneObject('Sphere', [], images) mgr.addSceneObject(obj) rep = obj.createRepr(ReprType._imgtimevolume) mgr.addSceneObjectRepr(rep) del obj del rep mgr.clearScene() # this should free up existing objects # attempt to create an object and repr with the same name as the above, this will crash if the repr doesn't choose unique names for materials, textures, etc. images = generateTimeSphereImages(step, dim) obj = ImageSceneObject('Sphere', [], images) mgr.addSceneObject(obj)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program (LICENSE.txt). If not, see <http://www.gnu.org/licenses/> import sys sys.path.append(scriptdir+'..') from eidolon import ReprType,ImageSceneObject,extendImage from TestUtils import generateTimeSphereImages step=0.1 dim=30 mx=2 my=3 mz=4 fillVal=3.0 images=generateTimeSphereImages(step,dim) obj=ImageSceneObject('Sphere',[],images) mgr.addSceneObject(obj) obj1=extendImage(obj,'ext',mx,my,mz,fillVal) mgr.addSceneObject(obj1) rep=obj1.createRepr(ReprType._imgtimestack) mgr.addSceneObjectRepr(rep) mgr.setCameraSeeAll()
# it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Eidolon is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program (LICENSE.txt). If not, see <http://www.gnu.org/licenses/> from eidolon import ImageSceneObject, generateSphereImageStack, ReprType, delayedcall images = generateSphereImageStack(50, 50, 50) obj = ImageSceneObject('Sphere', [], images) mgr.addSceneObject(obj) rep = obj.createRepr(ReprType._imgstack) mgr.addSceneObjectRepr(rep) mgr.setCameraSeeAll() d1 = mgr.create2DView() mgr.callThreadSafe(d1.setImageStackPosition, 25) d2 = mgr.create2DView() mgr.callThreadSafe(d2.setImageStackPosition, 25) # wait for 1 second, remove the second 2d window and then add a third
def _loadFile(filename, name, position=None, rot=None, toffset=None, interval=None, task=None): with f: filename = Future.get(filename) name = name or self.mgr.getUniqueObjName( splitPathExt(filename)[1]) recfile = os.path.splitext(filename)[0] if os.path.exists(recfile + '.rec'): recfile = recfile + '.rec' elif os.path.exists(recfile + '.REC'): recfile = recfile + '.REC' else: raise IOError("Cannot find rec file '%s.rec'" % recfile) geninfo, imginfo = parseParFile(filename) # read par file rec = np.fromfile(recfile, np.uint8) # read rec file # numorients=geninfo[genInfoFields.maxgrad[2]][0] # numslices=geninfo[genInfoFields.maxloc[2]][0] # numsteps=geninfo[genInfoFields.maxphase[2]][0] # slicenum=imgInfoFields.slicenum[-1] # trigger=imgInfoFields.trigger[-1] # numslices=len(set(i[slicenum] for i in imginfo)) # # count the number of times the slice number decreases one slice to the next, this indicates how many times the slice index loops back # numorients=1+sum(1 if imginfo[i][slicenum]>imginfo[i+1][slicenum] else 0 for i in range(len(imginfo)-1)) # # count the number of times the trigger time decreases one slice to the next, this indicates when the images transition between volumes # numvols=1+sum(1 if imginfo[i][trigger]>imginfo[i+1][trigger] else 0 for i in range(len(imginfo)-1))/(numorients*numslices) # if len(imginfo)!=(numvols*numorients*numslices*numsteps): # raise IOError,'Mismatch between stated orient, slice, and step numbers and number of images (%r != %r*%r*%r*%r)'%(len(imginfo),numorients,numslices,numsteps,numvols) # orientsize=len(imginfo)/numorients datasize = 0 objs = [] rpos = 0 typemap = { } # maps type ID to dict mapping dynamic ID to SharedImage lists for imgi in imginfo: # sum up the sizes of each image to compare against the actual size of the rec file w, h = imgi[imgInfoFields.reconres[-1]] pixelsize = imgi[imgInfoFields.imgpix[ -1]] / 8 # convert from bits to bytes datasize += w * h * pixelsize if rec.shape[0] != datasize: raise IOError( 'Rec file incorrect size, should be %i but is %i' % (datasize, rec.shape[0])) for imgi in imginfo: dynamic = imgi[imgInfoFields.dynnum[-1]] itype = imgi[imgInfoFields.imgtypemr[-1]] dims = imgi[imgInfoFields.reconres[-1]] trigger = imgi[imgInfoFields.trigger[-1]] orientation = imgi[imgInfoFields.sliceori[-1]] spacing = imgi[imgInfoFields.pixspace[-1]] offcenter = imgi[imgInfoFields.imgoff[-1]] angulation = imgi[imgInfoFields.imgang[-1]] pixelsize = imgi[imgInfoFields.imgpix[-1]] reslope = imgi[imgInfoFields.rescalesl[-1]] intercept = imgi[imgInfoFields.rescalein[-1]] if itype not in typemap: typemap[itype] = dict() if dynamic not in typemap[itype]: typemap[itype][dynamic] = [] images = typemap[itype][dynamic] dtype = np.dtype('uint' + str(pixelsize)) pos, rot = getTransformFromInfo(offcenter, angulation, orientation, vec3(*spacing), vec3(*dims)) imgsize = dims[0] * dims[1] * dtype.itemsize arr = rec[rpos:rpos + imgsize].view(dtype).reshape(dims) rpos += imgsize if scalemethod in ('dv', 'DV'): arr = (arr.astype(float) * reslope) + intercept # DV scaling method simg = SharedImage(recfile, pos, rot, dims, spacing, trigger) simg.allocateImg('%s_t%i_d%i_img%i' % (name, itype, dynamic, len(images))) #simg.setArrayImg(arr) simg.setMinMaxValues(arr.min(), arr.max()) np.asarray(simg.img)[:, :] = arr images.append(simg) for itype in typemap: for dynamic, images in typemap[itype].items(): vname = '%s_t%i_d%i' % (name, itype, dynamic) source = { 'geninfo': geninfo, 'imginfo': imginfo, 'filename': filename, 'scalemethod': scalemethod, 'loadorder': len(objs) } obj = ImageSceneObject(vname, source, images, self) objs.append(obj) # for numo in range(numorients): # orientimgs=imginfo[numo*orientsize:(numo+1)*orientsize] # # for numv in range(numvols): # volsimgs=[img for i,img in enumerate(orientimgs) if i%numvols==numv] # images=[] # for imgi in volsimgs: # vname='%s_o%i_v%i'%(name,numo,numv) # dims=imgi[imgInfoFields.reconres[-1]] # trigger=imgi[imgInfoFields.trigger[-1]] # orientation=imgi[imgInfoFields.sliceori[-1]] # spacing=imgi[imgInfoFields.pixspace[-1]] # offcenter=imgi[imgInfoFields.imgoff[-1]] # angulation=imgi[imgInfoFields.imgang[-1]] # pixelsize=imgi[imgInfoFields.imgpix[-1]] # # reslope=imgi[imgInfoFields.rescalesl[-1]] # intercept=imgi[imgInfoFields.rescalein[-1]] # # dtype=np.dtype('uint'+str(pixelsize)) # # pos,rot=self._getTransformFromInfo(offcenter,angulation,orientation,vec3(*spacing),vec3(*dims)) # # imgsize=dims[0]*dims[1]*dtype.itemsize # arr=rec[rpos:rpos+imgsize].view(dtype).reshape(dims) # rpos+=imgsize # # if scalemethod in ('dv','DV'): # arr=(arr.astype(float)*reslope)+intercept # DV scaling method # # simg=SharedImage(recfile,pos,rot,dims,spacing,trigger) # simg.allocateImg('%s_img%i'%(vname,len(images))) # simg.setArrayImg(arr) # images.append(simg) # # obj=ImageSceneObject(vname,{'geninfo':geninfo,'imginfo':imginfo,'filename':filename},images,self) # objs.append(obj) assert rpos == rec.shape[0], '%i != %i' % (rpos, rec.shape[0]) f.setObject(objs)