Exemplo n.º 1
0
 /*
  * (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");
 }