use of ini.trakem2.display.Treeline 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.Treeline 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());
}
use of ini.trakem2.display.Treeline in project TrakEM2 by trakem2.
the class Project method getUniqueTypes.
/**
* Returns a list of existing unique types in the template tree
* (thus the 'project' type is not included, nor the label).
* The basic types are guaranteed to be present even if there are no instances in the template tree.
* As a side effect, this method populates the HashMap of unique TemplateThing types.
*/
public String[] getUniqueTypes() {
synchronized (ht_unique_tt) {
// ensure the basic types (pipe, ball, profile, profile_list) are present
if (!ht_unique_tt.containsKey("profile"))
ht_unique_tt.put("profile", new TemplateThing("profile"));
if (!ht_unique_tt.containsKey("profile_list")) {
TemplateThing tpl = new TemplateThing("profile_list");
tpl.addChild((TemplateThing) ht_unique_tt.get("profile"));
ht_unique_tt.put("profile_list", tpl);
}
if (!ht_unique_tt.containsKey("pipe"))
ht_unique_tt.put("pipe", new TemplateThing("pipe"));
if (!ht_unique_tt.containsKey("polyline"))
ht_unique_tt.put("polyline", new TemplateThing("polyline"));
if (!ht_unique_tt.containsKey("treeline"))
ht_unique_tt.put("treeline", new TemplateThing("treeline"));
if (!ht_unique_tt.containsKey("areatree"))
ht_unique_tt.put("areatree", new TemplateThing("areatree"));
if (!ht_unique_tt.containsKey("connector"))
ht_unique_tt.put("connector", new TemplateThing("connector"));
if (!ht_unique_tt.containsKey("ball"))
ht_unique_tt.put("ball", new TemplateThing("ball"));
if (!ht_unique_tt.containsKey("area_list"))
ht_unique_tt.put("area_list", new TemplateThing("area_list"));
if (!ht_unique_tt.containsKey("dissector"))
ht_unique_tt.put("dissector", new TemplateThing("dissector"));
// this should be done automagically by querying the classes in the package ... but java can't do that without peeking into the .jar .class files. Buh.
TemplateThing project_tt = ht_unique_tt.remove("project");
/* // debug
for (Iterator it = ht_unique_tt.keySet().iterator(); it.hasNext(); ) {
Utils.log2("class: " + it.next().getClass().getName());
} */
final String[] ut = new String[ht_unique_tt.size()];
ht_unique_tt.keySet().toArray(ut);
ht_unique_tt.put("project", project_tt);
Arrays.sort(ut);
return ut;
}
}
use of ini.trakem2.display.Treeline in project TrakEM2 by trakem2.
the class TreelineGraphEditor method invoke.
public Object invoke(Object... args) {
if (null == args || args.length < 1 || null == args[0] || !(args[0] instanceof Treeline))
return null;
try {
Class RT = Class.forName("clojure.lang.RT");
Method var = RT.getDeclaredMethod("var", new Class[] { String.class, String.class });
Object fn = var.invoke(null, new Object[] { "treeline.graph_editor", "as-graph" });
return Class.forName("clojure.lang.Var").getDeclaredMethod("invoke", new Class[] { Object.class }).invoke(fn, new Object[] { args[0] });
} catch (Throwable e) {
IJError.print(e);
}
return null;
}
use of ini.trakem2.display.Treeline in project TrakEM2 by trakem2.
the class TMLHandler method makeLayerThing.
private LayerThing makeLayerThing(String type, final HashMap<String, String> ht_attributes) {
try {
type = type.toLowerCase();
if (0 == type.indexOf("t2_")) {
type = type.substring(3);
}
// long id = -1;
// final String sid = ht_attributes.get("id");
// if (null != sid) id = Long.parseLong(sid);
long oid = -1;
final String soid = ht_attributes.get("oid");
if (null != soid)
oid = Long.parseLong(soid);
if (type.equals("node")) {
if (null == last_tree) {
throw new NullPointerException("Can't create a node for null last_tree!");
}
final Node<?> node = last_tree.newNode(ht_attributes);
taggables.add(node);
// Put node into the list of nodes with that layer id, to update to proper Layer pointer later
final long ndlid = Long.parseLong(ht_attributes.get("lid"));
List<Node<?>> list = node_layer_table.get(ndlid);
if (null == list) {
list = new ArrayList<Node<?>>();
node_layer_table.put(ndlid, list);
}
list.add(node);
// Set node as root node or add as child to last node in the stack
if (null == last_root_node) {
last_root_node = node;
} else {
final String sconf = ht_attributes.get("c");
nodes.getLast().add((Node) node, null == sconf ? Node.MAX_EDGE_CONFIDENCE : Byte.parseByte(sconf));
}
// color?
final String scolor = ht_attributes.get("color");
if (null != scolor) {
final Color color = Utils.getRGBColorFromHex(scolor);
Collection<Node<?>> nodes = node_colors.get(color);
if (null == nodes) {
nodes = new ArrayList<Node<?>>();
node_colors.put(color, nodes);
}
nodes.add(node);
}
// Put node into stack of nodes (to be removed on closing the tag)
nodes.add(node);
} else if (type.equals("profile")) {
Profile profile = new Profile(this.project, oid, ht_attributes, ht_links);
profile.addToDatabase();
ht_displayables.put(oid, profile);
addToLastOpenLayer(profile);
last_displayable = profile;
return null;
} else if (type.equals("pipe")) {
Pipe pipe = new Pipe(this.project, oid, ht_attributes, ht_links);
pipe.addToDatabase();
ht_displayables.put(new Long(oid), pipe);
ht_zdispl.put(new Long(oid), pipe);
last_displayable = pipe;
addToLastOpenLayerSet(pipe);
return null;
} else if (type.equals("polyline")) {
Polyline pline = new Polyline(this.project, oid, ht_attributes, ht_links);
pline.addToDatabase();
last_displayable = pline;
ht_displayables.put(new Long(oid), pline);
ht_zdispl.put(new Long(oid), pline);
addToLastOpenLayerSet(pline);
return null;
} else if (type.equals("connector")) {
final Connector con = new Connector(this.project, oid, ht_attributes, ht_links);
if (ht_attributes.containsKey("origin")) {
legacy.add(new Runnable() {
public void run() {
con.readLegacyXML(al_layer_sets.get(al_layer_sets.size() - 1), ht_attributes, ht_links);
}
});
}
con.addToDatabase();
last_connector = con;
last_tree = con;
last_displayable = con;
ht_displayables.put(new Long(oid), con);
ht_zdispl.put(new Long(oid), con);
addToLastOpenLayerSet(con);
return null;
} else if (type.equals("path")) {
if (null != reca) {
reca.add(ht_attributes.get("d"));
return null;
}
return null;
} else if (type.equals("area")) {
reca = new ReconstructArea();
if (null != last_area_list) {
last_area_list_layer_id = Long.parseLong(ht_attributes.get("layer_id"));
}
return null;
} else if (type.equals("area_list")) {
AreaList area = new AreaList(this.project, oid, ht_attributes, ht_links);
// why? This looks like an onion
area.addToDatabase();
last_area_list = area;
last_displayable = area;
ht_displayables.put(new Long(oid), area);
ht_zdispl.put(new Long(oid), area);
addToLastOpenLayerSet(area);
return null;
} else if (type.equals("tag")) {
Taggable t = taggables.getLast();
if (null != t) {
Object ob = ht_attributes.get("key");
// defaults to 't'
int keyCode = KeyEvent.VK_T;
// KeyEvent.VK_U is char U, not u
if (null != ob)
keyCode = (int) ((String) ob).toUpperCase().charAt(0);
Tag tag = al_layer_sets.get(al_layer_sets.size() - 1).putTag(ht_attributes.get("name"), keyCode);
// could be null if name is not found
if (null != tag)
t.addTag(tag);
}
} else if (type.equals("ball_ob")) {
// add a ball to the last open Ball
if (null != last_ball) {
last_ball.addBall(Double.parseDouble(ht_attributes.get("x")), Double.parseDouble(ht_attributes.get("y")), Double.parseDouble(ht_attributes.get("r")), Long.parseLong(ht_attributes.get("layer_id")));
}
return null;
} else if (type.equals("ball")) {
Ball ball = new Ball(this.project, oid, ht_attributes, ht_links);
ball.addToDatabase();
last_ball = ball;
last_displayable = ball;
ht_displayables.put(new Long(oid), ball);
ht_zdispl.put(new Long(oid), ball);
addToLastOpenLayerSet(ball);
return null;
} else if (type.equals("stack")) {
Stack stack = new Stack(this.project, oid, ht_attributes, ht_links);
stack.addToDatabase();
last_stack = stack;
last_displayable = stack;
ht_displayables.put(new Long(oid), stack);
ht_zdispl.put(new Long(oid), stack);
addToLastOpenLayerSet(stack);
} else if (type.equals("treeline")) {
Treeline tline = new Treeline(this.project, oid, ht_attributes, ht_links);
tline.addToDatabase();
last_treeline = tline;
last_tree = tline;
last_treeline_data = new StringBuilder();
last_displayable = tline;
ht_displayables.put(oid, tline);
ht_zdispl.put(oid, tline);
addToLastOpenLayerSet(tline);
} else if (type.equals("areatree")) {
AreaTree art = new AreaTree(this.project, oid, ht_attributes, ht_links);
art.addToDatabase();
last_areatree = art;
last_tree = art;
last_displayable = art;
ht_displayables.put(oid, art);
ht_zdispl.put(oid, art);
addToLastOpenLayerSet(art);
} else if (type.equals("dd_item")) {
if (null != last_dissector) {
last_dissector.addItem(Integer.parseInt(ht_attributes.get("tag")), Integer.parseInt(ht_attributes.get("radius")), ht_attributes.get("points"));
}
} else if (type.equals("label")) {
DLabel label = new DLabel(project, oid, ht_attributes, ht_links);
label.addToDatabase();
ht_displayables.put(new Long(oid), label);
addToLastOpenLayer(label);
last_displayable = label;
return null;
} else if (type.equals("annot")) {
last_annotation = new StringBuilder();
return null;
} else if (type.equals("patch")) {
Patch patch = new Patch(project, oid, ht_attributes, ht_links);
patch.addToDatabase();
ht_displayables.put(new Long(oid), patch);
addToLastOpenLayer(patch);
last_patch = patch;
last_displayable = patch;
checkAlphaMasks(patch);
return null;
} else if (type.equals("filter")) {
last_patch_filters.add(newFilter(ht_attributes));
} else if (type.equals("dissector")) {
Dissector dissector = new Dissector(this.project, oid, ht_attributes, ht_links);
dissector.addToDatabase();
last_dissector = dissector;
last_displayable = dissector;
ht_displayables.put(new Long(oid), dissector);
ht_zdispl.put(new Long(oid), dissector);
addToLastOpenLayerSet(dissector);
} else if (type.equals("layer")) {
// find last open LayerSet, if any
for (int i = al_layer_sets.size() - 1; i > -1; ) {
LayerSet set = al_layer_sets.get(i);
Layer layer = new Layer(project, oid, ht_attributes);
layer.addToDatabase();
set.addSilently(layer);
al_layers.add(layer);
Object ot = ht_attributes.get("title");
return new LayerThing(template_layer_thing, project, -1, (null == ot ? null : (String) ot), layer, null);
}
} else if (type.equals("layer_set")) {
LayerSet set = new LayerSet(project, oid, ht_attributes, ht_links);
last_displayable = set;
set.addToDatabase();
ht_displayables.put(new Long(oid), set);
al_layer_sets.add(set);
addToLastOpenLayer(set);
Object ot = ht_attributes.get("title");
return new LayerThing(template_layer_set_thing, project, -1, (null == ot ? null : (String) ot), set, null);
} else if (type.equals("calibration")) {
// find last open LayerSet if any
for (int i = al_layer_sets.size() - 1; i > -1; ) {
LayerSet set = al_layer_sets.get(i);
set.restoreCalibration(ht_attributes);
return null;
}
} else if (type.equals("prop")) {
// Add property to last created Displayable
if (null != last_displayable) {
last_displayable.setProperty(ht_attributes.get("key"), ht_attributes.get("value"));
}
} else if (type.equals("linked_prop")) {
// Add linked property to last created Displayable. Has to wait until the Displayable ids have been resolved to instances.
if (null != last_displayable) {
putLinkedProperty(last_displayable, ht_attributes);
}
} else {
Utils.log2("TMLHandler Unknown type: " + type);
}
} catch (Exception e) {
IJError.print(e);
}
// default:
return null;
}
Aggregations