def free(): #Loader.releaseAllCaches() #System.out.println("Released all") # # Instead of releasing all, release half of all loaded images try: image_n_bytes = IMAGE_SIZE projects = Project.getProjects() if 0 == projects.size(): return loader = projects[0].getLoader() f = Loader.getDeclaredField("mawts") f.setAccessible(True) mawts = f.get(loader) n_cached_images = mawts.size() n_bytes_released = 0 if n_cached_images > 0: n_bytes_to_release = int((n_cached_images * 0.5) * image_n_bytes) n_bytes_released = loader.releaseMemory(n_bytes_to_release) if 0 == n_bytes_released: # There may be enough free memory so the loader refused to release anything, # therefore ask the cache instance itself to actually remove the amount requested n_bytes_released = mawts.removeAndFlushSome(n_bytes_to_release) System.out.println("Released " + str(n_bytes_released) + " out of " + str(n_bytes_to_release)) loader.printCacheStatus() if 0 == n_bytes_released: # All memory retained is in the form of native arrays stored for loading images later CachingThread.releaseAll() System.out.println("Cleared CachingThread cache.") except: traceback.print_exc(file=sys.stdout)
def run(): projects = Project.getProjects() if projects is None or projects.isEmpty(): IJ.log('No project open!') return ls = projects.get(0).getRootLayerSet() trees = ls.getZDisplayables(Treeline) trees.addAll(ls.getZDisplayables(AreaTree)) if trees.isEmpty(): IJ.log('No trees to process!') return dc = DirectoryChooser('Target folder') targetFolder = dc.getDirectory() if targetFolder is None: return # user canceled if targetFolder[len(targetFolder) -1] != '/': targetFolder += '/' fdir = File(targetFolder) for f in fdir.listFiles(): if f.isHidden(): continue yn = YesNoCancelDialog(IJ.getInstance(), "WARNING", "Folder not empty! Continue?") if yn.yesPressed(): break else: return process(trees, targetFolder)
def run(): global cal, pw, ph projects = Project.getProjects() if projects is None or projects.isEmpty(): IJ.log('No project open!') return p = projects.get(0) ls = p.getRootLayerSet() cal = ls.getCalibrationCopy() pw = float(cal.pixelWidth) ph = float(cal.pixelHeight) rpt = p.getRootProjectThing() add_recursively(rpt, None)
def run(): global cal, pw, ph projects = Project.getProjects() if projects is None or projects.isEmpty(): IJ.log('No project open!') return p = projects.get(0) ls = p.getRootLayerSet() cal = ls.getCalibrationCopy() pw = float(cal.pixelWidth) ph = float(cal.pixelHeight) rpt = p.getRootProjectThing() add_recursively(rpt,None) add_connectors_recursively(rpt)
# print 'found', connector if connector.intersectsOrigin(area, la): if nd in outgoing: outgoing[nd].append(connector) else: outgoing[nd] = [connector] else: if nd in incoming: incoming[nd].append(connector) else: incoming[nd] = [connector] return {'outgoing':outgoing, 'incoming':incoming} # get the first open project project = Project.getProjects().get(0) projectRoot = project.getRootProjectThing() neurites = projectRoot.findChildrenOfTypeR("neurite") for neurite in neurites: areatrees = neurite.findChildrenOfTypeR("areatree") for areatree in areatrees: areatree = areatree.getObject() root = areatree.getRoot() if root is None: continue layerset = areatree.getLayerSet() calibration = layerset.getCalibration() affine = areatree.getAffineTransform() # outAndInArray = areatree.findConnectors()
from java.lang.reflect import Field from java.lang import Runtime from ini.trakem2.persistence import FSLoader from ini.trakem2 import Project loader = Project.getProjects()[0].getLoader() f = FSLoader.getDeclaredField("regenerator") f.setAccessible(True) f.get(loader).shutdownNow() loader.restartMipMapThreads(Runtime.getRuntime().availableProcessors()) f = FSLoader.getDeclaredField("regenerating_mipmaps") f.setAccessible(True) f.get(loader).clear() f = FSLoader.getDeclaredField("n_regenerating") f.setAccessible(True) f.get(loader).set(0)
for node in tl.getRoot().getSubtreeNodes(): if node.getParent() is not None: if node.getConfidence() < 5: p = array([node.x, node.y], 'f') affine.transform(p, 0, p, 0, 1) x, y = p x *= cal.pixelWidth y *= cal.pixelHeight z = node.getLayer().getZ() * cal.pixelWidth locs.append([x, y, z]) print locs proj = Project.getProjects()[0] ls = proj.getRootLayerSet() neuToDisp = tl d3d = Display3D.get(ls) exe = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) allOuts = [] allOuts.append(exe.submit(d3d.createMesh(proj.findProjectThing(neuToDisp), neuToDisp, 1))) ii = 0 for iffy in locs: print iffy[0], iffy[1], iffy[2] ii += 1 allOuts.append(exe.submit(ContentCreator(d3d, createFatPoint(iffy[0],iffy[1],iffy[2],300), Color3f(Color.red), "name" + str(ii))))
def exportWavefront(zds, filepath): """ Takes a sequence of ZDisplayable instances and saves all as meshes to disk in wavefront format. A materials .mtl file is saved along with it. See: https://github.com/fiji/3D_Viewer/blob/master/src/main/java/customnode/WavefrontExporter.java """ meshes = { zd.getTitle(): d3d.createMesh(zd.project.findProjectThing(zd), zd, resampling_factor).call() for zd in zds } WavefrontExporter.save(meshes, filepath) project = Project.getProjects()[0] d3d = Display3D.getDisplay(project.getRootLayerSet()) def exportSelectedAsWavefront(project, filepath): """ Select a node in the Project Tree, then run this function to export the meshes of all ZDisplayable under the node in Wavefront format. """ exportWavefront(list(loadFromSelectedTreeNode(project)), filepath) # Strategy 1: provide a list of IDs # The IDs of the AreaList (zDisplayables: arealists, balls etc.) instances """ to_add = [67163, 66596]
# To create envelopes for all lineages, do: # regex = None # ... and then don't show the plots (all will be together): # show_3D = False # ASSUMES pipes have the same exact name across all TrakEM2 projects. # The 'name' is the title of the pipe node in the Project Tree # and any of its parent nodes, chained. So if you want all DPM lineages # and these are grouped in a DPM lineage group, then use "DPM". from ini.trakem2 import Project from java.awt import Color from java.io import File projects = [p for p in Project.getProjects()] # Add more colors if you have more than 6 projects open colors = [Color.white, Color.yellow, Color.magenta, Color.green, Color.blue, Color.orange] sources_color_table = {} for project, color in zip(projects, colors): sources_color_table[project] = color # 1. The project to use as reference--others are compared to it. reference_project = projects[0] # 2. The regular expression to match. Only pipes whose name matches it # will be analyzed. If null, all are matched. regex = None # For a single one, put its name: "DPMm2" # 3. A list of text strings containing regular expressions. # Any pipe whose name matches any will be ignored. ignore = ["unknown.*", "poorly.*", "MB.*", "peduncle.*", "TR.*"]
from ini.trakem2 import Project from ini.trakem2.display import Display projects = Project.getProjects() original = projects[0] new_project = projects[1] patches = None layer2 = None for display in Display.getDisplays(): if display.getProject() == original: patches = display.getSelection().getSelected() elif display.getProject() == new_project: layer2 = display.getLayer() for patch in patches: layer2.add(patch.clone(new_project, True))