Search in sources :

Example 31 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class Project method createNewProject.

private static Project createNewProject(Loader loader, boolean ask_for_template, TemplateThing template_root, boolean clone_ids) {
    Project project = new Project(loader);
    // Utils.log2("ask_for_template: " + ask_for_template);
    if (ask_for_template)
        template_root = project.loader.askForXMLTemplate(project);
    if (null == template_root) {
        template_root = new TemplateThing("anything");
    } else if (clone_ids) {
        // the given template_root belongs to another project from which we are cloning
        template_root = template_root.clone(project, true);
    }
    // else, use the given template_root as is.
    // create tree
    project.template_tree = new TemplateTree(project, template_root);
    project.root_tt = template_root;
    // collect unique TemplateThing instances
    synchronized (project.ht_unique_tt) {
        project.ht_unique_tt.clear();
        project.ht_unique_tt.putAll(template_root.getUniqueTypes(new HashMap<String, TemplateThing>()));
    }
    // add all TemplateThing objects to the database, recursively
    if (!clone_ids)
        template_root.addToDatabase(project);
    // else already done when cloning the root_tt
    // create a non-database bound template for the project Thing
    TemplateThing project_template = new TemplateThing("project");
    project.ht_unique_tt.put("project", project_template);
    project_template.addChild(template_root);
    // create the project Thing, to be root of the whole project thing tree
    try {
        project.root_pt = new ProjectThing(project_template, project, project);
    } catch (Exception e) {
        IJError.print(e);
    }
    // create the user objects tree
    project.project_tree = new ProjectTree(project, project.root_pt);
    // create the layer's tree
    project.createLayerTemplates();
    // initialized with default values, and null parent to signal 'root'
    project.layer_set = new LayerSet(project, "Top Level", 0, 0, null, 2048, 2048);
    try {
        project.root_lt = new LayerThing(Project.layer_set_template, project, project.layer_set);
        project.layer_tree = new LayerTree(project, project.root_lt);
    } catch (Exception e) {
        project.remove();
        IJError.print(e);
    }
    // create the project control window, containing the trees in a double JSplitPane
    // beware that this call is asynchronous, dispatched by the SwingUtilities.invokeLater to avoid havok with Swing components.
    ControlWindow.add(project, project.template_tree, project.project_tree, project.layer_tree);
    // register
    al_open_projects.add(project);
    return project;
}
Also used : ProjectTree(ini.trakem2.tree.ProjectTree) LayerTree(ini.trakem2.tree.LayerTree) HashMap(java.util.HashMap) LayerSet(ini.trakem2.display.LayerSet) LayerThing(ini.trakem2.tree.LayerThing) TemplateThing(ini.trakem2.tree.TemplateThing) TemplateTree(ini.trakem2.tree.TemplateTree) ProjectThing(ini.trakem2.tree.ProjectThing)

Example 32 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class Project method getParentTitle.

/**
 * Returns the title of the enclosing abstract node in the ProjectTree.
 */
public String getParentTitle(final Displayable d) {
    try {
        ProjectThing thing = findProjectThing(d);
        ProjectThing parent = (ProjectThing) thing.getParent();
        if (d instanceof Profile) {
            // skip the profile_list
            parent = (ProjectThing) parent.getParent();
        }
        if (null == parent)
            Utils.log2("null parent for " + d);
        if (null != parent && null == parent.getObject()) {
            Utils.log2("null ob for parent " + parent + " of " + d);
        }
        // the abstract thing should be enclosing a String object
        return parent.getObject().toString();
    } catch (Exception e) {
        IJError.print(e);
        return null;
    }
}
Also used : ProjectThing(ini.trakem2.tree.ProjectThing) Profile(ini.trakem2.display.Profile)

Example 33 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class Compare method extractPoints.

/**
 * Extracts the list of fiduciary points from the fiducial parent and, if their name is different than "ball", adds their title as key and their first ball as a fiduciary point value of the returned map. The map is never null but could be empty.
 * The values are calibrated.
 */
public static Map<String, Tuple3d> extractPoints(final ProjectThing fiducial) {
    if (!fiducial.getType().equals("fiducial_points")) {
        Utils.log("Can only extract points from 'fiducial_points' type.");
        return null;
    }
    final ArrayList<ProjectThing> fiducials = fiducial.getChildren();
    if (null == fiducials || 0 == fiducials.size()) {
        Utils.log("No fiducial points can be extracted from " + fiducial);
        return null;
    }
    final Map<String, Tuple3d> fide = new HashMap<String, Tuple3d>();
    for (final ProjectThing child : fiducials) {
        final Ball ball;
        final String title;
        if (child.getType().equals("ball")) {
            // Method 1: use the ball title as the fiducial type
            ball = (Ball) child.getObject();
            title = ball.getTitle();
        } else {
            // Method 2: use the ball's parent type as the fiducial type
            final ArrayList<ProjectThing> balls = child.findChildrenOfType("ball");
            if (null == balls || 0 == balls.size()) {
                Utils.log2("Ignoring empty fiducial " + child);
                continue;
            }
            // pick the first one only
            ball = (Ball) balls.get(0).getObject();
            title = child.getType();
        }
        // calibrated
        final double[][] b = ball.getWorldBalls();
        if (b.length > 0) {
            // get the first one only
            fide.put(title.toLowerCase(), new Point3d(b[0][0], b[0][1], b[0][2]));
            Utils.log2("Found fiducial point " + title.toLowerCase());
        }
    }
    return fide;
}
Also used : Ball(ini.trakem2.display.Ball) HashMap(java.util.HashMap) Tuple3d(org.scijava.vecmath.Tuple3d) Point3d(org.scijava.vecmath.Point3d) ProjectThing(ini.trakem2.tree.ProjectThing)

Example 34 with ProjectThing

use of ini.trakem2.tree.ProjectThing 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 35 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class Project method getMeaningfulTitle2.

public String getMeaningfulTitle2(final Displayable d) {
    final ProjectThing thing = findProjectThing(d);
    // happens if there is no associated node
    if (null == thing)
        return d.getTitle();
    if (!thing.getType().equals(d.getTitle())) {
        return new StringBuilder(!thing.getType().equals(d.getTitle()) ? d.getTitle() + " [" : "[").append(thing.getType()).append(']').toString();
    }
    // Else, search upstream for a ProjectThing whose name differs from its type
    Thing parent = (ProjectThing) thing.getParent();
    while (null != parent) {
        String type = parent.getType();
        Object ob = parent.getObject();
        if (ob.getClass() == Project.class)
            break;
        if (!ob.equals(type)) {
            return ob.toString() + " [" + thing.getType() + "]";
        }
        parent = parent.getParent();
    }
    if (d.getTitle().equals(thing.getType()))
        return "[" + thing.getType() + "]";
    return d.getTitle() + " [" + thing.getType() + "]";
}
Also used : DBObject(ini.trakem2.persistence.DBObject) ProjectThing(ini.trakem2.tree.ProjectThing) LayerThing(ini.trakem2.tree.LayerThing) TemplateThing(ini.trakem2.tree.TemplateThing) ProjectThing(ini.trakem2.tree.ProjectThing) Thing(ini.trakem2.tree.Thing)

Aggregations

ProjectThing (ini.trakem2.tree.ProjectThing)27 DBObject (ini.trakem2.persistence.DBObject)17 HashMap (java.util.HashMap)17 ZDisplayable (ini.trakem2.display.ZDisplayable)16 Displayable (ini.trakem2.display.Displayable)15 ArrayList (java.util.ArrayList)12 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 HashSet (java.util.HashSet)10 TreePath (javax.swing.tree.TreePath)10 Project (ini.trakem2.Project)9 TemplateThing (ini.trakem2.tree.TemplateThing)8 Layer (ini.trakem2.display.Layer)7 LayerSet (ini.trakem2.display.LayerSet)7 Map (java.util.Map)7 LayerThing (ini.trakem2.tree.LayerThing)6 GenericDialog (ij.gui.GenericDialog)5 Profile (ini.trakem2.display.Profile)5 TreeMap (java.util.TreeMap)5 ImagePlus (ij.ImagePlus)4 Display (ini.trakem2.display.Display)3