Java Code Examples for net.imglib2.util.Intervals#smallestContainingInterval()
The following examples show how to use
net.imglib2.util.Intervals#smallestContainingInterval() .
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: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private RandomAccessibleInterval<UnsignedLongType> getTransformedMaskSection(final SectionInfo sectionInfo) { final RealInterval sectionBounds = sectionInfo.sourceToDisplayTransform.estimateBounds(sectionInfo.sourceBoundingBox); final Interval sectionInterval = Intervals.smallestContainingInterval(sectionBounds); final RealRandomAccessible<UnsignedLongType> transformedMask = getTransformedMask(sectionInfo.mask, sectionInfo.sourceToDisplayTransform); final RandomAccessibleInterval<UnsignedLongType> transformedMaskInterval = Views.interval(Views.raster(transformedMask), sectionInterval); return Views.hyperSlice(transformedMaskInterval, 2, 0l); }
Example 2
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
private Interval scaleIntervalToLevel(final Interval interval, final int intervalLevel, final int targetLevel) { if (intervalLevel == targetLevel) { return interval; } final double[] min = LongStream.of(Intervals.minAsLongArray(interval)).asDoubleStream().toArray(); final double[] max = LongStream.of(Intervals.maxAsLongArray(interval)).asDoubleStream().map(d -> d + 1).toArray(); final double[] relativeScale = DataSource.getRelativeScales(this, 0, targetLevel, intervalLevel); LOG.debug("Scaling interval {} {} {}", min, max, relativeScale); org.janelia.saalfeldlab.util.grids.Grids.scaleBoundingBox(min, max, min, max, relativeScale); return Intervals.smallestContainingInterval(new FinalRealInterval(min, max)); }
Example 3
Source File: SceneBlockTree.java From paintera with GNU General Public License v2.0 | 4 votes |
public static BlockTree<BlockTreeFlatKey, BlockTreeNode<BlockTreeFlatKey>> createSceneBlockTree( final DataSource<?, ?> source, final ViewFrustum viewFrustum, final AffineTransform3D eyeToWorldTransform, final int levelOfDetail, final int coarsestScaleLevel, final int finestScaleLevel, final CellGrid[] rendererGrids, final BooleanSupplier wasInterrupted) { final int numScaleLevels = source.getNumMipmapLevels(); final double maxPixelsInProjectedVoxel = levelOfDetailMaxPixels[ Math.max(0, Math.min(levelOfDetail - MeshSettings.Defaults.Values.getMinLevelOfDetail(), levelOfDetailMaxPixels.length - 1)) ]; LOG.debug("levelOfDetail={}, maxPixelsInProjectedVoxel={}", levelOfDetail, maxPixelsInProjectedVoxel); final ViewFrustumCulling[] viewFrustumCullingInSourceSpace = new ViewFrustumCulling[numScaleLevels]; final double[] minMipmapPixelSize = new double[numScaleLevels]; for (int i = 0; i < viewFrustumCullingInSourceSpace.length; ++i) { final AffineTransform3D sourceToWorldTransform = new AffineTransform3D(); source.getSourceTransform(0, i, sourceToWorldTransform); final AffineTransform3D cameraToSourceTransform = new AffineTransform3D(); cameraToSourceTransform.preConcatenate(eyeToWorldTransform).preConcatenate(sourceToWorldTransform.inverse()); viewFrustumCullingInSourceSpace[i] = new ViewFrustumCulling(viewFrustum, cameraToSourceTransform); final double[] extractedScale = new double[3]; Arrays.setAll(extractedScale, d -> Affine3DHelpers.extractScale(cameraToSourceTransform.inverse(), d)); minMipmapPixelSize[i] = Arrays.stream(extractedScale).min().getAsDouble(); } final double[][] sourceScales = new double[numScaleLevels][]; Arrays.setAll(sourceScales, i -> DataSource.getScale(source, 0, i)); final BlockTree<BlockTreeFlatKey, BlockTreeNode<BlockTreeFlatKey>> blockTree = new BlockTree<>(); final LinkedHashMap<BlockTreeFlatKey, BlockTreeFlatKey> blockAndParentQueue = new LinkedHashMap<>(); // start with all blocks at the lowest resolution final int lowestResolutionScaleLevel = numScaleLevels - 1; final CellGrid rendererGridAtLowestResolution = rendererGrids[lowestResolutionScaleLevel]; final long numBlocksAtLowestResolution = Intervals.numElements(rendererGridAtLowestResolution.getGridDimensions()); LongStream.range(0, numBlocksAtLowestResolution).forEach(blockIndex -> blockAndParentQueue.put(new BlockTreeFlatKey(lowestResolutionScaleLevel, blockIndex), null)); while (!blockAndParentQueue.isEmpty() && !wasInterrupted.getAsBoolean()) { final Iterator<Map.Entry<BlockTreeFlatKey, BlockTreeFlatKey>> it = blockAndParentQueue.entrySet().iterator(); final Map.Entry<BlockTreeFlatKey, BlockTreeFlatKey> entry = it.next(); it.remove(); final BlockTreeFlatKey key = entry.getKey(); final BlockTreeFlatKey parentKey = entry.getValue(); final int scaleLevel = key.scaleLevel; final Interval blockInterval = Grids.getCellInterval(rendererGrids[scaleLevel], key.blockIndex); if (viewFrustumCullingInSourceSpace[scaleLevel].intersects(blockInterval)) { final double distanceFromCamera = viewFrustumCullingInSourceSpace[scaleLevel].distanceFromCamera(blockInterval); final double screenSizeToViewPlaneRatio = viewFrustum.screenSizeToViewPlaneRatio(distanceFromCamera); final double screenPixelSize = screenSizeToViewPlaneRatio * minMipmapPixelSize[scaleLevel]; LOG.debug("scaleIndex={}, screenSizeToViewPlaneRatio={}, screenPixelSize={}", scaleLevel, screenSizeToViewPlaneRatio, screenPixelSize); final BlockTreeNode<BlockTreeFlatKey> treeNode = new BlockTreeNode<>(parentKey, new HashSet<>(), distanceFromCamera); blockTree.nodes.put(key, treeNode); if (parentKey != null) blockTree.nodes.get(parentKey).children.add(key); // check if needed to subdivide the block if (scaleLevel > coarsestScaleLevel || (scaleLevel > finestScaleLevel && screenPixelSize > maxPixelsInProjectedVoxel)) { final int nextScaleLevel = scaleLevel - 1; final CellGrid rendererNextLevelGrid = rendererGrids[nextScaleLevel]; final double[] relativeScales = new double[3]; Arrays.setAll(relativeScales, d -> sourceScales[scaleLevel][d] / sourceScales[nextScaleLevel][d]); final double[] nextScaleLevelBlockMin = new double[3], nextScaleLevelBlockMax = new double[3]; for (int d = 0; d < 3; ++d) { nextScaleLevelBlockMin[d] = blockInterval.min(d) * relativeScales[d]; nextScaleLevelBlockMax[d] = (blockInterval.max(d) + 1) * relativeScales[d] - 1; } final Interval nextLevelBlockInterval = Intervals.smallestContainingInterval(new FinalRealInterval(nextScaleLevelBlockMin, nextScaleLevelBlockMax)); // find out what blocks at higher resolution intersect with this block final long[] intersectingNextLevelBlockIndices = Grids.getIntersectingBlocks(nextLevelBlockInterval, rendererNextLevelGrid); for (final long intersectingNextLevelBlockIndex : intersectingNextLevelBlockIndices) { final BlockTreeFlatKey childKey = new BlockTreeFlatKey(nextScaleLevel, intersectingNextLevelBlockIndex); blockAndParentQueue.put(childKey, key); } } } } return !wasInterrupted.getAsBoolean() ? blockTree : null; }
Example 4
Source File: CatmaidJsonLoader.java From paintera with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws IOException { PlatformImpl.startup(() -> {}); final Path path = Paths.get(System.getProperty("user.home"), "Downloads", "catmaid-meshes", "Block3.json"); final TriangleMesh mesh = new CatmaidJsonLoader().loadMesh(path); final double[] min = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}; final double[] max = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY}; for (int i = 0; i < mesh.getPoints().size(); i += 3) { for (int d = 0; d < 3; ++d) { min[d] = Math.min(min[d], mesh.getPoints().get(i + d)); max[d] = Math.max(max[d], mesh.getPoints().get(i + d)); } } System.out.print(Arrays.toString(min) +" " + Arrays.toString(max)); final Interval interval = Intervals.smallestContainingInterval(new FinalRealInterval(min, max)); final MeshView mv = new MeshView(mesh); mv.setMaterial(Meshes.painteraPhongMaterial(Color.WHITE)); mv.setDrawMode(DrawMode.FILL); mv.setCullFace(CullFace.BACK); final Viewer3DFX viewer = new Viewer3DFX(800, 600); viewer.meshesEnabledProperty().set(true); mv.setOpacity(1.0); viewer.setInitialTransformToInterval(interval); final MeshView mv2 = new MeshView(mesh); mv.setMaterial(Meshes.painteraPhongMaterial()); mv.setDrawMode(DrawMode.FILL); mv.setCullFace(CullFace.BACK); mv2.setTranslateX(100); viewer.meshesGroup().getChildren().addAll(mv, mv2); Platform.setImplicitExit(true); Platform.runLater(() -> { final Scene scene = new Scene(viewer); final Stage stage = new Stage(); stage.setScene(scene); stage.setWidth(800); stage.setHeight(600); stage.show(); }); // final String mesh = "<IndexedTriangleSet index='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35'><Coordinate point='440474 99212 136120 440474 119212 136120 460474 99212 136120 460474 99212 136120 440474 119212 136120 460474 119212 136120 440474 99212 136120 460474 99212 136120 460474 99212 156120 440474 99212 136120 460474 99212 156120 440474 99212 156120 440474 119212 136120 440474 119212 156120 460474 119212 156120 440474 119212 136120 460474 119212 156120 460474 119212 136120 440474 99212 156120 460474 119212 156120 440474 119212 156120 440474 99212 156120 460474 99212 156120 460474 119212 156120 440474 99212 136120 440474 119212 156120 440474 119212 136120 440474 99212 136120 440474 99212 156120 440474 119212 156120 460474 99212 136120 460474 119212 136120 460474 99212 156120 460474 119212 136120 460474 119212 156120 460474 99212 156120'/></IndexedTriangleSet>"; // final Document doc = Jsoup.parse(mesh); // System.out.println(doc); // System.out.println(doc.select("IndexedTriangleSet").attr("index")); }
Example 5
Source File: ObjLoader.java From paintera with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws IOException { PlatformImpl.startup(() -> {}); // https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html // final String objFile = "al.obj"; // final String objFile = "diamond.obj"; final String objFile = "alfa147.obj"; final Path path = Paths.get(System.getProperty("user.home"), "Downloads", objFile); final TriangleMesh mesh = new ObjLoader().loadMesh(path); final double[] min = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}; final double[] max = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY}; for (int i = 0; i < mesh.getPoints().size(); i += 3) { for (int d = 0; d < 3; ++d) { min[d] = Math.min(min[d], mesh.getPoints().get(i + d)); max[d] = Math.max(max[d], mesh.getPoints().get(i + d)); } } final Interval interval = Intervals.smallestContainingInterval(new FinalRealInterval(min, max)); final MeshView mv = new MeshView(mesh); mv.setMaterial(Meshes.painteraPhongMaterial(Color.WHITE)); mv.setDrawMode(DrawMode.FILL); mv.setCullFace(CullFace.BACK); final Viewer3DFX viewer = new Viewer3DFX(800, 600); viewer.meshesEnabledProperty().set(true); mv.setOpacity(1.0); viewer.setInitialTransformToInterval(interval); final MeshView mv2 = new MeshView(mesh); mv.setMaterial(Meshes.painteraPhongMaterial()); mv.setDrawMode(DrawMode.FILL); mv.setCullFace(CullFace.BACK); mv2.setTranslateX(100); viewer.meshesGroup().getChildren().addAll(mv, mv2); // final double factor = 1; // final double w = 1*factor, h = 2*factor, d = 3*factor; // final Box box = new Box(w, h, d); // box.setCullFace(CullFace.NONE); // box.setOpacity(1.0); // box.setMaterial(Meshes.painteraPhongMaterial(Color.RED)); // viewer.meshesGroup().getChildren().add(box); Platform.setImplicitExit(true); Platform.runLater(() -> { final Scene scene = new Scene(viewer); final Stage stage = new Stage(); stage.setScene(scene); stage.setWidth(800); stage.setHeight(600); stage.show(); }); }