/** * Creates the Canvas3D to visualize the 3D World. Used only in the creation * phase. */ private void createCanvas3D() { GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); template.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED); GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template); // create canvas canvas3d = new Canvas3D(config); canvas3d.setDoubleBufferEnable(true); // display j3d info Map map = canvas3d.queryProperties(); System.out.println("doubleBufferAvailable = " + map.get("doubleBufferAvailable")); System.out.println("sceneAntialiasingNumPasses = " + map.get("sceneAntialiasingNumPasses")); System.out.println("sceneAntialiasingAvailable = " + map.get("sceneAntialiasingAvailable")); System.out.println("texture3DAvailable = " + map.get("texture3DAvailable")); }
private Canvas3D getOffScreenCanvas() { if (offScreenCanvas3D != null) return offScreenCanvas3D; final GraphicsConfigTemplate3D templ = new GraphicsConfigTemplate3D(); templ.setDoubleBuffer(GraphicsConfigTemplate.UNNECESSARY); final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getBestConfiguration(templ); offScreenCanvas3D = new Canvas3D(gc, true); final Screen3D sOn = canvas3D.getScreen3D(); final Screen3D sOff = offScreenCanvas3D.getScreen3D(); sOff.setSize(sOn.getSize()); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); universe.getViewer().getView().addCanvas3D(offScreenCanvas3D); return offScreenCanvas3D; }
/** * Returns the template to configure the graphics of canvas 3D. */ private GraphicsConfigTemplate3D createGraphicsConfigurationTemplate3D() { if (System.getProperty("j3d.implicitAntialiasing") == null) { System.setProperty("j3d.implicitAntialiasing", "true"); } // Retrieve graphics configuration once GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); // Try to get antialiasing template.setSceneAntialiasing(GraphicsConfigTemplate3D.PREFERRED); if (OperatingSystem.isMacOSX() && OperatingSystem.isJavaVersionGreaterOrEqual("1.7")) { // Request depth size equal to 24 with Java 3D 1.6 template.setDepthSize(24); } // From http://www.java.net/node/683852 // Check if the user has set the Java 3D stereo option. String stereo = System.getProperty("j3d.stereo"); if (stereo != null) { if ("REQUIRED".equals(stereo)) template.setStereo(GraphicsConfigTemplate.REQUIRED); else if ("PREFERRED".equals(stereo)) template.setStereo(GraphicsConfigTemplate.PREFERRED); } return template; }
void createViewPlatform() { // viewplatform viewPlatform = new ViewPlatform(); viewPlatform.setActivationRadius(100f); viewPlatform.setViewAttachPolicy(View.NOMINAL_HEAD); // view view = new View(); view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); view.setViewPolicy(View.SCREEN_VIEW); view.attachViewPlatform(viewPlatform); // physical body PhysicalBody phyBody = new PhysicalBody(); view.setPhysicalBody(phyBody); // physical environment PhysicalEnvironment phyEnv = new PhysicalEnvironment(); view.setPhysicalEnvironment(phyEnv); // ???? pas compris , pour l'antiliasing GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); template.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED); GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template); // antialiasing view.setSceneAntialiasingEnable(true); /* * to add a onscreen canvas canvas3d = new Canvas3D(config); * view.addCanvas3D(canvas3d); */ // attach offscreen canvas to the view offscreenCanvas3D = new OffScreenCanvas3D(config); offscreenCanvas3D.getScreen3D().setSize(imageWidth, imageWidth); offscreenCanvas3D.getScreen3D().setPhysicalScreenHeight(0.5); offscreenCanvas3D.getScreen3D().setPhysicalScreenWidth(0.5); view.addCanvas3D(offscreenCanvas3D); addChild(viewPlatform); // turn canvas in front of X axis rotateY(-Math.PI / 2); }
/** * Returns a snapshot of the given size. */ public ImagePlus takeSnapshot(final int w, final int h) { final GraphicsConfigTemplate3D templ = new GraphicsConfigTemplate3D(); templ.setDoubleBuffer(GraphicsConfigTemplate.UNNECESSARY); final Canvas3D onCanvas = getCanvas(); if (offCanvas == null) { final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getBestConfiguration(templ); offCanvas = new Canvas3D(gc, true); System.out.println("construct canvas"); } final Screen3D sOn = onCanvas.getScreen3D(); final Screen3D sOff = offCanvas.getScreen3D(); sOff.setSize(sOn.getSize()); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); getViewer().getView().addCanvas3D(offCanvas); final Color3f bg = new Color3f(); ((ImageCanvas3D) onCanvas).getBG().getColor(bg); BufferedImage bImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final ImageComponent2D ic2d = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); offCanvas.setOffScreenBuffer(ic2d); offCanvas.renderOffScreenBuffer(); offCanvas.waitForOffScreenRendering(); bImage = offCanvas.getOffScreenBuffer().getImage(); getViewer().getView().removeCanvas3D(offCanvas); return new ImagePlus("Snapshot", bImage); }
public GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate gct) { return config; }
/** * Creates the universe to attach the scenegraph. Used only in the creation * phase. * * @param ed * the environment description. */ private void createUniverse(EnvironmentDescription ed) { System.out.println("create Universe"); // show infos Map map = VirtualUniverse.getProperties(); System.out.println("----------------------------------------"); System.out.println("j3d.version = " + map.get("j3d.version")); System.out.println("j3d.vendor = " + map.get("j3d.vendor")); System.out.println("j3d.specification.version = " + map.get("j3d.specification.version")); System.out.println("j3d.specification.vendor = " + map.get("j3d.specification.vendor")); System.out.println("j3d.renderer = " + map.get("j3d.renderer")); System.out.println("J3DThreadPriority = " + VirtualUniverse.getJ3DThreadPriority()); System.out.println("----------------------------------------"); createCanvas3D(); createSceneBranch(ed); universe = new VirtualUniverse(); Locale locale = new Locale(universe); // Create and add VIEW branch // locale->viewBranch->viewTransformGroup->viewPlatform viewBranch = new BranchGroup(); viewTransformGroup = new TransformGroup(); viewTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D t3d = new Transform3D(); t3d.setIdentity(); viewTransformGroup.setTransform(t3d); viewBranch.addChild(viewTransformGroup); // Creates View and viewplatform viewPlatform = new ViewPlatform(); viewPlatform.setViewAttachPolicy(View.NOMINAL_HEAD); viewPlatform.setActivationRadius(100); view = new View(); view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); view.setViewPolicy(View.SCREEN_VIEW); view.setVisibilityPolicy(View.VISIBILITY_DRAW_ALL); view.setFrontClipDistance(0.02); GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); template.setSceneAntialiasing(GraphicsConfigTemplate.REQUIRED); template.setDoubleBuffer(GraphicsConfigTemplate.PREFERRED); /* * GraphicsConfiguration config = GraphicsEnvironment * .getLocalGraphicsEnvironment().getDefaultScreenDevice() * .getBestConfiguration(template); */ // request antialiasing view.setSceneAntialiasingEnable(true); view.addCanvas3D(canvas3d); PhysicalBody phyBody = new PhysicalBody(); PhysicalEnvironment phyEnv = new PhysicalEnvironment(); view.setPhysicalBody(phyBody); view.setPhysicalEnvironment(phyEnv); view.attachViewPlatform(viewPlatform); viewTransformGroup.addChild(viewPlatform); // Add both branch to the unique locale locale.addBranchGraph(viewBranch); locale.addBranchGraph(sceneBranch); // Add mouse control in the canvas3d mouseOrbiter = new MouseOrbiter(canvas3d, viewTransformGroup); // sets initial viewpoint changeViewPoint(ed.worldViewPoint, null); }
public void init1() { ngView = NeuGenView.getInstance(); C3DScrollPane = ngView.getVisualScrollPane(); C3DSplitPane = ngView.getVisualDensSplitPane(); C3DScrollPane.setPreferredSize(new Dimension(PWIDTH, PHEIGHT)); C3DSplitPane.setPreferredSize(new Dimension(PWIDTH, PHEIGHT)); /*if (C3DSplitPane.getDividerLocation() < PWIDTH) { C3DSplitPane.setDividerLocation(PWIDTH); }*/ if (C3DSplitPane.getRightComponent() != null) { C3DSplitPane.remove(C3DSplitPane.getRightComponent()); } bounds = new BoundingSphere(new Point3d(0, 0, 0), BOUNDSIZE); /* //GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); //canvas3D = new Canvas3D(config); GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); template.setSceneAntialiasing(GraphicsConfigTemplate3D.PREFERRED); canvas3D = new Canvas3D(GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice(). getBestConfiguration(template)); canvas3D.setFocusable(true); canvas3D.requestFocus(); simpleU = new SimpleUniverse(canvas3D); simpleU.getViewer().getView().setMinimumFrameCycleTime(5); simpleU.getViewer().getView().setLocalEyeLightingEnable(true); //canvas3D.getView().setSceneAntialiasingEnable(true); * */ GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D(); if (NeuGenApp.antiAliasing) { gc3D.setSceneAntialiasing(GraphicsConfigTemplate3D.PREFERRED); } gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED); GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); canvas3D = new Canvas3D(gd[0].getBestConfiguration(gc3D)); simpleU = new SimpleUniverse(canvas3D); orbitControls(canvas3D); synBehavior = new SynchronBehavior(simpleU.getViewingPlatform().getViewPlatformTransform(), null); synBehavior.setSchedulingBounds(bounds); }
/** * Ignore template and return the only config we have * * @param gct the template configuration * @return the best configuration which is the only one */ public GraphicsConfiguration getBestConfiguration( GraphicsConfigTemplate gct) { return gc; }