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

The following examples show how to use net.imglib2.realtransform.AffineTransform3D#set() . 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: AppendSpimData2.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public < T extends RealType< T > & NativeType< T > > boolean exportImage( final RandomAccessibleInterval<T> img, final BoundingBoxGUI bb, final TimePoint tp, final ViewSetup vs, final double min, final double max )
{
	if ( appendToHdf5 != null )
		return appendToHdf5.exportImage( img, bb, tp, vs, min, max );

	// write the image
	if ( !this.saver.exportImage( img, bb, tp, vs, min, max ) )
		return false;

	// update the registrations
	final ViewRegistration vr = spimData.getViewRegistrations().getViewRegistration( new ViewId( tp.getId(), vs.getId() ) );

	final double scale = bb.getDownSampling();
	final AffineTransform3D m = new AffineTransform3D();
	m.set( scale, 0.0f, 0.0f, bb.min( 0 ),
		   0.0f, scale, 0.0f, bb.min( 1 ),
		   0.0f, 0.0f, scale, bb.min( 2 ) );
	final ViewTransform vt = new ViewTransformAffine( "fusion bounding box", m );

	vr.getTransformList().clear();
	vr.getTransformList().add( vt );

	return true;
}
 
Example 2
Source File: FlipAxes.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public static List<AffineTransform3D> getAccumulativeFlipTransform(final List<AffineTransform3D> currentTransforms, final boolean[] flipAxes)
{
	final List<AffineTransform3D> res = new ArrayList<>();

	for (final AffineTransform3D currentTransform : currentTransforms)
	{
		final Pair< AffineGet, AffineGet > decomp = TransformTools.decomposeIntoAffineAndTranslation( currentTransform );

		final AffineTransform3D flip = new AffineTransform3D();
		for (int d=0; d<3; d++)
		{
			if (flipAxes[d])
				flip.set( -1, d, d );
		}
		// transformation order should be: 
		// move to origin -> inverse affine to axis-aligned pixels -> flip -> re-apply affine -> re-apply translation
		flip.concatenate( decomp.getA().inverse() );
		flip.concatenate( decomp.getB().inverse() );
		flip.preConcatenate( decomp.getA() );
		flip.preConcatenate( decomp.getB() );

		res.add( flip );
	}

	return res;
}
 
Example 3
Source File: ExportSpimData2TIFF.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public < T extends RealType< T > & NativeType< T > > boolean exportImage( final RandomAccessibleInterval<T> img, final BoundingBoxGUI bb, final TimePoint tp, final ViewSetup vs, final double min, final double max )
{
	// write the image
	if ( !this.saver.exportImage( img, bb, tp, vs, min, max ) )
		return false;

	// update the registrations
	final ViewRegistration vr = spimData.getViewRegistrations().getViewRegistration( new ViewId( tp.getId(), vs.getId() ) );
	
	final double scale = bb.getDownSampling();
	final AffineTransform3D m = new AffineTransform3D();
	m.set( scale, 0.0f, 0.0f, bb.min( 0 ), 
		   0.0f, scale, 0.0f, bb.min( 1 ),
		   0.0f, 0.0f, scale, bb.min( 2 ) );
	final ViewTransform vt = new ViewTransformAffine( "fusion bounding box", m );

	vr.getTransformList().clear();
	vr.getTransformList().add( vt );
	
	return true;
}
 
Example 4
Source File: Apply_Transformation.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static void setModelToCalibration( final SpimData spimData, final ViewId viewId, final double minResolution )
{
	setModelToIdentity( spimData, viewId );
	
	final ViewRegistrations viewRegistrations = spimData.getViewRegistrations();
	final ViewRegistration r = viewRegistrations.getViewRegistration( viewId );
	
	final ViewDescription viewDescription = spimData.getSequenceDescription().getViewDescription( 
			viewId.getTimePointId(), viewId.getViewSetupId() );

	VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSizeOrLoad( viewDescription.getViewSetup(), viewDescription.getTimePoint(), spimData.getSequenceDescription().getImgLoader() );
	final double calX = voxelSize.dimension( 0 ) / minResolution;
	final double calY = voxelSize.dimension( 1 ) / minResolution;
	final double calZ = voxelSize.dimension( 2 ) / minResolution;
	
	final AffineTransform3D m = new AffineTransform3D();
	m.set( calX, 0.0f, 0.0f, 0.0f, 
		   0.0f, calY, 0.0f, 0.0f,
		   0.0f, 0.0f, calZ, 0.0f );
	final ViewTransform vt = new ViewTransformAffine( "calibration", m );
	r.preconcatenateTransform( vt );
}
 
Example 5
Source File: AffineTransform3DJsonAdapter.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AffineTransform3D deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext
		context)
throws JsonParseException
{
	final double[]          data      = context.deserialize(json, double[].class);
	final AffineTransform3D transform = new AffineTransform3D();
	transform.set(data);
	return transform;
}
 
Example 6
Source File: ViewFrustumTest.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp()
{
	camera = new PerspectiveCamera(true);
	camera.setNearClip(0.1);
	camera.setFarClip(10.0);
	camera.setFieldOfView(45);
	camera.setVerticalFieldOfView(true);

	frustumCamera = new ViewFrustum(camera, new double[] {800, 600});

	cameraTransform = new AffineTransform3D();
	cameraTransform.setTranslation(0, 0, -1);

	sceneTransform = new AffineTransform3D();
	sceneTransform.set(
			-1.9735242914056459E-4, -1.0436920839427981E-4, -2.061953312972022E-4, 3.0306137875177632,
			-1.2649862727035413E-4, -1.7813723813362014E-4, 2.11240737752298E-4, 0.956379113095983,
			-1.9341029860978865E-4, 2.2300587509429097E-4, 7.223755022420857E-5, -1.1240682338705246
		);

	sourceToWorldTransform = new AffineTransform3D();
	sourceToWorldTransform.set(
			64.0, 0.0, 0.0, 3674.0,
			0.0, 64.0, 0.0, 3674.0,
			0.0, 0.0, 80.0, 1540.0
		);
}
 
Example 7
Source File: Rotate.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: Apply_Transformation.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public void applyModels( final SpimData spimData, final double minResolution, final int applyTo, final Map< ViewDescription, Pair< double[], String > > modelLinks )
{
	for ( final ViewDescription vd : modelLinks.keySet() )
	{
		final double[] v = modelLinks.get( vd ).getA();
		final String modelDesc = modelLinks.get( vd ).getB();

		final TimePoint t = vd.getTimePoint();
		final Channel c = vd.getViewSetup().getChannel();
		final Illumination i = vd.getViewSetup().getIllumination();
		final Angle a = vd.getViewSetup().getAngle();

		if ( applyTo == 0 )
		{
			IOFunctions.println( "Reseting model to identity transform for timepoint " + t.getName() + ", channel " + c.getName() + ", illum " + i.getName() + ", angle " + a.getName() );
			setModelToIdentity( spimData, vd );
		}
		else if ( applyTo == 1 )
		{
			IOFunctions.println( "Reseting model to calibration for timepoint " + t.getName() + ", channel " + c.getName() + ", illum " + i.getName() + ", angle " + a.getName() );
			setModelToCalibration( spimData, vd, minResolution );
		}
		
		if ( v != null )
		{
			IOFunctions.println( "Applying model " + Util.printCoordinates( v ) + " (" + modelDesc + ") to timepoint " + t.getName() + ", channel " + c.getName() + ", illum " + i.getName() + ", angle " + a.getName() );
			
			final AffineTransform3D model = new AffineTransform3D();
			model.set( v );
			
			preConcatenateTransform( spimData, vd, model, "Manually defined transformation (" + modelDesc + ")" );
		}
	}
}
 
Example 9
Source File: StackList.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assembles the {@link ViewRegistration} object consisting of a list of {@link ViewRegistration}s for all {@link ViewDescription}s that are present
 * 
 * @param viewDescriptionList
 * @param minResolution - the smallest resolution in any dimension (distance between two pixels in the output image will be that wide)
 * @return
 */
protected static ViewRegistrations createViewRegistrations( final Map< ViewId, ViewDescription > viewDescriptionList, final double minResolution )
{
	final HashMap< ViewId, ViewRegistration > viewRegistrationList = new HashMap< ViewId, ViewRegistration >();
	
	for ( final ViewDescription viewDescription : viewDescriptionList.values() )
		if ( viewDescription.isPresent() )
		{
			final ViewRegistration viewRegistration = new ViewRegistration( viewDescription.getTimePointId(), viewDescription.getViewSetupId() );
			
			final VoxelDimensions voxelSize = viewDescription.getViewSetup().getVoxelSize(); 

			final double calX = voxelSize.dimension( 0 ) / minResolution;
			final double calY = voxelSize.dimension( 1 ) / minResolution;
			final double calZ = voxelSize.dimension( 2 ) / minResolution;
			
			final AffineTransform3D m = new AffineTransform3D();
			m.set( calX, 0.0f, 0.0f, 0.0f, 
				   0.0f, calY, 0.0f, 0.0f,
				   0.0f, 0.0f, calZ, 0.0f );
			final ViewTransform vt = new ViewTransformAffine( "calibration", m );
			viewRegistration.preconcatenateTransform( vt );
			
			viewRegistrationList.put( viewRegistration, viewRegistration );
		}
	
	return new ViewRegistrations( viewRegistrationList );
}
 
Example 10
Source File: SlideBook6.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
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();
            }
        }
    }
}
 
Example 11
Source File: PairwiseStitching.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
	{
		final AffineTransform3D m = new AffineTransform3D();
		double scale = 200;
		m.set( scale, 0.0f, 0.0f, 0.0f, 0.0f, scale, 0.0f, 0.0f, 0.0f, 0.0f, scale, 0.0f );

		final AffineTransform3D mShift = new AffineTransform3D();
		double shift = 100;
		mShift.set( 1.0f, 0.0f, 0.0f, shift, 0.0f, 1.0f, 0.0f, shift, 0.0f, 0.0f, 1.0f, shift );
		final AffineTransform3D mShift2 = new AffineTransform3D();
		double shift2x = 1200;
		double shift2y = 300;
		mShift2.set( 1.0f, 0.0f, 0.0f, shift2x, 0.0f, 1.0f, 0.0f, shift2y, 0.0f, 0.0f, 1.0f, 0.0f );

		final AffineTransform3D mShift3 = new AffineTransform3D();
		double shift3x = 500;
		double shift3y = 1300;
		mShift3.set( 1.0f, 0.0f, 0.0f, shift3x, 0.0f, 1.0f, 0.0f, shift3y, 0.0f, 0.0f, 1.0f, 0.0f );

		AffineTransform3D m2 = m.copy();
		AffineTransform3D m3 = m.copy();
		m.preConcatenate( mShift );
		m2.preConcatenate( mShift2 );
		m3.preConcatenate( mShift3 );

		Interval start = new FinalInterval( new long[] { -399, -399, 0 }, new long[] { 0, 0, 1 } );
		List< Interval > intervals = FractalSpimDataGenerator.generateTileList( start, 7, 6, 0.2f );

		List< Interval > falseStarts = FractalSpimDataGenerator.generateTileList( start, 7, 6, 0.30f );

		FractalSpimDataGenerator fsdg = new FractalSpimDataGenerator( 3 );
		fsdg.addFractal( m );
		fsdg.addFractal( m2 );
		fsdg.addFractal( m3 );

		Map< Integer, RandomAccessibleInterval< LongType > > rais = new HashMap< >();
		Map< Integer, TranslationGet > tr = new HashMap< >();

		List< TranslationGet > tileTranslations = FractalSpimDataGenerator.getTileTranslations( falseStarts );

		FractalImgLoader imgLoader = (FractalImgLoader) fsdg.generateSpimData( intervals ).getSequenceDescription()
				.getImgLoader();
		for ( int i = 0; i < intervals.size(); i++ )
		{
			rais.put( i, imgLoader.getImageAtInterval( intervals.get( i ) ) );
			tr.put( i, tileTranslations.get( i ) );
		}

		List< PairwiseStitchingResult< Integer > > pairwiseShifts = getPairwiseShifts( rais, tr,
				new PairwiseStitchingParameters(),
				Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors() ) );

		
		Map< Integer, AffineGet > collect = tr.entrySet().stream().collect( Collectors.toMap( e -> 
			e.getKey(), e -> {AffineTransform3D res = new AffineTransform3D(); res.set( e.getValue().getRowPackedCopy() ); return res; } ));
		
		// TODO: replace with new globalOpt code
		
//		Map< Set<Integer>, AffineGet > globalOptimization = GlobalTileOptimization.twoRoundGlobalOptimization( new TranslationModel3D(),
//				rais.keySet().stream().map( ( c ) -> {Set<Integer> s = new HashSet<>(); s.add( c ); return s;}).collect( Collectors.toList() ), 
//				null, 
//				collect,
//				pairwiseShifts, new GlobalOptimizationParameters() );
//
//		System.out.println( globalOptimization );
	}
 
Example 12
Source File: PreviewRegularGridPanel.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
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 13
Source File: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void getSourceTransform(int t, int level, AffineTransform3D transform) {
	transform.set(transforms[level]);
}
 
Example 14
Source File: ApplyBDVTransformationPopup.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent e )
{
	if ( panel == null )
	{
		IOFunctions.println( "Panel not set for " + this.getClass().getSimpleName() );
		return;
	}

	BigDataViewer bdv = panel.bdvPopup().getBDV();
	
	if (bdv == null)
	{
		IOFunctions.println( "BigDataViewer is not open. Please start it to access this functionality." );
		return;
	}			
	
	
	for (int i = 0; i < bdv.getViewer().getVisibilityAndGrouping().numSources(); ++i)
	{
		Integer tpId = bdv.getViewer().getState().getCurrentTimepoint();
		SourceState<?> s = bdv.getViewer().getVisibilityAndGrouping().getSources().get( i );
		
		// get manual transform
		AffineTransform3D tAffine = new AffineTransform3D();
		((TransformedSource< ? >)s.getSpimSource()).getFixedTransform( tAffine );
		
		// get old transform
		ViewRegistration vr = panel.getSpimData().getViewRegistrations().getViewRegistration( new ViewId(tpId, i ));
		AffineGet old = vr.getTransformList().get( 1 ).asAffine3D();
		
		// update transform in ViewRegistrations
		AffineTransform3D newTransform = new AffineTransform3D();
		newTransform.set( old.get( 0, 3 ) + tAffine.get( 0, 3 ), 0, 3 );
		newTransform.set( old.get( 1, 3 ) + tAffine.get( 1, 3 ), 1, 3 );
		newTransform.set( old.get( 2, 3 ) + tAffine.get( 2, 3 ), 2, 3 );
		
		ViewTransform newVt = new ViewTransformAffine( "Translation", newTransform );				
		vr.getTransformList().set( 1, newVt );
		vr.updateModel();
		
		// reset manual transform
		((TransformedSource< ? >)s.getSpimSource()).setFixedTransform( new AffineTransform3D() );
		bdv.getViewer().requestRepaint();
	}
	
	panel.bdvPopup().updateBDV();			
	
}
 
Example 15
Source File: GlobalOptimizationSubset.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param model
 * @param type
 * @param spimData
 * @param channelsToProcess - just to annotate the registration
 * @param description
 * @return
 */
public < M extends Model< M > > boolean computeGlobalOpt(
		final M model,
		final GlobalOptimizationType type,
		final SpimData2 spimData,
		final List< ChannelProcess > channelsToProcess,
		final String description )
{
	final HashMap< ViewId, Tile< M > > tiles = GlobalOpt.compute( model, type, this, type.considerTimePointsAsUnit() );

	if ( tiles == null )
		return false;
	
	String channelList = "[";
	for ( final ChannelProcess c : channelsToProcess )
		channelList += c.getLabel() + " (c=" + c.getChannel().getName() + "), ";
	channelList = channelList.substring( 0, channelList.length() - 2 ) + "]";

	final AffineTransform3D mapBackModel;
	
	// TODO: Map back first tile as good as possible to original location???
	if ( type.getMapBackReferenceTile( this ) != null && type.getMapBackModel() != null )
		mapBackModel = computeMapBackModel( tiles, type, spimData );
	else
		mapBackModel = null;

	// update the view registrations
	for ( final ViewId viewId : this.getViews() )
	{
		final Tile< M > tile = tiles.get( viewId );
		
		// TODO: we assume that M is an Affine3D, which is not necessarily true
		final Affine3D< ? > tilemodel = (Affine3D< ? >)tile.getModel();
		final double[][] m = new double[ 3 ][ 4 ];
		tilemodel.toMatrix( m );
		
		final AffineTransform3D t = new AffineTransform3D();
		t.set( m[0][0], m[0][1], m[0][2], m[0][3],
			   m[1][0], m[1][1], m[1][2], m[1][3],
			   m[2][0], m[2][1], m[2][2], m[2][3] );
		
		if ( mapBackModel != null )
		{
			t.preConcatenate( mapBackModel );
			IOFunctions.println( "ViewId=" + viewId.getViewSetupId() + ": " + t );
		}
		
		Apply_Transformation.preConcatenateTransform( spimData, viewId, t, description + " on " + channelList );
	}

	return true;
}
 
Example 16
Source File: TransformTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static AffineTransform3D mapBackTransform(AffineGet to, AffineGet from)
{
	final double[][] p = new double[][]{
		{ 0, 0, 0 },
		{ 1, 0, 0 },
		{ 0, 1, 0 },
		{ 1, 1, 0 },
		{ 0, 0, 1 },
		{ 1, 0, 1 },
		{ 0, 1, 1 },
		{ 1, 1, 1 }};

	final double[][] pa = new double[8][3];
	final double[][] pb = new double[8][3];
	
	for ( int i = 0; i < p.length; ++i )
		to.apply( p[ i ], pa[ i ] );
	
	for ( int i = 0; i < p.length; ++i )
		from.apply( p[ i ], pb[ i ] );
	
	// compute the model that maps pb >> pa
	AffineModel3D mapBackModel = new AffineModel3D();
	
	try
	{
		final ArrayList< PointMatch > pm = new ArrayList< PointMatch >();

		for ( int i = 0; i < p.length; ++i )
			pm.add( new PointMatch( new mpicbg.models.Point( pb[i] ), new mpicbg.models.Point( pa[i] ) ) );

		mapBackModel.fit( pm );
	}
	catch ( Exception e )
	{
		IOFunctions.println( "Could not compute model for mapping back: " + e );
		e.printStackTrace();
		return null;
	}

	final AffineTransform3D mapBack = new AffineTransform3D();
	final double[][] m = new double[3][4];
	( (Affine3D< ? >) mapBackModel ).toMatrix( m );

	mapBack.set( m[0][0], m[0][1], m[0][2], +m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0], m[2][1], m[2][2],
			m[2][3] );

	return mapBack;
	
}
 
Example 17
Source File: TileConfigurationHelpers.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
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 18
Source File: MinimalTest.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static SpimData twoAngles()
{
	final ArrayList< ViewSetup > setups = new ArrayList< ViewSetup >();
	final ArrayList< ViewRegistration > registrations = new ArrayList< ViewRegistration >();

	final Channel c0 = new Channel( 0, "test" );
	final Angle a0 = new Angle( 0 );
	final Angle a1 = new Angle( 1 );
	final Illumination i0 = new Illumination( 0 );

	final Dimensions d0 = new FinalDimensions( 512l, 512l, 86l );
	final VoxelDimensions vd0 = new FinalVoxelDimensions( "px", 0.4566360, 0.4566360, 2.0000000 );

	setups.add( new ViewSetup( 0, "setup 0", d0, vd0, c0, a0, i0 ) );
	setups.add( new ViewSetup( 1, "setup 1", d0, vd0, c0, a1, i0 ) );

	final ArrayList< TimePoint > t = new ArrayList< TimePoint >();
	t.add( new TimePoint( 0 ) );
	final TimePoints timepoints = new TimePoints( t );

	final ArrayList< ViewId > missing = new ArrayList< ViewId >();
	final MissingViews missingViews = new MissingViews( missing );

	final ImgLoader imgLoader = new ImgLoader()
	{
		@Override
		public SetupImgLoader< ? > getSetupImgLoader( int setupId )
		{
			return new MySetupImgLoader( setupId );
		}
	};

	for ( final ViewSetup vs : setups )
	{
		final ViewRegistration vr = new ViewRegistration( t.get( 0 ).getId(), vs.getId() );

		final double minResolution = Math.min( Math.min( vs.getVoxelSize().dimension( 0 ), vs.getVoxelSize().dimension( 1 ) ), vs.getVoxelSize().dimension( 2 ) );
		
		final double calX = vs.getVoxelSize().dimension( 0 ) / minResolution;
		final double calY = vs.getVoxelSize().dimension( 1 ) / minResolution;
		final double calZ = vs.getVoxelSize().dimension( 2 ) / minResolution;
		
		final AffineTransform3D m = new AffineTransform3D();
		m.set( calX, 0.0f, 0.0f, 0.0f, 
			   0.0f, calY, 0.0f, 0.0f,
			   0.0f, 0.0f, calZ, 0.0f );
		final ViewTransform vt = new ViewTransformAffine( "Calibration", m );
		vr.preconcatenateTransform( vt );

		vr.updateModel();		
		
		registrations.add( vr );
	}

	final SequenceDescription sd = new SequenceDescription( timepoints, setups, imgLoader, missingViews );
	final SpimData data = new SpimData( new File( "" ), sd, new ViewRegistrations( registrations ) );

	return data;
}
 
Example 19
Source File: ViewerState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public synchronized void getViewerTransform(final AffineTransform3D to)
{
	to.set(this.viewerTransform);
}
 
Example 20
Source File: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set {@code screenScaleTransform} to a screen scale transform at a given {@code screenScaleIndex}.
 *
 * @param screenScaleIndex
 * @param screenScaleTransform
 */
public synchronized void getScreenScaleTransform(final int screenScaleIndex, final AffineTransform3D screenScaleTransform)
{
	if (screenScaleIndex < this.screenScaleTransforms.length && this.screenScaleTransforms[screenScaleIndex] != null)
		screenScaleTransform.set(this.screenScaleTransforms[screenScaleIndex]);
}