コード例 #1
0
ファイル: PL02BranchGroup.java プロジェクト: bgarrels/jCAE
 /**
  * @param pt
  * @return the grid coordinates for a given point
  */
 protected int[] getGridCoordinate(float[] pt) {
   int[] ret = new int[3];
   for (int xyz = 0; xyz < 3; ++xyz) {
     double min = Double.POSITIVE_INFINITY;
     int idx = -1;
     for (int i = 0; i < grid[xyz].length; ++i) {
       double dist = Math.abs(grid[xyz][i] - pt[xyz]); // N1 norm
       if (dist < min) {
         min = dist;
         idx = i;
       }
     }
     ret[xyz] = idx;
   }
   return ret;
 }
コード例 #2
0
ファイル: PL02BranchGroup.java プロジェクト: bgarrels/jCAE
  /** Handles highlighting for edges */
  public void highlight(boolean on, Object parameter) {
    // Should always be a pick result since those Shape3D do not appear in
    // the JTree
    if (parameter instanceof PickResult) {
      PickResult result = (PickResult) parameter;
      result.setFirstIntersectOnly(true);
      PickIntersection pi = result.getIntersection(0);
      // indices of the picked line
      // should always be line at this point
      // Indices are set to vertex indices, as this is not an Index
      // Geometry object
      int[] idx = pi.getPrimitiveCoordinateIndices();
      Point3d point3d = pi.getPointCoordinates();
      double[] point = new double[3];
      point3d.get(point);
      FloatBuffer coords = (FloatBuffer) (pi.getGeometryArray()).getCoordRefBuffer().getBuffer();
      float[] pt1 = new float[3];
      float[] pt2 = new float[3];
      coords.position(idx[0] * 3);
      coords.get(pt1);
      coords.position(idx[1] * 3);
      coords.get(pt2);
      int[] gpt1 = getGridCoordinate(pt1);
      int[] gpt2 = getGridCoordinate(pt2);
      int dim = 0;
      // lines are parallel to one of the axis => only one coordinate
      // changes
      if (gpt1[0] != gpt2[0]) dim = 0;
      else if (gpt1[1] != gpt2[1]) dim = 1;
      else if (gpt1[2] != gpt2[2]) dim = 2;
      else System.err.println("Error: edge is not parallel to one of the axis");
      // use gpt1 and gpt2 as a variables for the new point => destroy
      // previous content
      gpt1[dim] =
          (int)
              Math.floor(
                  gpt1[dim]
                      + (point[dim] - pt1[dim]) * (gpt2[dim] - gpt1[dim]) / (pt2[dim] - pt1[dim]));
      System.out.println(
          "Edge end 0 vertex grid coordinates = ("
              + gpt1[0]
              + ", "
              + gpt1[1]
              + ", "
              + gpt1[2]
              + ")");
      gpt2[dim] = gpt1[dim] + 1;
      System.out.println(
          "Edge end 1 vertex grid coordinates = ("
              + gpt2[0]
              + ", "
              + gpt2[1]
              + ", "
              + gpt2[2]
              + ")");

      System.out.println("pi.getGeometryArray()=" + pi.getGeometryArray());
      System.out.println(
          "pi.getGeometryArray().getUserData()=" + pi.getGeometryArray().getUserData());

      // handle wire case
      Object userData = pi.getGeometryArray().getUserData();
      if (userData != null && userData instanceof int[]) {
        int[] info = (int[]) userData;
        if (info[0] < 0) {
          float[] color = getColorForOrder(info[0], on ? 2 : 0);
          idx = pi.getPrimitiveColorIndices();
          FloatBuffer colors =
              (FloatBuffer) (pi.getGeometryArray()).getColorRefBuffer().getBuffer();
          colors.position(idx[0] * 3);
          colors.put(color);
          colors.position(idx[1] * 3);
          colors.put(color);
        }
        toggleSelectedEdge(on, new SelectionEdge(gpt1, gpt2, info[0], info[1]));
      }
    }
    // event propagation
    System.out.println(System.currentTimeMillis() + " end of highlight");
  }
コード例 #3
0
ファイル: PL02BranchGroup.java プロジェクト: bgarrels/jCAE
 /*
  * (non-Javadoc)
  *
  * @see syn3d.base.ActiveNode#highlight(boolean, java.lang.Object)
  */
 public void highlight(boolean on, Object parameter) {
   System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
   System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
   System.out.println(System.currentTimeMillis() + " starting highlight with " + parameter);
   if (parameter instanceof PickResult) {
     PickResult result = (PickResult) parameter;
     result.setFirstIntersectOnly(true);
     PickIntersection pi = result.getIntersection(0);
     // indices of the picked quad
     // Indices are set to vertex indices, as this is not an Index
     // Geometry object
     // => easy to find the plate index from this
     int[] idx = pi.getPrimitiveCoordinateIndices();
     int plateNum = idx[0] / 4;
     Plate p = plates[plateNum];
     Point3d point3d = pi.getPointCoordinates();
     point3d.get(point);
     FloatBuffer coords =
         (FloatBuffer) ((NioQuadArray) (shape.getGeometry())).getCoordRefBuffer().getBuffer();
     for (int i = 0; i < idx.length; ++i) {
       coords.position(idx[i] * 3);
       coords.get(vertices[i]);
     }
     int d1 = 0, d2 = 0;
     if (p instanceof PlateX) {
       d1 = 1;
       d2 = 2;
     } else if (p instanceof PlateY) {
       d1 = 0;
       d2 = 2;
     } else if (p instanceof PlateZ) {
       d1 = 0;
       d2 = 1;
     }
     int u =
         (int)
             Math.floor(
                 (point[d1] - vertices[0][d1])
                     * (p.max1 - p.min1)
                     / (vertices[3][d1] - vertices[0][d1]));
     int v =
         (int)
             Math.floor(
                 (point[d2] - vertices[0][d2])
                     * (p.max2 - p.min2)
                     / (vertices[1][d2] - vertices[0][d2]));
     int quadIdx = v * (p.max1 - p.min1) + u;
     u += p.min1;
     v += p.min2;
     System.out.println(
         (on ? "" : "de") + "selected quad " + quadIdx + " in plate " + plateNum + " in group ");
     System.out.println("Grid positions for the quad (x,y,z) indices:");
     int[] pos = p.getXYZGridIndices(u, v);
     System.out.println("vertex1 = (" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")");
     pos = p.getXYZGridIndices(u, v + 1);
     System.out.println("vertex2 = (" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")");
     pos = p.getXYZGridIndices(u + 1, v + 1);
     System.out.println("vertex3 = (" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")");
     pos = p.getXYZGridIndices(u + 1, v);
     System.out.println("vertex4 = (" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")");
     float[] color = getColorForOrder(groupIdx, on ? 1 : 0);
     for (int i = 0; i < idx.length; ++i) {
       colors.position(idx[i] * 3);
       colors.put(color);
     }
     toggleSelectedQuad(on, new SelectionQuad(p, u, v, groupIdx));
     // Use event propagation, but don't call
     // setAppearanceForHighlight
     FloatBuffer tmp = colors;
     colors = null;
     colors = tmp;
   }
   System.out.println(System.currentTimeMillis() + " end of highlight");
 }