Java Code Examples for bdv.viewer.Source#getSourceTransform()
The following examples show how to use
bdv.viewer.Source#getSourceTransform() .
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: FitToInterval.java From paintera with GNU General Public License v2.0 | 6 votes |
@Override public void onChanged(final Change<? extends Source<?>> change) { while (change.next()) if (change.wasAdded() && change.getList().size() == 1) { final Source<?> addedSource = change.getAddedSubList().get(0); final double[] min = Arrays.stream(Intervals.minAsLongArray(addedSource.getSource( 0, 0 ))).asDoubleStream().toArray(); final double[] max = Arrays.stream(Intervals.maxAsLongArray(addedSource.getSource( 0, 0 ))).asDoubleStream().toArray(); final AffineTransform3D tf = new AffineTransform3D(); addedSource.getSourceTransform(0, 0, tf); tf.apply(min, min); tf.apply(max, max); fitToInterval.fit(Intervals.smallestContainingInterval(new FinalRealInterval(min, max))); } }
Example 2
Source File: DataSource.java From paintera with GNU General Public License v2.0 | 6 votes |
/** * Returns transforms for all scale levels in the given {@link Source} into the world coordinates * without the half-pixel offset. This is useful for converting between coordinate spaces * when pixel coordinates represent the top-left corner of the pixel instead of its center. * @param source * @param t * @return */ static AffineTransform3D[] getUnshiftedWorldTransforms(final Source<?> source, final int t) { // get mipmap transforms without the half-pixel shift final AffineTransform3D[] unshiftedWorldTransforms = new AffineTransform3D[source.getNumMipmapLevels()]; final AffineTransform3D fullResToWorldTransform = new AffineTransform3D(); source.getSourceTransform(0, 0, fullResToWorldTransform); for (int i = 0; i < unshiftedWorldTransforms.length; ++i) { final double[] scales = DataSource.getRelativeScales(source, 0, 0, i); final Scale3D toFullResTransform = new Scale3D(scales); unshiftedWorldTransforms[i] = new AffineTransform3D(); unshiftedWorldTransforms[i].preConcatenate(toFullResTransform).preConcatenate(fullResToWorldTransform); } return unshiftedWorldTransforms; }
Example 3
Source File: MultiResolutionRendererGeneric.java From paintera with GNU General Public License v2.0 | 5 votes |
private static <T> RandomAccessible<T> getTransformedSource( final Source<T> source, final int timepoint, final AffineTransform3D viewerTransform, final AffineTransform3D screenScaleTransform, final int mipmapIndex, final CacheHints cacheHints, final Interpolation interpolation) { final RandomAccessibleInterval<T> img = source.getSource(timepoint, mipmapIndex); if (VolatileCachedCellImg.class.isInstance(img)) ((VolatileCachedCellImg<?, ?>) img).setCacheHints(cacheHints); final RealRandomAccessible<T> ipimg = source.getInterpolatedSource(timepoint, mipmapIndex, interpolation); final AffineTransform3D sourceToScreen = viewerTransform.copy(); final AffineTransform3D sourceTransform = new AffineTransform3D(); source.getSourceTransform(timepoint, mipmapIndex, sourceTransform); sourceToScreen.concatenate(sourceTransform); sourceToScreen.preConcatenate(screenScaleTransform); LOG.debug( "Getting transformed source {} (name={}) for t={} level={} transform={} screen-scale={} hints={} " + "interpolation={}", source, source.getName(), timepoint, mipmapIndex, sourceToScreen, screenScaleTransform, cacheHints, interpolation ); return RealViews.affine(ipimg, sourceToScreen); }
Example 4
Source File: CreateDataset.java From paintera with GNU General Public License v2.0 | 5 votes |
private void populateFrom(Source<?> source) { if (source == null) return; if (source instanceof N5DataSource<?, ?>) { N5DataSource<?, ?> n5s = (N5DataSource<?, ?>) source; if (n5s.meta() instanceof N5FSMeta) { n5Container.directoryProperty().setValue(new File(((N5FSMeta) n5s.meta()).basePath())); } } final RandomAccessibleInterval<?> data = source.getSource(0, 0); this.dimensions.getX().valueProperty().set(data.dimension(0)); this.dimensions.getY().valueProperty().set(data.dimension(1)); this.dimensions.getZ().valueProperty().set(data.dimension(2)); if (data instanceof AbstractCellImg<?, ?, ?, ?>) { final CellGrid grid = ((AbstractCellImg<?, ?, ?, ?>) data).getCellGrid(); this.blockSize.getX().valueProperty().set(grid.cellDimension(0)); this.blockSize.getY().valueProperty().set(grid.cellDimension(1)); this.blockSize.getZ().valueProperty().set(grid.cellDimension(2)); } AffineTransform3D transform = new AffineTransform3D(); source.getSourceTransform(0, 0, transform); this.resolution.getX().valueProperty().set(transform.get(0, 0)); this.resolution.getY().valueProperty().set(transform.get(1, 1)); this.resolution.getZ().valueProperty().set(transform.get(2, 2)); this.offset.getX().valueProperty().set(transform.get(0, 3)); this.offset.getY().valueProperty().set(transform.get(1, 3)); this.offset.getZ().valueProperty().set(transform.get(2, 3)); }
Example 5
Source File: MultiResolutionRendererGeneric.java From paintera with GNU General Public License v2.0 | 4 votes |
private static <T> void prefetch( final Source<T> source, final int timepoint, final AffineTransform3D viewerTransform, final AffineTransform3D screenScaleTransform, final int mipmapIndex, final CacheHints prefetchCacheHints, final Dimensions screenInterval, final Interpolation interpolation) { final RandomAccessibleInterval<T> img = source.getSource(timepoint, mipmapIndex); if (VolatileCachedCellImg.class.isInstance(img)) { final VolatileCachedCellImg<?, ?> cellImg = (VolatileCachedCellImg<?, ?>) img; CacheHints hints = prefetchCacheHints; if (hints == null) { final CacheHints d = cellImg.getDefaultCacheHints(); hints = new CacheHints(LoadingStrategy.VOLATILE, d.getQueuePriority(), false); } cellImg.setCacheHints(hints); final int[] cellDimensions = new int[3]; cellImg.getCellGrid().cellDimensions(cellDimensions); final long[] dimensions = new long[3]; cellImg.dimensions(dimensions); final RandomAccess<?> cellsRandomAccess = cellImg.getCells().randomAccess(); final AffineTransform3D sourceToScreen = viewerTransform.copy(); final AffineTransform3D sourceTransform = new AffineTransform3D(); source.getSourceTransform(timepoint, mipmapIndex, sourceTransform); sourceToScreen.concatenate(sourceTransform); sourceToScreen.preConcatenate(screenScaleTransform); Prefetcher.fetchCells( sourceToScreen, cellDimensions, dimensions, screenInterval, interpolation, cellsRandomAccess ); } }
Example 6
Source File: MultiBoxOverlayRendererFX.java From paintera with GNU General Public License v2.0 | 4 votes |
/** * Update data to show in the box overlay. */ public synchronized void setViewerState(final ViewerState viewerState) { synchronized (viewerState) { final int timepoint = viewerState.getTimepoint(); final int numSources = this.allSources.size(); final int numPresentSources = (int) IntStream.range( 0, numSources ).mapToObj(allSources::get).filter(s -> s.isPresent( timepoint)).count(); LOG.debug( "numSources={} numPresentSources={} boxSources.size={}", numSources, numPresentSources, boxSources.size() ); if (boxSources.size() != numPresentSources) { while (boxSources.size() < numPresentSources) { boxSources.add(new IntervalAndTransform()); } while (boxSources.size() > numPresentSources) { boxSources.remove(boxSources.size() - 1); } } final AffineTransform3D sourceToViewer = new AffineTransform3D(); final AffineTransform3D sourceTransform = new AffineTransform3D(); for (int i = 0, j = 0; i < numSources; ++i) { final Source<?> source = this.allSources.get(i); if (source.isPresent(timepoint)) { LOG.debug("Setting box for source i={}, j={} boxSources.size={}", i, j, boxSources.size()); final IntervalAndTransform boxsource = boxSources.get(j++); viewerState.getViewerTransform(sourceToViewer); source.getSourceTransform(timepoint, 0, sourceTransform); sourceToViewer.concatenate(sourceTransform); boxsource.setSourceToViewer(sourceToViewer); boxsource.setSourceInterval(source.getSource(timepoint, 0)); boxsource.setVisible(this.visibleSources.contains(source)); } } } }
Example 7
Source File: DataSource.java From paintera with GNU General Public License v2.0 | 3 votes |
/** * 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)}; }