Search in sources :

Example 71 with Layer

use of ini.trakem2.display.Layer in project TrakEM2 by trakem2.

the class Display method adjustProperties.

public void adjustProperties() {
    final GenericDialog gd = new GenericDialog("Properties", Display.this.frame);
    // gd.addNumericField("layer_scroll_step: ", this.scroll_step, 0);
    gd.addSlider("layer_scroll_step: ", 1, layer.getParent().size(), Display.this.scroll_step);
    gd.addChoice("snapshots_mode", LayerSet.snapshot_modes, LayerSet.snapshot_modes[layer.getParent().getSnapshotsMode()]);
    gd.addCheckbox("prefer_snapshots_quality", layer.getParent().snapshotsQuality());
    final Loader lo = getProject().getLoader();
    final boolean using_mipmaps = lo.isMipMapsRegenerationEnabled();
    gd.addCheckbox("enable_mipmaps", using_mipmaps);
    gd.addCheckbox("enable_layer_pixels virtualization", layer.getParent().isPixelsVirtualizationEnabled());
    final double max = layer.getParent().getLayerWidth() < layer.getParent().getLayerHeight() ? layer.getParent().getLayerWidth() : layer.getParent().getLayerHeight();
    gd.addSlider("max_dimension of virtualized layer pixels: ", 0, max, layer.getParent().getPixelsMaxDimension());
    gd.addCheckbox("Show arrow heads in Treeline/AreaTree", layer.getParent().paint_arrows);
    gd.addCheckbox("Show edge confidence boxes in Treeline/AreaTree", layer.getParent().paint_edge_confidence_boxes);
    gd.addSlider("Stroke width (Treeline, AreaTree, Ball)", 1.0, 10.0, DisplayCanvas.DEFAULT_STROKE.getLineWidth());
    gd.addCheckbox("Show color cues", layer.getParent().color_cues);
    gd.addSlider("+/- layers to color cue", 0, 10, layer.getParent().n_layers_color_cue);
    gd.addCheckbox("Show color cues for areas", layer.getParent().area_color_cues);
    gd.addCheckbox("Use red/blue for color cues", layer.getParent().use_color_cue_colors);
    gd.addCheckbox("Prepaint images", layer.getParent().prepaint);
    gd.addSlider("Preload ahead from sections: ", 0, layer.getParent().size(), layer.getParent().preload_ahead);
    // --------
    gd.showDialog();
    if (gd.wasCanceled())
        return;
    // --------
    int sc = (int) gd.getNextNumber();
    if (sc < 1)
        sc = 1;
    Display.this.scroll_step = sc;
    updateInDatabase("scroll_step");
    // 
    layer.getParent().setSnapshotsMode(gd.getNextChoiceIndex());
    layer.getParent().setSnapshotsQuality(gd.getNextBoolean());
    // 
    final boolean using_mipmaps2 = gd.getNextBoolean();
    if (using_mipmaps2 == using_mipmaps) {
    // Nothing changed
    } else if (!using_mipmaps2 && using_mipmaps) {
        // Desactivate mipmaps
        lo.setMipMapsRegeneration(false);
        lo.flushMipMaps(true);
    } else if (using_mipmaps2 && !using_mipmaps) {
        // Reactivate mipmaps
        lo.setMipMapsRegeneration(true);
        lo.generateMipMaps(layer.getParent().getDisplayables(Patch.class));
    }
    // 
    layer.getParent().setPixelsVirtualizationEnabled(gd.getNextBoolean());
    layer.getParent().setPixelsMaxDimension((int) gd.getNextNumber());
    layer.getParent().paint_arrows = gd.getNextBoolean();
    layer.getParent().paint_edge_confidence_boxes = gd.getNextBoolean();
    DisplayCanvas.DEFAULT_STROKE = new BasicStroke((float) Math.max(1, gd.getNextNumber()), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    layer.getParent().color_cues = gd.getNextBoolean();
    layer.getParent().n_layers_color_cue = (int) gd.getNextNumber();
    layer.getParent().area_color_cues = gd.getNextBoolean();
    layer.getParent().use_color_cue_colors = gd.getNextBoolean();
    layer.getParent().prepaint = gd.getNextBoolean();
    layer.getParent().preload_ahead = (int) Math.min(gd.getNextNumber(), layer.getParent().size());
    Display.repaint(layer.getParent());
}
Also used : BasicStroke(java.awt.BasicStroke) GenericDialog(ij.gui.GenericDialog) Loader(ini.trakem2.persistence.Loader) Point(java.awt.Point)

Example 72 with Layer

use of ini.trakem2.display.Layer in project TrakEM2 by trakem2.

the class Layer method exportXML.

@Override
public void exportXML(final StringBuilder sb_body, final String indent, final XMLOptions options) {
    final String in = indent + "\t";
    // 1 - open tag
    sb_body.append(indent).append("<t2_layer oid=\"").append(id).append("\"\n").append(in).append(" thickness=\"").append(thickness).append("\"\n").append(in).append(" z=\"").append(z).append("\"\n");
    // TODO this search is linear!
    final LayerThing lt = project.findLayerThing(this);
    String title;
    if (null == lt)
        title = null;
    else
        title = lt.getTitle();
    if (null == title)
        title = "";
    // TODO 'title' should be a property of the Layer, not the LayerThing. Also, the LayerThing should not exist: LayerSet and Layer should be directly presentable in a tree. They are not Things as in "objects of the sample", but rather, structural necessities such as Patch.
    sb_body.append(in).append(" title=\"").append(title).append("\"\n");
    sb_body.append(indent).append(">\n");
    // 2 - export children
    if (null != al_displayables) {
        for (final Displayable d : al_displayables) {
            d.exportXML(sb_body, in, options);
        }
    }
    // 3 - close tag
    sb_body.append(indent).append("</t2_layer>\n");
}
Also used : LayerThing(ini.trakem2.tree.LayerThing)

Example 73 with Layer

use of ini.trakem2.display.Layer in project TrakEM2 by trakem2.

the class Project method removeAll.

/**
 * Remove any set of Displayable objects from the Layer, LayerSet and Project Tree as necessary.
 *  ASSUMES there aren't any nested LayerSet objects in @param col.
 */
public final boolean removeAll(final Set<Displayable> col, final DefaultMutableTreeNode top_node) {
    // 0. Sort into Displayable and ZDisplayable
    final Set<ZDisplayable> zds = new HashSet<ZDisplayable>();
    final List<Displayable> ds = new ArrayList<Displayable>();
    for (final Displayable d : col) {
        if (d instanceof ZDisplayable) {
            zds.add((ZDisplayable) d);
        } else {
            ds.add(d);
        }
    }
    // Displayable:
    // 1. First the Profile from the Project Tree, one by one,
    // while creating a map of Layer vs Displayable list to remove in that layer:
    final HashMap<Layer, Set<Displayable>> ml = new HashMap<Layer, Set<Displayable>>();
    for (final Iterator<Displayable> it = ds.iterator(); it.hasNext(); ) {
        final Displayable d = it.next();
        if (d.getClass() == Profile.class) {
            if (!project_tree.remove(false, findProjectThing(d), null)) {
                // like Profile.remove2
                Utils.log("Could NOT delete " + d);
                continue;
            }
            // remove the Profile
            it.remove();
            continue;
        }
        // The map of Layer vs Displayable list
        Set<Displayable> l = ml.get(d.getLayer());
        if (null == l) {
            l = new HashSet<Displayable>();
            ml.put(d.getLayer(), l);
        }
        l.add(d);
    }
    // 2. Then the rest, in bulk:
    if (ml.size() > 0) {
        for (final Map.Entry<Layer, Set<Displayable>> e : ml.entrySet()) {
            e.getKey().removeAll(e.getValue());
        }
    }
    // 3. Stacks
    if (zds.size() > 0) {
        final Set<ZDisplayable> stacks = new HashSet<ZDisplayable>();
        for (final Iterator<ZDisplayable> it = zds.iterator(); it.hasNext(); ) {
            final ZDisplayable zd = it.next();
            if (zd.getClass() == Stack.class) {
                it.remove();
                stacks.add(zd);
            }
        }
        layer_set.removeAll(stacks);
    }
    // 4. ZDisplayable: bulk removal
    if (zds.size() > 0) {
        // 1. From the Project Tree:
        Set<Displayable> not_removed = project_tree.remove(zds, top_node);
        // 2. Then only those successfully removed, from the LayerSet:
        zds.removeAll(not_removed);
        layer_set.removeAll(zds);
    }
    // TODO
    return true;
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) Set(java.util.Set) HashSet(java.util.HashSet) LayerSet(ini.trakem2.display.LayerSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Layer(ini.trakem2.display.Layer) ZDisplayable(ini.trakem2.display.ZDisplayable) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 74 with Layer

use of ini.trakem2.display.Layer in project TrakEM2 by trakem2.

the class Project method openDBProject.

/**
 * Open a TrakEM2 project from the database. Queries the database for existing projects and if more than one, asks which one to open.
 */
public static Project openDBProject() {
    if (Utils.wrongImageJVersion())
        return null;
    DBLoader loader = new DBLoader();
    if (!loader.isReady())
        return null;
    // check connection
    if (!loader.isConnected()) {
        Utils.showMessage("Can't talk to database.");
        loader.destroy();
        return null;
    }
    // query the database for existing projects
    Project[] projects = loader.getProjects();
    if (null == projects) {
        Utils.showMessage("Can't talk to database (null list of projects).");
        loader.destroy();
        return null;
    }
    Project project = null;
    if (0 == projects.length) {
        Utils.showMessage("No projects in this database.");
        loader.destroy();
        return null;
    } else if (1 == projects.length) {
        project = projects[0];
    } else {
        // ask to choose one
        String[] titles = new String[projects.length];
        for (int i = 0; i < projects.length; i++) {
            titles[i] = projects[i].title;
        }
        GenericDialog gd = new GenericDialog("Choose");
        gd.addMessage("Choose project to open:");
        gd.addChoice("project: ", titles, titles[titles.length - 1]);
        gd.showDialog();
        if (gd.wasCanceled()) {
            loader.destroy();
            return null;
        }
        project = projects[gd.getNextChoiceIndex()];
    }
    // check if the selected project is open already
    for (final Project p : al_open_projects) {
        if (loader.isIdenticalProjectSource(p.loader) && p.id == project.id && p.title.equals(project.title)) {
            Utils.showMessage("A project with title " + p.title + " and id " + p.id + " from the same database is already open.");
            loader.destroy();
            return null;
        }
    }
    // now, open the selected project
    // assign loader
    project.loader = loader;
    // grab the XML template
    TemplateThing template_root = loader.getTemplateRoot(project);
    if (null == template_root) {
        Utils.showMessage("Failed to retrieve the template tree.");
        project.destroy();
        return null;
    }
    project.template_tree = new TemplateTree(project, template_root);
    synchronized (project.ht_unique_tt) {
        project.ht_unique_tt.clear();
        project.ht_unique_tt.putAll(template_root.getUniqueTypes(new HashMap<String, TemplateThing>()));
    }
    // create the project Thing, to be root of the whole user Thing tree (and load all its objects)
    // to collect all created displayables, and  then reassign to the proper layers.
    HashMap<Long, Displayable> hs_d = new HashMap<Long, Displayable>();
    try {
        // create a template for the project Thing
        TemplateThing project_template = new TemplateThing("project");
        project.ht_unique_tt.put("project", project_template);
        project_template.addChild(template_root);
        project.root_pt = loader.getRootProjectThing(project, template_root, project_template, hs_d);
        // restore parent/child and attribute ownership and values (now that all Things exist)
        project.root_pt.setup();
    } catch (Exception e) {
        Utils.showMessage("Failed to retrieve the Thing tree for the project.");
        IJError.print(e);
        project.destroy();
        return null;
    }
    // create the user objects tree
    project.project_tree = new ProjectTree(project, project.root_pt);
    // restore the expanded state of each node
    loader.restoreNodesExpandedState(project);
    // create the layers templates
    project.createLayerTemplates();
    // fetch the root layer thing and the root layer set (will load all layers and layer sets, with minimal contents of patches; gets the basic objects -profile, pipe, etc.- from the project.root_pt). Will open all existing displays for each layer.
    LayerThing root_layer_thing = null;
    try {
        root_layer_thing = loader.getRootLayerThing(project, project.root_pt, Project.layer_set_template, Project.layer_template);
        if (null == root_layer_thing) {
            project.destroy();
            Utils.showMessage("Could not retrieve the root layer thing.");
            return null;
        }
        // set the child/parent relationships now that everything exists
        root_layer_thing.setup();
        project.layer_set = (LayerSet) root_layer_thing.getObject();
        if (null == project.layer_set) {
            project.destroy();
            Utils.showMessage("Could not retrieve the root layer set.");
            return null;
        }
        // set the active layer to each ZDisplayable
        project.layer_set.setup();
        // debug:
        // Utils.log2("$$$ root_lt: " + root_layer_thing + "   ob: " + root_layer_thing.getObject().getClass().getName() + "\n children: " + ((LayerSet)root_layer_thing.getObject()).getLayers().size());
        project.layer_tree = new LayerTree(project, root_layer_thing);
        project.root_lt = root_layer_thing;
    } catch (Exception e) {
        Utils.showMessage("Failed to retrieve the Layer tree for the project.");
        IJError.print(e);
        project.destroy();
        return null;
    }
    // if all when well, register as open:
    al_open_projects.add(project);
    // create the project control window, containing the trees in a double JSplitPane
    ControlWindow.add(project, project.template_tree, project.project_tree, project.layer_tree);
    // now open the displays that were stored for later, if any:
    Display.openLater();
    return project;
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) HashMap(java.util.HashMap) LayerThing(ini.trakem2.tree.LayerThing) TemplateTree(ini.trakem2.tree.TemplateTree) ProjectTree(ini.trakem2.tree.ProjectTree) LayerTree(ini.trakem2.tree.LayerTree) DBLoader(ini.trakem2.persistence.DBLoader) GenericDialog(ij.gui.GenericDialog) TemplateThing(ini.trakem2.tree.TemplateThing)

Example 75 with Layer

use of ini.trakem2.display.Layer in project TrakEM2 by trakem2.

the class Project method createSubproject.

/**
 * Create a new subproject for the given layer range and ROI.
 *   Create a new Project using the given project as template. This means the DTD of the given project is copied, as well as the storage and mipmaps folders; everything else is empty in the new project.
 */
public Project createSubproject(final Rectangle roi, final Layer first, final Layer last, final boolean ignore_hidden_patches) {
    try {
        // The order matters.
        final Project pr = new Project(new FSLoader(this.getLoader().getStorageFolder()));
        pr.id = this.id;
        // copy properties
        pr.title = this.title;
        pr.ht_props.putAll(this.ht_props);
        // copy template
        pr.root_tt = this.root_tt.clone(pr, true);
        pr.template_tree = new TemplateTree(pr, pr.root_tt);
        synchronized (pr.ht_unique_tt) {
            pr.ht_unique_tt.clear();
            pr.ht_unique_tt.putAll(root_tt.getUniqueTypes(new HashMap<String, TemplateThing>()));
        }
        TemplateThing project_template = new TemplateThing("project");
        project_template.addChild(pr.root_tt);
        pr.ht_unique_tt.put("project", project_template);
        // create the layers templates
        pr.createLayerTemplates();
        // copy LayerSet and all involved Displayable objects
        // (A two-step process to provide the layer_set pointer and all Layer pointers to the ZDisplayable to copy and crop.)
        pr.layer_set = (LayerSet) this.layer_set.clone(pr, first, last, roi, false, true, ignore_hidden_patches);
        LayerSet.cloneInto(this.layer_set, first, last, pr, pr.layer_set, roi, true);
        // create layer tree
        pr.root_lt = new LayerThing(Project.layer_set_template, pr, pr.layer_set);
        pr.layer_tree = new LayerTree(pr, pr.root_lt);
        // add layer nodes to the layer tree (solving chicken-and-egg problem)
        pr.layer_set.updateLayerTree();
        // copy project tree
        pr.root_pt = this.root_pt.subclone(pr);
        pr.project_tree = new ProjectTree(pr, pr.root_pt);
        // not copying node expanded state.
        // register
        al_open_projects.add(pr);
        // add to gui:
        ControlWindow.add(pr, pr.template_tree, pr.project_tree, pr.layer_tree);
        // Above, the id of each object is preserved from this project into the subproject.
        // The abstract structure should be copied in full regardless, without the basic objects
        // included if they intersect the roi.
        // Regenerate mipmaps (blocks GUI from interaction other than navigation)
        pr.loader.regenerateMipMaps(pr.layer_set.getDisplayables(Patch.class));
        pr.restartAutosaving();
        return pr;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : FSLoader(ini.trakem2.persistence.FSLoader) LayerTree(ini.trakem2.tree.LayerTree) ProjectTree(ini.trakem2.tree.ProjectTree) HashMap(java.util.HashMap) LayerThing(ini.trakem2.tree.LayerThing) TemplateTree(ini.trakem2.tree.TemplateTree) TemplateThing(ini.trakem2.tree.TemplateThing) Patch(ini.trakem2.display.Patch)

Aggregations

Layer (ini.trakem2.display.Layer)61 ArrayList (java.util.ArrayList)52 Patch (ini.trakem2.display.Patch)43 Rectangle (java.awt.Rectangle)34 HashSet (java.util.HashSet)27 ImagePlus (ij.ImagePlus)26 Displayable (ini.trakem2.display.Displayable)25 AffineTransform (java.awt.geom.AffineTransform)23 GenericDialog (ij.gui.GenericDialog)22 Worker (ini.trakem2.utils.Worker)22 Point (mpicbg.models.Point)22 HashMap (java.util.HashMap)21 Point (java.awt.Point)19 Area (java.awt.geom.Area)19 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)18 File (java.io.File)16 Future (java.util.concurrent.Future)16 LayerSet (ini.trakem2.display.LayerSet)15 ExecutorService (java.util.concurrent.ExecutorService)14 Collection (java.util.Collection)13