Пример #1
0
  private void doUpdate() {
    if (restorePending) {
      return; // we will get called again
      // after the restore is
      // complete
    }
    canvas.stopRenderer();
    canvas.setDoubleBufferEnable(doubleBufferAttr.getValue());
    if (coordSysAttr.getValue()) {
      coordSwitch.setWhichChild(Switch.CHILD_ALL);
    } else {
      coordSwitch.setWhichChild(Switch.CHILD_NONE);
    }
    if (getAnnotationsAttr().getValue()) {
      staticBackAnnotationSwitch.setWhichChild(Switch.CHILD_ALL);
      dynamicBackAnnotationSwitch.setWhichChild(Switch.CHILD_ALL);
      staticFrontAnnotationSwitch.setWhichChild(Switch.CHILD_ALL);
      dynamicFrontAnnotationSwitch.setWhichChild(Switch.CHILD_ALL);
    } else {
      staticBackAnnotationSwitch.setWhichChild(Switch.CHILD_NONE);
      dynamicBackAnnotationSwitch.setWhichChild(Switch.CHILD_NONE);
      staticFrontAnnotationSwitch.setWhichChild(Switch.CHILD_NONE);
      dynamicFrontAnnotationSwitch.setWhichChild(Switch.CHILD_NONE);
    }
    if (perspectiveAttr.getValue()) {
      view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
    } else {
      view.setProjectionPolicy(View.PARALLEL_PROJECTION);
    }
    if (renderer != renderers[rendererAttr.getValue()]) {
      // TODO: renderer.clear();
      // TODO: handle gui
      try {
        System.out.println("Clearing Attached : VolRend-doUpdate()");
        clearAttach();

      } catch (Exception e) {
        e.printStackTrace();
      }
      renderer = renderers[rendererAttr.getValue()];
      renderer.attach(dynamicAttachGroup, staticAttachGroup);
    }
    try {
      renderer.update();
      annotations.update();
    } catch (Exception e) {

      e.printStackTrace();
    } catch (OutOfMemoryError e) {
      JOptionPane.showMessageDialog(
          null, "Ran out of memory!", "Render Error", JOptionPane.ERROR_MESSAGE);
    }
    int newVolEditId;
    if ((newVolEditId = volume.update()) != volEditId) {
      updateCenter(volume.minCoord, volume.maxCoord);
      newVolEditId = volEditId;
    }
    eyePtChanged();
    canvas.startRenderer();
  }
Пример #2
0
  public VolRend(boolean timing, boolean debug) {

    if (timing) {
      canvas = new TimingCanvas3D(SimpleUniverse.getPreferredConfiguration(), this);
    } else {
      canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    }
    canvas.setMinimumSize(new Dimension(1, 1));
  }
Пример #3
0
  public View(Frame frame, int resolutionX, int resolutionY, int colorDepth, boolean fullscreen) {
    this.frame = frame;

    // *** set up graphics configuration ***
    if (fullscreen) {
      frame.setUndecorated(true);

      if (GraphicsEnvironment.getLocalGraphicsEnvironment()
          .getDefaultScreenDevice()
          .isFullScreenSupported()) {
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .setFullScreenWindow(frame);
      }

      if (GraphicsEnvironment.getLocalGraphicsEnvironment()
          .getDefaultScreenDevice()
          .isDisplayChangeSupported()) {
        DisplayMode displayMode =
            new DisplayMode(resolutionX, resolutionY, colorDepth, DisplayMode.REFRESH_RATE_UNKNOWN);
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .setDisplayMode(displayMode);
      }
    }
    graphicsConfiguration = SimpleUniverse.getPreferredConfiguration();
    canvas3D = new MyCanvas3D(graphicsConfiguration);
    canvas3D.setDoubleBufferEnable(true);
    canvas3D.getGraphicsContext3D().setBufferOverride(false);

    // *** create universe ***
    universe = new SimpleUniverse(canvas3D);
    universe.getViewer().getView().setSceneAntialiasingEnable(true);
    canvas3D.getView().setFrontClipDistance(0.1f);
    canvas3D.getView().setBackClipDistance(50000f);
    // universe.setJ3DThreadPriority(Thread.MIN_PRIORITY);

    // *** create camera ***
    TransformGroup cameraTransformGroup =
        universe.getViewingPlatform().getMultiTransformGroup().getTransformGroup(0);
    camera = new Camera(cameraTransformGroup);

    canvas3D.startRenderer();
  }
Пример #4
0
  public static void main(String args[]) {
    JFrame frame = new JFrame("Box and Sphere");

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D canvas = new Canvas3D(config);

    canvas.setSize(400, 400);

    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();

    BranchGroup group = new BranchGroup();
    group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    // group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

    universe.addBranchGraph(group);

    frame.setSize(500, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(canvas, BorderLayout.CENTER);
    frame.setVisible(true);
    Sphere sphere =
        new Sphere(1.1f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, null);

    BranchGroup b = new BranchGroup();
    b.addChild(sphere);

    group.addChild(b);

    {
      Sphere sphere2 =
          new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, null);

      b = new BranchGroup();
      b.addChild(sphere2);

      Util3D.enablePicking(b);

      group.addChild(b);
    }
  }
Пример #5
0
  void setupScene() {

    // Setup the graphics
    // Create a simple scene and attach it to
    // the virtual universe
    BranchGroup scene = createSceneGraph();
    universe = new SimpleUniverse(canvas);

    // This will move the ViewPlatform back a
    // bit so the
    // objects in the scene can be viewed.
    universe.getViewingPlatform().setNominalViewingTransform();

    // get the primary view
    view = universe.getViewer().getView();

    // switch to a parallel projection, which
    // is faster for texture mapping
    view.setProjectionPolicy(View.PARALLEL_PROJECTION);
    view.setBackClipDistance(10000);

    universe.addBranchGraph(scene);

    canvas.setDoubleBufferEnable(true);

    // setup the renderers
    renderers = new Renderer[1];
    renderers[0] = new Axis2DRenderer(view, context, volume);
    // renderers[1] = new Axis3DRenderer(view,
    // context, volume);
    // renderers[2] = new
    // SlicePlane3DRenderer(view, context,
    // volume);
    // renderers[3] = new
    // SlicePlane2DRenderer(view, context,
    // volume);

    renderer = renderers[rendererAttr.getValue()];

    // Add the volume to the scene
    clearAttach();
    renderer.attach(dynamicAttachGroup, staticAttachGroup);

    // Set up the annotations
    annotations = new Annotations(view, context, volume);
    annotations.attach(dynamicFrontAnnotationSwitch, staticFrontAnnotationSwitch);
    annotations.attachBack(dynamicBackAnnotationSwitch, staticBackAnnotationSwitch);
  }
Пример #6
0
  public BufferedImage getRenderedImage(Dimension d, boolean withBackground) {
    if (offscreenCanvas == null) {
      offscreenCanvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration(), true);
    }
    offscreenCanvas.setSize(getSize());
    offscreenCanvas.getScreen3D().setSize(getScreen3D().getSize());
    offscreenCanvas.getScreen3D().setPhysicalScreenWidth(getScreen3D().getPhysicalScreenWidth());
    offscreenCanvas.getScreen3D().setPhysicalScreenHeight(getScreen3D().getPhysicalScreenHeight());
    BufferedImage bufImage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    ImageComponent2D imgComp = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bufImage);
    BufferedImage transparentImage =
        new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    ImageComponent2D transparentComp =
        new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, transparentImage);

    Color3f tempColor = new Color3f();
    background.getColor(tempColor);
    if (!withBackground) {
      background.setImage(transparentComp);
    }

    view.addCanvas3D(offscreenCanvas);
    offscreenCanvas.setOffScreenBuffer(imgComp);
    offscreenCanvas.renderOffScreenBuffer();
    offscreenCanvas.waitForOffScreenRendering();

    if (!withBackground) {
      background.setImage(null);
    }

    bufImage = offscreenCanvas.getOffScreenBuffer().getImage();
    // To release the reference of buffer inside Java 3D.
    offscreenCanvas.setOffScreenBuffer(null);
    view.removeCanvas3D(offscreenCanvas);

    return bufImage;
  }
Пример #7
0
  private void start() throws PluginException, IfcModelInterfaceException {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try {
      setIconImage(ImageIO.read(getClass().getResource("haussmall.png")));
    } catch (IOException e) {
      LOGGER.error("", e);
    }
    setSize(800, 600);
    getContentPane().setBackground(Color.BLACK);
    setTitle("IFC Visualiser");
    setVisible(true);

    VirtualUniverse universe = new VirtualUniverse();
    Locale locale = new Locale(universe);
    canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

    sceneBranchGroup = new BranchGroup();
    sceneBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    sceneBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    createLoaderSceneGraph();
    locale.addBranchGraph(sceneBranchGroup);

    showLoader = true;
    new Thread() {
      public void run() {
        float x = 0;
        float y = 0;
        while (showLoader) {
          Matrix3f matrixX = new Matrix3f();
          matrixX.rotX(x);

          Matrix3f matrixY = new Matrix3f();
          matrixY.rotY(y);

          Matrix3f rot = new Matrix3f();
          rot.mul(matrixX, matrixY);

          Transform3D transform3d = new Transform3D();
          transform3d.setRotation(rot);
          transform3d.setTranslation(new Vector3d(10, 0, 0));
          loaderTransformGroup.setTransform(transform3d);
          y -= 0.05;
          x += 0.015;
          try {
            Thread.sleep(25);
          } catch (InterruptedException e) {
            LOGGER.error("", e);
          }
        }
      };
    }.start();

    viewBranchGroup = new BranchGroup();
    createViewBranch();
    viewBranchGroup.compile();
    locale.addBranchGraph(viewBranchGroup);

    add(canvas, BorderLayout.CENTER);

    canvas.setVisible(true);
    validate();

    sharedGroup = new SharedGroup();
    try {
      pluginManager = LocalDevPluginLoader.createPluginManager(new File("home"));
    } catch (PluginException e) {
      LOGGER.error("", e);
    }

    DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", true);
    Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
    deserializer.init(pluginManager.requireSchemaDefinition());
    File file = new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc");

    try {
      model = deserializer.read(file);
    } catch (DeserializationException e) {
      LOGGER.error("", e);
    } catch (Exception e) {
      LOGGER.error("", e);
    }

    ifcEngine = pluginManager.requireRenderEngine().createRenderEngine(new PluginConfiguration());
    ifcEngine.init();
    try {
      ifcEngineModel = ifcEngine.openModel(file);
      try {
        RenderEngineSurfaceProperties initializeModelling = ifcEngineModel.initializeModelling();
        geometry = ifcEngineModel.finalizeModelling(initializeModelling);
        createSceneGraph();
      } finally {
        ifcEngineModel.close();
      }
    } finally {
      ifcEngine.close();
    }
  }