use of mpicbg.trakem2.transform.InvertibleCoordinateTransformList in project TrakEM2 by trakem2.
the class TMLHandler method makeCoordinateTransform.
private final void makeCoordinateTransform(String type, final HashMap<String, String> ht_attributes) {
try {
type = type.toLowerCase();
if (type.equals("ict_transform")) {
final CoordinateTransform ct = (CoordinateTransform) Class.forName(ht_attributes.get("class")).newInstance();
ct.init(ht_attributes.get("data"));
if (ct_list_stack.isEmpty()) {
if (last_patch != null)
last_ct = ct;
} else {
ct_list_stack.get(ct_list_stack.size() - 1).add(ct);
}
} else if (type.equals("iict_transform")) {
final InvertibleCoordinateTransform ict = (InvertibleCoordinateTransform) Class.forName(ht_attributes.get("class")).newInstance();
ict.init(ht_attributes.get("data"));
if (ct_list_stack.isEmpty()) {
if (last_patch != null)
last_ct = ict;
else if (last_stack != null)
last_ict = ict;
} else {
ct_list_stack.get(ct_list_stack.size() - 1).add(ict);
}
} else if (type.equals("ict_transform_list")) {
final CoordinateTransformList<CoordinateTransform> ctl = new CoordinateTransformList<CoordinateTransform>();
if (ct_list_stack.isEmpty()) {
if (last_patch != null)
last_ct = ctl;
} else
ct_list_stack.get(ct_list_stack.size() - 1).add(ctl);
ct_list_stack.add((TransformList) ctl);
} else if (type.equals("iict_transform_list")) {
final InvertibleCoordinateTransformList<InvertibleCoordinateTransform> ictl = new InvertibleCoordinateTransformList<InvertibleCoordinateTransform>();
if (ct_list_stack.isEmpty()) {
if (last_patch != null)
last_ct = ictl;
else if (last_stack != null)
last_ict = ictl;
} else
ct_list_stack.get(ct_list_stack.size() - 1).add(ictl);
ct_list_stack.add((TransformList) ictl);
}
} catch (Exception e) {
IJError.print(e);
}
}
use of mpicbg.trakem2.transform.InvertibleCoordinateTransformList in project TrakEM2 by trakem2.
the class Stack method fetchFutureImage.
private final Future<Image> fetchFutureImage(final Long imageId, final double magnification, final Layer active_layer, final boolean trigger_repaint_event) {
synchronized (futureImages) {
Future<Image> fu = futureImages.get(imageId);
if (null == fu) {
fu = project.getLoader().doLater(new Callable<Image>() {
@Override
public Image call() {
final InvertibleCoordinateTransformList<mpicbg.models.InvertibleCoordinateTransform> ictl = new InvertibleCoordinateTransformList<mpicbg.models.InvertibleCoordinateTransform>();
if (ict != null) {
// Utils.log2( "ictScale of " + getTitle() + " is " + ictScale );
ictl.add(ict);
/* Remove boundingBox shift ict ... */
final TranslationModel3D unShiftBounds = new TranslationModel3D();
unShiftBounds.set(-boundsMin[0], -boundsMin[1], 0);
ictl.add(unShiftBounds);
if (ictScale != 1.0) {
final AffineModel3D unScaleXY = new AffineModel3D();
unScaleXY.set(1.0 / ictScale, 0, 0, 0, 0, 1.0 / ictScale, 0, 0, 0, 0, 1.0, 0);
ictl.add(unScaleXY);
}
}
/* TODO remove that scale from ict and put it into atp */
final ImagePlus imp = project.getLoader().fetchImagePlus(Stack.this);
final ImageProcessor ip = imp.getStack().getProcessor(1).createProcessor((int) Math.ceil((boundsMax[0] - boundsMin[0]) / ictScale), (int) Math.ceil((boundsMax[1] - boundsMin[1]) / ictScale));
// Utils.log2( "ictScale is " + ictScale );
// Utils.log2( "rendering an image of " + ip.getWidth() + " x " + ip.getHeight() + " px" );
final double currentZ = active_layer.getZ();
final TranslationModel3D sliceShift = new TranslationModel3D();
sliceShift.set(0, 0, -currentZ);
ictl.add(sliceShift);
/* optimization: if ict is affine, reduce ictl into a single affine */
final InverseTransformMapping<mpicbg.models.InvertibleCoordinateTransform> mapping;
if (AffineModel3D.class.isInstance(ict)) {
final AffineModel3D ictAffine = new AffineModel3D();
boolean isAffine = true;
for (final mpicbg.models.InvertibleCoordinateTransform t : ictl.getList(null)) {
if (AffineModel3D.class.isInstance(t))
ictAffine.preConcatenate((AffineModel3D) t);
else if (TranslationModel3D.class.isInstance(t))
ictAffine.preConcatenate((TranslationModel3D) t);
else {
isAffine = false;
break;
}
}
if (isAffine)
mapping = new InverseTransformMapping<mpicbg.models.InvertibleCoordinateTransform>(ictAffine);
else
mapping = new InverseTransformMapping<mpicbg.models.InvertibleCoordinateTransform>(ictl);
} else
mapping = new InverseTransformMapping<mpicbg.models.InvertibleCoordinateTransform>(ictl);
mapping.mapInterpolated(imp.getStack(), ip);
// wast: atp
final double s = estimateAffineScale(new AffineTransform(at));
final double smoothMag = magnification * s * ictScale;
if (smoothMag < 1.0f) {
Filter.smoothForScale(ip, smoothMag, 0.5f, 0.5f);
}
final Image image = ip.createImage();
if (null == image) {
Utils.log2("Stack.paint: null image, returning");
// TEMPORARY from lazy
return null;
// repaints after closing a
// Project
}
project.getLoader().cacheAWT(imageId, image);
synchronized (futureImages) {
futureImages.remove(imageId);
}
if (trigger_repaint_event) {
// Display.repaint( active_layer, Stack.this );
Display.repaint(active_layer);
}
return image;
}
});
}
// else {
// Utils.log2( "fu is not null" );
// // We don't do anything: we wait for itself to launch a
// repaint event
// }
futureImages.put(imageId, fu);
return fu;
}
}
Aggregations