use of amira.AmiraMeshDecoder in project TrakEM2 by trakem2.
the class AmiraImporter method importAmiraLabels.
/**
* Returns the array of AreaList or null if the file dialog is canceled. The xo,yo is the pivot of reference.
*/
public static Collection<AreaList> importAmiraLabels(Layer first_layer, double xo, double yo, final String default_dir) {
// open file
OpenDialog od = new OpenDialog("Choose Amira Labels File", default_dir, "");
String filename = od.getFileName();
if (null == filename || 0 == filename.length())
return null;
String dir = od.getDirectory();
if (IJ.isWindows())
dir = dir.replace('\\', '/');
if (!dir.endsWith("/"))
dir += "/";
String path = dir + filename;
AmiraMeshDecoder dec = new AmiraMeshDecoder();
if (!dec.open(path)) {
YesNoDialog yn = new YesNoDialog("Error", "File was not an Amira labels file.\nChoose another one?");
if (yn.yesPressed())
return importAmiraLabels(first_layer, xo, yo, default_dir);
return null;
}
ImagePlus imp = null;
if (dec.isTable()) {
Utils.showMessage("Select the other file (the labels)!");
return null;
} else {
FileInfo fi = new FileInfo();
fi.fileName = filename;
fi.directory = dir;
imp = new ImagePlus("Amira", dec.getStack());
dec.parameters.setParameters(imp);
}
return extractAmiraLabels(imp, dec.parameters, first_layer, xo, yo);
}
use of amira.AmiraMeshDecoder in project TrakEM2 by trakem2.
the class Loader method importLabelsAsAreaLists.
/**
* If base_x or base_y are Double.MAX_VALUE, then those values are asked for in a GenericDialog.
*/
public Bureaucrat importLabelsAsAreaLists(final Layer first_layer, final String path_, final double base_x_, final double base_y_, final float alpha_, final boolean add_background_) {
final Worker worker = new Worker("Import labels as arealists") {
@Override
public void run() {
startedWorking();
try {
String path = path_;
if (null == path) {
final OpenDialog od = new OpenDialog("Select stack", "");
final String name = od.getFileName();
if (null == name || 0 == name.length()) {
return;
}
String dir = od.getDirectory().replace('\\', '/');
if (!dir.endsWith("/"))
dir += "/";
path = dir + name;
}
if (path.toLowerCase().endsWith(".xml")) {
Utils.log("Avoided opening a TrakEM2 project.");
return;
}
double base_x = base_x_;
double base_y = base_y_;
float alpha = alpha_;
boolean add_background = add_background_;
Layer layer = first_layer;
if (Double.MAX_VALUE == base_x || Double.MAX_VALUE == base_y || alpha < 0 || alpha > 1) {
final GenericDialog gd = new GenericDialog("Base x, y");
Utils.addLayerChoice("First layer:", first_layer, gd);
gd.addNumericField("Base_X:", 0, 0);
gd.addNumericField("Base_Y:", 0, 0);
gd.addSlider("Alpha:", 0, 100, 40);
gd.addCheckbox("Add background (zero)", false);
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
layer = first_layer.getParent().getLayer(gd.getNextChoiceIndex());
base_x = gd.getNextNumber();
base_y = gd.getNextNumber();
if (Double.isNaN(base_x) || Double.isNaN(base_y)) {
Utils.log("Base x or y is NaN!");
return;
}
alpha = (float) (gd.getNextNumber() / 100);
add_background = gd.getNextBoolean();
}
releaseToFit(new File(path).length() * 3);
final ImagePlus imp;
if (path.toLowerCase().endsWith(".am")) {
final AmiraMeshDecoder decoder = new AmiraMeshDecoder();
if (decoder.open(path))
imp = new ImagePlus(path, decoder.getStack());
else
imp = null;
} else {
imp = openImagePlus(path);
}
if (null == imp) {
Utils.log("Could not open image at " + path);
return;
}
final Map<Float, AreaList> alis = AmiraImporter.extractAreaLists(imp, layer, base_x, base_y, alpha, add_background);
if (!hasQuitted() && alis.size() > 0) {
layer.getProject().getProjectTree().insertSegmentations(alis.values());
}
} catch (final Exception e) {
IJError.print(e);
} finally {
finishedWorking();
}
}
};
return Bureaucrat.createAndStart(worker, first_layer.getProject());
}
Aggregations