Java Code Examples for net.imglib2.realtransform.AffineTransform3D#get()

The following examples show how to use net.imglib2.realtransform.AffineTransform3D#get() . 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: RemoveRotation.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public void removeRotationCenteredAt(final double x, final double y)
{

	final double[] mouseLocation = new double[3];

	final RealPoint p = RealPoint.wrap(mouseLocation);
	p.setPosition(x, 0);
	p.setPosition(y, 1);
	p.setPosition(0, 2);

	final AffineTransform3D global = new AffineTransform3D();

	synchronized (lock)
	{
		global.set(globalTransform);
		viewerTransform.applyInverse(mouseLocation, mouseLocation);
	}
	final double[] inOriginalSpace = mouseLocation.clone();
	global.apply(mouseLocation, mouseLocation);

	final AffineTransform3D affine = new AffineTransform3D();
	for (int i = 0; i < affine.numDimensions(); ++i)
	{
		double val = 0.0;
		for (int k = 0; k < affine.numDimensions(); ++k)
		{
			final double entry = global.get(k, i);
			val += entry * entry;
		}
		val = Math.sqrt(val);
		affine.set(val, i, i);
		affine.set(mouseLocation[i] - inOriginalSpace[i] * val, i, 3);
	}
	LOG.debug("Updating transform to {}", affine);
	submitTransform.accept(affine);
}
 
Example 2
Source File: Transforms.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public static Affine toTransformFX(final AffineTransform3D transform)
{
	return new Affine(
			transform.get(0, 0), transform.get(0, 1), transform.get(0, 2), transform.get(0, 3),
			transform.get(1, 0), transform.get(1, 1), transform.get(1, 2), transform.get(1, 3),
			transform.get(2, 0), transform.get(2, 1), transform.get(2, 2), transform.get(2, 3)
		);
}
 
Example 3
Source File: TileConfigurationHelpers.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static Map<ViewId, Translation3D> getTransformsForData(Map<ViewId, Translation3D> locations, boolean pixelUnits, AbstractSpimData< ? > data )
{
	final Map<ViewId, Translation3D> res = new HashMap<>();
	final Set< ViewId > vidsWithTransformations = locations.keySet();
	final Collection< BasicViewDescription< ? > > vds = (Collection< BasicViewDescription< ? > >) data.getSequenceDescription().getViewDescriptions().values();

	for ( BasicViewDescription< ? > vd : vds )
	{
		ViewId key;
		if (vidsWithTransformations.contains( vd ))
			key = vd;
		else if (vidsWithTransformations.contains( new ViewId(-1, vd.getViewSetupId()) ))
			key = new ViewId(-1, vd.getViewSetupId());
		else
			continue;

		final ViewRegistration vr = data.getViewRegistrations().getViewRegistration( vd );
		final AffineTransform3D calib = new AffineTransform3D();
		calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() );

		final VoxelDimensions voxelDims = vd.getViewSetup().getVoxelSize();

		final Translation3D translation3d = locations.get( key );
		final double[] translationVec = translation3d.getTranslationCopy();

		if (!pixelUnits)
			for (int d = 0; d<voxelDims.numDimensions(); d++)
				translationVec[d] /= voxelDims.dimension( d );

		for (int d = 0; d<calib.numDimensions(); d++)
			translationVec[d] *= calib.get( d, d );

		res.put( new ViewId(vd.getTimePointId(), vd.getViewSetupId()), new Translation3D( translationVec ) );
	}
	return res;
}
 
Example 4
Source File: SimilarityTransformInterpolator.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public SimilarityTransformInterpolator(
		final AffineTransform3D transformStart,
		final AffineTransform3D transformEnd
		) {
	qStart = new double[ 4 ];
	final double[] qStartInv = new double[ 4 ];
	final double[] qEnd = new double[ 4 ];
	final double[] qEndInv = new double[ 4 ];
	qDiff = new double[ 4 ];
	Affine3DHelpers.extractRotation( transformStart, qStart );
	LinAlgHelpers.quaternionInvert( qStart, qStartInv );

	Affine3DHelpers.extractRotation( transformEnd, qEnd );
	LinAlgHelpers.quaternionInvert( qEnd, qEndInv );

	LinAlgHelpers.quaternionMultiply( qStartInv, qEnd, qDiff );
	if ( qDiff[ 0 ] < 0 )
		LinAlgHelpers.scale( qDiff, -1, qDiff );

	scaleStart = Affine3DHelpers.extractScale( transformStart, 0 );
	scaleEnd = Affine3DHelpers.extractScale( transformEnd, 0 );
	scaleDiff = scaleEnd - scaleStart;
	scaleRate = scaleEnd / scaleStart;

	final double[] tStart = new double[ 3 ];
	final double[] tEnd = new double[ 3 ];
	for ( int d = 0; d < 3; ++d )
	{
		tStart[ d ] = transformStart.get( d, 3 ) / scaleStart;
		tEnd[ d ] = transformEnd.get( d, 3 ) / scaleEnd;
	}

	xg0Start = new double[3];
	final double[] xg0End = new double[3];
	xg0Diff = new double[3];

	final double[][] R = new double[ 3 ][ 3 ];
	LinAlgHelpers.quaternionToR( qStartInv, R );
	LinAlgHelpers.mult( R, tStart, xg0Start );
	LinAlgHelpers.scale( xg0Start, -1, xg0Start );
	LinAlgHelpers.quaternionToR( qEndInv, R );
	LinAlgHelpers.mult( R, tEnd, xg0End );
	LinAlgHelpers.scale( xg0End, -1, xg0End );
	LinAlgHelpers.subtract( xg0End, xg0Start, xg0Diff );
}
 
Example 5
Source File: DataSource.java    From paintera with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Convenience method to extract the scale of a {@link Source} from the diagonal of the {@link AffineTransform3D} at
 * {@code t} and {@code level}.
 * @param source Extract scale from this source
 * @param t Extract scale at this time points
 * @param level Extract scale at this mipmap level
 * @return diagonal of transform of {@code source} at time {@code t} and level {@code level}.
 */
static double[] getScale(final Source<?> source, final int t, final int level)
{
	final AffineTransform3D transform = new AffineTransform3D();
	source.getSourceTransform(t, level, transform);
	return new double[] {transform.get(0, 0), transform.get(1, 1), transform.get(2, 2)};
}