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

The following examples show how to use net.imglib2.realtransform.AffineTransform3D#scale() . 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: DisplayTransformUpdateOnResize.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private void setCanvasSize(final double width, final double height, final boolean updateTransform)
{
	if (width == 0 || height == 0)
		return;
	if (updateTransform) // && false )
	{
		synchronized (lock)
		{
			final AffineTransform3D transform = this.displayTransform;
			transform.set(0, 0, 3);
			transform.set(0, 1, 3);
			transform.scale(width / canvasW);
			transform.set(width / 2, 0, 3);
			transform.set(height / 2, 1, 3);
			displayTransformUpdater.setTransform(transform);
		}
	}
	canvasW = width;
}
 
Example 2
Source File: Zoom.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public void zoomCenteredAt(final double delta, final double x, final double y)
{

	if (delta == 0.0)
	{
		return;
	}

	final AffineTransform3D global = new AffineTransform3D();
	synchronized (lock)
	{
		global.set(this.global);
	}
	final double[] location = new double[] {x, y, 0};
	concatenated.applyInverse(location, location);
	global.apply(location, location);

	final double dScale = speed.getAsDouble();
	final double scale  = delta > 0 ? 1.0 / dScale : dScale;

	for (int d = 0; d < location.length; ++d)
		global.set(global.get(d, 3) - location[d], d, 3);
	global.scale(scale);
	for (int d = 0; d < location.length; ++d)
		global.set(global.get(d, 3) + location[d], d, 3);

	manager.setTransform(global);
}
 
Example 3
Source File: FitToInterval.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public void fit(final Interval interval)
{
	final double[] translation = IntStream
			.range(0, interval.numDimensions())
			.mapToDouble(d -> -0.5 * (interval.min(d) + interval.max(d)))
			.toArray();
	final AffineTransform3D tf = new AffineTransform3D();
	tf.translate(translation);
	tf.scale(width.getAsDouble() / interval.dimension(0));
	manager.setTransform(tf);
}
 
Example 4
Source File: BDVRenderer.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ImageProcessor render(RenderingState kf) {
	BDVRenderingState bkf = (BDVRenderingState)kf;
	ViewerPanel panel = viewer.getViewer();
	ViewerState state = panel.getState();

	SetupAssignments setupAssignments = viewer.getSetupAssignments();
	for(int s = 0; s < state.numSources(); s++) {
		final ConverterSetup setup = setupAssignments.getConverterSetups().get(s);
		setup.setColor(new ARGBType(bkf.getChannelColor(s).getRGB()));
		setup.setDisplayRange(bkf.getChannelMin(s), bkf.getChannelMax(s));
	}

	DisplayMode displaymode = bkf.getDisplayMode();
	Interpolation interpolation = bkf.getInterpolation();
	int timepoint = bkf.getTimepoint();
	int currentSource = bkf.getCurrentSource();

	panel.setDisplayMode(displaymode);
	if(state.getInterpolation() != interpolation)
		panel.toggleInterpolation();
	panel.setTimepoint(timepoint);
	panel.getVisibilityAndGrouping().setCurrentSource(currentSource);

	CombinedTransform transform = kf.getFwdTransform();

	float[] tmp = calculateForwardTransform(transform);


	int w = panel.getWidth();
	int h = panel.getHeight();

	double rw = 2 * rotationCenter[0];
	double rh = 2 * rotationCenter[1];
	double scaleX = w / rw;
	double scaleY = h / rh;
	double scale = Math.min(scaleX, scaleY);
	rw = rw * scale;
	rh = rh * scale;
	double tx = (w - rw) / 2;
	double ty = (h - rh) / 2;

	AffineTransform3D affine = new AffineTransform3D();

	affine.set(toDouble(tmp));

	affine.scale(scale);
	affine.translate(tx, ty, 0);

	panel.setCurrentViewerTransform(affine);

	return takeSnapshot().getProcessor();
}
 
Example 5
Source File: TransformTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
{
	AffineTransform3D scale = new AffineTransform3D();
	
	scale.scale( 2.0 );
	//scale.rotate( 0, 45 );
	
	
	AffineTransform3D translate = new AffineTransform3D();
	translate.translate( new double[] {100.0, 100.0, 100.0} );
	AffineTransform3D translate2 = new AffineTransform3D();
	translate2.translate( new double[] {200.0, 200.0, 200.0} );
	
	AffineTransform3D conc = scale.copy().preConcatenate( translate );
	scale.scale( 3.0 );
	AffineTransform3D conc2 = scale.copy().preConcatenate( translate2 );
	//System.out.println( scale );
	//System.out.println( translate );
	System.out.println( conc );
	System.out.println( conc2 );
	
	RealPoint p1 = new RealPoint( 3 );
	conc.apply( p1, p1 );
	RealPoint p2 = new RealPoint( 3 );
	conc2.apply( p2, p2 );
	
	System.out.println( p1 );
	System.out.println( p2 );
	
	AffineTransform3D everythingbuttraslation = conc.copy();
	everythingbuttraslation.set( 0, 0, 3 );
	everythingbuttraslation.set( 0, 1, 3 );
	everythingbuttraslation.set( 0, 2, 3 );
	
	AffineTransform3D everythingbuttraslation2 = conc2.copy();
	everythingbuttraslation2.set( 0, 0, 3 );
	everythingbuttraslation2.set( 0, 1, 3 );
	everythingbuttraslation2.set( 0, 2, 3 );
	
	double[] trans1 = conc.getTranslation();
	double[] trans2 = conc2.getTranslation();
	
	everythingbuttraslation.inverse().apply( trans1, trans1 );
	everythingbuttraslation2.inverse().apply( trans2, trans2 );
	
	System.out.println( new RealPoint( trans1 ) );
	System.out.println( new RealPoint( trans2 ) );
	
	
	System.out.println( mapBackTransform( everythingbuttraslation, everythingbuttraslation2 ) );
	
	
	
	
}