コード例 #1
0
ファイル: Canvas3D.java プロジェクト: ningyu18/datawarrior
  protected void calculateScreenCoordinates() {
    // Calculate coordinates
    minZ = Double.MAX_VALUE;
    maxZ = -minZ;
    synchronized (shapes) {
      for (Shape shape : shapes) {
        if (shape == null || shape.realCoordinates == null) continue;
        shape.screenCoordinates = visualizer3D.screenPosition(shape.realCoordinates);

        if (shape.screenCoordinates != null) {
          minZ = Math.min(minZ, shape.screenCoordinates.z);
          maxZ = Math.max(maxZ, shape.screenCoordinates.z);
        }
      }
    }
    minZ -= visualizer3D.scalePixelsPerAngstrom * 2;
    maxZ += visualizer3D.scalePixelsPerAngstrom * 4;
  }
コード例 #2
0
ファイル: Canvas3D.java プロジェクト: ningyu18/datawarrior
  /**
   * Paint the Canvas in an Image
   *
   * @param g
   * @param buffer
   * @param width
   * @param height
   */
  public final void paint(Graphics2D g, int width, int height) {
    if (highQuality) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    }
    background = Color.black;
    String stereo = getStereoMode();

    if ("parallel".equals(stereo)) {
      final double d = 3 * Math.PI / 180;
      visualizer3D.rotate(-d, 0);
      visualizer3D.setScreenDimension(width / 2, height);
      g.setClip(0, 0, width / 2, height);
      paintShapes(g);
      visualizer3D.rotate(d, 0);

      visualizer3D.rotate(d, 0);
      visualizer3D.setScreenDimension(width / 2, height);
      g.setClip(width / 2, 0, width / 2, height);
      g.translate(width / 2, 0);
      paintShapes(g);
      g.translate(-width / 2, 0);
      g.setClip(null);
      visualizer3D.rotate(-d, 0);

    } else if ("interlaced".equals(stereo)) {
      background = new Color(100, 100, 150);
      // Point p = getLocationOnScreen();
      boolean even = true; // p.x%2==0;
      // Creates buffer
      BufferedImage buf = new BufferedImage(width * 2, height, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = (Graphics2D) buf.getGraphics();
      final double d = 1.8 * Math.PI / 180;
      final double t = -100000000;
      visualizer3D.getCenterOfRotation().z += t;
      visualizer3D.rotate(-d, 0);
      visualizer3D.getCenterOfRotation().z -= t;
      visualizer3D.setScreenDimension(width, height);
      paintShapes(g2);
      visualizer3D.getCenterOfRotation().z += t;
      visualizer3D.rotate(d, 0);
      visualizer3D.getCenterOfRotation().z -= t;
      visualizer3D.getCenterOfRotation().z += t;
      visualizer3D.rotate(d, 0);
      visualizer3D.getCenterOfRotation().z -= t;
      visualizer3D.setScreenDimension(width, height);
      g2.translate(width, 0);
      paintShapes(g2);
      g2.translate(-width, 0);
      visualizer3D.getCenterOfRotation().z += t;
      visualizer3D.rotate(-d, 0);
      visualizer3D.getCenterOfRotation().z -= t;
      g2.dispose();

      // Interlace in g
      int width2 = 2 * width;
      // int[] rgb = (int[]) buf.getRaster().getDataElements(0, 0, width2, height, new
      // int[width2*height]);
      DataBufferInt b = (DataBufferInt) buf.getRaster().getDataBuffer();
      int[] rgb = b.getData();
      // System.out.println(b.);
      // int[] rgb = (int[]) .;
      // buf.getRGB(0, 0, width2, height, rgb, 0, width2);
      final int dev = 5;
      for (int x = 0; x + 1 < width - dev; x += 2) {
        {
          int i = x, j = x;
          for (int y = 0; y < height; y++) {
            rgb[i] = ((rgb[j] & 0xFEFEFEFE) >> 1) + ((rgb[j + 1] & 0xFEFEFEFE) >> 1);
            i += width2;
            j += width2;
          }
        }
        {
          int i = x + 1, j = width + x + dev;
          for (int y = 0; y < height; y++) {
            rgb[i] = ((rgb[j] & 0xFEFEFEFE) >> 1) + ((rgb[j + 1] & 0xFEFEFEFE) >> 1);
            i += width2;
            j += width2;
          }
        }
      }
      // Arrays.fill(rgb, 0xFF);
      // buf.getRaster().setDataElements(0, 0, width2, height, rgb);
      // buf.setRGB(0, 0, width2, height, rgb, 0, width2);

      g.drawImage(buf, even ? 0 : 1, 0, width, height, 0, 0, width - (even ? 0 : 1), height, this);
    } else {
      visualizer3D.setScreenDimension(width, height);
      paintShapes(g);
    }
  }