Esempio n. 1
0
 private void stepSimplicies3() {
   if (count3 < complex.getSimplicies()[3].getSize()) {
     Simplex simplex3 = (Simplex) complex.getSimplicies()[3].get(count3);
     addTetrahedron(simplex3, Colors.yellow);
     System.out.println(count3 + ": alpha3 = " + simplex3.getAlpha());
     count3++;
   }
 }
Esempio n. 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;
  }
Esempio n. 3
0
 private void stepSimplicies23() {
   if ((count2 < complex.getSimplicies()[2].getSize())
       && (count3 < complex.getSimplicies()[3].getSize())) {
     Simplex simplex2 = (Simplex) complex.getSimplicies()[2].get(count2);
     Simplex simplex3 = (Simplex) complex.getSimplicies()[3].get(count3);
     if (simplex3.getAlpha() < simplex2.getAlpha()) {
       addTetrahedron(simplex3, Colors.yellow);
       System.out.println(count3 + ": alpha3 = " + simplex3.getAlpha());
       count3++;
     } else {
       System.out.println(count2 + ": alpha2 = " + simplex2.getAlpha());
       addTriangle(simplex2, Colors.yellow);
       count2++;
     }
   } else {
     if (count2 < complex.getSimplicies()[2].getSize()) {
       Simplex simplex2 = (Simplex) complex.getSimplicies()[2].get(count2);
       System.out.println(count2 + ": alpha2 = " + simplex2.getAlpha());
       addTriangle(simplex2, Colors.yellow);
       count2++;
     } else {
       if (count3 < complex.getSimplicies()[3].getSize()) {
         Simplex simplex3 = (Simplex) complex.getSimplicies()[3].get(count3);
         addTetrahedron(simplex3, Colors.yellow);
         System.out.println(count3 + ": alpha3 = " + simplex3.getAlpha());
         count3++;
       }
     }
   }
 }
Esempio n. 4
0
 public void addSphere(Simplex simplex, double radius, Color3f color) {
   geom3d.Point3d p = (Point3d) complex.getPoints().get(simplex.getPoints()[0]);
   BranchGroup bgSphere = new BranchGroup();
   bgSphere.setCapability(BranchGroup.ALLOW_DETACH);
   Appearance ap = new Appearance();
   ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
   ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
   ap.setColoringAttributes(new ColoringAttributes(color, ColoringAttributes.NICEST));
   simplex.setSphere(new Sphere(new Float(radius), ap));
   simplex.getSphere().getShape().setCapability(Shape3D.ALLOW_APPEARANCE_READ);
   simplex.getSphere().getShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
   Transform3D tr = new Transform3D();
   tr.setTranslation(new javax.vecmath.Vector3d(p.getX(), p.getY(), p.getZ()));
   TransformGroup tgSphere = new TransformGroup(tr);
   tgSphere.addChild(simplex.getSphere());
   bgSphere.addChild(tgSphere);
   spin.addChild(bgSphere);
 }
Esempio n. 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;
  }
Esempio n. 6
0
  public void actionPerformed(ActionEvent actionEvent) {
    String cmd = actionEvent.getActionCommand();
    if ("Console"
        .equals(
            cmd)) { // opens a window to read the coordinates of a point that is added to the point
      // set.
      new InputPanelPointApplet(this);
    } else if ("Select_Point"
        .equals(cmd)) { // opens a window with the list of points. One is to be selected.
      new SelectPointPanelApplet(this);
    } else if ("Select_Cell"
        .equals(cmd)) { // opens a window with the list of cells. One is to be selected.
      //				new SelectCellPanelApplet(this);
    } else if ("Random Point".equals(cmd)) { // adds random point to the point set
      /*				 com.artchase.geom3d.Point3d pointToAdd = new com.artchase.geom3d.Point3d(randGen);
      				 int size = getCells().getVertices().getSize();
      				 Vertex v = new Vertex(pointToAdd, size);
      				 getCells().getVertices().insert(v);
      				 addSphere(v, 0.02f, Colors.red);
      				 getCells().setNrVertices(size+1);
      */ } else if ("Selected_Point_Move".equals(cmd)) {
      //			 new SelectedPointMovePanel(this);
    } else if ("Selected_Cell_Adjacent".equals(cmd)) {
      /*				 if (selectedCell != null) {
      					 System.out.println("selectedCell is not null");
      					 if (selectedAdjCell != null) {
      						 System.out.println("adjacentCellShown is TRUE");
      						 selectedAdjCell.changeAppearance(1, LineAttributes.PATTERN_SOLID, Colors.yellow);
      						 selectedAdjCell = null;
      					 }
      					 System.out.println("adjacentCellShown is FALSE");
      					 if (cells.getNrCells() > 0) {
      						 System.out.println("Number of cells is " + cells.getNrCells());
      						 int nrIter = 0;
      						 do {
      							 nrIter++;
      							 selectedAdjCellIndex = (++selectedAdjCellIndex)%4;
      							 System.out.println("selectedAdjCellIndex = " + selectedAdjCellIndex);
      							 selectedAdjCell = selectedCell.getAdjCell(selectedAdjCellIndex);
      						 } while (selectedAdjCell.isInfiniteCell() && (nrIter < 4));
      						 if (!selectedAdjCell.isInfiniteCell()) {         // adjacent cell found
      							 System.out.println("i am here displaying cell " + selectedAdjCellIndex);
      							 selectedAdjCell.changeAppearance(5, LineAttributes.PATTERN_SOLID, Colors.magenta);
      						 } else selectedAdjCell = null;                   // all adjacent cells are infinite
      					 }
      				 }
      */ } else if ("Selected_Cell_Circumcircle".equals(cmd)) {
      /*				 if (circumCircleShown) {
      					 circumCircleBranchGroup.detach();
      					 circumCircleShown = false;
      				 }
      				 else {
      					 com.artchase.geom3d.Point3d[] points = selectedCell.getPoints();
      					 Sphere3d sphere = new Sphere3d(points[0],points[1],points[2],points[3]);
      					 com.artchase.geom3d.Point3d center = sphere.getCenter();
      					 circumCircleBranchGroup = addSphere(center, sphere.getRadius(), Colors.green);
      					 circumCircleShown = true;
      				 }
      */ } else if ("Random".equals(cmd)) {
      complex.clear();
      spin.removeAllChildren();
      setNrSpannedVerticesField(0);
      setNrEdgesField(0);
      setNrFacesField(0);
      setNrCellsField(0);
      // Open window to get the number of random points to be generated.
      new InputPanelRandomApplet(this);
    } else if ("Clear".equals(cmd)) {
      complex.clear();
      spin.removeAllChildren();
      setNrSpannedVerticesField(0);
      setNrEdgesField(0);
      setNrFacesField(0);
      setNrCellsField(0);
      selectedSimplex = null;
      selectedAdjCell = null;
      count2 = count3 = 0;
    } else if ("Run".equals(cmd)) {
      Simplex simplex;
      if (!complex.getPoints().isEmpty() && complex.isEmpty()) {
        simplex = complex.first3Simplex();
        //					 addTriangle(simplex,Colors.yellow);
        while (!complex.getStack().isEmpty()) complex.next4Simplex();
        /*					 int size = complex.simplicies[3].getSize();
        					 for (int i = 0; i < size; i++) {
        						 simplex = (Simplex)complex.simplicies[3].get(i);
        						 addTetrahedron(simplex,Colors.yellow);
        					 }
        */ complex.computeAlphaValues();
        SorterSelection sorter = new SorterSelection();
        SortToolSimplexAlpha sortTool = new SortToolSimplexAlpha();
        sorter.Sort(complex.getSimplicies()[1], sortTool, false);
        sorter.Sort(complex.getSimplicies()[2], sortTool, false);
        sorter.Sort(complex.getSimplicies()[3], sortTool, false);
        complex.toConsole(complex.getSimplicies()[1]);
        complex.toConsole(complex.getSimplicies()[2]);
        complex.toConsole(complex.getSimplicies()[3]);
      }
      /*				 if (!complex.points.isEmpty()) {
      					 while (!complex.stack.isEmpty()) complex.next4Simplex();
      					 int size = complex.simplicies[3].getSize();
      					 for (int i = 0; i < size; i++) {
      						 simplex = (Simplex)complex.simplicies[3].get(i);
      						 addTetrahedron(simplex,Colors.yellow);
      					 }

      				 }
      */ } else if ("Step".equals(cmd)) stepSimplicies3(); // stepSimplicies23 also available
    else if ("Step1".equals(cmd)) {
      if (complex.isEmpty()) {
        Simplex simplex = complex.first3Simplex();
        addTriangle(simplex, Colors.yellow);
      }
      Simplex simplex = complex.next4Simplex();
      if (simplex != null) addTetrahedron(simplex, Colors.yellow);
    } else if ("Save".equals(cmd)) {
      try {
        BufferedWriter bw = new BufferedWriter(new FileWriter("data"));
        PrintWriter out = new PrintWriter(bw);
        int size = complex.getPoints().getSize();
        Point3d p;
        for (int i = 0; i < size; i++) {
          p = (Point3d) complex.getPoints().get(i);
          out.print(p.getX() + " " + p.getY() + " " + p.getZ() + '\n');
        }
        out.close();
      } catch (IOException e) {
        System.out.println("IOException error!");
        e.printStackTrace();
      }
    } else if ("Load".equals(cmd)) {
      complex.clear();
      spin.removeAllChildren();
      geom3d.PointSet3d points = new PointSet3d("data");
      int size = points.getSize();
      Point3d point;
      for (int i = 0; i < size; i++) {
        point = (Point3d) points.get(i);
        complex.getPoints().insert(point);
        Simplex simplex = new Simplex(i);
        complex.insert(simplex);
        addSphere(simplex, 0.02f, Colors.red);
      }
    } else if ("PDB".equals(cmd)) {
      complex.clear();
      spin.removeAllChildren();
      Protein protein = new Protein("1CR4", 0, true);
      PointSet3d points = protein.getPointSet();
      points.translate(points.getCentroid());
      int size = points.getSize();
      Point3d point;
      for (int i = 0; i < size; i++) {
        point = (Point3d) points.get(i);
        complex.getPoints().insert(point);
        Simplex simplex = new Simplex(i);
        complex.insert(simplex);
        addSphere(simplex, 0.02f, Colors.red);
      }
      //				 new InputPanelPDBApplet(this);
    } else if ("Point".equals(cmd)) {
      /*				 ap.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_POINT, PolygonAttributes.CULL_BACK, 0));
      				 ap.setPointAttributes(new PointAttributes(5, false)); }
      			 else if ("Line".equals(cmd)) {
      /*				 ap.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0));
      				 ap.setLineAttributes(new LineAttributes(2, LineAttributes.PATTERN_DASH,false));
      */ } else if ("Polygon".equals(cmd)) {
      //				 ap.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
      // PolygonAttributes.CULL_BACK, 0));
    } else if ("Gouraud".equals(cmd)) {
      /*				 ColoringAttributes ca = new ColoringAttributes();
      				 ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
      				 ap.setColoringAttributes(ca);
      				 ap.setMaterial(null);
      				 RenderingAttributes ra = new RenderingAttributes();
      				 ra.setIgnoreVertexColors(false);
      				 ap.setRenderingAttributes(ra);
      */ } else if ("Lighting".equals(cmd)) {
      /*				 ap.setMaterial(new Material());
      				 RenderingAttributes ra = new RenderingAttributes();
      				 ra.setIgnoreVertexColors(true);
      				 ap.setRenderingAttributes(ra);
      */ }
  }
Esempio n. 7
0
 public ComplexViewer(Delaunay3d complex) {
   super();
   this.complex = complex;
   complex.setViewer(this);
   toProcess = new Stack();
 }