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);
}
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;
}
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());
}
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");
}
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;
}
Aggregations