Java Code Examples for net.imglib2.util.Intervals#union()

The following examples show how to use net.imglib2.util.Intervals#union() . 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: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Request a repaint of the given display interval from the painter thread. The painter thread will trigger a {@link #paint} as
 * soon as possible (that is, immediately or after the currently running {@link #paint} has completed).
 */
public synchronized void requestRepaint(final Interval interval, final int screenScaleIndex)
{
	if (Intervals.isEmpty(interval))
		return;

	if (renderingMayBeCancelled && projector != null)
		projector.cancel();

	if (screenScaleIndex > requestedScreenScaleIndex)
		requestedScreenScaleIndex = screenScaleIndex;

	// FIXME: there is a race condition that sometimes may cause an ArrayIndexOutOfBounds exception:
	// Screen scales are first initialized with the default setting (see RenderUnit),
	// then the project metadata is loaded, and the screen scales are changed to the saved configuration.
	// If the project screen scales are [1.0], sometimes the renderer receives a request to re-render the screen at screen scale 1, which results in the exception.
	if (requestedScreenScaleIndex >= pendingRepaintRequests.length)
		return;

	if (pendingRepaintRequests[requestedScreenScaleIndex] == null)
		pendingRepaintRequests[requestedScreenScaleIndex] = interval;
	else
		pendingRepaintRequests[requestedScreenScaleIndex] = Intervals.union(pendingRepaintRequests[requestedScreenScaleIndex], interval);

	painterThread.requestRepaint();
}
 
Example 2
Source File: ShapeInterpolationMode.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private SectionInfo createSectionInfo(final PainteraBaseView paintera)
{
	Interval selectionSourceBoundingBox = null;
	for (final TLongObjectIterator<SelectedObjectInfo> it = selectedObjects.iterator(); it.hasNext();)
	{
		it.advance();
		if (selectionSourceBoundingBox == null)
			selectionSourceBoundingBox = it.value().sourceBoundingBox;
		else
			selectionSourceBoundingBox = Intervals.union(selectionSourceBoundingBox, it.value().sourceBoundingBox);
	}

	final AffineTransform3D globalTransform = new AffineTransform3D();
	paintera.manager().getTransform(globalTransform);

	return new SectionInfo(
			mask,
			globalTransform,
			getMaskDisplayTransformIgnoreScaling(SHAPE_INTERPOLATION_SCALE_LEVEL),
			selectionSourceBoundingBox,
			new TLongObjectHashMap<>(selectedObjects)
		);
}
 
Example 3
Source File: PaintClickOrDrag.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void paint(final double viewerX, final double viewerY)
{

	LOG.debug( "At {} {}", viewerX, viewerY );

	if (!this.isPainting) {
		LOG.debug("Not currently activated for painting, returning without action");
		return;
	}

	final RandomAccessibleInterval<UnsignedLongType> mask = getMaskIfIsPaintingOrNull();
	if (mask == null) {
		LOG.debug("Current mask is null, returning without action");
		return;
	}
	final double radius = brushRadius.getAsDouble();
	final Interval trackedInterval = Paint2D.paint(
			Views.extendValue(mask, new UnsignedLongType(Label.INVALID)),
			this.fillLabel,
			viewerX,
			viewerY,
			radius,
			brushDepth.getAsDouble(),
			labelToViewerTransform,
			globalToViewerTransform,
			labelToGlobalTransform);
	this.interval = this.interval == null
			? trackedInterval
			: Intervals.union(trackedInterval, this.interval);
	++this.fillLabel;

	final RealInterval trackedIntervalInGlobalSpace = IntervalHelpers.extendAndTransformBoundingBox(trackedInterval, labelToGlobalTransform, 0.5);
	this.paintera.orthogonalViews().requestRepaint(trackedIntervalInGlobalSpace);

}
 
Example 4
Source File: OrthoSliceFX.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private void updateTexture(final RenderUnit.RenderResult newv)
{
	if (newv.getImage() == null || newv.getScreenScaleIndex() == -1)
		return;

	// FIXME: there is a race condition that sometimes may cause an ArrayIndexOutOfBounds exception:
	// Screen scales are first initialized with the default setting (see RenderUnit),
	// then the project metadata is loaded, and the screen scales are changed to the saved configuration.
	// If the project screen scales are [1.0], sometimes the renderer receives a request to re-render the screen at screen scale 1, which results in the exception.
	if (newv.getScreenScaleIndex() >= textures.length)
		return;

	final int[] textureImageSize = {(int) newv.getImage().getWidth(), (int) newv.getImage().getHeight()};
	final Texture texture = getTexture(newv.getScreenScaleIndex(), textureImageSize);

	final Interval interval = Intervals.intersect(
		Intervals.smallestContainingInterval(newv.getRenderTargetRealInterval()),
		new FinalInterval(new FinalDimensions(textureImageSize))
	);

	// copy relevant part of the rendered image into the first texture image
	final PixelReader pixelReader = newv.getImage().getPixelReader();
	final PixelWriter pixelWriter = texture.originalImage.getPixelWriter();
	pixelWriter.setPixels(
		(int) interval.min(0), // dst x
		(int) interval.min(1), // dst y
		(int) interval.dimension(0), // w
		(int) interval.dimension(1),	// h
		pixelReader, // src
		(int) interval.min(0), // src x
		(int) interval.min(1)  // src y
	);

	if (updateIntervals[newv.getScreenScaleIndex()] == null)
		updateIntervals[newv.getScreenScaleIndex()] = interval;
	else
		updateIntervals[newv.getScreenScaleIndex()] = Intervals.union(interval, updateIntervals[newv.getScreenScaleIndex()]);

	// set up a task for updating the texture of the mesh
	final int newScreenScaleIndex = newv.getScreenScaleIndex();
	final Runnable updateTextureTask = () -> InvokeOnJavaFXApplicationThread.invoke(
		() -> {
			if (newScreenScaleIndex >= textures.length || textures[newScreenScaleIndex] != texture)
				return;

			final Interval textureImageInterval = new FinalInterval(textureImageSize[0], textureImageSize[1]);
			final Interval updateInterval = updateIntervals[newScreenScaleIndex] != null
					? Intervals.intersect(updateIntervals[newScreenScaleIndex], textureImageInterval)
					: textureImageInterval;
			setTextureOpacityAndShading(texture, updateInterval);
			updateIntervals[newScreenScaleIndex] = null;

			// calculate new texture coordinates depending on the ratio between the screen size and the rendered image
			final RealPoint texCoordMin = new RealPoint(2), texCoordMax = new RealPoint(2);
			for (int d = 0; d < 2; ++d)
				texCoordMax.setPosition(dimensions[d] / (textureImageSize[d] / screenScales[newScreenScaleIndex]), d);

			if (orthoslicesMesh.get() != null)
			{
				orthoslicesMesh.get().getMaterial().setSelfIlluminationMap(texture.selfIlluminationMapImage);
				orthoslicesMesh.get().getMaterial().setDiffuseMap(texture.diffuseMapImage);
				orthoslicesMesh.get().setTexCoords(texCoordMin, texCoordMax);
			}

			this.currentTextureScreenScaleIndex = newScreenScaleIndex;
		}
	);

	// prioritize higher resolution texture to minimize blinking because of switching between low-res and high-res
	final int priority = -newv.getScreenScaleIndex();
	delayedTextureUpdateExecutor.schedule(updateTextureTask, priority);
}