Search in sources :

Example 31 with LayerSet

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

the class Graph method extractAndShowGraph.

/**
 * Shows a dialog to pick which classes is one interested in.
 */
public static final void extractAndShowGraph(final LayerSet ls) {
    GenericDialog gd = new GenericDialog("Graph elements");
    Class<Displayable>[] c = new Class[] { AreaList.class, AreaTree.class, Ball.class, Connector.class, Patch.class, Pipe.class, Polyline.class, Profile.class, DLabel.class, Treeline.class };
    String[] types = new String[] { "AreaList", "AreaTree", "Ball", "Connector", "Image", "Pipe", "Polyline", "Profile", "Text", "Treeline" };
    boolean[] states = new boolean[] { true, true, false, false, false, false, true, true, false, true };
    assert (c.length == types.length && types.length == states.length);
    for (int i = 0; i < c.length; i++) {
        if (ZDisplayable.class.isAssignableFrom(c[i])) {
            if (!ls.contains(c[i]))
                states[i] = false;
        } else if (!ls.containsDisplayable(c[i]))
            states[i] = false;
    }
    gd.addCheckboxGroup(types.length, 1, types, states, new String[] { "Include only:" });
    gd.showDialog();
    if (gd.wasCanceled())
        return;
    HashSet<Class<Displayable>> only = new HashSet<Class<Displayable>>();
    for (int i = 0; i < types.length; i++) {
        if (gd.getNextBoolean())
            only.add(c[i]);
    }
    Graph.extractAndShowGraph(ls, only);
}
Also used : AreaTree(ini.trakem2.display.AreaTree) Ball(ini.trakem2.display.Ball) Connector(ini.trakem2.display.Connector) Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) Pipe(ini.trakem2.display.Pipe) AreaList(ini.trakem2.display.AreaList) Profile(ini.trakem2.display.Profile) Point(java.awt.Point) DLabel(ini.trakem2.display.DLabel) Treeline(ini.trakem2.display.Treeline) GenericDialog(ij.gui.GenericDialog) Polyline(ini.trakem2.display.Polyline) Patch(ini.trakem2.display.Patch) HashSet(java.util.HashSet)

Example 32 with LayerSet

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

the class Graph method extractGraph.

public static final <T extends Displayable> Map<String, StringBuilder> extractGraph(final LayerSet ls, final Set<Class<T>> only) {
    final StringBuilder sif = new StringBuilder(4096), xml = new StringBuilder(4096).append("<graph>\n"), names = new StringBuilder(4096);
    final Set<Displayable> seen = new HashSet<Displayable>();
    for (final Connector con : ls.getAll(Connector.class)) {
        Set<Displayable> origins = con.getOrigins();
        if (origins.isEmpty()) {
            Utils.log("Graph: ignoring connector without origins: #" + con.getId());
            continue;
        }
        List<Set<Displayable>> target_lists = con.getTargets();
        if (target_lists.isEmpty()) {
            Utils.log("Graph: ignoring connector without targets: #" + con.getId());
            continue;
        }
        for (final Displayable origin : origins) {
            if (Thread.currentThread().isInterrupted())
                return null;
            if (null != only && !only.contains(origin.getClass()))
                continue;
            seen.add(origin);
            for (final Set<Displayable> targets : target_lists) {
                for (final Displayable target : targets) {
                    if (null != only && !only.contains(target.getClass()))
                        continue;
                    sif.append(origin.getId()).append(" pd ").append(target.getId()).append('\n');
                    xml.append('\t').append("<edge cid=\"").append(con.getId()).append("\" origin=\"").append(origin.getId()).append("\" target=\"").append(target.getId()).append("\" />\n");
                    seen.add(target);
                }
            }
        }
    }
    xml.append("</graph>\n");
    for (final Displayable d : seen) {
        names.append(d.getId()).append('\t').append(d.getProject().getMeaningfulTitle(d)).append('\n');
    }
    final Map<String, StringBuilder> m = new HashMap<String, StringBuilder>();
    m.put("sif", sif);
    m.put("xml", xml);
    m.put("names", names);
    return m;
}
Also used : Connector(ini.trakem2.display.Connector) 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) HashSet(java.util.HashSet)

Example 33 with LayerSet

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

the class Display3D method getProfileContent.

/**
 * Checks if the given Displayable is a Profile, and tries to find a possible Content object in the Image3DUniverse of its LayerSet according to the title as created from its profile_list ProjectThing.
 */
public static Content getProfileContent(final Displayable d) {
    if (null == d)
        return null;
    if (d.getClass() != Profile.class)
        return null;
    final Display3D d3d = get(d.getLayer().getParent());
    if (null == d3d)
        return null;
    ProjectThing pt = d.getProject().findProjectThing(d);
    if (null == pt)
        return null;
    pt = (ProjectThing) pt.getParent();
    return d3d.universe.getContent(new StringBuilder(pt.toString()).append(" #").append(pt.getId()).toString());
}
Also used : ProjectThing(ini.trakem2.tree.ProjectThing)

Example 34 with LayerSet

use of ini.trakem2.display.LayerSet 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 35 with LayerSet

use of ini.trakem2.display.LayerSet 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)

Aggregations

ArrayList (java.util.ArrayList)24 Layer (ini.trakem2.display.Layer)22 LayerSet (ini.trakem2.display.LayerSet)20 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)19 Rectangle (java.awt.Rectangle)14 Patch (ini.trakem2.display.Patch)13 ImagePlus (ij.ImagePlus)11 GenericDialog (ij.gui.GenericDialog)11 ProjectThing (ini.trakem2.tree.ProjectThing)11 AffineTransform (java.awt.geom.AffineTransform)11 Map (java.util.Map)11 Future (java.util.concurrent.Future)11 Displayable (ini.trakem2.display.Displayable)10 ZDisplayable (ini.trakem2.display.ZDisplayable)10 Area (java.awt.geom.Area)10 Worker (ini.trakem2.utils.Worker)9 Point (java.awt.Point)9 TreeMap (java.util.TreeMap)9 DBObject (ini.trakem2.persistence.DBObject)8