Java Code Examples for net.imglib2.realtransform.AffineTransform3D#rotate()
The following examples show how to use
net.imglib2.realtransform.AffineTransform3D#rotate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Rotate.java From paintera with GNU General Public License v2.0 | 5 votes |
public void rotate(final double x, final double y, final double startX, final double startY) { final AffineTransform3D affine = new AffineTransform3D(); synchronized (lock) { final double v = ROTATION_STEP * this.speed.getAsDouble(); affine.set(affineDragStart); final double[] point = new double[] {x, y, 0}; final double[] origin = new double[] {startX, startY, 0}; displayTransform.applyInverse(point, point); displayTransform.applyInverse(origin, origin); final double[] delta = new double[] {point[0] - origin[0], point[1] - origin[1], 0}; // TODO do scaling separately. need to swap .get( 0, 0 ) and // .get( 1, 1 ) ? final double[] rotation = new double[] { +delta[1] * v * displayTransform.get(0, 0), -delta[0] * v * displayTransform.get(1, 1), 0}; globalToViewerTransform.applyInverse(origin, origin); globalToViewerTransform.applyInverse(rotation, rotation); // center shift for (int d = 0; d < origin.length; ++d) affine.set(affine.get(d, 3) - origin[d], d, 3); for (int d = 0; d < rotation.length; ++d) affine.rotate(d, rotation[d]); // center un-shift for (int d = 0; d < origin.length; ++d) affine.set(affine.get(d, 3) + origin[d], d, 3); submitTransform.accept(affine); } }
Example 2
Source File: KeyRotate.java From paintera with GNU General Public License v2.0 | 5 votes |
public void rotate(final double x, final double y) { final AffineTransform3D displayTransformCopy = new AffineTransform3D(); final AffineTransform3D globalToViewerTransformCopy = new AffineTransform3D(); final AffineTransform3D globalTransformCopy = new AffineTransform3D(); synchronized (lock) { displayTransformCopy.set(displayTransform); globalToViewerTransformCopy.set(globalToViewerTransform); globalTransformCopy.set(globalTransform); } final AffineTransform3D concatenated = displayTransformCopy .copy() .concatenate(globalToViewerTransformCopy) .concatenate(globalTransformCopy); concatenated.set(concatenated.get(0, 3) - x, 0, 3); concatenated.set(concatenated.get(1, 3) - y, 1, 3); LOG.debug("Rotating {} around axis={} by angle={}", concatenated, axis, step); concatenated.rotate(axis.get().axis, step.getAsDouble()); concatenated.set(concatenated.get(0, 3) + x, 0, 3); concatenated.set(concatenated.get(1, 3) + y, 1, 3); submit.accept(displayTransformCopy.copy().concatenate(globalToViewerTransformCopy).inverse().concatenate( concatenated)); }
Example 3
Source File: Align.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Img< FloatType > a = ImgLib2Util.openAs32Bit( new File( "73.tif.zip" ) ); Img< FloatType > b = ImgLib2Util.openAs32Bit( new File( "74.tif.zip" ) ); TranslationGet t1 = new Translation3D(); TranslationGet t2 = new Translation3D(460, 0, 0); ArrayList< Pair< RealInterval, AffineGet > > views = new ArrayList<Pair<RealInterval, AffineGet>>(); views.add( new ValuePair< RealInterval, AffineGet >( a, t1 ) ); views.add( new ValuePair< RealInterval, AffineGet >( b, t2 ) ); RealInterval overlap = BoundingBoxMaximalGroupOverlap.getMinBoundingIntervalSingle( views ); final RealInterval transformed1 = TransformTools.applyTranslation( a, t1, new boolean[] {false, false, false} ); final RealInterval transformed2 = TransformTools.applyTranslation( b, t2, new boolean[] {false, false, false} ); // get overlap in images' coordinates final RealInterval localOverlap1 = TransformTools.getLocalOverlap( transformed1, overlap ); final RealInterval localOverlap2 = TransformTools.getLocalOverlap( transformed2, overlap ); // round to integer interval final Interval interval1 = TransformTools.getLocalRasterOverlap( localOverlap1 ); final Interval interval2 = TransformTools.getLocalRasterOverlap( localOverlap2 ); //final WarpFunction warp = new TranslationWarp(3); final WarpFunction warp = new RigidWarp(3); //final WarpFunction warp = new AffineWarp( 3 ); // rotate second image AffineTransform3D rot = new AffineTransform3D(); rot.rotate( 2, 2 * Math.PI / 180 ); RandomAccessibleInterval< FloatType > rotated = Views.interval( RealViews.affine( Views.interpolate( Views.extendBorder( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ), rot.copy() ), interval2); // show input new ImageJ(); ImageJFunctions.show( Views.interval( a, interval1 ), "target" ); ImageJFunctions.show( rotated, "in"); // downsample input RandomAccessibleInterval< FloatType > simple2x1 = Downsample.simple2x( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), new boolean[] {true, true, false} ); RandomAccessibleInterval< FloatType > simple2x2 = Downsample.simple2x( Views.zeroMin( Views.interval( rotated, interval2 ) ), new ArrayImgFactory<>(), new boolean[] {true, true, false} ); // align //Align< FloatType > lk = new Align<>( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), warp ); Align< FloatType > lk = new Align<>( simple2x1, new ArrayImgFactory<>(), warp ); //System.out.println( Util.printCoordinates( lk.align( Views.zeroMin( Views.interval( b, interval2 ) ), 100, 0.01 ).getRowPackedCopy() ) ); //final AffineTransform transform = lk.align( Views.zeroMin( rotated ), 100, 0.01 ); final AffineTransform transform = lk.align( simple2x2, 100, 0.01 ); final AffineTransform scale = new AffineTransform( 3 ); scale.set( 2, 0, 0 ); scale.set( 1, 1, 1 ); transform.preConcatenate( scale ); // transformation matrix System.out.println( Util.printCoordinates( transform.getRowPackedCopy() ) ); // correct input and show RandomAccessibleInterval< FloatType > backRotated = Views.interval( RealViews.affine( Views.interpolate( Views.extendBorder( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ), rot.copy().preConcatenate( transform ).copy() ), interval2); ImageJFunctions.show( backRotated, "out" ); // constructor needs column packed matrix, therefore the transpose Matrix mt = new Matrix( transform.getRowPackedCopy(), 4).transpose(); Matrix rigid = mt.getMatrix( 0, 2, 0, 2 ); // check whether result is rotation matrix (det == +-1, orthogonal) System.out.println( rigid.det() ); System.out.println( Util.printCoordinates( rigid.times( rigid.transpose() ).getRowPackedCopy() ) ); }
Example 4
Source File: PreviewRegularGridPanel.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
private void updateBDV() { BigDataViewer bdv = parent.bdvPopup().getBDV(); if ( bdv != null ) { //FilteredAndGroupedExplorerPanel.resetBDVManualTransformations( bdv ); RegularTranslationParameters params = new RegularTranslationParameters(); params.nDimensions = 3; params.alternating = alternating; params.dimensionOrder = dimensionOrder; params.increasing = increasing; params.overlaps = overlaps; params.nSteps = steps; params.keepRotation = rotate; Dimensions size = parent.getSpimData().getSequenceDescription().getViewDescriptions() .get( selectedVDs.get( 0 ).get( 0 ) ).getViewSetup().getSize(); List< Translation3D > generateRegularGrid = RegularTranformHelpers.generateRegularGrid( params, size ); int i = 0; for ( List< BasicViewDescription< ? > > lvd : selectedVDs ) { // we did not generate enough transformations // -> leave the rest of the views as-is if (i>generateRegularGrid.size()) break; for ( BasicViewDescription< ? > vd : lvd ) { int sourceIdx = StitchingExplorerPanel.getBDVSourceIndex( vd.getViewSetup(), parent.getSpimData() ); SourceState< ? > s = parent.bdvPopup().getBDV().getViewer().getState().getSources().get( sourceIdx ); ViewRegistration vr = parent.getSpimData().getViewRegistrations().getViewRegistration( vd ); AffineTransform3D inv = vr.getModel().copy().inverse(); AffineTransform3D calib = new AffineTransform3D(); calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() ); //invAndCalib.preConcatenate( vr.getTransformList().get( 0 ).asAffine3D() ); AffineTransform3D grid = new AffineTransform3D(); if (i < generateRegularGrid.size()) grid.set( generateRegularGrid.get( i ).getRowPackedCopy() ); AffineTransform3D gridTransform = ( i < generateRegularGrid.size() ) ? inv.preConcatenate( grid.copy() ) : inv.copy(); gridTransform.preConcatenate( calib ); if (rotate) { AffineTransform3D rotation = new AffineTransform3D(); Pair< Double, Integer > rotAngleAndAxis = RegularTranformHelpers.getRoatationFromMetadata( vd.getViewSetup().getAttribute( Angle.class ) ); if (rotAngleAndAxis != null) { rotation.rotate( rotAngleAndAxis.getB(), rotAngleAndAxis.getA() ); gridTransform.preConcatenate( rotation.copy() ); } } ( (TransformedSource< ? >) s.getSpimSource() ).setFixedTransform( gridTransform ); } i++; } bdv.getViewer().requestRepaint(); } }
Example 5
Source File: TileConfigurationHelpers.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void applyToData(Map<ViewId, Translation3D> locations, boolean pixelUnits, boolean keepRotation, AbstractSpimData< ? > data) { if (data == null) return; final Map< ViewId, Translation3D > transformsForData = getTransformsForData( locations, pixelUnits, data ); final Collection< BasicViewDescription< ? > > vds = (Collection< BasicViewDescription< ? > >) data.getSequenceDescription().getViewDescriptions().values(); for ( BasicViewDescription< ? > vd : vds ) { if (!vd.isPresent()) continue; if (!transformsForData.containsKey( vd )) continue; final ViewRegistration vr = data.getViewRegistrations().getViewRegistration( vd ); final ViewTransform vtCalib = vr.getTransformList().get( vr.getTransformList().size() - 1 ); final AffineTransform3D calib = new AffineTransform3D(); calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() ); vr.getTransformList().clear(); vr.preconcatenateTransform( vtCalib ); final AffineTransform3D tr = new AffineTransform3D(); tr.set( transformsForData.get( vd ).getRowPackedCopy() ); ViewTransformAffine vtTC = new ViewTransformAffine( "Translation from Tile Configuration", tr ); vr.preconcatenateTransform( vtTC ); if (keepRotation) { AffineTransform3D rotation = new AffineTransform3D(); Pair< Double, Integer > rotAngleAndAxis = RegularTranformHelpers.getRoatationFromMetadata( vd.getViewSetup().getAttribute( Angle.class ) ); if (rotAngleAndAxis != null) { rotation.rotate( rotAngleAndAxis.getB(), rotAngleAndAxis.getA() ); vr.preconcatenateTransform( new ViewTransformAffine( "Rotation from Metadata", rotation.copy() )); } } vr.updateModel(); } }
Example 6
Source File: TileConfigurationHelpers.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void updateBDVPreview(Map<ViewId, Translation3D> locations, boolean pixelUnits, boolean keepRotation, AbstractSpimData< ? > data, BigDataViewer bdv) { if (data == null || bdv == null ) return; final Map< ViewId, Translation3D > transformsForData = getTransformsForData( locations, pixelUnits, data ); final Collection< BasicViewDescription< ? > > vds = (Collection< BasicViewDescription< ? > >) data.getSequenceDescription().getViewDescriptions().values(); final int currentTPId = data.getSequenceDescription().getTimePoints().getTimePointsOrdered() .get( bdv.getViewer().getState().getCurrentTimepoint() ).getId(); for ( BasicViewDescription< ? > vd : vds ) { if (vd.getTimePointId() != currentTPId) continue; final int sourceIdx = StitchingExplorerPanel.getBDVSourceIndex( vd.getViewSetup(), data ); final SourceState< ? > s = bdv.getViewer().getState().getSources().get( sourceIdx ); final ViewRegistration vr = data.getViewRegistrations().getViewRegistration( vd ); final AffineTransform3D inv = vr.getModel().copy().inverse(); final AffineTransform3D calib = new AffineTransform3D(); calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() ); AffineTransform3D transform; if (transformsForData.containsKey( vd )) { transform = inv.copy().preConcatenate( calib ).preConcatenate( transformsForData.get( vd ) ); } else continue; if (keepRotation) { AffineTransform3D rotation = new AffineTransform3D(); Pair< Double, Integer > rotAngleAndAxis = RegularTranformHelpers.getRoatationFromMetadata( vd.getViewSetup().getAttribute( Angle.class ) ); if (rotAngleAndAxis != null) { rotation.rotate( rotAngleAndAxis.getB(), rotAngleAndAxis.getA() ); transform.preConcatenate( rotation.copy() ); } } ( (TransformedSource< ? >) s.getSpimSource() ).setFixedTransform( transform ); } bdv.getViewer().requestRepaint(); }
Example 7
Source File: SlideBook6.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public static void applyAxis(final SpimData data, final double minResolution) { ViewRegistrations viewRegistrations = data.getViewRegistrations(); for (final ViewDescription vd : data.getSequenceDescription().getViewDescriptions().values()) { if (vd.isPresent()) { final Angle a = vd.getViewSetup().getAngle(); if (a.hasRotation()) { final ViewRegistration vr = viewRegistrations.getViewRegistration(vd); final Dimensions dim = vd.getViewSetup().getSize(); VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSizeOrLoad(vd.getViewSetup(), vd.getTimePoint(), data.getSequenceDescription().getImgLoader()); final double calX = voxelSize.dimension(0) / minResolution; final double calY = voxelSize.dimension(1) / minResolution; final double calZ = voxelSize.dimension(2) / minResolution; AffineTransform3D calModel = new AffineTransform3D(); calModel.set( 1, 0, 0, -dim.dimension(0) / 2 * calX, 0, 1, 0, -dim.dimension(1) / 2 * calY, 0, 0, 1, -dim.dimension(2) / 2 * calZ); ViewTransform vt = new ViewTransformAffine("Center view", calModel); vr.preconcatenateTransform(vt); final double[] tmp = new double[16]; final double[] axis = a.getRotationAxis(); final double degrees = a.getRotationAngleDegrees(); final AffineTransform3D rotModel = new AffineTransform3D(); final String d; if (axis[0] == 1 && axis[1] == 0 && axis[2] == 0) { rotModel.rotate(0, Math.toRadians(degrees)); d = "Rotation around x-axis by " + degrees + " degrees"; } else if (axis[0] == 0 && axis[1] == 1 && axis[2] == 0) { rotModel.rotate(1, Math.toRadians(degrees)); d = "Rotation around y-axis by " + degrees + " degrees"; } else if (axis[0] == 0 && axis[0] == 0 && axis[2] == 1) { rotModel.rotate(2, Math.toRadians(degrees)); d = "Rotation around z-axis by " + degrees + " degrees"; } else { IOFunctions.println("Arbitrary rotation axis not supported yet."); continue; } vt = new ViewTransformAffine(d, rotModel); vr.preconcatenateTransform(vt); vr.updateModel(); } } } }