示例#1
0
  /**
   * Method to access appearance for cells in 3D
   *
   * @param initValue no null if appearance has to be changed according to user value. Using this
   *     mechanism to avoid the creation of new Boolean() just for the checking
   */
  public static void setCellAppearanceValues(Object initValue) {
    Color3f userColor = new Color3f(new Color(User.getColor(User.ColorPrefType.INSTANCE_3D)));

    if (cellApp == null) {
      cellApp = new J3DAppearance(TransparencyAttributes.SCREEN_DOOR, 0, null);

      RenderingAttributes ra = new RenderingAttributes();
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
      ra.setVisible(J3DUtils.is3DCellBndOn());
      cellApp.setRenderingAttributes(ra);

      // Set up the polygon attributes
      PolygonAttributes pa = new PolygonAttributes();
      pa.setCullFace(PolygonAttributes.CULL_NONE);
      pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
      cellApp.setPolygonAttributes(pa);

      //            TextureAttributes texAttr = new TextureAttributes();
      //            texAttr.setTextureMode(TextureAttributes.MODULATE);
      //            //texAttr.setTextureColorTable(pattern);
      //            cellApp.setTextureAttributes(texAttr);

      LineAttributes lineAttr = new LineAttributes();
      lineAttr.setLineAntialiasingEnable(true);
      cellApp.setLineAttributes(lineAttr);

      // ** Data for cells
      ColoringAttributes ca = new ColoringAttributes();
      ca.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
      ca.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
      ca.setColor(userColor);
      cellApp.setColoringAttributes(ca);
      cellApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
      cellApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    } else if (initValue == null) // redoing color only when it was changed in GUI
    {
      ColoringAttributes ca = cellApp.getColoringAttributes();
      Color3f curColor = new Color3f();
      ca.getColor(curColor);
      if (!userColor.equals(curColor)) ca.setColor(userColor);
    }
  }
示例#2
0
  /**
   * Method to access appearance of axes in 3D
   *
   * @param initValue false if appearance has to be changed according to user value
   */
  public static void setAxisAppearanceValues(Object initValue) {
    int[] colors = J3DUtils.get3DColorAxes();

    for (int i = 0; i < axisApps.length; i++) {
      Color userColor = new Color(colors[i]);

      if (axisApps[i] == null) {
        axisApps[i] = new J3DAppearance(TransparencyAttributes.NONE, 0.5f, userColor);

        // Turn off face culling so we can see the back side of the labels
        // (since we're not using font extrusion)
        PolygonAttributes polygonAttributes = new PolygonAttributes();
        polygonAttributes.setCullFace(PolygonAttributes.CULL_NONE);

        // Make the axis lines 2 pixels wide
        LineAttributes lineAttributes = new LineAttributes();
        lineAttributes.setLineWidth(3.0f);

        ColoringAttributes colorAttrib = new ColoringAttributes();
        colorAttrib.setColor(new Color3f(userColor));
        colorAttrib.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
        colorAttrib.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
        axisApps[i].setColoringAttributes(colorAttrib);
        axisApps[i].setPolygonAttributes(polygonAttributes);
        axisApps[i].setLineAttributes(lineAttributes);
        axisApps[i].setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
        axisApps[i].setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

        RenderingAttributes ra = new RenderingAttributes();
        ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
        ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
        ra.setVisible(J3DUtils.is3DAxesOn());
        axisApps[i].setRenderingAttributes(ra);
      } else if (initValue == null) // redoing color only when it was changed in GUI
      axisApps[i].set3DColor(null, userColor);
    }
  }
示例#3
0
  private void setOtherAppearanceValues(int mode, float factor, Color color, boolean visible) {
    // Transparency values
    TransparencyAttributes ta = new TransparencyAttributes(mode, factor);
    ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
    ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    ta.setCapability(TransparencyAttributes.ALLOW_MODE_READ);
    ta.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    setTransparencyAttributes(ta);

    setCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
    setCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
    // For highlight
    setCapability(ALLOW_MATERIAL_READ);
    setCapability(ALLOW_MATERIAL_WRITE);
    // For visibility
    setCapability(ALLOW_RENDERING_ATTRIBUTES_READ);
    setCapability(ALLOW_RENDERING_ATTRIBUTES_WRITE);
    // Color
    setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

    // Adding Rendering attributes to access visibility flag if layer is available
    if (layer != null) {
      RenderingAttributes ra = new RenderingAttributes();
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
      ra.setCapability(RenderingAttributes.ALLOW_DEPTH_ENABLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_DEPTH_ENABLE_WRITE);
      ra.setVisible(visible);
      setRenderingAttributes(ra);
      if (mode != TransparencyAttributes.NONE) ra.setDepthBufferEnable(true);
    }

    // Set up the polygon attributes
    // PolygonAttributes pa = new PolygonAttributes();
    // pa.setCullFace(PolygonAttributes.CULL_NONE);
    // pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    // setPolygonAttributes(pa);

    // TextureAttributes texAttr = new TextureAttributes();
    // texAttr.setTextureMode(TextureAttributes.MODULATE);
    // texAttr.setTextureColorTable(pattern);
    // setTextureAttributes(texAttr);

    // LineAttributes lineAttr = new LineAttributes();
    // lineAttr.setLineAntialiasingEnable(true);
    // setLineAttributes(lineAttr);

    // Adding to internal material
    //				Material mat = new Material(objColor, black, objColor, white, 70.0f);
    if (color != null) {
      Color3f objColor = new Color3f(color);
      // Emissive is black and specular is plastic!
      // Color3f specular = new Color3f(color.brighter());
      Material mat =
          new Material(objColor, J3DUtils.black, objColor, J3DUtils.plastic /*J3DUtils.white*/, 17);
      mat.setLightingEnable(true);
      mat.setCapability(Material.ALLOW_COMPONENT_READ);
      mat.setCapability(Material.ALLOW_COMPONENT_WRITE);
      mat.setCapability(Material.AMBIENT_AND_DIFFUSE);
      setMaterial(mat);
    }
  }
  public Annotations(View view, Context context, Volume vol) {
    super(view, context, vol);
    viewPtAttr = (CoordAttr) context.getAttr("Vol Ref Pt");
    perspectiveAttr = (ToggleAttr) context.getAttr("Perspective");
    boxAttr[PLUS_X] = (ToggleAttr) context.getAttr("Plus X Box");
    boxAttr[PLUS_Y] = (ToggleAttr) context.getAttr("Plus Y Box");
    boxAttr[PLUS_Z] = (ToggleAttr) context.getAttr("Plus Z Box");
    boxAttr[MINUS_X] = (ToggleAttr) context.getAttr("Minus X Box");
    boxAttr[MINUS_Y] = (ToggleAttr) context.getAttr("Minus Y Box");
    boxAttr[MINUS_Z] = (ToggleAttr) context.getAttr("Minus Z Box");
    imageAttr[PLUS_X] = (StringAttr) context.getAttr("Plus X Image");
    imageAttr[PLUS_Y] = (StringAttr) context.getAttr("Plus Y Image");
    imageAttr[PLUS_Z] = (StringAttr) context.getAttr("Plus Z Image");
    imageAttr[MINUS_X] = (StringAttr) context.getAttr("Minus X Image");
    imageAttr[MINUS_Y] = (StringAttr) context.getAttr("Minus Y Image");
    imageAttr[MINUS_Z] = (StringAttr) context.getAttr("Minus Z Image");

    volume = vol;
    frontRoot = new BranchGroup();
    frontRoot.setCapability(BranchGroup.ALLOW_DETACH);
    frontRoot.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
    backRoot = new BranchGroup();
    backRoot.setCapability(BranchGroup.ALLOW_DETACH);
    backRoot.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);

    int stripLength[] = new int[1];
    stripLength[0] = 5;

    ColoringAttributes ca = new ColoringAttributes(1.0f, 0.0f, 0.0f, ColoringAttributes.SHADE_FLAT);
    Appearance boxAppearance = new Appearance();
    boxAppearance.setColoringAttributes(ca);

    TexCoord2f[] texCoords = new TexCoord2f[4];
    texCoords[0] = new TexCoord2f(0.0f, 0.0f);
    texCoords[1] = new TexCoord2f(1.0f, 0.0f);
    texCoords[2] = new TexCoord2f(1.0f, 1.0f);
    texCoords[3] = new TexCoord2f(0.0f, 1.0f);

    TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.0f);
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    PolygonAttributes pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setDepthBufferEnable(false);

    for (int i = 0; i < 6; i++) {
      faceGroup[i] = new SharedGroup();
      frontAnnotations.addChild(new Link(faceGroup[i]));
      backAnnotations.addChild(new Link(faceGroup[i]));
      boxLine[i] = new LineStripArray(5, GeometryArray.COORDINATES, stripLength);
      boxLine[i].setCoordinates(0, volume.facePoints[i], 0, 4);
      boxLine[i].setCoordinate(4, volume.facePoints[i][0]);
      boxLine[i].setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
      Shape3D box = new Shape3D(boxLine[i], boxAppearance);
      boxSwitch[i] = new Switch();
      boxSwitch[i].setCapability(Switch.ALLOW_SWITCH_WRITE);
      boxSwitch[i].addChild(box);
      if (boxAttr[i].getValue() == true) {
        boxSwitch[i].setWhichChild(Switch.CHILD_ALL);
      } else {
        boxSwitch[i].setWhichChild(Switch.CHILD_NONE);
      }
      faceGroup[i].addChild(boxSwitch[i]);
      imageQuad[i] =
          new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
      imageQuad[i].setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
      imageQuad[i].setCoordinates(0, volume.facePoints[i], 0, 4);
      imageQuad[i].setTextureCoordinates(0, 0, texCoords, 0, 4);
      imageAppearance[i] = new Appearance();
      imageAppearance[i].setTransparencyAttributes(ta);
      imageAppearance[i].setPolygonAttributes(pa);
      imageAppearance[i].setRenderingAttributes(ra);
      imageAppearance[i].setTextureAttributes(texAttr);
      imageAppearance[i].setCapability(Appearance.ALLOW_TEXTURE_WRITE);
      imageSwitch[i] = new Switch();
      imageSwitch[i].setCapability(Switch.ALLOW_SWITCH_WRITE);
      imageFile[i] = imageAttr[i].getValue();
      if (imageFile[i].length() > 0) {
        try {
          URL imageURL = new URL(context.getCodeBase().toString() + imageFile[i]);
          imageTexture[i] = new TextureLoader(imageURL, null).getTexture();
        } catch (Exception e) {
          System.err.println("Error " + e + " loading image:" + imageFile[i] + ".");
        }
      }
      imageAppearance[i].setTexture(imageTexture[i]);
      if (imageTexture[i] != null) {
        imageSwitch[i].setWhichChild(Switch.CHILD_ALL);
      } else {
        imageSwitch[i].setWhichChild(Switch.CHILD_NONE);
      }
      Shape3D imageShape = new Shape3D(imageQuad[i], imageAppearance[i]);
      imageSwitch[i].addChild(imageShape);
      faceGroup[i].addChild(imageSwitch[i]);
    }
    frontAnnotations.setCapability(Switch.ALLOW_SWITCH_WRITE);
    backAnnotations.setCapability(Switch.ALLOW_SWITCH_WRITE);

    faceNormal[PLUS_X] = new Vector3d(1.0, 0.0, 0.0);
    faceCenter[PLUS_X] = new Point3d(volume.maxCoord.x, 0.0, 0.0);
    faceNormal[PLUS_Y] = new Vector3d(0.0, 1.0, 0.0);
    faceCenter[PLUS_Y] = new Point3d(0.0, volume.maxCoord.y, 0.0);
    faceNormal[PLUS_Z] = new Vector3d(0.0, 0.0, 1.0);
    faceCenter[PLUS_Z] = new Point3d(0.0, 0.0, volume.maxCoord.z);
    faceNormal[MINUS_X] = new Vector3d(-1.0, 0.0, 0.0);
    faceCenter[MINUS_X] = new Point3d(volume.minCoord.x, 0.0, 0.0);
    faceNormal[MINUS_Y] = new Vector3d(0.0, -1.0, 0.0);
    faceCenter[MINUS_Y] = new Point3d(0.0, volume.minCoord.y, 0.0);
    faceNormal[MINUS_Z] = new Vector3d(0.0, 0.0, -1.0);
    faceCenter[MINUS_Z] = new Point3d(0.0, 0.0, volume.minCoord.z);
    volCenter.x = (volume.maxCoord.x + volume.minCoord.x) / 2;
    volCenter.y = (volume.maxCoord.y + volume.minCoord.y) / 2;
    volCenter.z = (volume.maxCoord.z + volume.minCoord.z) / 2;

    frontRoot.addChild(frontAnnotations);
    backRoot.addChild(backAnnotations);
  }