use of ini.trakem2.persistence.Loader in project TrakEM2 by trakem2.
the class DBLoader method getRootLayerThing.
/**
* Fetches the root LayerSet, fills it with children (recursively) and uses the profiles, pipes, etc., from the project_thing. Will reconnect the links and open Displays for the layers that have one.
*/
public LayerThing getRootLayerThing(Project project, ProjectThing project_thing, TemplateThing layer_set_tt, TemplateThing layer_tt) {
synchronized (db_lock) {
// connect if disconnected
if (!connectToDatabase()) {
return null;
}
HashMap hs_pt = new HashMap();
unpack(project_thing, hs_pt);
LayerThing root = null;
try {
// -1 signals root
ResultSet r = connection.prepareStatement("SELECT * FROM ab_things WHERE project_id=" + project.getId() + " AND type='layer_set' AND parent_id=-1").executeQuery();
if (r.next()) {
root = getLayerThing(r, project, hs_pt, layer_set_tt, layer_tt);
}
r.close();
if (null == root) {
Utils.log("Loader.getRootLayerThing: can't find it for project id=" + project.getId());
return null;
}
// Redo the links! hs_pt contains now all Displayable objects.
ResultSet rl = connection.prepareStatement("SELECT * FROM ab_links WHERE project_id=" + project.getId()).executeQuery();
while (rl.next()) {
Long id1 = new Long(rl.getLong("id1"));
Long id2 = new Long(rl.getLong("id2"));
Object ob1 = hs_pt.get(id1);
Object ob2 = hs_pt.get(id2);
if (null != ob1 && null != ob2) {
Displayable d = (Displayable) ob1;
d.link((Displayable) ob2, false);
} else {
Utils.log("Loader: broken link between " + id1 + " and " + id2);
}
}
rl.close();
} catch (Exception e) {
IJError.print(e);
return null;
}
return root;
}
}
use of ini.trakem2.persistence.Loader in project TrakEM2 by trakem2.
the class PatchStack method decacheAll.
/**
* Remove all awts and snaps from the loader's cache, and repaint (which will remake as many as needed)
*/
public void decacheAll() {
// record already flushed imps, since there can be shared imps among Patch instances (for example in stacks)
final HashSet<ImagePlus> hs = new HashSet<ImagePlus>();
final Loader loader = patch[currentSlice - 1].getProject().getLoader();
for (int i = 0; i < patch.length; i++) {
ImagePlus imp = loader.fetchImagePlus(patch[i]);
if (hs.contains(imp))
continue;
else if (null != imp)
hs.add(imp);
loader.decache(imp);
loader.flushMipMaps(patch[i].getId());
Display.repaint(patch[i].getLayer(), patch[i], 0);
}
}
use of ini.trakem2.persistence.Loader in project TrakEM2 by trakem2.
the class PatchStack method invertLookupTable.
public void invertLookupTable() {
Loader loader = patch[currentSlice - 1].getProject().getLoader();
ImagePlus imp = loader.fetchImagePlus(patch[currentSlice - 1]);
imp.getProcessor().invert();
Display.repaint(patch[currentSlice - 1].getLayer(), patch[currentSlice - 1], 0);
// TODO if the database updates are too much, then one could put a "save" button somewhere that shows as "unsaved" (red?) when there are unsaved changes.
patch[currentSlice - 1].updateInDatabase("tiff_working");
// just saved
imp.changes = false;
}
use of ini.trakem2.persistence.Loader in project TrakEM2 by trakem2.
the class PatchStack method createColor256Copy.
// WARNING This method will fail if the stack has slices of different dimensions
/**
* Does not respect local transform of the patches, this is intended for confocal stacks.
*/
public ImagePlus createColor256Copy() {
final Rectangle box = patch[0].getBoundingBox();
final int width = box.width;
final int height = box.height;
Loader loader = patch[0].getProject().getLoader();
// the montage, in RGB
patch[0].getProject().getLoader().releaseToFit(4 * patch.length * width * height);
final ColorProcessor montage = new ColorProcessor(width * patch.length, height);
for (int i = 0; i < patch.length; i++) {
montage.insert(this.stack.getProcessor(i + 1), i * width, 0);
}
final MedianCut mc = new MedianCut(montage);
loader.releaseToFit(patch.length * width * height);
ImageProcessor m2 = mc.convertToByte(256);
final ImageStack st = new ImageStack(width, height);
for (int i = 0; i < patch.length; i++) {
m2.setRoi(i * width, 0, width, height);
loader.releaseToFit(width * height);
st.addSlice(null, m2.crop());
}
ImagePlus imp = new ImagePlus("color256", st);
imp.setCalibration(patch[0].getLayer().getParent().getCalibrationCopy());
// imp.getCalibration().pixelDepth = patch[0].getLayer().getThickness();
return imp;
}
use of ini.trakem2.persistence.Loader in project TrakEM2 by trakem2.
the class PatchStack method createGray8Copy.
// WARNING This method will fail if the stack has slices of different dimensions
/**
* Does not respect local transform of the patches, this is intended for confocal stacks.
*/
public ImagePlus createGray8Copy() {
final Rectangle box = patch[0].getBoundingBox();
final int width = box.width;
final int height = box.height;
// compute minimum bounding box
ImageStack st = new ImageStack(width, height);
Loader loader = patch[0].getProject().getLoader();
for (int i = 1; i < patch.length; i++) {
loader.releaseToFit(width * height);
st.addSlice(Integer.toString(i), this.stack.getProcessor(i).convertToByte(true));
}
ImagePlus imp = new ImagePlus("byte", st);
imp.setCalibration(patch[0].getLayer().getParent().getCalibrationCopy());
// imp.getCalibration().pixelDepth = patch[0].getLayer().getThickness();
return imp;
}
Aggregations