Пример #1
0
 /** i_square,resultの有効期間は、この関数の終了までです。 */
 protected void onUpdateHandler(NyARSquare i_square, NyARDoubleMatrix44 result) {
   try {
     NyARGLUtil.toCameraViewRH(result, 1.0, this.gltransmat);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void display(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   synchronized (this._camera) {
     try {
       gl.glClear(
           GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
       NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0);
       this._nyar.update(this._camera);
       if (this._nyar.isExistMarker(this.ids[0])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       if (this._nyar.isExistMarker(this.ids[1])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       Thread.sleep(1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Пример #3
0
 static int atoi(String a) {
   int i = 0;
   try {
     i = Integer.parseInt(a);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return i;
 }
Пример #4
0
 // エントリポイント
 public static void main(String[] args) {
   try {
     NyARParam cparam = NyARParam.createFromARParamFile(new FileInputStream(PARAM_FILE));
     cparam.changeScreenSize(SCREEN_X, SCREEN_Y);
     new SingleARMarker(cparam);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return;
 }
 public static void main(String[] args) {
   try {
     NyARMarkerSystemConfig config =
         new NyARMarkerSystemConfig(new FileInputStream(PARAM_FILE), SCREEN_X, SCREEN_Y);
     new SimpleLiteMStandard(config);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return;
 }
Пример #6
0
 /** カメラデバイスからのコールバック */
 public void onUpdateBuffer(Buffer i_buffer) {
   try {
     synchronized (this._sync_object) {
       this._cap_image.setBuffer(i_buffer);
       // フレームワークに画像を転送
       this._processor.detectMarker(this._cap_image);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
    public MainFrame() {
      try {
        mainPanel.setLayout(new BorderLayout());
        mainPanel.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
        mainPanel.add(outputContainer, java.awt.BorderLayout.CENTER);
        outputArea.setLineWrap(true);
        outputContainer.add(new JScrollPane(outputArea), java.awt.BorderLayout.CENTER);
        outputContainer.setBorder(new javax.swing.border.TitledBorder("Results"));

        this.getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);

        java.util.ArrayList<JButton> btns = new java.util.ArrayList<JButton>();
        {
          JPanel westPanel = new JPanel(new GridLayout(0, 1, 0, 10));
          westPanel.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
          JPanel opsPanel = new JPanel(new GridLayout(6, 1));
          opsPanel.setBorder(new javax.swing.border.TitledBorder("Operations"));

          for (Action action : operations) {
            JPanel p = new JPanel(new BorderLayout());
            JButton jb = new JButton(action);
            btns.add(jb);
            p.add(jb, BorderLayout.NORTH);
            opsPanel.add(p);
          }

          westPanel.add(opsPanel);
          controlContainer.add(westPanel, BorderLayout.CENTER);
        }

        this.getContentPane().add(controlContainer, BorderLayout.WEST);
        this.pack();

        Dimension dim = btns.get(0).getSize();
        for (JButton btn : btns) {
          btn.setPreferredSize(dim);
        }

        java.awt.Dimension prefSize = this.getPreferredSize();
        prefSize.setSize(prefSize.getWidth(), 1.1 * prefSize.getHeight());
        this.setSize(prefSize);

        java.awt.Dimension parentSize;
        java.awt.Point parentLocation = new java.awt.Point(0, 0);
        parentSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
        int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
        this.setLocation(x, y);
        this.setResizable(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
Пример #8
0
  public void run() {
    try {
      while (running) {

        try {
          Thread.sleep(framerate);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        repaint();
        updateObjects();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #9
0
  /* The following routine loads Iterated Function System codes.  Note
   * that loadifs() only reads the very first set of IFS codes in the
   * file and ignores the name label in the file entirely.
   */
  void loadifs() {
    BufferedReader in = null;
    try {
      in =
          new BufferedReader(
              new InputStreamReader(
                  Thread.currentThread().getContextClassLoader().getResourceAsStream(ifsfile)));
    } catch (Exception e) {
      System.out.println(e.toString());
    }
    ;

    transitions = 0;

    String line = null;

    // throw away first line
    try {
      line = in.readLine();
    } catch (IOException e) {
      System.out.println(e.toString());
    }

    try {
      while ((line = in.readLine()) != null) {
        String[] tokens = line.trim().split("\\s+"); // Tokens separated by "whitespace"
        if (tokens[0].equals("}")) return;
        try {
          rotate_scale_xx[transitions] = Double.parseDouble(tokens[0]);
          rotate_scale_xy[transitions] = Double.parseDouble(tokens[1]);
          rotate_scale_yx[transitions] = Double.parseDouble(tokens[2]);
          rotate_scale_yy[transitions] = Double.parseDouble(tokens[3]);
          trans_x[transitions] = Double.parseDouble(tokens[4]);
          trans_y[transitions] = Double.parseDouble(tokens[5]);
          prob[transitions] = Double.parseDouble(tokens[6]);
        } catch (NumberFormatException ex) {
          System.out.println("Not a double ");
          System.out.println(ex);
        }
        transitions++;
      }
    } catch (IOException e) {
      System.out.println(e.toString());
    }
  }
Пример #10
0
  public void display(GLAutoDrawable drawable) {
    if (!_cap_image.hasBuffer()) {
      return;
    }
    // 背景を書く
    this._gl.glClear(
        GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
    // OnEnter,OnUpdateの間に、transmatに初回行列がストアされる実行されることを防ぎます。
    try {
      NyARGLDrawUtil.drawBackGround(this._gl, this._cap_image, 1.0);
      synchronized (this._sync_object) {
        if (this._processor.current_code < 0) {

        } else {
          // Projection transformation.
          this._gl.glMatrixMode(GL.GL_PROJECTION);
          this._gl.glLoadMatrixd(_camera_projection, 0);
          this._gl.glMatrixMode(GL.GL_MODELVIEW);
          // Viewing transformation.
          this._gl.glLoadIdentity();
          this._gl.glLoadMatrixd(this._processor.gltransmat, 0);
          // All other lighting and geometry goes here.
          this._gl.glPushMatrix();
          this._gl.glDisable(GL.GL_LIGHTING);

          // マーカのXZ平面をマーカの左上、表示開始位置を10cm上空へ。
          // くるーんくるん
          Date d = new Date();
          float r = (d.getTime() / 50) % 360;
          this._gl.glRotatef(r, 0f, 0f, 1.0f);
          this._gl.glTranslatef(-70f, 0f, 1.0f);
          this._gl.glRotatef(90, 1.0f, 0f, 0f);
          NyARGLDrawUtil.drawText("MarkerId:" + this._processor.current_code, 1f);
          this._gl.glPopMatrix();
          Thread.sleep(1); // タスク実行権限を一旦渡す
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return;
  }
Пример #11
0
  public static void main(String[] args) {
    int type = USE_NEWT;
    String tstName = "demos.es2.perftst.PerfVBOLoad"; // default

    for (int i = args.length - 1; i >= 0; i--) {
      if (args[i].equals("-awt")) {
        type |= USE_AWT;
      }
      if (args[i].equals("-test") && i + 1 < args.length) {
        tstName = args[i + 1];
      }
    }

    try {
      PerfModule pmod = (PerfModule) Class.forName(tstName).newInstance();
      new Perftst().run(type, pmod);
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
Пример #12
0
  /**
   * Reads an image from an archived file and return it as ByteBuffer object.
   *
   * @author Mike Butler, Kiet Le
   */
  private ByteBuffer readImage(String filename, Dimension dim) {
    if (dim == null) dim = new Dimension(0, 0);
    ByteBuffer bytes = null;
    try {
      DataInputStream dis =
          new DataInputStream(getClass().getClassLoader().getResourceAsStream(filename));
      dim.width = dis.readInt();
      dim.height = dis.readInt();
      System.out.println("Creating buffer, width: " + dim.width + " height: " + dim.height);
      // byte[] buf = new byte[3 * dim.height * dim.width];
      bytes = BufferUtil.newByteBuffer(3 * dim.width * dim.height);
      for (int i = 0; i < bytes.capacity(); i++) {
        bytes.put(dis.readByte());
      }
      dis.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    bytes.rewind();
    return bytes;
  }
Пример #13
0
  public void init(GLAutoDrawable drawable) {
    this._gl = drawable.getGL();
    this._gl.glEnable(GL.GL_DEPTH_TEST);
    NyARGLDrawUtil.setFontStyle("SansSerif", Font.BOLD, 36);
    NyARGLDrawUtil.setFontColor(Color.RED);
    this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    // NyARToolkitの準備
    try {
      // プロセッサの準備
      this._processor =
          new MarkerProcessor(this._ar_param, this._cap_image.getBufferType(), this._glnya);
      this._processor.setARCodeTable(_code_table, 16, 80.0);

      // カメラパラメータの計算
      NyARGLUtil.toCameraFrustumRH(this._ar_param, 1.0, 10, 10000, this._camera_projection);
      // キャプチャ開始
      this._capture.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    this._animator = new Animator(drawable);
    this._animator.start();
    return;
  }