コード例 #1
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);
  }
コード例 #2
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();
  }
コード例 #3
0
 @Override
 public void transformChanged(int type, Transform3D xform) {
   renderer.transformChanged(type, xform);
   renderer.eyePtChanged();
   annotations.eyePtChanged();
   getScaleAttr().set(xform);
   getTranslationAttr().set(xform);
   getRotationAttr().set(xform);
 }
コード例 #4
0
  BranchGroup createSceneGraph() {
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(0.0f, 0.0f, 1.0f);
    Color3f alColor = new Color3f(1.0f, 1.0f, 1.0f);

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a transform group to scale the
    // whole scene
    TransformGroup scaleGroup = new TransformGroup();
    Transform3D scaleXform = new Transform3D();
    double scale = 1;
    scaleXform.setScale(scale);
    scaleGroup.setTransform(scaleXform);
    objRoot.addChild(scaleGroup);

    // Create the static ordered group
    OrderedGroup scaleOGroup = new OrderedGroup();
    scaleGroup.addChild(scaleOGroup);

    // Create the static annotation group
    staticBackAnnotationSwitch = new Switch();
    staticBackAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    staticBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    staticBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    staticBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scaleOGroup.addChild(staticBackAnnotationSwitch);

    // Create the static attachment group
    staticAttachGroup = new Group();
    staticAttachGroup.setCapability(Group.ALLOW_CHILDREN_READ);
    staticAttachGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    staticAttachGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scaleOGroup.addChild(staticAttachGroup);

    // Create a TG at the origin
    objectGroup = new TransformGroup();

    // Enable the TRANSFORM_WRITE capability
    // so that our behavior code
    // can modify it at runtime. Add it to the
    // root of the subgraph.
    //
    objectGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objectGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    scaleOGroup.addChild(objectGroup);

    // Create the static annotation group
    staticFrontAnnotationSwitch = new Switch();
    staticFrontAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    staticFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    staticFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    staticFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scaleOGroup.addChild(staticFrontAnnotationSwitch);
    // added after objectGroup so it shows up
    // in front

    // Create the transform group node and
    // initialize it center the
    // object around the origin
    centerGroup = new TransformGroup();
    updateCenter(new Point3d(0.0, 0.0, 0.0), new Point3d(1.0, 1.0, 1.0));
    centerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objectGroup.addChild(centerGroup);

    // Set up the annotation/volume/annotation
    // sandwitch
    OrderedGroup centerOGroup = new OrderedGroup();
    centerGroup.addChild(centerOGroup);

    // create the back dynamic annotation
    // point
    dynamicBackAnnotationSwitch = new Switch(Switch.CHILD_ALL);
    dynamicBackAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    dynamicBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    dynamicBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    dynamicBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    centerOGroup.addChild(dynamicBackAnnotationSwitch);

    // create the dynamic attachment point
    dynamicAttachGroup = new Group();
    dynamicAttachGroup.setCapability(Group.ALLOW_CHILDREN_READ);
    dynamicAttachGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    dynamicAttachGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    centerOGroup.addChild(dynamicAttachGroup);

    // create the front dynamic annotation
    // point
    dynamicFrontAnnotationSwitch = new Switch(Switch.CHILD_ALL);
    dynamicFrontAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    dynamicFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    dynamicFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    dynamicFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    centerOGroup.addChild(dynamicFrontAnnotationSwitch);

    // Create the annotations
    Annotations annotations = new Annotations(view, context, volume);
    annotations.attachBack(dynamicBackAnnotationSwitch, staticBackAnnotationSwitch);
    annotations.attach(dynamicFrontAnnotationSwitch, staticFrontAnnotationSwitch);

    coordSwitch = new Switch(Switch.CHILD_ALL);
    coordSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    coordSwitch.addChild(new CoordSys(0.2, new Vector3d(-0.1, -0.1, -0.1)));
    centerGroup.addChild(coordSwitch);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10000000.0);

    FirstFramesBehavior ff = new FirstFramesBehavior(this);
    ff.setSchedulingBounds(bounds);
    objRoot.addChild(ff);

    updateBehavior = new UpdateBehavior();
    updateBehavior.setSchedulingBounds(bounds);
    objRoot.addChild(updateBehavior);

    // ExitKeyBehavior eb = new
    // ExitKeyBehavior();
    // eb.setSchedulingBounds(bounds);
    // objRoot.addChild(eb);

    BranchGroup trueRoot = new BranchGroup();
    TransformGroup trueTransform = new TransformGroup();

    trueTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trueTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    trueRoot.addChild(trueTransform);
    trueTransform.addChild(objRoot);

    // MouseTranslate mt = new
    // MouseTranslate();
    // mt.setupCallback(this);
    // mt.setTransformGroup(trueTransform);
    // mt.setSchedulingBounds(bounds);
    // trueRoot.addChild(mt);

    MouseZoom mz = new MouseZoom();
    mz.setupCallback(this);
    mz.setTransformGroup(trueTransform);
    mz.setSchedulingBounds(bounds);
    trueRoot.addChild(mz);

    MouseRotate mr = new MouseRotate();
    mr.setupCallback(this);
    mr.setTransformGroup(trueTransform);
    mr.setSchedulingBounds(bounds);
    mr.setFactor(0.007);
    trueRoot.addChild(mr);

    // trueTransform.addChild(objRoot);
    // trueRoot.addChild(trueTransform);
    return trueRoot;
  }