Beispiel #1
0
  public Tetrahedron() {
    int i;

    TriangleArray tetra =
        new TriangleArray(
            12,
            TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2);

    tetra.setCoordinates(0, verts);
    for (i = 0; i < 12; i++) {
      tetra.setTextureCoordinate(i, texCoord[i % 3]);
    }

    int face;
    Vector3f normal = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Point3f[] pts = new Point3f[3];
    for (i = 0; i < 3; i++) pts[i] = new Point3f();

    for (face = 0; face < 4; face++) {
      tetra.getCoordinates(face * 3, pts);
      v1.sub(pts[1], pts[0]);
      v2.sub(pts[2], pts[0]);
      normal.cross(v1, v2);
      normal.normalize();
      for (i = 0; i < 3; i++) {
        tetra.setNormal((face * 3 + i), normal);
      }
    }
    this.setGeometry(tetra);
    this.setAppearance(new Appearance());
  }
Beispiel #2
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;
  }
  private Geometry Triangle3DGeometry(
      Iterator<il.ac.idc.jdt.Triangle> triangles_iter, int num_of_triangles) {
    _triangle_arr =
        new TriangleArray(3 * num_of_triangles, TriangleArray.COORDINATES | TriangleArray.COLOR_3);

    int i = 0;
    while ((i < num_of_triangles) && (triangles_iter.hasNext())) {
      il.ac.idc.jdt.Triangle curr_triangle = triangles_iter.next();

      if ((curr_triangle.getA() != null)
          && (curr_triangle.getB() != null)
          && (curr_triangle.getC() != null)) {
        _triangle_arr.setCoordinate(
            3 * i,
            new Point3d(
                curr_triangle.getA().getX(),
                curr_triangle.getA().getY(),
                curr_triangle.getA().getZ()));
        _triangle_arr.setCoordinate(
            3 * i + 1,
            new Point3d(
                curr_triangle.getB().getX(),
                curr_triangle.getB().getY(),
                curr_triangle.getB().getZ()));
        _triangle_arr.setCoordinate(
            3 * i + 2,
            new Point3d(
                curr_triangle.getC().getX(),
                curr_triangle.getC().getY(),
                curr_triangle.getC().getZ()));
        _triangle_arr.setColor(3 * i, get_col_by_height((int) curr_triangle.getA().getZ()));
        _triangle_arr.setColor(3 * i + 1, get_col_by_height((int) curr_triangle.getB().getZ()));
        _triangle_arr.setColor(3 * i + 2, get_col_by_height((int) curr_triangle.getC().getZ()));
        i++;
      }
    }
    System.out.println("DEBUG INFO successfuly displayed " + i + " Triangles");

    return _triangle_arr;
  }
Beispiel #4
0
  public void createTriangles(
      IfcRoot ifcRootObject, IfcModelInterface ifcModel, TransformGroup buildingTransformGroup)
      throws RenderEngineException {
    RenderEngineInstance instance =
        ifcEngineModel.getInstanceFromExpressId(ifcRootObject.getExpressId());
    RenderEngineInstanceVisualisationProperties instanceInModelling =
        instance.getVisualisationProperties();
    if (instanceInModelling.getPrimitiveCount() != 0) {
      Appearance appearance = appearances.getAppearance(ifcRootObject);
      if (appearance != null) {
        Point3f[] coordinates = new Point3f[instanceInModelling.getPrimitiveCount() * 3];
        Vector3f[] normals = new Vector3f[instanceInModelling.getPrimitiveCount() * 3];
        for (int i = instanceInModelling.getStartIndex();
            i < instanceInModelling.getPrimitiveCount() * 3 + instanceInModelling.getStartIndex();
            i += 3) {
          int offsetIndex = i - instanceInModelling.getStartIndex();
          int i1 = geometry.getIndex(i);
          int i2 = geometry.getIndex(i + 1);
          int i3 = geometry.getIndex(i + 2);

          coordinates[offsetIndex] =
              new Point3f(
                  geometry.getVertex(i1 * 3),
                  geometry.getVertex(i1 * 3 + 1),
                  geometry.getVertex(i1 * 3 + 2));
          coordinates[offsetIndex + 1] =
              new Point3f(
                  geometry.getVertex(i3 * 3),
                  geometry.getVertex(i3 * 3 + 1),
                  geometry.getVertex(i3 * 3 + 2));
          coordinates[offsetIndex + 2] =
              new Point3f(
                  geometry.getVertex(i2 * 3),
                  geometry.getVertex(i2 * 3 + 1),
                  geometry.getVertex(i2 * 3 + 2));

          normals[offsetIndex] =
              new Vector3f(
                  geometry.getNormal(i1 * 3),
                  geometry.getNormal(i1 * 3 + 1),
                  geometry.getNormal(i1 * 3 + 2));
          normals[offsetIndex + 1] =
              new Vector3f(
                  geometry.getNormal(i3 * 3),
                  geometry.getNormal(i3 * 3 + 1),
                  geometry.getNormal(i3 * 3 + 2));
          normals[offsetIndex + 2] =
              new Vector3f(
                  geometry.getNormal(i2 * 3),
                  geometry.getNormal(i2 * 3 + 1),
                  geometry.getNormal(i2 * 3 + 2));
        }
        TriangleArray triangleArray =
            new TriangleArray(
                coordinates.length, GeometryArray.COORDINATES | GeometryArray.NORMALS);
        triangleArray.setCoordinates(0, coordinates);
        triangleArray.setNormals(0, normals);
        Shape3D myShape = new Shape3D(triangleArray, appearance);
        buildingTransformGroup.addChild(myShape);
        myShape.setUserData(ifcRootObject);
      }
    }
  }
Beispiel #5
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;
  }
  /**
   * Build the 3D scene on a Java3D enabled draw.
   *
   * @param objRot the transform object
   */
  @Override
  public void buildJava3DScene(TransformGroup objRot) {
    if (objRot == null) return;

    AtomInfo ai = AtomInfo.getInstance();
    double xMin = gridProperty.getBoundingBox().getUpperLeft().getX(),
        yMin = gridProperty.getBoundingBox().getUpperLeft().getY(),
        zMin = gridProperty.getBoundingBox().getUpperLeft().getZ();
    double f1, f2, f3;
    double[] functionValues = gridProperty.getFunctionValues();
    double incInX = gridProperty.getXIncrement(),
        incInY = gridProperty.getYIncrement(),
        incInZ = gridProperty.getZIncrement();
    int pointsAlongX = gridProperty.getNoOfPointsAlongX(),
        pointsAlongY = gridProperty.getNoOfPointsAlongY(),
        pointsAlongZ = gridProperty.getNoOfPointsAlongZ();

    int i, j, k;

    Atom atom;
    String symbol;
    SphereTriSetGenerator stsg;
    Point3DI point1, point2, point3;

    int noOfAtoms = molecule.getNumberOfAtoms();
    int pointsAlongSlice = pointsAlongY * pointsAlongZ;
    HashMap<String, SphereTriSetGenerator> triSetTableTmp =
        new HashMap<String, SphereTriSetGenerator>(5);

    if (noOfAtoms > largeMoleculeSize) triSetTableTmp = triSetTable;

    Matrix3D tmat = new Matrix3D();
    tmat.unit();

    TransformGroup surfaceScene = new TransformGroup();

    for (int atomIndex = 0; atomIndex < noOfAtoms; atomIndex++) {
      atom = molecule.getAtom(atomIndex);

      // check to see if we are with in the bounding box?
      if (!gridProperty.getBoundingBox().contains(atom.getAtomCenter())) continue;

      symbol = atom.getSymbol();

      if ((stsg = triSetTableTmp.get(symbol)) == null) {
        stsg =
            new SphereTriSetGenerator(
                atom.getAtomCenter(), ai.getVdwRadius(symbol), numberOfSphereDivisions);
        triSetTableTmp.put(symbol, stsg);
      } // end if

      // setup color
      Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
      Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
      Color3f objColor = new Color3f(colorMap.getInterpolatedColor(currentFunctionValue));

      Appearance app = new Appearance();
      Material mm = new Material(objColor, eColor, objColor, sColor, 100.0f);
      mm.setLightingEnable(true);
      app.setMaterial(mm);

      if (fillTransperency > 0) {
        app.setTransparencyAttributes(
            new TransparencyAttributes(
                TransparencyAttributes.NICEST, (float) (fillTransperency / 255.0)));
      } // end if

      int idx = 0;

      stsg.setTransform(tmat);
      stsg.setCenter(atom.getAtomCenter());

      ArrayList<Point3d> validPoints = new ArrayList<Point3d>();
      ArrayList<Color3f> validColors = new ArrayList<Color3f>();

      while (true) {
        Triangle t = stsg.nextVisibleTriSet();

        if (t == null) break;

        // first point
        point1 = t.getPoint1();
        i = (int) Math.round(Math.abs((point1.getX() - xMin) / incInX));
        j = (int) Math.round(Math.abs((point1.getY() - yMin) / incInY));
        k = (int) Math.round(Math.abs((point1.getZ() - zMin) / incInZ));

        if (i > pointsAlongX - 1) i = pointsAlongX - 1;
        if (j > pointsAlongY - 1) j = pointsAlongY - 1;
        if (k > pointsAlongZ - 1) k = pointsAlongZ - 1;

        f1 = functionValues[(i * pointsAlongSlice) + (j * pointsAlongZ) + k];

        // second point
        point2 = t.getPoint2();
        i = (int) Math.round(Math.abs((point2.getX() - xMin) / incInX));
        j = (int) Math.round(Math.abs((point2.getY() - yMin) / incInY));
        k = (int) Math.round(Math.abs((point2.getZ() - zMin) / incInZ));

        if (i > pointsAlongX - 1) i = pointsAlongX - 1;
        if (j > pointsAlongY - 1) j = pointsAlongY - 1;
        if (k > pointsAlongZ - 1) k = pointsAlongZ - 1;

        f2 = functionValues[(i * pointsAlongSlice) + (j * pointsAlongZ) + k];

        // third point
        point3 = t.getPoint3();
        i = (int) Math.round(Math.abs((point3.getX() - xMin) / incInX));
        j = (int) Math.round(Math.abs((point3.getY() - yMin) / incInY));
        k = (int) Math.round(Math.abs((point3.getZ() - zMin) / incInZ));

        if (i > pointsAlongX - 1) i = pointsAlongX - 1;
        if (j > pointsAlongY - 1) j = pointsAlongY - 1;
        if (k > pointsAlongZ - 1) k = pointsAlongZ - 1;

        f3 = functionValues[(i * pointsAlongSlice) + (j * pointsAlongZ) + k];

        validPoints.add(new Point3d(point1.getX(), point1.getY(), point1.getZ()));
        validColors.add(new Color3f(colorMap.getInterpolatedColor(f1)));

        validPoints.add(new Point3d(point2.getX(), point2.getY(), point2.getZ()));
        validColors.add(new Color3f(colorMap.getInterpolatedColor(f2)));

        validPoints.add(new Point3d(point3.getX(), point3.getY(), point3.getZ()));
        validColors.add(new Color3f(colorMap.getInterpolatedColor(f3)));
      } // end while

      TriangleArray ta =
          new TriangleArray(validPoints.size(), GeometryArray.COORDINATES | GeometryArray.COLOR_3);

      for (idx = 0; idx < validPoints.size(); idx++) {
        ta.setCoordinate(idx, validPoints.get(idx));
        ta.setColor(idx, validColors.get(idx));
      }

      validColors = null;
      validPoints = null;

      GeometryInfo gi = new GeometryInfo(ta);
      gi.compact();
      gi.recomputeIndices();

      // generate normals
      NormalGenerator ng = new NormalGenerator();
      ng.generateNormals(gi);

      // stripify
      Stripifier st = new Stripifier();
      st.stripify(gi);

      surfaceScene.addChild(new Shape3D(gi.getGeometryArray(), app));
    } // end for

    if (showBoundingBox) {
      boundingBox.setTransform(transform);
      boundingBox.applyTransforms();
      (new ScreenCuboidJ3D(boundingBox)).buildJava3DScene(surfaceScene);
    } // end if

    objRot.addChild(surfaceScene);
  }