コード例 #1
0
ファイル: WorldObject.java プロジェクト: celison/3D-OpenGL
  public void setupBuffers(GL4 gl, int[] vbo, int index) {
    this.vbo = vbo;
    this.index = index;

    Vertex3D[] vertices = myShape.getVertices();
    int[] indices = myShape.getIndices();

    float[] fvalues = new float[indices.length * 3];
    float[] tvalues = new float[indices.length * 2];
    float[] nvalues = new float[indices.length * 3];

    for (int i = 0; i < indices.length; i++) {
      fvalues[i * 3] = (float) (vertices[indices[i]]).getX();
      fvalues[i * 3 + 1] = (float) (vertices[indices[i]]).getY();
      fvalues[i * 3 + 2] = (float) (vertices[indices[i]]).getZ();
      tvalues[i * 2] = (float) (vertices[indices[i]]).getS();
      tvalues[i * 2 + 1] = (float) (vertices[indices[i]]).getT();
      nvalues[i * 3] = (float) (vertices[indices[i]]).getNormalX();
      nvalues[i * 3 + 1] = (float) (vertices[indices[i]]).getNormalY();
      nvalues[i * 3 + 2] = (float) (vertices[indices[i]]).getNormalZ();
    }

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index++]);
    FloatBuffer vertBuf = FloatBuffer.wrap(fvalues);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, vertBuf.limit() * 4, vertBuf, GL.GL_STATIC_DRAW);

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index++]);
    FloatBuffer texBuf = FloatBuffer.wrap(tvalues);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, texBuf.limit() * 4, texBuf, GL.GL_STATIC_DRAW);

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index++]);
    FloatBuffer norBuf = FloatBuffer.wrap(nvalues);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, norBuf.limit() * 4, norBuf, GL.GL_STATIC_DRAW);
  }
コード例 #2
0
ファイル: GlCylinder.java プロジェクト: caomw/nehe-android
  private void generateData() {

    slicesBuffers = new FloatBuffer[slices];
    if (normals) {
      normalsBuffers = new FloatBuffer[slices];
    }
    if (texCoords) {
      texCoordsBuffers = new FloatBuffer[slices];
    }

    for (int i = 0; i < slices; i++) {

      float[] vertexCoords = new float[3 * 2 * (stacks + 1)];
      float[] normalCoords = new float[3 * 2 * (stacks + 1)];
      float[] textureCoords = new float[2 * 2 * (stacks + 1)];

      double alpha0 = (i + 0) * (2 * Math.PI) / slices;
      double alpha1 = (i + 1) * (2 * Math.PI) / slices;

      float cosAlpha0 = (float) Math.cos(alpha0);
      float sinAlpha0 = (float) Math.sin(alpha0);
      float cosAlpha1 = (float) Math.cos(alpha1);
      float sinAlpha1 = (float) Math.sin(alpha1);

      for (int j = 0; j <= stacks; j++) {

        float z = height * (0.5f - ((float) j) / stacks);
        float r = top + (base - top) * j / stacks;

        Utils.setXYZ(vertexCoords, 3 * 2 * j, r * cosAlpha1, r * sinAlpha1, z);

        Utils.setXYZ(vertexCoords, 3 * 2 * j + 3, r * cosAlpha0, r * sinAlpha0, z);

        if (normals) {
          Utils.setXYZn(
              normalCoords, 3 * 2 * j, height * cosAlpha1, height * sinAlpha1, base - top);
          Utils.setXYZn(
              normalCoords, 3 * 2 * j + 3, height * cosAlpha0, height * sinAlpha0, base - top);
        }

        if (texCoords) {
          textureCoords[2 * 2 * j + 0] = ((float) (i + 1)) / slices;
          textureCoords[2 * 2 * j + 1] = ((float) (j + 0)) / stacks;

          textureCoords[2 * 2 * j + 2] = ((float) (i + 0)) / slices;
          textureCoords[2 * 2 * j + 3] = ((float) (j + 0)) / stacks;
        }
      }

      slicesBuffers[i] = FloatBuffer.wrap(vertexCoords);

      if (normals) {
        normalsBuffers[i] = FloatBuffer.wrap(normalCoords);
      }

      if (texCoords) {
        texCoordsBuffers[i] = FloatBuffer.wrap(textureCoords);
      }
    }
  }
コード例 #3
0
  public void draw(GLAutoDrawable drawable) {

    // TODO Auto-generated method stub
    GL4 gl = drawable.getGL().getGL4();
    // rotate the sun around its Y axis
    this.getTranslation().setToIdentity();
    this.getTranslation().translate(0.5, 0, 1);

    count += 0.0001;
    // reverse the rotation direction
    if (count > 5) count = -5;
    FloatBuffer verBuf, texBuf, norBuf;

    norBuf = FloatBuffer.wrap(this.getNormals(this.getVertex_positions()));
    verBuf = FloatBuffer.wrap(this.getVertex_positions());
    texBuf = FloatBuffer.wrap(texel_positions);
    // active the first buffer and load data for vertices into shader
    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, points_vbo[0]);
    gl.glBufferData(GL4.GL_ARRAY_BUFFER, verBuf.limit() * 4, verBuf, GL4.GL_STATIC_DRAW);
    gl.glVertexAttribPointer(0, 3, GL4.GL_FLOAT, false, 0, 0);
    gl.glEnableVertexAttribArray(0);
    // active the second buffer and load texture coord into shader
    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, points_vbo[1]);
    gl.glBufferData(GL4.GL_ARRAY_BUFFER, norBuf.limit() * 4, norBuf, GL4.GL_STATIC_DRAW);
    gl.glVertexAttribPointer(1, 3, GL4.GL_FLOAT, false, 0, 0);
    gl.glEnableVertexAttribArray(1);

    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, points_vbo[2]);
    gl.glBufferData(GL4.GL_ARRAY_BUFFER, texBuf.limit() * 4, texBuf, GL4.GL_STATIC_DRAW);
    gl.glVertexAttribPointer(2, 2, GL4.GL_FLOAT, false, 0, 0);
    gl.glEnableVertexAttribArray(2);

    gl.glDrawArrays(GL4.GL_TRIANGLES, 0, 72);
  }
コード例 #4
0
ファイル: BaseDataBuffer.java プロジェクト: joachimdb/nd4j
 @Override
 public FloatBuffer asNioFloat() {
   if (wrappedBuffer == null) {
     if (offset() == 0) {
       return FloatBuffer.wrap(floatData);
     } else return (FloatBuffer) FloatBuffer.wrap(floatData).position(offset());
   }
   if (offset() == 0) {
     return wrappedBuffer.asFloatBuffer();
   } else return (FloatBuffer) wrappedBuffer.asFloatBuffer().position(offset());
 }
コード例 #5
0
 public Buffer getNormals() {
   float v[] = new float[normals.size()];
   for (int i = 0; i < normals.size(); i++) {
     v[i] = (normals.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
コード例 #6
0
ファイル: BaseDataBuffer.java プロジェクト: evaleen/nd4j
 @Override
 public FloatBuffer asNioFloat() {
   if (wrappedBuffer == null) {
     return FloatBuffer.wrap(floatData);
   }
   return wrappedBuffer.asFloatBuffer();
 }
コード例 #7
0
  private void createVBO(GL gl, GLU glu, JoglFrameBufferObject theFBO) {
    final int w = theFBO.getPixelWidth();
    final int h = theFBO.getPixelHeight();

    // setup buffer object for 4 floats per item
    int[] tmp = new int[1];
    gl.glGenBuffers(1, tmp, 0);
    _myVBO = tmp[0];
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, _myVBO);
    gl.glBufferData(
        GL.GL_ARRAY_BUFFER, w * h * 4 * BufferUtil.SIZEOF_FLOAT, null, GL.GL_STREAM_COPY);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

    /* create float buffer for pointsizes */
    float[] myValues = new float[w * h * 3];

    for (int i = 0; i < myValues.length; i += 3) {
      myValues[i + 0] = (i / 3) % w; // x
      myValues[i + 1] = (i / 3) / w; // y
      myValues[i + 2] = (float) Math.random() * 1; // pointsize
    }

    gl.glGenBuffers(1, tmp, 0);
    _myIBO = tmp[0];
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, _myIBO);
    gl.glBufferData(
        GL.GL_ARRAY_BUFFER,
        w * h * 3 * BufferUtil.SIZEOF_FLOAT,
        FloatBuffer.wrap(myValues),
        GL.GL_STATIC_DRAW);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

    /* check for errors */
    JoglUtil.printGLError(gl, glu, getClass().getSimpleName() + ".createVBO()", true);
  }
コード例 #8
0
 public Buffer getVertices() {
   float v[] = new float[points.size()];
   for (int i = 0; i < points.size(); i++) {
     v[i] = (points.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
コード例 #9
0
ファイル: Renderer.java プロジェクト: harishd10/cloud-track
  void takeSnapShot(String op) {
    float[] buf = new float[width * height * 4];
    FloatBuffer fbuf = FloatBuffer.wrap(buf);
    gl.glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_FLOAT, fbuf);
    try {
      FileOutputStream os = new FileOutputStream(op);
      BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
      int ct = 0;

      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          int rr = (int) (buf[ct] * 255);
          int gg = (int) (buf[ct + 1] * 255);
          int bb = (int) (buf[ct + 2] * 255);
          int aa = (int) (buf[ct + 3] * 255);
          int rgba = 0;
          rgba |= (bb & 0xff);
          rgba |= ((gg & 0xff) << 8);
          rgba |= ((rr & 0xff) << 16);
          rgba |= ((aa & 0xff) << 24);
          img.setRGB(j, (height - i - 1), rgba);
          ct += 4;
        }
      }
      ImageIO.write(img, "png", os);
      os.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #10
0
 public Buffer getUV() {
   float v[] = new float[uv.size()];
   for (int i = 0; i < uv.size(); i++) {
     v[i] = (uv.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
コード例 #11
0
ファイル: Bug735Inv0AppletAWT.java プロジェクト: metsci/jogl
  private void setup(GL2ES2 gl) {
    if (60 < TARGET_FPS) {
      // Disables vsync
      gl.setSwapInterval(0);
    }
    glu = new GLU();

    vertShader =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            LandscapeES2.class,
            "shader",
            "shader/bin",
            "landscape",
            true);
    fragShader =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            LandscapeES2.class,
            "shader",
            "shader/bin",
            "landscape",
            true);
    vertShader.defaultShaderCustomization(gl, true, true);
    fragShader.defaultShaderCustomization(gl, true, true);
    shaderProg = new ShaderProgram();
    shaderProg.add(gl, vertShader, System.err);
    shaderProg.add(gl, fragShader, System.err);

    shaderState = new ShaderState();
    shaderState.attachShaderProgram(gl, shaderProg, true);

    resolution =
        new GLUniformData("iResolution", 3, FloatBuffer.wrap(new float[] {width, height, 0}));
    shaderState.ownUniform(resolution);
    shaderState.uniform(gl, resolution);

    time = new GLUniformData("iGlobalTime", 0.0f);
    shaderState.ownUniform(time);

    vertices =
        GLArrayDataServer.createGLSL("inVertex", 2, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    vertices.putf(-1.0f);
    vertices.putf(-1.0f);
    vertices.putf(+1.0f);
    vertices.putf(-1.0f);
    vertices.putf(-1.0f);
    vertices.putf(+1.0f);
    vertices.putf(+1.0f);
    vertices.putf(+1.0f);
    vertices.seal(gl, true);
    shaderState.ownAttribute(vertices, true);
    shaderState.useProgram(gl, false);

    doneSetup = true;
  }
コード例 #12
0
ファイル: MyCube.java プロジェクト: kvan1/Demo6DoF
  public MyCube(float[] pos, float[] dcm) {
    // Set initial camera coordinates
    set_pos(pos);
    set_dcm(dcm);

    // Vertex buffer for renderer
    VertexBuf = new FloatBuffer[6];
    for (int i = 0; i < 6; i++) VertexBuf[i] = FloatBuffer.wrap(cCoords[i]);
  }
コード例 #13
0
ファイル: BasicFloat.java プロジェクト: susotajuraj/jdk8u-jdk
  public static void test() {
    testAllocate();
    test(0, FloatBuffer.allocate(7 * 1024), false);
    test(0, FloatBuffer.wrap(new float[7 * 1024], 0, 7 * 1024), false);
    test(new float[1024]);

    callReset(FloatBuffer.allocate(10));

    putBuffer();
  }
コード例 #14
0
ファイル: PerlinNoise.java プロジェクト: hubdaba/cs5625Final
  public static void init(GL2 gl) throws OpenGLException {
    // permutation setup
    permutation = new int[256];
    for (int i = 0; i < 256; i++) {
      permutation[i] = i;
    }

    Random rand = new Random();
    for (int i = 255; i > 0; i--) {
      int index = rand.nextInt(i + 1);
      int tmp = permutation[i];
      permutation[i] = permutation[index];
      permutation[index] = tmp;
    }
    byte[] permutationBytes = new byte[256 * 4];
    int count = 0;
    for (int i = 0; i < 255; i++) {
      permutationBytes[count++] = (byte) (0xFF & permutation[i]);
      permutationBytes[count++] = (byte) (0xFF & permutation[i]);
      permutationBytes[count++] = (byte) (0xFF & permutation[i]);
      permutationBytes[count++] = (byte) (0xFF & permutation[i]);
    }
    ByteBuffer permBuff = ByteBuffer.wrap(permutationBytes);

    permutationTexture = new Texture2D(gl, Format.RGBA, Datatype.INT8, 256, 1, permBuff);
    permutationTexture.setWrapModeOne(gl, WrapMode.REPEAT, TextureWrapCoordinate.S);
    permutationTexture.setWrapModeOne(gl, WrapMode.CLAMP, TextureWrapCoordinate.T);
    permutationTexture.enableInterpolation(gl, false);

    // gradient setup
    gradients =
        new int[][] {
          {1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1}, {1, 0, -1},
          {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}, {1, 1, 0}, {0, -1, 1},
          {-1, 1, 0}, {0, -1, -1}
        };

    float[] gradientBytes = new float[16 * 4];
    for (int i = 0; i < 16; i++) {
      gradientBytes[i * 4] = gradients[i][0];
      gradientBytes[i * 4 + 1] = gradients[i][1];
      gradientBytes[i * 4 + 2] = gradients[i][2];
      gradientBytes[i * 4 + 3] = 1;
    }

    FloatBuffer gradBuff = FloatBuffer.wrap(gradientBytes);

    gradientTexture = new Texture2D(gl, Format.RGBA, Datatype.FLOAT16, 16, 1, gradBuff);
    // gradientTexture.setWrapModeOne(gl, WrapMode.REPEAT, TextureWrapCoordinate.S);
    // gradientTexture.setWrapModeOne(gl, WrapMode.CLAMP, TextureWrapCoordinate.T);
    gradientTexture.setWrapModeAll(gl, WrapMode.REPEAT);
    gradientTexture.enableInterpolation(gl, false);
  }
コード例 #15
0
  void LoadTextures(final GL gl) {
    // There is only one texture needed here--we'll set up a basic
    // checkerboard--which is used to modulate the diffuse channel in the
    // fragment shader.
    final int[] handle = new int[1];
    gl.glGenTextures(1, handle, 0);

    // Basic OpenGL texture state setup
    gl.glBindTexture(GL.GL_TEXTURE_2D, handle[0]);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP_SGIS, GL.GL_TRUE);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);

    // Fill in the texture map.
    final int RES = 512;
    final float[] data = new float[RES * RES * 4];
    int dp = 0;
    for (int i = 0; i < RES; ++i)
      for (int j = 0; j < RES; ++j) {
        if ((i / 32 + j / 32) % 2 != 0) {
          data[dp++] = .7f;
          data[dp++] = .7f;
          data[dp++] = .7f;
        } else {
          data[dp++] = .1f;
          data[dp++] = .1f;
          data[dp++] = .1f;
        }
        data[dp++] = 1.0f;
      }

    gl.glTexImage2D(
        GL.GL_TEXTURE_2D,
        0,
        GL.GL_RGBA,
        RES,
        RES,
        0,
        GL.GL_RGBA,
        GL.GL_FLOAT,
        FloatBuffer.wrap(data));

    // Tell Cg which texture handle should be associated with the sampler2D
    // parameter to the fragment shader.
    CgGL.cgGLSetTextureParameter(
        CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap"), handle[0]);
  }
コード例 #16
0
  /**
   * A utility method to load vertex data into an OpenGL "vertex array object" (VAO) for efficient
   * rendering. The VAO stores several "vertex buffer objects" (VBOs) that contain the vertex
   * attribute data.
   *
   * @param data reference to the vertex data to be loaded into a VAO
   */
  private void initArrayBuffer(GLVertexData data) {

    // Make a vertex array object (VAO) for this vertex data
    // and store a reference to it
    GLVertexArrayObject vao = new GLVertexArrayObject(gl, data.getElements().size() + 1);
    data.setVAO(vao);

    // Bind (activate) the VAO for the vertex data in OpenGL.
    // The subsequent OpenGL operations on VBOs will be recorded (stored)
    // in the VAO.
    vao.bind();

    // Store all vertex attributes in vertex buffer objects (VBOs)
    ListIterator<VertexData.VertexElement> itr = data.getElements().listIterator(0);
    data.getVAO().rewindVBO();
    while (itr.hasNext()) {
      VertexData.VertexElement e = itr.next();

      // Bind the vertex buffer object (VBO)
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, data.getVAO().getNextVBO());
      // Upload vertex data
      gl.glBufferData(
          GL3.GL_ARRAY_BUFFER,
          e.getData().length * 4,
          FloatBuffer.wrap(e.getData()),
          GL3.GL_DYNAMIC_DRAW);
    }

    // Bind the default vertex buffer objects
    gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);

    // Store the vertex data indices into the last vertex buffer
    gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, data.getVAO().getNextVBO());
    gl.glBufferData(
        GL3.GL_ELEMENT_ARRAY_BUFFER,
        data.getIndices().length * 4,
        IntBuffer.wrap(data.getIndices()),
        GL3.GL_DYNAMIC_DRAW);

    // Bind the default vertex array object. This "deactivates" the VAO
    // of the vertex data
    gl.glBindVertexArray(0);
  }
コード例 #17
0
ファイル: AllTests.java プロジェクト: Crysty-Yui/ice
  public static TestIntfPrx allTests(Ice.Communicator communicator, PrintWriter out) {
    out.print("testing stringToProxy... ");
    out.flush();
    String ref = "test:default -p 12010";
    Ice.ObjectPrx obj = communicator.stringToProxy(ref);
    test(obj != null);
    out.println("ok");

    out.print("testing checked cast... ");
    out.flush();
    TestIntfPrx t = TestIntfPrxHelper.checkedCast(obj);
    test(t != null);
    test(t.equals(obj));
    out.println("ok");

    out.print("testing custom sequences... ");
    out.flush();

    {
      //
      // Create a sequence of C instances, where elements 1..n simply point to element 0.
      //
      C[] seq = new C[5];
      seq[0] = new C();
      for (int i = 1; i < seq.length; i++) {
        seq[i] = seq[0];
      }

      //
      // Invoke each operation and verify that the returned sequences have the same
      // structure as the original.
      //
      CSeqHolder seqH = new CSeqHolder();
      C[] seqR = t.opCSeq(seq, seqH);
      test(seqR.length == seq.length);
      test(seqH.value.length == seq.length);
      for (int i = 1; i < seq.length; i++) {
        test(seqR[i] != null);
        test(seqR[i] == seqR[0]);
        test(seqR[i] == seqH.value[i]);
      }

      ArrayList<C> arr = new ArrayList<C>(Arrays.asList(seq));
      CArrayHolder arrH = new CArrayHolder();
      List<C> arrR = t.opCArray(arr, arrH);
      test(arrR.size() == arr.size());
      test(arrH.value.size() == arr.size());
      for (int i = 1; i < arr.size(); i++) {
        test(arrR.get(i) != null);
        test(arrR.get(i) == arrR.get(0));
        test(arrR.get(i) == arrH.value.get(i));
      }

      LinkedList<C> list = new LinkedList<C>(Arrays.asList(seq));
      CListHolder listH = new CListHolder();
      List<C> listR = t.opCList(list, listH);
      test(listR.size() == list.size());
      test(listH.value.size() == list.size());
      for (int i = 1; i < list.size(); i++) {
        test(listR.get(i) != null);
        test(listR.get(i) == listR.get(0));
        test(listR.get(i) == listH.value.get(i));
      }
    }

    {
      final Boolean[] seq = {
        Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE
      };
      ArrayList<Boolean> list = new ArrayList<Boolean>(Arrays.asList(seq));
      BoolSeqHolder listH = new BoolSeqHolder();
      List<Boolean> listR = t.opBoolSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final Byte[] seq = {
        new Byte((byte) 0), new Byte((byte) 1), new Byte((byte) 2), new Byte((byte) 3)
      };
      ArrayList<Byte> list = new ArrayList<Byte>(Arrays.asList(seq));
      ByteSeqHolder listH = new ByteSeqHolder();
      List<Byte> listR = t.opByteSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final Short[] seq = {
        new Short((short) 0), new Short((short) 1), new Short((short) 2), new Short((short) 3)
      };
      ArrayList<Short> list = new ArrayList<Short>(Arrays.asList(seq));
      ShortSeqHolder listH = new ShortSeqHolder();
      List<Short> listR = t.opShortSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final Integer[] seq = {new Integer(0), new Integer(1), new Integer(2), new Integer(3)};
      ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(seq));
      IntSeqHolder listH = new IntSeqHolder();
      List<Integer> listR = t.opIntSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final Long[] seq = {new Long(0), new Long(1), new Long(2), new Long(3)};
      ArrayList<Long> list = new ArrayList<Long>(Arrays.asList(seq));
      LongSeqHolder listH = new LongSeqHolder();
      List<Long> listR = t.opLongSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final Float[] seq = {new Float(0), new Float(1), new Float(2), new Float(3)};
      ArrayList<Float> list = new ArrayList<Float>(Arrays.asList(seq));
      FloatSeqHolder listH = new FloatSeqHolder();
      List<Float> listR = t.opFloatSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final Double[] seq = {new Double(0), new Double(1), new Double(2), new Double(3)};
      ArrayList<Double> list = new ArrayList<Double>(Arrays.asList(seq));
      DoubleSeqHolder listH = new DoubleSeqHolder();
      List<Double> listR = t.opDoubleSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final String[] seq = {"0", "1", "2", "3", "4"};
      ArrayList<String> list = new ArrayList<String>(Arrays.asList(seq));
      StringSeqHolder listH = new StringSeqHolder();
      List<String> listR = t.opStringSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      final E[] seq = {E.E1, E.E2, E.E3};
      ArrayList<E> list = new ArrayList<E>(Arrays.asList(seq));
      ESeqHolder listH = new ESeqHolder();
      List<E> listR = t.opESeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      S[] seq = new S[5];
      for (int i = 0; i < seq.length; i++) {
        seq[i] = new S();
        seq[i].en = E.values()[i % 3];
      }
      ArrayList<S> list = new ArrayList<S>(Arrays.asList(seq));
      SSeqHolder listH = new SSeqHolder();
      List<S> listR = t.opSSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      ArrayList<Map<Integer, String>> list = new ArrayList<Map<Integer, String>>();
      for (int i = 0; i < 5; i++) {
        Map<Integer, String> m = new HashMap<Integer, String>();
        for (int j = 0; j < 4; j++) {
          m.put(j, "" + j);
        }
        list.add(m);
      }
      DSeqHolder listH = new DSeqHolder();
      List<Map<Integer, String>> listR = t.opDSeq(list, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(list));
    }

    {
      List<List<String>> seq = new LinkedList<List<String>>();
      for (int i = 0; i < 5; i++) {
        final String[] arr = {"0", "1", "2", "3", "4"};
        seq.add(new ArrayList<String>(Arrays.asList(arr)));
      }
      StringSeqSeqHolder listH = new StringSeqSeqHolder();
      List<List<String>> listR = t.opStringSeqSeq(seq, listH);
      test(listH.value.equals(listR));
      test(listH.value.equals(seq));
    }

    {
      final byte[] fullSeq = new byte[] {0, 1, 2, 3, 4, 5, 6, 7};
      final byte[] usedSeq = new byte[] {2, 3, 4, 5};

      ByteBuffer buffer = ByteBuffer.wrap(fullSeq, 2, 4);
      Ice.Holder<ByteBuffer> bufferH = new Ice.Holder<ByteBuffer>();
      ByteBuffer bufferR = t.opByteBufferSeq(buffer, bufferH);

      byte[] arr = new byte[bufferH.value.limit()];
      bufferH.value.get(arr, 0, bufferH.value.limit());
      test(Arrays.equals(arr, usedSeq));
      arr = new byte[bufferR.limit()];
      bufferR.get(arr, 0, bufferR.limit());
      test(Arrays.equals(arr, usedSeq));
    }

    {
      final short[] fullSeq = new short[] {0, 1, 2, 3, 4, 5, 6, 7};
      final short[] usedSeq = new short[] {2, 3, 4, 5};

      ShortBuffer buffer = ShortBuffer.wrap(fullSeq, 2, 4);
      Ice.Holder<ShortBuffer> bufferH = new Ice.Holder<ShortBuffer>();
      ShortBuffer bufferR = t.opShortBufferSeq(buffer, bufferH);

      short[] arr = new short[bufferH.value.limit()];
      bufferH.value.get(arr, 0, bufferH.value.limit());
      test(Arrays.equals(arr, usedSeq));
      arr = new short[bufferR.limit()];
      bufferR.get(arr, 0, bufferR.limit());
      test(Arrays.equals(arr, usedSeq));
    }

    {
      final int[] fullSeq = new int[] {0, 1, 2, 3, 4, 5, 6, 7};
      final int[] usedSeq = new int[] {2, 3, 4, 5};

      IntBuffer buffer = IntBuffer.wrap(fullSeq, 2, 4);
      Ice.Holder<IntBuffer> bufferH = new Ice.Holder<IntBuffer>();
      IntBuffer bufferR = t.opIntBufferSeq(buffer, bufferH);

      int[] arr = new int[bufferH.value.limit()];
      bufferH.value.get(arr, 0, bufferH.value.limit());
      test(Arrays.equals(arr, usedSeq));
      arr = new int[bufferR.limit()];
      bufferR.get(arr, 0, bufferR.limit());
      test(Arrays.equals(arr, usedSeq));
    }

    {
      final long[] fullSeq = new long[] {0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L};
      final long[] usedSeq = new long[] {2L, 3L, 4L, 5L};

      LongBuffer buffer = LongBuffer.wrap(fullSeq, 2, 4);
      Ice.Holder<LongBuffer> bufferH = new Ice.Holder<LongBuffer>();
      LongBuffer bufferR = t.opLongBufferSeq(buffer, bufferH);

      long[] arr = new long[bufferH.value.limit()];
      bufferH.value.get(arr, 0, bufferH.value.limit());
      test(Arrays.equals(arr, usedSeq));
      arr = new long[bufferR.limit()];
      bufferR.get(arr, 0, bufferR.limit());
      test(Arrays.equals(arr, usedSeq));
    }

    {
      final float[] fullSeq = new float[] {0, 1, 2, 3, 4, 5, 6, 7};
      final float[] usedSeq = new float[] {2, 3, 4, 5};

      FloatBuffer buffer = FloatBuffer.wrap(fullSeq, 2, 4);
      Ice.Holder<FloatBuffer> bufferH = new Ice.Holder<FloatBuffer>();
      FloatBuffer bufferR = t.opFloatBufferSeq(buffer, bufferH);

      float[] arr = new float[bufferH.value.limit()];
      bufferH.value.get(arr, 0, bufferH.value.limit());
      test(Arrays.equals(arr, usedSeq));
      arr = new float[bufferR.limit()];
      bufferR.get(arr, 0, bufferR.limit());
      test(Arrays.equals(arr, usedSeq));
    }

    {
      final double[] fullSeq = new double[] {0, 1, 2, 3, 4, 5, 6, 7};
      final double[] usedSeq = new double[] {2, 3, 4, 5};

      DoubleBuffer buffer = DoubleBuffer.wrap(fullSeq, 2, 4);
      Ice.Holder<DoubleBuffer> bufferH = new Ice.Holder<DoubleBuffer>();
      DoubleBuffer bufferR = t.opDoubleBufferSeq(buffer, bufferH);

      double[] arr = new double[bufferH.value.limit()];
      bufferH.value.get(arr, 0, bufferH.value.limit());
      test(Arrays.equals(arr, usedSeq));
      arr = new double[bufferR.limit()];
      bufferR.get(arr, 0, bufferR.limit());
      test(Arrays.equals(arr, usedSeq));
    }

    out.println("ok");

    return t;
  }
コード例 #18
0
ファイル: BasicFloat.java プロジェクト: susotajuraj/jdk8u-jdk
  public static void test(int level, final FloatBuffer b, boolean direct) {

    show(level, b);

    if (direct != b.isDirect()) fail("Wrong direction", b);

    // Gets and puts

    relPut(b);
    relGet(b);
    absGet(b);
    bulkGet(b);

    absPut(b);
    relGet(b);
    absGet(b);
    bulkGet(b);

    bulkPutArray(b);
    relGet(b);

    bulkPutBuffer(b);
    relGet(b);

    // Compact

    relPut(b);
    b.position(13);
    b.compact();
    b.flip();
    relGet(b, 13);

    // Exceptions

    relPut(b);
    b.limit(b.capacity() / 2);
    b.position(b.limit());

    tryCatch(
        b,
        BufferUnderflowException.class,
        new Runnable() {
          public void run() {
            b.get();
          }
        });

    tryCatch(
        b,
        BufferOverflowException.class,
        new Runnable() {
          public void run() {
            b.put((float) 42);
          }
        });

    // The index must be non-negative and lesss than the buffer's limit.
    tryCatch(
        b,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            b.get(b.limit());
          }
        });
    tryCatch(
        b,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            b.get(-1);
          }
        });

    tryCatch(
        b,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            b.put(b.limit(), (float) 42);
          }
        });

    tryCatch(
        b,
        InvalidMarkException.class,
        new Runnable() {
          public void run() {
            b.position(0);
            b.mark();
            b.compact();
            b.reset();
          }
        });

    // Values

    b.clear();
    b.put((float) 0);
    b.put((float) -1);
    b.put((float) 1);
    b.put(Float.MAX_VALUE);
    b.put(Float.MIN_VALUE);

    b.put(-Float.MAX_VALUE);
    b.put(-Float.MIN_VALUE);
    b.put(Float.NEGATIVE_INFINITY);
    b.put(Float.POSITIVE_INFINITY);
    b.put(Float.NaN);
    b.put(0.91697687f); // Changes value if incorrectly swapped

    float v;
    b.flip();
    ck(b, b.get(), 0);
    ck(b, b.get(), (float) -1);
    ck(b, b.get(), 1);
    ck(b, b.get(), Float.MAX_VALUE);
    ck(b, b.get(), Float.MIN_VALUE);

    ck(b, b.get(), -Float.MAX_VALUE);
    ck(b, b.get(), -Float.MIN_VALUE);
    ck(b, b.get(), Float.NEGATIVE_INFINITY);
    ck(b, b.get(), Float.POSITIVE_INFINITY);
    if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
      fail(b, (long) Float.NaN, (long) v);
    ck(b, b.get(), 0.91697687f);

    // Comparison
    b.rewind();
    FloatBuffer b2 = FloatBuffer.allocate(b.capacity());
    b2.put(b);
    b2.flip();
    b.position(2);
    b2.position(2);
    if (!b.equals(b2)) {
      for (int i = 2; i < b.limit(); i++) {
        float x = b.get(i);
        float y = b2.get(i);
        if (x != y || Float.compare(x, y) != 0) out.println("[" + i + "] " + x + " != " + y);
      }
      fail("Identical buffers not equal", b, b2);
    }
    if (b.compareTo(b2) != 0) fail("Comparison to identical buffer != 0", b, b2);

    b.limit(b.limit() + 1);
    b.position(b.limit() - 1);
    b.put((float) 99);
    b.rewind();
    b2.rewind();
    if (b.equals(b2)) fail("Non-identical buffers equal", b, b2);
    if (b.compareTo(b2) <= 0) fail("Comparison to shorter buffer <= 0", b, b2);
    b.limit(b.limit() - 1);

    b.put(2, (float) 42);
    if (b.equals(b2)) fail("Non-identical buffers equal", b, b2);
    if (b.compareTo(b2) <= 0) fail("Comparison to lesser buffer <= 0", b, b2);

    // Check equals and compareTo with interesting values
    for (float x : VALUES) {
      FloatBuffer xb = FloatBuffer.wrap(new float[] {x});
      if (xb.compareTo(xb) != 0) {
        fail("compareTo not reflexive", xb, xb, x, x);
      }
      if (!xb.equals(xb)) {
        fail("equals not reflexive", xb, xb, x, x);
      }
      for (float y : VALUES) {
        FloatBuffer yb = FloatBuffer.wrap(new float[] {y});
        if (xb.compareTo(yb) != -yb.compareTo(xb)) {
          fail("compareTo not anti-symmetric", xb, yb, x, y);
        }
        if ((xb.compareTo(yb) == 0) != xb.equals(yb)) {
          fail("compareTo inconsistent with equals", xb, yb, x, y);
        }
        if (xb.compareTo(yb) != Float.compare(x, y)) {

          if (x == 0.0 && y == 0.0) continue;

          fail("Incorrect results for FloatBuffer.compareTo", xb, yb, x, y);
        }
        if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) {
          fail("Incorrect results for FloatBuffer.equals", xb, yb, x, y);
        }
      }
    }

    // Sub, dup

    relPut(b);
    relGet(b.duplicate());
    b.position(13);
    relGet(b.duplicate(), 13);
    relGet(b.duplicate().slice(), 13);
    relGet(b.slice(), 13);
    relGet(b.slice().duplicate(), 13);

    // Slice

    b.position(5);
    FloatBuffer sb = b.slice();
    checkSlice(b, sb);
    b.position(0);
    FloatBuffer sb2 = sb.slice();
    checkSlice(sb, sb2);

    if (!sb.equals(sb2)) fail("Sliced slices do not match", sb, sb2);
    if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
      fail("Array offsets do not match: " + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);

    // Read-only views

    b.rewind();
    final FloatBuffer rb = b.asReadOnlyBuffer();
    if (!b.equals(rb)) fail("Buffer not equal to read-only view", b, rb);
    show(level + 1, rb);

    tryCatch(
        b,
        ReadOnlyBufferException.class,
        new Runnable() {
          public void run() {
            relPut(rb);
          }
        });

    tryCatch(
        b,
        ReadOnlyBufferException.class,
        new Runnable() {
          public void run() {
            absPut(rb);
          }
        });

    tryCatch(
        b,
        ReadOnlyBufferException.class,
        new Runnable() {
          public void run() {
            bulkPutArray(rb);
          }
        });

    tryCatch(
        b,
        ReadOnlyBufferException.class,
        new Runnable() {
          public void run() {
            bulkPutBuffer(rb);
          }
        });

    // put(FloatBuffer) should not change source position
    final FloatBuffer src = FloatBuffer.allocate(1);
    tryCatch(
        b,
        ReadOnlyBufferException.class,
        new Runnable() {
          public void run() {
            rb.put(src);
          }
        });
    ck(src, src.position(), 0);

    tryCatch(
        b,
        ReadOnlyBufferException.class,
        new Runnable() {
          public void run() {
            rb.compact();
          }
        });

    if (rb.getClass().getName().startsWith("java.nio.Heap")) {

      tryCatch(
          b,
          ReadOnlyBufferException.class,
          new Runnable() {
            public void run() {
              rb.array();
            }
          });

      tryCatch(
          b,
          ReadOnlyBufferException.class,
          new Runnable() {
            public void run() {
              rb.arrayOffset();
            }
          });

      if (rb.hasArray()) fail("Read-only heap buffer's backing array is accessible", rb);
    }

    // Bulk puts from read-only buffers

    b.clear();
    rb.rewind();
    b.put(rb);

    relPut(b); // Required by testViews
  }
コード例 #19
0
ファイル: BasicFloat.java プロジェクト: susotajuraj/jdk8u-jdk
  public static void test(final float[] ba) {
    int offset = 47;
    int length = 900;
    final FloatBuffer b = FloatBuffer.wrap(ba, offset, length);
    show(0, b);
    ck(b, b.capacity(), ba.length);
    ck(b, b.position(), offset);
    ck(b, b.limit(), offset + length);

    // The offset must be non-negative and no larger than <array.length>.
    tryCatch(
        ba,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            FloatBuffer.wrap(ba, -1, ba.length);
          }
        });
    tryCatch(
        ba,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            FloatBuffer.wrap(ba, ba.length + 1, ba.length);
          }
        });
    tryCatch(
        ba,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            FloatBuffer.wrap(ba, 0, -1);
          }
        });
    tryCatch(
        ba,
        IndexOutOfBoundsException.class,
        new Runnable() {
          public void run() {
            FloatBuffer.wrap(ba, 0, ba.length + 1);
          }
        });

    // A NullPointerException will be thrown if the array is null.
    tryCatch(
        ba,
        NullPointerException.class,
        new Runnable() {
          public void run() {
            FloatBuffer.wrap((float[]) null, 0, 5);
          }
        });
    tryCatch(
        ba,
        NullPointerException.class,
        new Runnable() {
          public void run() {
            FloatBuffer.wrap((float[]) null);
          }
        });
  }
コード例 #20
0
ファイル: BasicFloat.java プロジェクト: susotajuraj/jdk8u-jdk
 private static void tryCatch(float[] t, Class<?> ex, Runnable thunk) {
   tryCatch(FloatBuffer.wrap(t), ex, thunk);
 }
コード例 #21
0
ファイル: GUI.java プロジェクト: BNHeadrick/AFM-GUI
  public void setup() {
    minim = new Minim(this);
    size(winWidth, winHeight, OPENGL);
    background(bGround);
    sm = new SceneManager(minim);
    rulesChecker = new RulesChecker();

    controlP5 = new ControlP5(this);
    // ruleChoiceList = controlP5.addDropdownList("ruleChoiceList",850,100,100,100);
    // customize(ruleChoiceList);
    selectedRule = 0;
    selectedCamera = 0;
    gl = ((PGraphicsOpenGL) g).gl;

    picker = new Picker(this);
    oscP5 = new OscP5(this, port);
    // TODO(sanjeet): Change the address
    interfaceAddr = new NetAddress("127.0.0.1", port);

    noStroke();
    lines = loadStrings("fileFriedrich.txt"); // Hardcoded input file name
    String[] tokens = split(lines[0], " ");
    if (tokens.length != 1) {
      println("Incorrect file format for number of cameras");
      return;
    }
    int numOfCams = PApplet.parseInt(tokens[0]);
    for (int i = 1; i < numOfCams + 1; i++) {

      tokens = split(lines[i], " ");
      float[] matrix = new float[16];
      for (int j = 0; j < tokens.length; j++) {
        matrix[j] = PApplet.parseFloat(tokens[j]);
      }

      cameras.add(new Cam(FloatBuffer.wrap(matrix))); // add all the cameras
    }

    tokens = split(lines[1 + numOfCams], " ");
    if (tokens.length != 1) {
      println("Incorrect file format for number of characters");
      return;
    }
    int numOfChars = PApplet.parseInt(tokens[0]);
    for (int i = 2 + numOfCams; i < lines.length; i++) {
      tokens = split(lines[i], " ");
      float[] matrix = new float[16];
      for (int j = 0; j < tokens.length; j++) {
        matrix[j] = PApplet.parseFloat(tokens[j]);
      }

      characters.add(new Character(FloatBuffer.wrap(matrix))); // add all the characters
    }

    characters.get(0).col = color(255, 255, 0);
    characters.get(1).col = color(255, 0, 255);

    timeline = new Timeline(sm);
    // add initial tick to the begining of the timeline
    timeline.addTick(cameras.get(0));

    debug = new Debug(controlP5);

    // title, start, end, initVal, xpos, ypos, width, height
    // controlP5.addSlider("Timeline", 0,120,0,100,winHeight-50,winWidth-200,30);

  }
コード例 #22
0
ファイル: TestIndex.java プロジェクト: heptagon/druid
  public static Index convertMMapToIndex(MMappedIndex mmappedIndex) {
    Indexed<String> dimsIndexed = mmappedIndex.getAvailableDimensions();
    String[] dimensions = new String[dimsIndexed.size()];
    for (int i = 0; i < dimsIndexed.size(); ++i) {
      dimensions[i] = dimsIndexed.get(i);
    }

    Indexed<String> metricsIndexed = mmappedIndex.getAvailableMetrics();
    String[] metrics = new String[metricsIndexed.size()];
    for (int i = 0; i < metricsIndexed.size(); ++i) {
      metrics[i] = metricsIndexed.get(i);
    }

    IndexedLongs timeBuf = mmappedIndex.getReadOnlyTimestamps();
    long[] timestamps = new long[timeBuf.size()];
    timeBuf.fill(0, timestamps);
    Closeables.closeQuietly(timeBuf);

    Map<String, MetricHolder> metricVals = Maps.newLinkedHashMap();
    for (String metric : metrics) {
      MetricHolder holder = mmappedIndex.getMetricHolder(metric);
      switch (holder.getType()) {
        case FLOAT:
          IndexedFloats mmappedFloats = holder.getFloatType();
          float[] metricValsArray = new float[mmappedFloats.size()];
          mmappedFloats.fill(0, metricValsArray);
          Closeables.closeQuietly(mmappedFloats);

          metricVals.put(
              metric,
              MetricHolder.floatMetric(
                  metric,
                  CompressedFloatsIndexedSupplier.fromFloatBuffer(
                      FloatBuffer.wrap(metricValsArray), ByteOrder.nativeOrder())));
          break;
        case COMPLEX:
          Indexed complexObjects = holder.getComplexType();
          Object[] vals = new Object[complexObjects.size()];
          for (int i = 0; i < complexObjects.size(); ++i) {
            vals[i] = complexObjects.get(i);
          }

          final ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(holder.getTypeName());
          if (serde == null) {
            throw new ISE("Unknown type[%s]", holder.getTypeName());
          }

          metricVals.put(
              metric,
              MetricHolder.complexMetric(
                  metric,
                  holder.getTypeName(),
                  new ArrayIndexed(vals, serde.getObjectStrategy().getClazz())));
          break;
      }
    }

    Map<String, Map<String, Integer>> dimIdLookup = Maps.newHashMap();
    Map<String, String[]> reverseDimLookup = Maps.newHashMap();
    Map<String, ImmutableConciseSet[]> invertedIndexesMap = Maps.newHashMap();
    Map<String, DimensionColumn> dimensionColumns = Maps.newHashMap();

    for (String dimension : dimensions) {
      final Indexed<String> dimValueLookup = mmappedIndex.getDimValueLookup(dimension);
      String[] values = new String[dimValueLookup.size()];
      for (int i = 0; i < dimValueLookup.size(); ++i) {
        values[i] = dimValueLookup.get(i);
      }

      Map<String, Integer> lookupMap = Maps.newHashMapWithExpectedSize(dimValueLookup.size());
      for (int i = 0; i < values.length; i++) {
        lookupMap.put(values[i], i);
      }

      ImmutableConciseSet[] invertedIndexes = new ImmutableConciseSet[values.length];
      final Indexed<String> dimValuesIndexed = mmappedIndex.getDimValueLookup(dimension);
      for (int i = 0; i < dimValuesIndexed.size(); ++i) {
        invertedIndexes[i] = mmappedIndex.getInvertedIndex(dimension, dimValuesIndexed.get(i));
      }

      int[] dimValues = new int[timestamps.length];
      Map<List<Integer>, Integer> rowGroupings = Maps.newHashMap();
      final Indexed<? extends IndexedInts> dimColumn = mmappedIndex.getDimColumn(dimension);
      for (int i = 0; i < dimColumn.size(); ++i) {
        int[] expansionValue = Indexedids.arrayFromIndexedInts(dimColumn.get(i));
        Integer value = rowGroupings.get(Ints.asList(expansionValue));
        if (value == null) {
          value = rowGroupings.size();
          rowGroupings.put(Ints.asList(expansionValue), value);
        }
        dimValues[i] = value;
      }

      int[][] expansionValues = new int[rowGroupings.size()][];
      for (Map.Entry<List<Integer>, Integer> entry : rowGroupings.entrySet()) {
        expansionValues[entry.getValue()] = Ints.toArray(entry.getKey());
      }

      dimIdLookup.put(dimension, lookupMap);
      reverseDimLookup.put(dimension, values);
      invertedIndexesMap.put(dimension, invertedIndexes);
      dimensionColumns.put(dimension, new DimensionColumn(expansionValues, dimValues));
    }

    return new Index(
        dimensions,
        metrics,
        mmappedIndex.getDataInterval(),
        timestamps,
        metricVals,
        dimIdLookup,
        reverseDimLookup,
        invertedIndexesMap,
        dimensionColumns);
  }
コード例 #23
0
ファイル: GLRender.java プロジェクト: zhihaoliang/book
  @Override
  public void onDrawFrame(GL10 gl) {
    ByteBuffer indices = ByteBuffer.wrap(new byte[] {1, 0, 2, 3});
    FloatBuffer vertices = FloatBuffer.wrap(new float[12]);
    FloatBuffer texcoords = FloatBuffer.wrap(new float[8]);

    /* Clear The Screen And The Depth Buffer */
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    /* Set pointers to vertices and texcoords */
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texcoords);

    /* Enable vertices and texcoords arrays */
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    /* Move Into The Screen 5 Units */
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -2.0f);

    /* Select Our Logo Texture */
    gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);

    /* Start Drawing A Textured Quad */
    texcoords.clear();
    texcoords.put(0.0f);
    texcoords.put(-roll + 3.0f);
    texcoords.put(3.0f);
    texcoords.put(-roll + 3.0f);
    texcoords.put(3.0f);
    texcoords.put(-roll + 0.0f);
    texcoords.put(0.0f);
    texcoords.put(-roll + 0.0f);
    vertices.clear();
    vertices.put(-1.1f);
    vertices.put(-1.1f);
    vertices.put(0.0f);
    vertices.put(1.1f);
    vertices.put(-1.1f);
    vertices.put(0.0f);
    vertices.put(1.1f);
    vertices.put(1.1f);
    vertices.put(0.0f);
    vertices.put(-1.1f);
    vertices.put(1.1f);
    vertices.put(0.0f);
    /* Draw one textured plane using two stripped triangles */
    gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices);

    /* Enable Blending */
    gl.glEnable(GL10.GL_BLEND);
    /* Disable Depth Testing */
    gl.glDisable(GL10.GL_DEPTH_TEST);

    /* Is masking enables */
    if (masking) {
      gl.glBlendFunc(GL10.GL_DST_COLOR, GL10.GL_ZERO);
    }

    /* Draw the second scene? */
    if (scene) {
      /* Translate Into The Screen One Unit */
      gl.glTranslatef(0.0f, 0.0f, -1.0f);
      /* Rotate On The Z Axis 360 Degrees */
      gl.glRotatef(roll * 360, 0.0f, 0.0f, 1.0f);

      if (masking) {
        /* Select The Second Mask Texture */
        gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]);

        /* Start Drawing A Textured Quad */
        texcoords.clear();
        texcoords.put(0.0f);
        texcoords.put(1.0f);
        texcoords.put(1.0f);
        texcoords.put(1.0f);
        texcoords.put(1.0f);
        texcoords.put(0.0f);
        texcoords.put(0.0f);
        texcoords.put(0.0f);

        vertices.clear();
        vertices.put(-1.1f);
        vertices.put(-1.1f);
        vertices.put(0.0f);
        vertices.put(1.1f);
        vertices.put(-1.1f);
        vertices.put(0.0f);
        vertices.put(1.1f);
        vertices.put(1.1f);
        vertices.put(0.0f);
        vertices.put(-1.1f);
        vertices.put(1.1f);
        vertices.put(0.0f);

        /* Draw one textured plane using two stripped triangles */
        gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices);
      }

      /* Copy Image 2 Color To The Screen */
      gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
      /* Select The Second Image Texture */
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]);

      /* Start Drawing A Textured Quad */
      texcoords.clear();
      texcoords.put(0.0f);
      texcoords.put(1.0f);
      texcoords.put(1.0f);
      texcoords.put(1.0f);
      texcoords.put(1.0f);
      texcoords.put(0.0f);
      texcoords.put(0.0f);
      texcoords.put(0.0f);

      vertices.clear();
      vertices.put(-1.1f);
      vertices.put(-1.1f);
      vertices.put(0.0f);
      vertices.put(1.1f);
      vertices.put(-1.1f);
      vertices.put(0.0f);
      vertices.put(1.1f);
      vertices.put(1.1f);
      vertices.put(0.0f);
      vertices.put(-1.1f);
      vertices.put(1.1f);
      vertices.put(0.0f);

      /* Draw one textured plane using two stripped triangles */
      gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices);
    } else {
      if (masking) {
        /* Select The First Mask Texture */
        gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]);

        /* Start Drawing A Textured Quad */
        texcoords.clear();
        texcoords.put(roll + 0.0f);
        texcoords.put(4.0f);
        texcoords.put(roll + 4.0f);
        texcoords.put(4.0f);
        texcoords.put(roll + 4.0f);
        texcoords.put(0.0f);
        texcoords.put(roll + 0.0f);
        texcoords.put(0.0f);
        vertices.clear();
        vertices.put(-1.1f);
        vertices.put(-1.1f);
        vertices.put(0.0f);
        vertices.put(1.1f);
        vertices.put(-1.1f);
        vertices.put(0.0f);
        vertices.put(1.1f);
        vertices.put(1.1f);
        vertices.put(0.0f);
        vertices.put(-1.1f);
        vertices.put(1.1f);
        vertices.put(0.0f);

        /* Draw one textured plane using two stripped triangles */
        gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices);
      }

      /* Copy Image 1 Color To The Screen */
      gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
      /* Select The First Image Texture */
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]);

      /* Start Drawing A Textured Quad */
      texcoords.clear();
      texcoords.put(roll + 0.0f);
      texcoords.put(4.0f);
      texcoords.put(roll + 4.0f);
      texcoords.put(4.0f);
      texcoords.put(roll + 4.0f);
      texcoords.put(0.0f);
      texcoords.put(roll + 0.0f);
      texcoords.put(0.0f);
      vertices.clear();
      vertices.put(-1.1f);
      vertices.put(-1.1f);
      vertices.put(0.0f);
      vertices.put(1.1f);
      vertices.put(-1.1f);
      vertices.put(0.0f);
      vertices.put(1.1f);
      vertices.put(1.1f);
      vertices.put(0.0f);
      vertices.put(-1.1f);
      vertices.put(1.1f);
      vertices.put(0.0f);

      /* Draw one textured plane using two stripped triangles */
      gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices);
    }

    gl.glEnable(GL10.GL_DEPTH_TEST); /* Enable Depth Testing */
    gl.glDisable(GL10.GL_BLEND); /* Disable Blending     */

    /* Disable texcoords and vertices arrays */
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    /* Draw it to the screen */
    gl.glFinish();

    /* Increase Our Texture Roll Variable */
    roll += 0.002f;
    if (roll > 1.0f) {
      roll -= 1.0f;
    }

    xrot += 0.3f; /* X Axis Rotation */
    yrot += 0.2f; /* Y Axis Rotation */
    zrot += 0.4f; /* Z Axis Rotation */
  }
コード例 #24
0
ファイル: GUI.java プロジェクト: BNHeadrick/AFM-GUI
  /*
   * Method used to receive messages from Kinnect or MSB in the future
   */
  public void oscEvent(OscMessage theOscMessage) {

    // Friedrich added this select camera event
    if (theOscMessage != null && theOscMessage.checkAddrPattern("/selectActorByName")) {
      println("select Actor!");
      String myNewCamera = theOscMessage.get(0).stringValue();

      println(myNewCamera);

      // RAFACTOR THIS PART; MAYBE MAKE A DYNAMIC ENUM IN THE CAM DATA STRUCTURE?
      if (myNewCamera.compareTo("Camera1") == 0) selectedCamera = 0;
      if (myNewCamera.compareTo("Camera2") == 0) selectedCamera = 1;
      if (myNewCamera.compareTo("Camera3") == 0) selectedCamera = 2;
      if (myNewCamera.compareTo("Camera4") == 0) selectedCamera = 3;

      // Friedrich changed the coloring code here
      for (int i = 0; i < cameras.size(); i++) {
        cameras.get(i).changeToDefaultColor();
        cameras.get(i).isSelected = false;
      }

      cameras.get(selectedCamera).isSelected = true;
      cameras.get(selectedCamera).changeToSelectedColor();
      //    println(""  + timeline.getTickArr());
      timeline.getActiveTick().setCam(cameras.get(selectedCamera));
    }

    // Friedrich changed the AddressPattern for the submitted package - we can ignore the first
    // string part of the message
    if (theOscMessage != null
        && theOscMessage.checkAddrPattern("/setPropertyForSelected/string/matrix4f")) {
      float[] matrix = new float[16];

      // we do not need to use this in Processing, but let's pop it off the stack anyway
      String propertyName = theOscMessage.get(0).stringValue();

      for (int i = 1; i <= 16; i++) {
        if (i > 12 && i <= 15) {
          matrix[i - 1] = theOscMessage.get(i).floatValue() * 10;
        } else {
          matrix[i - 1] = theOscMessage.get(i).floatValue();
        }
      }

      matrix[2] = -matrix[2];
      matrix[8] = -matrix[8];

      // Friedrich - manual scaling adjustments
      matrix[12] = (700 - matrix[12]) * 2.0f;
      matrix[14] = matrix[14] * 1.5f;
      // println (matrix[12]);

      FloatBuffer fb = FloatBuffer.allocate(16);
      fb = FloatBuffer.wrap(matrix);
      // TODO(sanjeet): Currently using only camera 5
      // Change this variable based on the data received from OSC
      //    int selectedCamera = 5;
      cameras.get(selectedCamera).modelViewMatrix = fb;
    }

    // receive the currentFrame from kinect
    // this is where the playhead is on the timeline
    // currentFrame is global
    if (theOscMessage != null && theOscMessage.checkAddrPattern("/setPlayheadFrame/int")) {
      currentFrame = theOscMessage.get(0).intValue();
      println("Current Frame: " + currentFrame);
    }
  }