Search in sources :

Example 1 with InvertibleCoordinateTransformList

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);
    }
}
Also used : InvertibleCoordinateTransformList(mpicbg.trakem2.transform.InvertibleCoordinateTransformList) InvertibleCoordinateTransform(mpicbg.trakem2.transform.InvertibleCoordinateTransform) InvertibleCoordinateTransformList(mpicbg.trakem2.transform.InvertibleCoordinateTransformList) CoordinateTransformList(mpicbg.trakem2.transform.CoordinateTransformList) InvertibleCoordinateTransformList(mpicbg.trakem2.transform.InvertibleCoordinateTransformList) TransformList(mpicbg.models.TransformList) CoordinateTransformList(mpicbg.trakem2.transform.CoordinateTransformList) CoordinateTransform(mpicbg.trakem2.transform.CoordinateTransform) InvertibleCoordinateTransform(mpicbg.trakem2.transform.InvertibleCoordinateTransform) SAXException(org.xml.sax.SAXException) SAXParseException(org.xml.sax.SAXParseException)

Example 2 with InvertibleCoordinateTransformList

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;
    }
}
Also used : Image(java.awt.Image) ImagePlus(ij.ImagePlus) Callable(java.util.concurrent.Callable) InvertibleCoordinateTransformList(mpicbg.models.InvertibleCoordinateTransformList) ImageProcessor(ij.process.ImageProcessor) InvertibleCoordinateTransform(mpicbg.trakem2.transform.InvertibleCoordinateTransform) TranslationModel3D(mpicbg.models.TranslationModel3D) AffineTransform(java.awt.geom.AffineTransform) AffineModel3D(mpicbg.models.AffineModel3D) InverseTransformMapping(mpicbg.ij.stack.InverseTransformMapping)

Aggregations

InvertibleCoordinateTransform (mpicbg.trakem2.transform.InvertibleCoordinateTransform)2 ImagePlus (ij.ImagePlus)1 ImageProcessor (ij.process.ImageProcessor)1 Image (java.awt.Image)1 AffineTransform (java.awt.geom.AffineTransform)1 Callable (java.util.concurrent.Callable)1 InverseTransformMapping (mpicbg.ij.stack.InverseTransformMapping)1 AffineModel3D (mpicbg.models.AffineModel3D)1 InvertibleCoordinateTransformList (mpicbg.models.InvertibleCoordinateTransformList)1 TransformList (mpicbg.models.TransformList)1 TranslationModel3D (mpicbg.models.TranslationModel3D)1 CoordinateTransform (mpicbg.trakem2.transform.CoordinateTransform)1 CoordinateTransformList (mpicbg.trakem2.transform.CoordinateTransformList)1 InvertibleCoordinateTransformList (mpicbg.trakem2.transform.InvertibleCoordinateTransformList)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1