Esempio n. 1
0
  public BranchGroup addTriangle(Simplex simplex, Color3f color) {

    int[] p = simplex.getPoints();
    BranchGroup bgTriangle = new BranchGroup();
    bgTriangle.setCapability(BranchGroup.ALLOW_DETACH);

    javax.vecmath.Point3d[] coords = new javax.vecmath.Point3d[6];
    TriangleArray ta = new TriangleArray(6, TriangleArray.COORDINATES | TriangleArray.COLOR_3);

    Point3d p0 = (Point3d) complex.getPoints().get(simplex.getPoints()[0]);
    Point3d p1 = (Point3d) complex.getPoints().get(simplex.getPoints()[1]);
    Point3d p2 = (Point3d) complex.getPoints().get(simplex.getPoints()[2]);
    coords[0] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coords[1] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coords[2] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coords[3] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coords[4] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coords[5] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());

    ta.setCoordinates(0, coords);
    Color3f[] colors = new Color3f[6];
    for (int i = 0; i < 3; i++) colors[i] = Colors.black;
    for (int i = 3; i < 6; i++) colors[i] = Colors.yellow;

    ta.setColors(0, colors);

    Appearance ap = new Appearance();
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    ap.setLineAttributes(new LineAttributes(2, LineAttributes.PATTERN_SOLID, false));
    ap.setMaterial(new Material());
    ap.setTransparencyAttributes(
        new TransparencyAttributes(TransparencyAttributes.SCREEN_DOOR, 0.5f));

    Shape3D shape = new Shape3D(ta, ap);

    shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    simplex.setTriangle(shape);
    //			 simplex.bgTriangle = bgTriangle;

    TransformGroup tgTriangle = new TransformGroup();
    tgTriangle.addChild(shape);

    bgTriangle.addChild(tgTriangle);
    spin.addChild(bgTriangle);
    return bgTriangle;
  }
Esempio n. 2
0
  public BranchGroup addTetrahedron(Simplex simplex, Color3f color) {

    BranchGroup bgTetrahedron = new BranchGroup();
    bgTetrahedron.setCapability(BranchGroup.ALLOW_DETACH);

    javax.vecmath.Point3d[] coords = new javax.vecmath.Point3d[12];
    LineArray la = new LineArray(12, LineArray.COORDINATES | LineArray.COLOR_3);

    Point3d p0 = (Point3d) complex.getPoints().get(simplex.getPoints()[0]);
    Point3d p1 = (Point3d) complex.getPoints().get(simplex.getPoints()[1]);
    Point3d p2 = (Point3d) complex.getPoints().get(simplex.getPoints()[2]);
    Point3d p3 = (Point3d) complex.getPoints().get(simplex.getPoints()[3]);

    coords[0] = coords[2] = coords[4] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coords[1] = coords[6] = coords[8] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coords[3] = coords[7] = coords[10] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coords[5] = coords[9] = coords[11] = new javax.vecmath.Point3d(p3.getX(), p3.getY(), p3.getZ());

    la.setCoordinates(0, coords);
    Color3f[] colors = new Color3f[12];
    for (int i = 0; i < 12; i++) colors[i] = Colors.black;
    la.setColors(0, colors);

    javax.vecmath.Point3d[] coordsTr = new javax.vecmath.Point3d[24];
    TriangleArray tr = new TriangleArray(24, TriangleArray.COORDINATES | TriangleArray.COLOR_3);
    coordsTr[0] =
        coordsTr[3] = coordsTr[6] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coordsTr[1] =
        coordsTr[4] = coordsTr[9] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coordsTr[2] =
        coordsTr[7] = coordsTr[10] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coordsTr[5] =
        coordsTr[8] = coordsTr[11] = new javax.vecmath.Point3d(p3.getX(), p3.getY(), p3.getZ());

    coordsTr[12] =
        coordsTr[15] = coordsTr[18] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coordsTr[14] =
        coordsTr[17] = coordsTr[21] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coordsTr[13] =
        coordsTr[20] = coordsTr[23] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coordsTr[16] =
        coordsTr[19] = coordsTr[22] = new javax.vecmath.Point3d(p3.getX(), p3.getY(), p3.getZ());

    tr.setCoordinates(0, coordsTr);
    Color3f[] colorsTr = new Color3f[24];
    for (int i = 0; i < 24; i++) colorsTr[i] = Colors.green;
    tr.setColors(0, colorsTr);

    Appearance ap = new Appearance();
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    //			 ap.setCapability(Appearance.ALLOW_MATERIAL_READ);
    //			 ap.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
    ap.setLineAttributes(new LineAttributes(2, LineAttributes.PATTERN_SOLID, false));
    ap.setMaterial(new Material());
    //			 ap.setTransparencyAttributes(new
    // TransparencyAttributes(TransparencyAttributes.SCREEN_DOOR, 0.5f));

    //			 LineArray la = cell.getLineArray();
    Shape3D shape = new Shape3D(la, ap);
    Shape3D shapeTr = new Shape3D(tr, ap);

    shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    simplex.setTetrahedron(shape);
    //			 cell.setLineArray(la);
    simplex.setTriangleArray(tr);
    simplex.setBgTetrahedron(bgTetrahedron);

    TransformGroup tgTetrahedron = new TransformGroup();
    tgTetrahedron.addChild(shape);
    tgTetrahedron.addChild(shapeTr);

    bgTetrahedron.addChild(tgTetrahedron);
    spin.addChild(bgTetrahedron);
    return bgTetrahedron;
  }