com.jogamp.opengl.GL2

Here are the examples of the java api com.jogamp.opengl.GL2 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

340 Examples 7

19 Source : ImageDisplay.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Utility method to check for GL errors. Prints stacked up errors up to a limit.
 *    @param g the GL context
 *    @param glu the GLU used to obtain the error strings
 *    @param msg an error message to log to e.g., show the context
 */
private void checkGLError(GL2 g, String msg) {
    int error = g.glGetError();
    int nerrors = 3;
    while ((error != GL.GL_NO_ERROR) && (nerrors-- != 0)) {
        StackTraceElement[] trace = Thread.currentThread().getStackTrace();
        if (trace.length > 1) {
            String clreplacedName = trace[2].getClreplacedName();
            String methodName = trace[2].getMethodName();
            int lineNumber = trace[2].getLineNumber();
            log.warning("GL error number " + error + " " + glu.gluErrorString(error) + " : " + msg + " at " + clreplacedName + "." + methodName + " (line " + lineNumber + ")");
        } else {
            log.warning("GL error number " + error + " " + glu.gluErrorString(error) + " : " + msg);
        }
        error = g.glGetError();
    }
}

19 Source : RoboQuadSocialSonar.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    if (!isFilterEnabled()) {
        return;
    // if(isRelaxed) return;
    }
    GL2 gl = drawable.getGL().getGL2();
    // draw bar for speechiness signal, part in grey and part above threshold in red
    gl.glPushMatrix();
    // 1/2 for threshold
    float f = ((speechinessFilter.getValue() / (2 * responseModulationThreshold)));
    int sx = chip.getSizeX();
    if (f <= .5f) {
        gl.glColor3d(0.7, 0.7, 0.7);
        gl.glRectf(2, 2, 2 + (f * sx), 3);
    } else {
        gl.glColor3d(0.7, 0.7, 0.7);
        gl.glRectf(2, 2, sx / 2, 3);
        // red
        gl.glColor3d(1, 0, 0);
        gl.glRectf(sx / 2, 2, f * sx, 3);
    }
    gl.glPopMatrix();
// show state of Goalie (arm shows its own state)
// gl.glColor3d(1, 1, 1);
// gl.glPushMatrix();
// int font=GLUT.BITMAP_HELVETICA_12;
// gl.glRasterPos3f(1, 1, 0);
// annotate the cluster with the arm state, e.g. relaxed or learning
// String stats=String.format("%s rateFilter=%.2f speechinessFilter=%.2f isSomeoneThere=%s responseFraction=%.1f",
// overallState.toString(),rateModulationFilter.getValue(),speechinessFilter.getValue(),isSomeoneThere(),getResponseFraction());
// chip.getCanvas().getGlut().glutBitmapString(font, stats);
// gl.glPopMatrix();
}

19 Source : PendulumTracker.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    if (pendulum != null) {
        pendulum.draw(gl);
    }
}

19 Source : FoosballCNNBallTracker.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    AEChipRenderer renderer = (AEChipRenderer) chip.getRenderer();
    GL2 gl = drawable.getGL().getGL2();
    if (apsDvsNet != null && apsDvsNet.getNetname() != null) {
        MultilineAnnotationTextRenderer.resetToYPositionPixels(chip.getSizeY() * 1f);
        MultilineAnnotationTextRenderer.setScale(.3f);
        MultilineAnnotationTextRenderer.renderMultilineString(apsDvsNet.getNetname());
        if (measurePerformance && performanceString != null) /*&& !performanceString.equals(lastPerformanceString)*/
        {
            MultilineAnnotationTextRenderer.renderMultilineString(performanceString);
            lastPerformanceString = performanceString;
        }
    }
    nbTarget = 0;
    xTarget = 0;
    yTarget = 0;
    gl.glColor3f(0, 0, 1);
    gl.glPointSize(8);
    gl.glBegin(GL.GL_POINTS);
    for (int i = 0; i < 90; i++) {
        for (int j = 0; j < 120; j++) {
            if (resHeatMap[0][i][j] == 1) {
                nbTarget++;
                xTarget += j;
                yTarget += i;
                gl.glVertex2f(j * 2, i * 2);
            }
        }
    }
    gl.glEnd();
    gl.glLineWidth(4);
    gl.glColor3f(1, 0, 0);
    gl.glBegin(GL.GL_LINE_LOOP);
    gl.glVertex2f(xTarget - 5, yTarget - 5);
    gl.glVertex2f(xTarget - 5, yTarget + 5);
    gl.glVertex2f(xTarget + 5, yTarget + 5);
    gl.glVertex2f(xTarget + 5, yTarget - 5);
    gl.glEnd();
// output is heat map
// renderer.resetAnnotationFrame(0.0f);
// float[] output = apsDvsNet.getOutputLayer().getActivations();
}

19 Source : MeanEventLocationTrackerStdDevReference.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Called after events are rendered. Here we just render something to show the mean location.
 *
 * @param drawable the open GL surface.
 */
@Override
public void annotate(GLAutoDrawable drawable) {
    // called after events are rendered
    // get the openGL context
    GL2 gl = drawable.getGL().getGL2();
    // choose RGB color and alpha<1 so we can see through the square
    gl.glColor4f(1.0f, 1.0f, 0.0f, 0.1f);
    gl.glBegin(GL.GL_LINE_LOOP);
    gl.glVertex2f(xmean - xstd, ymean - ystd);
    gl.glVertex2f(xmean + xstd, ymean - ystd);
    gl.glVertex2f(xmean + xstd, ymean + ystd);
    gl.glVertex2f(xmean - xstd, ymean + ystd);
    gl.glVertex2f(xmean - xstd, ymean - ystd);
    gl.glEnd();
// gl.glRectf(xmean - xstd, ymean - ystd, xmean + xstd, ymean + ystd); // draw a little rectangle over the mean location
}

19 Source : MeanEventLocationTrackerLiveTutorial.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Called after events are rendered. Here we just render something to show the mean location.
 *
 * @param drawable the open GL surface.
 */
@Override
public void annotate(GLAutoDrawable drawable) {
    // called after events are rendered
    // get the openGL context
    GL2 gl = drawable.getGL().getGL2();
    // choose RGB color and alpha<1 so we can see through the square
    gl.glColor4f(1, 1, 0, .3f);
    // draw a little rectangle over the mean location
    gl.glRectf(xmean - xstd, ymean - ystd, xmean + xstd, ymean + ystd);
}

19 Source : PigTracker.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glColor3f(0, 1, 1);
    gl.glLineWidth(5f);
    gl.glBegin(GL.GL_LINES);
    for (int n = 0; n < numberOfLinesInUse; n++) {
        gl.glVertex2d((sx2 * (lsx[n] + 1)), (sy2 * (lsy[n] + 1)));
        gl.glVertex2d((sx2 * (lex[n] + 1)), (sy2 * (ley[n] + 1)));
    // g.drawLine((int) (sx2 * (gsx + 1) * 4), (int) (sy2 * (gsy + 1) * 4), (int) (sx2 * (gex + 1) * 4), (int) (sy2 * (gey + 1) * 4));
    }
    gl.glEnd();
    // show matrix
    MultilineAnnotationTextRenderer.resetToYPositionPixels(chip.getSizeY());
    StringBuilder sb = new StringBuilder("PigTracker\n");
    sb.append(String.format("# lines = %d\nm=\n", numberOfLinesInUse));
    sb.append(String.format("%6.3f %6.3f %6.3f\n", cm[0], cm[1], cm[2]));
    sb.append(String.format("%6.3f %6.3f %6.3f\n", cm[3], cm[4], cm[5]));
    sb.append(String.format("%6.3f %6.3f %6.3f\n", cm[6], cm[7], cm[8]));
    MultilineAnnotationTextRenderer.renderMultilineString(sb.toString());
}

19 Source : CochleaGenderClassifier.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    // gl.glColor3f(1,1,1);
    // gl.glRasterPos3f(10,10,0);
    // glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18,gender.toString());
    // replacedle
    replacedleRenderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
    switch(gender) {
        case Male:
            replacedleRenderer.setColor(Color.RED);
            break;
        case Female:
            replacedleRenderer.setColor(Color.GREEN);
            break;
        case Unknown:
            replacedleRenderer.setColor(Color.WHITE);
            break;
    }
    replacedleRenderer.draw(String.format("%10s %-6.2f", gender.toString(), SCALE * genderDotProduct), replacedleArea.width / 2, replacedleArea.height / 2);
    replacedleRenderer.endRendering();
    gl.glPushMatrix();
    gl.glLoadIdenreplacedy();
    gl.glTranslatef(drawable.getSurfaceWidth() / 2, drawable.getSurfaceHeight() / 2, 0);
    switch(gender) {
        case Male:
            gl.glColor3f(1, 0, 0);
            break;
        case Female:
            gl.glColor3f(0, 1, 0);
            break;
        case Unknown:
            gl.glColor3f(1, 1, 1);
            break;
    }
    float w = drawable.getSurfaceWidth() * genderDotProduct * 5;
    gl.glRectf(0, -10, w, 10);
    gl.glPopMatrix();
}

19 Source : BeeCounter.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public synchronized void annotate(GLAutoDrawable drawable) {
    if (!isFilterEnabled()) {
        return;
    }
    super.annotate(drawable);
    final int sx = chip.getSizeX(), sy = chip.getSizeY();
    final GL2 gl = drawable.getGL().getGL2();
    gl.glLineWidth(2f);
    gl.glColor3f(0, 0, 1);
    gl.glRasterPos3f(0, sy * getTopLine(), 0);
    glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_24, String.format("%d exited", nOut));
    gl.glRasterPos3f(0, sy * getBotLine(), 0);
    glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_24, String.format("%d entered", nIn));
    gl.glBegin(GL.GL_LINES);
    gl.glVertex2f(0, sy * getTopLine());
    gl.glVertex2f(sx, sy * getTopLine());
    gl.glVertex2f(0, sy * getBotLine());
    gl.glVertex2f(sx, sy * getBotLine());
    gl.glEnd();
}

19 Source : Vector2D.java
with GNU Lesser General Public License v2.1
from SensorsINI

public void drawVector(GL2 gl, float origX, float origY, float headlength, float Scale) {
    DrawGL.drawVector(gl, origX, origY, this.x, this.y, headlength, Scale);
}

19 Source : Vector2D.java
with GNU Lesser General Public License v2.1
from SensorsINI

public void drawVector(GL2 gl, float origX, float origY) {
    drawVector(gl, origX, origY, 1, 1);
}

19 Source : Vector2D.java
with GNU Lesser General Public License v2.1
from SensorsINI

public void drawVector(GL2 gl) {
    drawVector(gl, 0, 0, 1, 1);
}

19 Source : LatencyTest.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    float csx = chip.getSizeX(), csy = chip.getSizeY();
    final float sx = size * chip.getSizeX(), sy = size * chip.getSizeY();
    final float inx = inset * chip.getSizeX(), iny = inset * chip.getSizeY();
    gl.glColor3f(1, 1, 1);
    switch(getCorner()) {
        case 0:
            gl.glRectf(inx, iny, inx + sx, iny + sy);
            break;
        case 1:
            gl.glRectf(csx - inx, iny, csx - inx - sx, iny + sy);
            break;
        // case 2:
        // gl.glRectf(csx-inx, csy-iny, csx-inx - sx, csy-iny - sy);
        // break;
        // case 3:
        // gl.glRectf(inx, csy-iny, inx + sx, csy-iny - sy);
        // break;
        default:
    }
    delayCount++;
    if (delayCount > delayFrames) {
        delayCount = 0;
        corner++;
        if (corner > 1) {
            corner = 0;
        }
    }
}

19 Source : AbstractHistogram.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void draw(GLAutoDrawable drawable, TextRenderer renderer, float x, float y, int height, int resolution) {
    // TODO if resolution is larger than histogram size (e.g. resolution = 100 bins and histogram is only 32 bins) then drawing does not work correctly.
    GL2 gl = drawable.getGL().getGL2();
    int from, to;
    if (drawAllBins) {
        from = this.start;
        to = this.getSize();
    } else {
        // show only bins from 10-90% replacedmulative bin count
        from = 0;
        float total = 0;
        while (total < 0.1 && from < this.getSize()) {
            total += this.getNormalized(from);
            from++;
        }
        to = from;
        from = Math.max(0, from - 2);
        while (total < 0.9 && to < this.getSize()) {
            total += this.getNormalized(to);
            to++;
        }
        to = Math.min(to + 2, this.nBins);
    }
    // e.g. for 1024 bins and 100 pixel resolution, pack is 1025/100=102
    int pack = (to - from) / resolution + 1;
    // make new histogram that adds up bins from original, e.g. 103 bins
    float[] sum = new float[resolution + 1];
    int counter = 0;
    for (int i = from; i < to; i++) {
        sum[counter] += this.getNormalized(i);
        if (i % pack == 0 && i != 0) {
            // every 102 i increment packed histogram bin counter
            counter++;
        }
    }
    float max = 0;
    for (int i = 0; i < sum.length; i++) {
        if (max < sum[i])
            max = sum[i];
    }
    for (int i = 0; i < sum.length; i++) {
        // draw packed histogram
        float h = sum[i] / max * (height - 4);
        gl.glBegin(GL.GL_LINE_LOOP);
        {
            gl.glVertex2f(x + i, y - height + 3);
            gl.glVertex2f(x + i, y - height + h + 3);
            gl.glVertex2f(x + i + 1, y - height + h + 3);
            gl.glVertex2f(x + i + 1, y - height + 3);
        }
        gl.glEnd();
    }
    renderer.begin3DRendering();
    // renderer.draw3D("histogram [au]: " + (this.start + from * this.step) + ", " + (this.start + to * this.step) + ".", x, y, 0, 0.5f);
    String s = String.format("range [%d,%d], N=%d, entropy=%.2f", this.start + from * this.step, this.start + to * this.step, this.getN(), computeEntropy());
    renderer.draw3D(s, x, y, 0, 0.2f);
    renderer.end3DRendering();
}

19 Source : DVSLatencyMeasurement.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    noiseFilter.annotate(drawable);
    GL2 gl = drawable.getGL().getGL2();
    canvas = chip.getCanvas();
    glCanvas = (GLCanvas) canvas.getCanvas();
    float csx = chip.getSizeX(), csy = chip.getSizeY();
    gl.glColor3f(1, 1, 1);
    gl.glLineWidth(2);
    gl.glBegin(GL.GL_LINES);
    gl.glEnd();
    timeStats.draw(gl);
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws a box using current open gl color
 *
 * @param gl the opengl context
 * @param centerX the box origin location x
 * @param centerY the box origin location x
 * @param width The x length of box
 * @param height the y length of box
 * @param angle the angle relative to E
 */
public static void drawBox(final GL2 gl, final float centerX, final float centerY, final float width, final float height, final float angle) {
    gl.glTranslatef(centerX, centerY, 0);
    if (angle != 0) {
        gl.glRotatef(angle * RAD_TO_DEG, 0, 0, 1);
    }
    if (boxDisplayListId == 0 || width != 2 * boxLastW || height != 2 * boxLastH) {
        if (boxDisplayListId != 0) {
            gl.glDeleteLists(boxDisplayListId, 1);
        }
        boxDisplayListId = gl.glGenLists(1);
        gl.glNewList(boxDisplayListId, GL2.GL_COMPILE);
        boxLastW = width / 2;
        boxLastH = height / 2;
        gl.glBegin(GL.GL_LINE_LOOP);
        {
            gl.glVertex2f(-boxLastW, -boxLastH);
            gl.glVertex2f(+boxLastW, -boxLastH);
            gl.glVertex2f(+boxLastW, +boxLastH);
            gl.glVertex2f(-boxLastW, +boxLastH);
        }
        gl.glEnd();
        gl.glEndList();
    }
    gl.glCallList(boxDisplayListId);
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws a line. Set the line width before drawing, and push and pop matrix.
 *
 * @param gl
 * @param startX
 * @param startY
 * @param lengthX
 * @param lengthY
 * @param scale scales the line length by this factor
 */
public static void drawLine(GL2 gl, float startX, float startY, float lengthX, float lengthY, float scale) {
    gl.glTranslatef(startX, startY, 0);
    gl.glBegin(GL.GL_LINES);
    gl.glVertex2f(0, 0);
    gl.glVertex2f(lengthX * scale, lengthY * scale);
    gl.glEnd();
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws a cross using current open gl color
 *
 * @param gl the opengl context
 * @param centerX the cross origin location x
 * @param centerY the cross origin location x
 * @param length The x length of cross
 * @param angle the angle relative to E
 */
public static void drawCross(final GL2 gl, final float centerX, final float centerY, final float length, final float angle) {
    gl.glTranslatef(centerX, centerY, 0);
    if (angle != 0) {
        gl.glRotatef(angle * RAD_TO_DEG, 0, 0, 1);
    }
    if (crossDisplayListId == 0 || length != 2 * crossLastL) {
        if (crossDisplayListId != 0) {
            gl.glDeleteLists(crossDisplayListId, 1);
        }
        crossDisplayListId = gl.glGenLists(1);
        gl.glNewList(crossDisplayListId, GL2.GL_COMPILE);
        crossLastL = length / 2;
        gl.glBegin(GL.GL_LINES);
        {
            gl.glVertex2f(-crossLastL, -crossLastL);
            gl.glVertex2f(+crossLastL, +crossLastL);
            gl.glVertex2f(+crossLastL, -crossLastL);
            gl.glVertex2f(-crossLastL, +crossLastL);
        }
        gl.glEnd();
        gl.glEndList();
    }
    gl.glCallList(crossDisplayListId);
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws an arrow vector using current open gl color, using headlength 1 and
 * scaling 1
 *
 * @param gl the opengl context
 * @param origX the arrow origin location x
 * @param origY the arrow origin location x
 * @param headX The x length of arrow
 * @param headY the y length of arrow
 */
public static void drawVector(GL2 gl, float origX, float origY, float headX, float headY) {
    drawVector(gl, origX, origY, headX, headY, 1, 1);
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws an arrow vector using current open gl color
 *
 * @param gl the opengl context
 * @param origX the arrow origin location x
 * @param origY the arrow origin location x
 * @param headX The x length of arrow
 * @param headY the y length of arrow
 * @param headlength the length of the arrow tip segments as fraction of
 * entire arrow length, after scaling
 * @param scale the scaling used for drawing the arrow
 */
public static void drawVector(GL2 gl, float origX, float origY, float headX, float headY, float headlength, float scale) {
    float endx = headX * scale, endy = headY * scale;
    // halfway between pointing back to origin
    float arx = -endx + endy, ary = -endx - endy;
    // length
    float l = (float) Math.sqrt((arx * arx) + (ary * ary));
    arx = (arx / l) * headlength;
    // normalize to headlength
    ary = (ary / l) * headlength;
    gl.glTranslatef(origX, origY, 0);
    gl.glBegin(GL2.GL_LINES);
    {
        gl.glVertex2f(0, 0);
        gl.glVertex2f(endx, endy);
        // draw arrow (half)
        gl.glVertex2f(endx, endy);
        gl.glVertex2f(endx + arx, endy + ary);
        // other half, 90 degrees
        gl.glVertex2f(endx, endy);
        gl.glVertex2f(endx + ary, endy - arx);
    }
    gl.glEnd();
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws a circle. Set the line width before drawing, and push and pop
 * matrix
 *
 * @param gl
 * @param centerX
 * @param centerY
 * @param radius
 * @param N number of segments used to draw ellipse
 */
public static void drawCircle(GL2 gl, float centerX, float centerY, float radius, int N) {
    drawEllipse(gl, centerX, centerY, radius, radius, 0, N);
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws ellipse. Set the line width before drawing, and push and pop matrix
 *
 * @param gl
 * @param centerX
 * @param centerY
 * @param radiusX
 * @param radiusY
 * @param angle
 * @param N number of segments used to draw ellipse
 */
public static void drawEllipse(GL2 gl, float centerX, float centerY, float radiusX, float radiusY, float angle, int N) {
    final float r2d = (float) (180 / Math.PI);
    gl.glTranslatef(centerX, centerY, 0);
    if (angle != 0) {
        gl.glRotatef(angle * r2d, 0, 0, 1);
    }
    gl.glBegin(GL.GL_LINE_LOOP);
    {
        for (int i = 0; i < N; i++) {
            double a = ((float) i / N) * 2 * Math.PI;
            double cosA = Math.cos(a);
            double sinA = Math.sin(a);
            gl.glVertex2d(radiusX * cosA, radiusY * sinA);
        }
    }
    gl.glEnd();
}

19 Source : DrawGL.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draws an arrow vector using current open gl color, starting from 0,0,
 * using head length 1 and scaling 1
 *
 * @param gl the opengl context
 * @param headX The x length of arrow
 * @param headY the y length of arrow
 */
public static void drawVector(GL2 gl, float headX, float headY) {
    drawVector(gl, 0, 0, headX, headY, 1, 1);
}

19 Source : XYChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draw the decoration.
 */
@Override
protected void drawDecoration(GL2 gl) {
    axisLabelRenderer.beginRendering(getWidth(), getHeight());
    axisLabelRenderer.setColor(getForeground());
    axisLabelRenderer.draw(axesLabels[0], axisLabelAreas[0].x, axisLabelAreas[0].y);
    axisLabelRenderer.draw(axesLabels[1], axisLabelAreas[1].x, axisLabelAreas[1].y);
    axisLabelRenderer.endRendering();
}

19 Source : XYChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Layout the components.
 */
@Override
protected void layoutComponents(GL2 gl, int x, int y, int width, int height) {
    Insets insets = getInsets();
    // layout x-axis labels
    axisLabelAreas[0].x = (bodyArea.x + bodyArea.width) - axisLabelAreas[0].width;
    axisLabelAreas[0].y = insets.bottom / 2;
    bodyArea.y += axisLabelAreas[0].height;
    bodyArea.height -= axisLabelAreas[0].height;
    // layout y-axis labels
    axisLabelAreas[1].x = insets.left / 2;
    axisLabelAreas[1].y = (bodyArea.y + bodyArea.height) - axisLabelAreas[1].height;
    bodyArea.x += axisLabelAreas[1].width;
    bodyArea.width -= axisLabelAreas[1].width;
}

19 Source : XYChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Create the components.
 */
@Override
protected void createComponents(GL2 gl) {
    axisLabelRenderer = new TextRenderer(new Font("Helvetica", Font.PLAIN, 12));
    textRenderer = new TextRenderer(new Font("Helvetica", Font.PLAIN, 10));
    axesLabels = new String[2];
    axisLabelAreas = new Rectangle[axesLabels.length];
    for (int i = 0; i < axesLabels.length; i++) {
        StringBuilder buf = new StringBuilder();
        // for(Category s : categories) {
        Category s = categories[0];
        buf.append(s.axes[i].replacedle);
        if (s.axes[i].unit != null) {
            buf.append(" [" + s.axes[i].unit + "]");
        }
        buf.append('\n');
        // }
        String str = buf.toString();
        axesLabels[i] = str.substring(0, str.length() - 1);
        Rectangle2D bounds = axisLabelRenderer.getBounds(axesLabels[i]);
        axisLabelAreas[i] = new Rectangle((int) bounds.getWidth(), (int) bounds.getHeight());
    }
}

19 Source : XYChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draw the background of the chart. The grid could be drawn by this method.
 * An OpenGL list is created for this.
 */
@Override
protected void drawStaticBackground(GL2 gl) {
    float[] fg = new float[4];
    getForeground().getColorComponents(fg);
    gl.glColor3fv(fg, 0);
    gl.glBegin(GL.GL_LINE_LOOP);
    gl.glVertex2f(0.0f, 0.0f);
    gl.glVertex2f(1.0f, 0.0f);
    gl.glVertex2f(1.0f, 1.0f);
    gl.glVertex2f(0.0f, 1.0f);
    gl.glEnd();
    if (isGridEnabled()) {
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2f(0.0f, 0.25f);
        gl.glVertex2f(1.0f, 0.25f);
        gl.glVertex2f(0.0f, 0.5f);
        gl.glVertex2f(1.0f, 0.5f);
        gl.glVertex2f(0.0f, 0.75f);
        gl.glVertex2f(1.0f, 0.75f);
        gl.glColor3f(0.5f, 0.5f, 0.5f);
        gl.glVertex2f(0.0f, 0.125f);
        gl.glVertex2f(1.0f, 0.125f);
        gl.glVertex2f(0.0f, 0.375f);
        gl.glVertex2f(1.0f, 0.375f);
        gl.glVertex2f(0.0f, 0.625f);
        gl.glVertex2f(1.0f, 0.625f);
        gl.glVertex2f(0.0f, 0.875f);
        gl.glVertex2f(1.0f, 0.875f);
        gl.glEnd();
    }
}

19 Source : VectorSeries.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draw the vectors.
 * The gl object must be always the same.
 * <code>method</code> is ignored - the vectors are always drawn as lines.
 */
@Override
public synchronized void draw(GL2 gl, int method) {
    gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
    /* draw data series */
    cache.position(0);
    // draw vertices of float from cache beginning at 0
    gl.glVertexPointer(dimension, GL.GL_FLOAT, 0, cache);
    gl.glDrawArrays(GL.GL_LINES, 0, elementsCount / dimension);
}

19 Source : VectorFieldChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Create the components.
 */
@Override
protected void createComponents(GL2 gl) {
}

19 Source : VectorFieldChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draw the background of the chart. The grid could be drawn by this method.
 * An OpenGL list is created for this.
 */
@Override
protected void drawStaticBackground(GL2 gl) {
    float[] fg = new float[4];
    getForeground().getColorComponents(fg);
    gl.glColor3fv(fg, 0);
    gl.glBegin(GL.GL_LINE_LOOP);
    gl.glVertex2f(0.0f, 0.0f);
    gl.glVertex2f(1.0f, 0.0f);
    gl.glVertex2f(1.0f, 1.0f);
    gl.glVertex2f(0.0f, 1.0f);
    gl.glEnd();
}

19 Source : VectorFieldChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
protected void drawDecoration(GL2 gl) {
}

19 Source : VectorFieldChart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Layout the components.
 */
@Override
protected void layoutComponents(GL2 gl, int x, int y, int width, int height) {
}

19 Source : Series.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * The Series clreplaced.
 * A Series is a data series in a chart; its view is a Category object.
 * The data are cached and then transferred to an OpenGL device.
 */
public clreplaced Series {

    static Logger log = Logger.getLogger("chart");

    /**
     * Default capacity of series
     */
    protected static final int DEFAULT_CAPACITY = 10000;

    /**
     * The dimension of the elements (=vertices)
     */
    protected int dimension;

    /**
     * The max number of data points in the series.
     */
    protected int capacity;

    /**
     * number of bytes per element
     */
    protected final int elementSize;

    /**
     * number of flushed elements (= dimension * verticesCount)
     */
    protected int elementsCount;

    /**
     * The size of the buffer
     */
    // private int flushedBytes;
    /**
     * A buffer to cache new data points before they are transfered to the OpenGL device - if buffer extension available.
     */
    protected FloatBuffer cache;

    /**
     * Local buffer that holds charted points in case buffer extension not available.
     */
    protected FloatBuffer vertices;

    /**
     * The interface to opengl
     */
    protected GL2 gl;

    /**
     * the opengl buffer id
     */
    private int bufferId;

    // /** The line width of the series in pixels, default 1.*/
    // protected float lineWidth=1;
    GLU glu = new GLU();

    private volatile boolean clearEnabled = false;

    /**
     * Create a new Series object with <code>capacity</code>.
     * @param dimensions the number of dimensions (2 or 3)
     * @param capacity max number of points
     */
    public Series(int dimensions, int capacity) {
        dimension = dimensions;
        this.capacity = capacity;
        elementSize = Float.SIZE / 8;
        cache = Buffers.newDirectFloatBuffer(dimension * capacity);
    }

    /**
     * Create a new Series object with default capacity.
     * @param dimensions the number of dimensions (2 or 3)
     */
    public Series(int dimensions) {
        this(dimensions, DEFAULT_CAPACITY);
    }

    /**
     * Add a data item to the series cache.
     * @param x the x value
     * @param y the y value
     */
    synchronized public void add(float x, float y) {
        // data is added here and drained by the draw method as it is copied to the opengl buffer
        replacedert dimension == 2;
        if (cache.position() >= (cache.capacity() - 2)) {
            // have to wait and drop some data
            return;
        // TODO when we render from the buffer, we need to clear the buffer here or set position to 0
        }
        cache.put(x);
        cache.put(y);
    }

    /**
     * Add a data item to the series cache.
     */
    synchronized public void add(float x, float y, float z) {
        replacedert dimension == 3;
        if (cache.position() >= (cache.capacity() - 3)) {
            // have to wait and drop some data
            return;
        }
        cache.put(x);
        cache.put(y);
        cache.put(z);
    }

    /**
     * Set the capacity of the series cache.
     */
    synchronized public void setCapacity(int capacity) {
        this.capacity = capacity;
        cache = Buffers.newDirectFloatBuffer(dimension * capacity);
    }

    /**
     * Schedules a clear of existing points in vertex buffer on the next {@code display()}.
     * Call {@code clear()} if you want to clear out existing points before drawing
     * new ones that you have added to the Series.
     */
    synchronized public void clear() {
        clearEnabled = true;
    }

    /**
     * Utility method to check for GL errors. Prints stacked up errors up to a limit.
     *    @param g the GL context
     *    @param glu the GLU used to obtain the error strings
     *    @param msg an error message to log to e.g., show the context
     */
    public void checkGLError(GL2 g, GLU glu, String msg) {
        if (g == null) {
            log.warning("null GL");
            return;
        }
        int error = g.glGetError();
        int nerrors = 3;
        while ((error != GL.GL_NO_ERROR) && (nerrors-- != 0)) {
            StackTraceElement[] trace = Thread.currentThread().getStackTrace();
            if (trace.length > 1) {
                String clreplacedName = trace[2].getClreplacedName();
                String methodName = trace[2].getMethodName();
                int lineNumber = trace[2].getLineNumber();
                log.warning("GL error number " + error + " " + glu.gluErrorString(error) + " : " + msg + " at " + clreplacedName + "." + methodName + " (line " + lineNumber + ")");
            } else {
                log.warning("GL error number " + error + " " + glu.gluErrorString(error) + " : " + msg);
            }
            // Thread.dumpStack();
            error = g.glGetError();
        }
    }

    // /**
    // * @return the lineWidth
    // */
    // public float getLineWidth() {
    // return lineWidth;
    // }
    // 
    // /**
    // * @param lineWidth the lineWidth to set
    // */
    // public void setLineWidth(float lineWidth) {
    // this.lineWidth = lineWidth;
    // }
    private boolean hasBufferExtension = false, checkedBufferExtension = false;

    /**
     * Flushes data to opengl graphics device and draws the vertices.
     * The gl object must be always the same; if not the existing one is discarded and a new one obtained to bind a vertex buffer to it.
     * @param gl the OpenGL context (must be identical between calls)
     * @param method the method of drawing the series line segments, e.g. <code>GL2.GL_LINE_STRIP</code>.
     */
    synchronized public void draw(GL2 gl, int method) {
        if (!checkedBufferExtension) {
            log.info("checking once to see if vertex buffer extensions available (OpenGL 1.5+)");
            String glVersion = gl.glGetString(GL.GL_VERSION);
            hasBufferExtension = gl.isExtensionAvailable("GL_VERSION_1_5");
            checkedBufferExtension = true;
            log.info("Open GL version " + glVersion + ", gl.isExtensionAvailable(\"GL_VERSION_1_5\") = " + hasBufferExtension);
        }
        /* bind to gl object if necessary (implicit 2nd phase constructor) */
        if (this.gl == null) {
            gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
            int[] bufferIds = new int[1];
            if (hasBufferExtension) {
                // create buffer id
                gl.glGenBuffers(1, bufferIds, 0);
                bufferId = bufferIds[0];
            }
        } else if (this.gl != gl) {
            // error: cannot bind to multiple devices
            log.warning("Chart data series: Expected the same GL object! this.gl=" + this.gl + " but called gl=" + gl + ". Discarding GL context to make a new one");
            this.gl = null;
            return;
        }
        if (hasBufferExtension) {
            // gl.glLineWidth(lineWidth);
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferId);
            // check for new data...
            int add = cache.position();
            if ((add > 0) || (this.gl == null) || clearEnabled) {
                // ...and transfer them to opengl buffer if necessary
                cache.position(0);
                if ((elementsCount >= capacity) || clearEnabled) {
                    // if we filled up this buffer to our limit, null the gl to force us to make a new data buffer
                    this.gl = null;
                    elementsCount = 0;
                }
                if ((this.gl == null) || clearEnabled) {
                    // if clear is enabled, then just allocated a new buffer pointer and bind it
                    // create buffer and flush
                    gl.glBufferData(GL.GL_ARRAY_BUFFER, dimension * capacity * elementSize, cache, GL.GL_STATIC_DRAW);
                    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferId);
                    this.gl = gl;
                } else {
                    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferId);
                    // flush
                    gl.glBufferSubData(GL.GL_ARRAY_BUFFER, elementsCount * elementSize, add * elementSize, cache);
                }
                // move position
                elementsCount += add;
                cache.position(0);
            }
            /* draw data series */
            // 2D-vertices of float from current opengl buffer beginning at 0
            gl.glVertexPointer(2, GL.GL_FLOAT, 0, 0);
            gl.glDrawArrays(method, 0, elementsCount / dimension);
        /* flush data to opengl device if necessary.
            if we don't have vertex buffer extension, we must render all the data again, from the cache itself. */
        } else {
            // no GPU buffer extension, must render cache as host vertex buffer
            if (clearEnabled) {
                if (vertices != null) {
                    vertices.clear();
                }
            }
            if ((vertices == null) || clearEnabled) {
                // allocates direct buffer
                vertices = Buffers.newDirectFloatBuffer(dimension * capacity);
            }
            if (this.gl == null) {
                this.gl = gl;
            }
            // gl.glLineWidth(lineWidth);
            if (cache.position() > 0) {
                // if new points have been added, copy new values to end of vertices buffer
                try {
                    // copy them to the vertices
                    vertices.put((FloatBuffer) cache.flip());
                } catch (BufferOverflowException e) {
                    // if vertices is full, just clear it and start over
                    vertices.clear();
                }
                // ready for new data to be put here
                cache.clear();
            }
            // this many values to plot
            int elements = vertices.position();
            // point to start
            vertices.position(0);
            // tell gl where to look
            gl.glVertexPointer(2, GL.GL_FLOAT, 0, vertices);
            // draw the vertices
            gl.glDrawArrays(method, 0, elements / dimension);
            // continue adding from here
            vertices.position(elements);
        }
        checkGLError(this.gl, glu, "after Series draw");
        clearEnabled = false;
    }

    public int getCapacity() {
        return capacity;
    }
}

19 Source : Series.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Utility method to check for GL errors. Prints stacked up errors up to a limit.
 *    @param g the GL context
 *    @param glu the GLU used to obtain the error strings
 *    @param msg an error message to log to e.g., show the context
 */
public void checkGLError(GL2 g, GLU glu, String msg) {
    if (g == null) {
        log.warning("null GL");
        return;
    }
    int error = g.glGetError();
    int nerrors = 3;
    while ((error != GL.GL_NO_ERROR) && (nerrors-- != 0)) {
        StackTraceElement[] trace = Thread.currentThread().getStackTrace();
        if (trace.length > 1) {
            String clreplacedName = trace[2].getClreplacedName();
            String methodName = trace[2].getMethodName();
            int lineNumber = trace[2].getLineNumber();
            log.warning("GL error number " + error + " " + glu.gluErrorString(error) + " : " + msg + " at " + clreplacedName + "." + methodName + " (line " + lineNumber + ")");
        } else {
            log.warning("GL error number " + error + " " + glu.gluErrorString(error) + " : " + msg);
        }
        // Thread.dumpStack();
        error = g.glGetError();
    }
}

19 Source : Series.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Flushes data to opengl graphics device and draws the vertices.
 * The gl object must be always the same; if not the existing one is discarded and a new one obtained to bind a vertex buffer to it.
 * @param gl the OpenGL context (must be identical between calls)
 * @param method the method of drawing the series line segments, e.g. <code>GL2.GL_LINE_STRIP</code>.
 */
synchronized public void draw(GL2 gl, int method) {
    if (!checkedBufferExtension) {
        log.info("checking once to see if vertex buffer extensions available (OpenGL 1.5+)");
        String glVersion = gl.glGetString(GL.GL_VERSION);
        hasBufferExtension = gl.isExtensionAvailable("GL_VERSION_1_5");
        checkedBufferExtension = true;
        log.info("Open GL version " + glVersion + ", gl.isExtensionAvailable(\"GL_VERSION_1_5\") = " + hasBufferExtension);
    }
    /* bind to gl object if necessary (implicit 2nd phase constructor) */
    if (this.gl == null) {
        gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
        int[] bufferIds = new int[1];
        if (hasBufferExtension) {
            // create buffer id
            gl.glGenBuffers(1, bufferIds, 0);
            bufferId = bufferIds[0];
        }
    } else if (this.gl != gl) {
        // error: cannot bind to multiple devices
        log.warning("Chart data series: Expected the same GL object! this.gl=" + this.gl + " but called gl=" + gl + ". Discarding GL context to make a new one");
        this.gl = null;
        return;
    }
    if (hasBufferExtension) {
        // gl.glLineWidth(lineWidth);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferId);
        // check for new data...
        int add = cache.position();
        if ((add > 0) || (this.gl == null) || clearEnabled) {
            // ...and transfer them to opengl buffer if necessary
            cache.position(0);
            if ((elementsCount >= capacity) || clearEnabled) {
                // if we filled up this buffer to our limit, null the gl to force us to make a new data buffer
                this.gl = null;
                elementsCount = 0;
            }
            if ((this.gl == null) || clearEnabled) {
                // if clear is enabled, then just allocated a new buffer pointer and bind it
                // create buffer and flush
                gl.glBufferData(GL.GL_ARRAY_BUFFER, dimension * capacity * elementSize, cache, GL.GL_STATIC_DRAW);
                gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferId);
                this.gl = gl;
            } else {
                gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferId);
                // flush
                gl.glBufferSubData(GL.GL_ARRAY_BUFFER, elementsCount * elementSize, add * elementSize, cache);
            }
            // move position
            elementsCount += add;
            cache.position(0);
        }
        /* draw data series */
        // 2D-vertices of float from current opengl buffer beginning at 0
        gl.glVertexPointer(2, GL.GL_FLOAT, 0, 0);
        gl.glDrawArrays(method, 0, elementsCount / dimension);
    /* flush data to opengl device if necessary.
            if we don't have vertex buffer extension, we must render all the data again, from the cache itself. */
    } else {
        // no GPU buffer extension, must render cache as host vertex buffer
        if (clearEnabled) {
            if (vertices != null) {
                vertices.clear();
            }
        }
        if ((vertices == null) || clearEnabled) {
            // allocates direct buffer
            vertices = Buffers.newDirectFloatBuffer(dimension * capacity);
        }
        if (this.gl == null) {
            this.gl = gl;
        }
        // gl.glLineWidth(lineWidth);
        if (cache.position() > 0) {
            // if new points have been added, copy new values to end of vertices buffer
            try {
                // copy them to the vertices
                vertices.put((FloatBuffer) cache.flip());
            } catch (BufferOverflowException e) {
                // if vertices is full, just clear it and start over
                vertices.clear();
            }
            // ready for new data to be put here
            cache.clear();
        }
        // this many values to plot
        int elements = vertices.position();
        // point to start
        vertices.position(0);
        // tell gl where to look
        gl.glVertexPointer(2, GL.GL_FLOAT, 0, vertices);
        // draw the vertices
        gl.glDrawArrays(method, 0, elements / dimension);
        // continue adding from here
        vertices.position(elements);
    }
    checkGLError(this.gl, glu, "after Series draw");
    clearEnabled = false;
}

19 Source : Chart.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draw the background of the chart. The grid could be drawn by this method.
 * An OpenGL list is created for this.
 */
protected void drawStaticBackground(GL2 gl) {
}

19 Source : Category.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Draw the category.
 * Buffer series onto opengl device.
 */
public void draw(GL2 gl) {
    replacedert gl != null;
    /* set drawing parameters */
    gl.glColor3fv(color, 0);
    gl.glLineWidth(lineWidth);
    /* set cliping area for body: left, right, bottom, top. */
    gl.glClipPlane(GL2ES1.GL_CLIP_PLANE0, new double[] { 1.0, 0.0, 0.0, 0.0 }, 0);
    gl.glClipPlane(GL2ES1.GL_CLIP_PLANE1, new double[] { -1.0, 0.0, 0.0, 1.0 }, 0);
    gl.glClipPlane(GL2ES1.GL_CLIP_PLANE2, new double[] { 0.0, 1.0, 0.0, 0.0 }, 0);
    gl.glClipPlane(GL2ES1.GL_CLIP_PLANE3, new double[] { 0.0, -1.0, 0.0, 1.0 }, 0);
    /* transform and draw series inside clipping area*/
    gl.glPushMatrix();
    gl.glScaled(1 / axes[0].size, 1 / axes[1].size, 1 / axes[2].size);
    gl.glTranslated(-axes[0].min, -axes[1].min, -axes[2].min);
    gl.glMultMatrixd(transform, 0);
    gl.glEnable(GL2ES1.GL_CLIP_PLANE0);
    gl.glEnable(GL2ES1.GL_CLIP_PLANE1);
    gl.glEnable(GL2ES1.GL_CLIP_PLANE2);
    gl.glEnable(GL2ES1.GL_CLIP_PLANE3);
    data.draw(gl, GL2.GL_LINE_STRIP);
    gl.glDisable(GL2ES1.GL_CLIP_PLANE0);
    gl.glDisable(GL2ES1.GL_CLIP_PLANE1);
    gl.glDisable(GL2ES1.GL_CLIP_PLANE2);
    gl.glDisable(GL2ES1.GL_CLIP_PLANE3);
    gl.glPopMatrix();
}

19 Source : JaerAviWriter.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    if (showTimeFactor) {
        String s = null;
        if (timeExpansionFactor < 1) {
            s = String.format("%.1fX slow-down", 1 / timeExpansionFactor);
        } else {
            s = String.format("%.1fX speed-up", timeExpansionFactor);
        }
        MultilineAnnotationTextRenderer.resetToYPositionPixels(chip.getSizeY() * .1f);
        MultilineAnnotationTextRenderer.setScale(showTimeFactorTextScale);
        MultilineAnnotationTextRenderer.setColor(Color.blue);
        MultilineAnnotationTextRenderer.renderMultilineString(s);
    }
    if (isRecordingActive() && isWriteEnabled()) {
        GL2 gl = drawable.getGL().getGL2();
        BufferedImage bi = toImage(gl, drawable.getNativeSurface().getSurfaceWidth(), drawable.getNativeSurface().getSurfaceHeight());
        int timecode = chip.getAeViewer().getAePlayer().getTime();
        writeFrame(bi, timecode);
    }
}

19 Source : AbstractAviWriter.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Turns gl to BufferedImage with fixed format
 *
 * @param gl
 * @param w
 * @param h
 * @return
 */
protected BufferedImage toImage(GL2 gl, int w, int h) {
    // or GL.GL_BACK
    gl.glReadBuffer(GL.GL_FRONT);
    ByteBuffer glBB = Buffers.newDirectByteBuffer(4 * w * h);
    gl.glReadPixels(0, 0, w, h, GL2.GL_BGRA, GL.GL_BYTE, glBB);
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
    int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int b = 2 * glBB.get();
            int g = 2 * glBB.get();
            int r = 2 * glBB.get();
            // not using
            int a = glBB.get();
            bd[(h - y - 1) * w + x] = (b << 16) | (g << 8) | r | 0xFF000000;
        }
    }
    return bi;
}

19 Source : StereoClusterTracker.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
synchronized public void annotate(GLAutoDrawable drawable) {
    super.annotate(drawable);
    // in pixels
    final float LINE_WIDTH = 6f;
    if (!isFilterEnabled()) {
        return;
    }
    // when we getString this we are already set up with updateShape 1=1 pixel, at LL corner
    GL2 gl = drawable.getGL().getGL2();
    if (gl == null) {
        log.warning("null GL in StereoClusterTracker.annotate");
        return;
    }
    float[] rgb = new float[4];
    gl.glPushMatrix();
    try {
        for (Cluster b : clusters) {
            StereoCluster c = (StereoCluster) b;
            if (c.isVisible() || isShowAllClusters()) {
                int x = (int) c.getLocation().x;
                int y = (int) c.getLocation().y;
                // sx sy are (half) size of rectangle
                int sy = (int) c.getRadius();
                int sx = sy;
                // 
                // if ( isColorClustersDifferentlyEnabled () ){
                // } else{
                // float brightness = (float)Math.max (0.1f,Math.min (1f,c.getLifetime () / fullbrightnessLifetime));
                // 
                // c.setColor(new Color(brightness,brightness,0,1f));
                // }
                // c.getColor ().getRGBComponents (rgb);
                // if (c.isVisible()) {
                // gl.glColor3fv(rgb, 0);
                // } else {
                // gl.glColor3f(.3f, .3f, .3f);
                // }
                // gl.glLineWidth (LINE_WIDTH);
                // 
                // gl.glPushMatrix();
                // drawGL.drawBox(gl, x, y, 2*sx, 2*sy, 0);
                // if (isDynamicAngleEnabled()) {
                // drawGL.drawLine(gl, 0, 0, sx, 0, 1);
                // }
                // gl.glPopMatrix();
                // // draw left and right disparity clusters
                // left
                if (c.isVisible()) {
                    // green
                    gl.glColor3f(0, 1, 0);
                    gl.glLineWidth(LINE_WIDTH / 2);
                    int x2 = (int) (x - (c.getDisparity() / 2));
                    gl.glPushMatrix();
                    DrawGL.drawBox(gl, x2, y, 2 * sx, 2 * sy, 0);
                    if (isDynamicAngleEnabled()) {
                        DrawGL.drawLine(gl, 0, 0, sx, 0, 1);
                    }
                    gl.glPopMatrix();
                    // red right
                    // green
                    gl.glColor3f(1, 0, 0);
                    gl.glLineWidth(LINE_WIDTH / 2);
                    x2 = (int) (x + (c.getDisparity() / 2));
                    gl.glPushMatrix();
                    DrawGL.drawBox(gl, x2, y, 2 * sx, 2 * sy, 0);
                    if (isDynamicAngleEnabled()) {
                        DrawGL.drawLine(gl, 0, 0, sx, 0, 1);
                    }
                    gl.glPopMatrix();
                }
                // gl.glPointSize (LINE_WIDTH);
                // gl.glBegin (GL.GL_POINTS);
                // {
                // java.util.List<ClusterPathPoint> points = c.getPath ();
                // for ( Point2D.Float p:points ){
                // gl.glVertex2f (p.x,p.y);
                // }
                // }
                // gl.glEnd ();
                // // now draw velocityPPT vector
                // if ( isUseVelocity () ){
                // gl.glBegin (GL2.GL_LINES);
                // {
                // gl.glVertex2i (x,y);
                // gl.glVertex2f (x + c.getVelocityPPS ().x * getVelocityVectorScaling(),y + c.getVelocityPPS ().y * getVelocityVectorScaling());
                // }
                // gl.glEnd ();
                // }
                if (isDisplayStereoClusterAnnotation()) {
                    int font = GLUT.BITMAP_TIMES_ROMAN_24;
                    GLUT glut = chip.getCanvas().getGlut();
                    gl.glColor3f(1, 1, 1);
                    gl.glRasterPos3f(c.location.x, c.location.y, 0);
                    glut.glutBitmapString(font, String.format("d=%.1f, dv=%.1f", c.disparity, c.disparityVelocity));
                }
            }
        // visible cluster
        }
        // clusters
        if (isDisplayStereoClusterAnnotation() && (getNearestCluster() != null)) {
            StereoCluster c = getNearestCluster();
            int font = GLUT.BITMAP_TIMES_ROMAN_24;
            GLUT glut = chip.getCanvas().getGlut();
            gl.glColor3f(1, 1, 1);
            gl.glRasterPos3f(1, 13, 0);
            glut.glutBitmapString(font, String.format("x,y,z=%5.2f, %5.2f, %5.2f", c.location3dm.x, c.location3dm.y, c.location3dm.z));
            gl.glRasterPos3f(1, 8, 0);
            glut.glutBitmapString(font, String.format("vx,vy,vz=%5.2f, %5.2f, %5.2f", c.velocity3dmps.x, c.velocity3dmps.y, c.velocity3dmps.z));
            gl.glRasterPos3f(1, 3, 0);
            glut.glutBitmapString(font, String.format("disp=%6.1f dispVel=%6.1f", c.getDisparity(), c.disparityVelocity));
        }
    // text for closest cluster only
    } catch (java.util.ConcurrentModificationException e) {
        // this is in case cluster list is modified by real time filter during rendering of clusters
        log.warning(e.getMessage());
    }
    gl.glPopMatrix();
}

19 Source : DisparityFilter.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    if (!isFilterEnabled()) {
        return;
    }
    GL2 gl = drawable.getGL().getGL2();
    if (gl == null) {
        return;
    }
    gl.glColor3f(1f, 1f, 1f);
    gl.glRasterPos3f(0f, 3f, 0f);
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "DisparityFilter search range: " + meanSearchRange);
}

19 Source : AutomaticReplayPlayer.java
with GNU Lesser General Public License v2.1
from SensorsINI

@Override
public void annotate(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glPushMatrix();
    String s = state.toString();
    gl.glScalef(.1f, .1f, 1);
    // float l=glut.glutStrokeLengthf(GLUT.STROKE_ROMAN,s);
    gl.glTranslatef(0, chip.getSizeY() * .8f, 0);
    gl.glLineWidth(3);
    gl.glColor3f(1, 0, 0);
    glut.glutStrokeString(GLUT.STROKE_ROMAN, s);
    gl.glPopMatrix();
    switch(state) {
        case Replay:
            // draw replay progress bar
            gl.glPushMatrix();
            gl.glColor3f(0, 0, 1);
            gl.glRectf(1, 1, (chip.getSizeX() * (float) currentReplayPosition) / numEventsRecorded, 3);
            gl.glPopMatrix();
            break;
        case Live:
        case Init:
    }
}

19 Source : TimestampImage3DDisplayMethod.java
with GNU Lesser General Public License v2.1
from SensorsINI

// TODO it doesn't make sense to redraw all data for each mouse drag transform change. All we should have to do is
// to change the projection matrix.
@Override
public void display(final GLAutoDrawable drawable) {
    // GL2 gl=setupGL(drawable);
    // AEChipRenderer renderer = (AEChipRenderer) (getChipCanvas().getRenderer());
    // log.info("display");
    final Chip2D chip = getChipCanvas().getChip();
    if (glut == null) {
        glut = new GLUT();
    }
    final GL2 gl = drawable.getGL().getGL2();
    if (gl == null) {
        log.warning("null GL context - not displaying");
        return;
    }
    {
        gl.glPushMatrix();
        gl.glClearColor(0, 0, 0, 0);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        if (useCubeEnabled) {
            if (!spikeListCreated) {
                spikeList = gl.glGenLists(1);
                gl.glNewList(spikeList, GL2.GL_COMPILE);
                {
                    // tobi make it a unit cube so we can see it from the side
                    gl.glScalef(1, 1, 1);
                    glut.glutSolidCube(1);
                    spikeListCreated = true;
                // gl.glRectf(.5f,.5f, .5f,.5f);
                }
                gl.glEndList();
            }
        }
        // rotate viewpoint
        // rotate viewpoint by angle deg around the upvector
        gl.glRotatef(getChipCanvas().getAngley(), 0, 1, 0);
        // rotate viewpoint by angle deg around the upvector
        gl.glRotatef(getChipCanvas().getAnglex(), 1, 0, 0);
        gl.glTranslatef(getChipCanvas().getOrigin3dx(), getChipCanvas().getOrigin3dy(), 0);
        // draw 3d axes
        gl.glColor3f(0, 0, 1);
        gl.glLineWidth(.4f);
        {
            gl.glBegin(GL.GL_LINES);
            gl.glVertex3f(0, 0, 0);
            gl.glVertex3f(chip.getSizeX(), 0, 0);
            gl.glVertex3f(0, 0, 0);
            gl.glVertex3f(0, chip.getSizeY(), 0);
            gl.glVertex3f(0, 0, 0);
            gl.glVertex3f(0, 0, chip.getMaxSize());
            gl.glEnd();
        }
        // render events
        // AEPacket2D ae = renderer.getAe();
        final EventPacket packet = (EventPacket) chip.getLastData();
        if (packet == null) {
            log.warning("null packet to render");
            gl.glPopMatrix();
            return;
        }
        final int n = packet.getSize();
        if (n == 0) {
            gl.glPopMatrix();
            return;
        }
        // if(ae==null || ae.getNumEvents()==0) return;
        // int n = ae.getNumEvents();
        final int t0 = packet.getFirstTimestamp();
        final int dt = packet.getDurationUs() + 1;
        // int t0 = ae.getFirstTimestamp();
        // int dt = ae.getLastTimestamp()-t0+1;
        float z;
        final float zfac = chip.getMaxSize();
        // int count=0;
        Iterator evItr = packet.iterator();
        if (packet instanceof ApsDvsEventPacket) {
            final ApsDvsEventPacket apsPacket = (ApsDvsEventPacket) packet;
            evItr = apsPacket.fullIterator();
            if ((config == null) && (chip != null) && (chip instanceof DavisChip)) {
                config = (DavisDisplayConfigInterface) chip.getBiasgen();
            }
            if (config != null) {
                displayEvents = config.isDisplayEvents();
                displayFrames = config.isDisplayFrames();
            }
        }
        while (evItr.hasNext()) {
            final BasicEvent ev = (BasicEvent) evItr.next();
            // Check if event needs to be rendered (APS/DVS).
            if (ev instanceof ApsDvsEvent) {
                final ApsDvsEvent apsEv = (ApsDvsEvent) ev;
                if ((!displayFrames && apsEv.isApsData()) || (!displayEvents && apsEv.isDVSEvent()) || apsEv.isImuSample()) {
                    continue;
                }
            }
            // z goes from 0 (oldest) to 1 (youngest)
            z = (float) (ev.timestamp - t0) / dt;
            {
                gl.glPushMatrix();
                // z goes from 0 (oldest) to 1 (youngest)
                z = (float) (ev.timestamp - t0) / dt;
                computeRGBFromZ(z);
                gl.glColor3fv(rgb, 0);
                if (useCubeEnabled) {
                    gl.glTranslatef(ev.x, ev.y, z * zfac);
                    gl.glCallList(spikeList);
                } else {
                    gl.glTranslatef(0, 0, z * zfac);
                    gl.glRectf(ev.x - .5f, ev.y - .5f, ev.x + .5f, ev.y + .5f);
                }
                gl.glPopMatrix();
            }
        }
        // draw axes labels x,y,t. See tutorial at http://jerome.jouvie.free.fr/OpenGl/Tutorials/Tutorial18.php
        final int font = GLUT.BITMAP_HELVETICA_18;
        {
            gl.glPushMatrix();
            // distance in pixels of text from endZoom of axis
            final int FS = 1;
            gl.glRasterPos3f(chip.getSizeX() + FS, 0, 0);
            glut.glutBitmapString(font, "x=" + chip.getSizeX());
            gl.glRasterPos3f(0, chip.getSizeY() + FS, 0);
            glut.glutBitmapString(font, "y=" + chip.getSizeY());
            // label time end value
            // gl.glRasterPos3f(0, -2 , chip.getMaxSize() + FS);
            // glut.glutBitmapCharacter(font, '0');
            gl.glRasterPos3f(0, 0, chip.getMaxSize() + FS);
            glut.glutBitmapString(font, "t=" + engFmt.format(dt * AEConstants.TICK_DEFAULT_US * 1e-6f) + "s");
            gl.glPopMatrix();
        }
        // log.info("done rendering");
        checkGLError(gl);
        gl.glPopMatrix();
    }
    displayStatusChangeText(drawable);
}

19 Source : TimestampImage3DDisplayMethod.java
with GNU Lesser General Public License v2.1
from SensorsINI

void checkGLError(final GL2 gl) {
    int error = gl.glGetError();
    int nerrors = 10;
    while ((error != GL.GL_NO_ERROR) && (nerrors-- != 0)) {
        if (glu == null) {
            glu = new GLU();
        }
        log.warning("GL error number " + error + " " + glu.gluErrorString(error));
        error = gl.glGetError();
    }
}

19 Source : SpaceTimeRollingEventDisplayMethod.java
with GNU Lesser General Public License v2.1
from SensorsINI

boolean checkGLError(final GL2 gl, String msg) {
    boolean r = false;
    int error = gl.glGetError();
    int nerrors = 10;
    while ((error != GL.GL_NO_ERROR) && (nerrors-- != 0)) {
        if (glu == null) {
            glu = new GLU();
        }
        StackTraceElement[] st = Thread.currentThread().getStackTrace();
        log.warning("GL error number " + error + " " + glu.gluErrorString(error) + "\n");
        new RuntimeException("GL error number " + error + " " + glu.gluErrorString(error)).printStackTrace();
        error = gl.glGetError();
        r = true;
    }
    return r;
}

19 Source : Histogram3dDisplayMethod.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 *  the 3-d histogram display.
 * Draws a 3-d histogram, where each bin corresponds to one element of collected rendered frame data from ChipRenderer.
 * This data is float[][][] array. First dimension is y, 2nd is x, 3rd is RGB 3 vector.
 * Each element is rendered as a box of height corresponding to element value.
 */
@Override
public void display(GLAutoDrawable drawable) {
    GL2 gl = setupGL(drawable).getGL2();
    float[] fr = getRenderer().getPixmapArray();
    if (fr == null) {
        return;
    }
    float gray = getRenderer().getGrayValue();
    gl.glClearColor(gray, gray, gray, 0f);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    // gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    // gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDisable(GL.GL_DEPTH_TEST);
    gl.glPushMatrix();
    {
        // rotate viewpoint
        // rotate viewpoint by angle deg around the upvector
        gl.glRotatef(getChipCanvas().getAngley(), 0, 1, 0);
        // rotate viewpoint by angle deg around the upvector
        gl.glRotatef(getChipCanvas().getAnglex(), 1, 0, 0);
        gl.glTranslatef(getChipCanvas().getOrigin3dx(), getChipCanvas().getOrigin3dy(), 0);
        // draw 3d axes
        gl.glColor3f(0, 0, 1);
        gl.glLineWidth(1f);
        gl.glBegin(GL2.GL_LINES);
        {
            gl.glVertex3f(0, 0, 0);
            gl.glVertex3f(chip.getSizeX(), 0, 0);
            gl.glVertex3f(0, 0, 0);
            gl.glVertex3f(0, chip.getSizeY(), 0);
            gl.glVertex3f(0, 0, 0);
            gl.glVertex3f(0, 0, chip.getMaxSize());
        }
        gl.glEnd();
        // draw axes labels x,y,#. See tutorial at http://jerome.jouvie.free.fr/OpenGl/Tutorials/Tutorial18.php
        int font = GLUT.BITMAP_HELVETICA_18;
        gl.glPushMatrix();
        // distance in pixels of text from endZoom of axis
        final int FS = 1;
        gl.glRasterPos3f(chip.getSizeX() + FS, 0, 0);
        glut.glutBitmapCharacter(font, 'X');
        gl.glRasterPos3f(0, chip.getSizeY() + FS, 0);
        glut.glutBitmapCharacter(font, 'Y');
        gl.glRasterPos3f(0, 0, chip.getMaxSize() + FS);
        glut.glutBitmapCharacter(font, '#');
        gl.glPopMatrix();
        try {
            // for(int i=0;i<fr.length;i++){
            // for(int j=0;j<fr[i].length;j++){
            // now iterate over the frame (fr)
            int ind = 0;
            for (int x = zoom.getStartPoint().x; x < zoom.getEndPoint().x; x++) {
                for (int y = zoom.getStartPoint().y; y < zoom.getEndPoint().y; y++) {
                    if ((fr[ind] == gray) && (fr[ind + 1] == gray) && (fr[ind + 2] == gray)) {
                        ind += 3;
                        continue;
                    }
                    float[] rgb = Arrays.copyOfRange(fr, ind, 3);
                    drawHistogramBoxes(gl, x, y, rgb);
                    ind += 3;
                }
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            log.warning("while drawing frame buffer");
            e.printStackTrace();
            // in case it was some other chip had set the zoom
            getChipCanvas().unzoom();
            gl.glPopMatrix();
        }
    }
    gl.glPopMatrix();
}

19 Source : Histogram3dDisplayMethod.java
with GNU Lesser General Public License v2.1
from SensorsINI

void drawHistogramBoxes(GL2 gl, int x, int y, float[] rgbValues) {
    float[] rgb = new float[3];
    int histScale = chip.getMaxSize();
    float g = getRenderer().getGrayValue();
    gl.glPushMatrix();
    {
        // centered on pixel
        gl.glTranslatef(x, y, 0f);
        AEChipRenderer.ColorMode colorMode = ((AEChipRenderer) getRenderer()).getColorMode();
        if (colorMode == AEChipRenderer.ColorMode.RedGreen) {
            for (int i = 0; i < 3; i++) {
                // rgb components of hist
                float c = rgbValues[i];
                if (c == g) {
                    continue;
                }
                c *= histScale;
                for (int j = 0; j < 3; j++) {
                    rgb[j] = 0;
                }
                rgb[i] = 1;
                gl.glBegin(GL2.GL_QUADS);
                gl.glColor3fv(rgb, 0);
                // draw squares for each RGB component offset in y direction
                float y0 = i / 3f, y1 = y0 + 0.3333f;
                // top
                gl.glVertex3f(0, y0, c);
                gl.glVertex3f(1, y0, c);
                gl.glVertex3f(1, y1, c);
                gl.glVertex3f(0, y1, c);
                gl.glEnd();
            }
        } else {
            float h = rgbValues[0] * histScale;
            for (int j = 0; j < 3; j++) {
                rgb[j] = 1;
            }
            gl.glBegin(GL2.GL_QUADS);
            // draw squares for each RGB component offset in y direction
            // CCW winding for all faces
            // top
            gl.glColor3fv(rgb, 0);
            gl.glVertex3f(0, 0, h);
            gl.glVertex3f(1, 0, h);
            gl.glVertex3f(1, 1, h);
            gl.glVertex3f(0, 1, h);
            // for(int j=0;j<3;j++){ rgb[j]=.5f;}
            // gl.glColor3fv(rgb,0);
            // 
            // //front
            // gl.glVertex3f(0,0,0);
            // gl.glVertex3f(1,0,0);
            // gl.glVertex3f(1,0,h);
            // gl.glVertex3f(0,0,h);
            // 
            // //right
            // gl.glVertex3f(1,0,0);
            // gl.glVertex3f(1,1,0);
            // gl.glVertex3f(1,1,h);
            // gl.glVertex3f(1,0,h);
            // 
            // //left
            // gl.glVertex3f(0,0,0);
            // gl.glVertex3f(0,0,h);
            // gl.glVertex3f(0,1,h);
            // gl.glVertex3f(0,1,0);
            // 
            // //back
            // gl.glVertex3f(0,1,0);
            // gl.glVertex3f(0,1,h);
            // gl.glVertex3f(1,1,h);
            // gl.glVertex3f(1,1,0);
            // 
            gl.glEnd();
        }
    }
    gl.glPopMatrix();
}

19 Source : EyeTarget.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Called by the drawable immediately after the OpenGL context is
 *     initialized. Can be used to perform one-time OpenGL
 *     initialization such as setup of lights and display lists. Note
 *     that this method may be called more than once if the underlying
 *     OpenGL context for the GLAutoDrawable is destroyed and
 *     recreated, for example if a GLCanvas is removed from the widget
 *     hierarchy and later added again.
 */
@Override
public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.setSwapInterval(1);
    gl.glShadeModel(GLLightingFunc.GL_FLAT);
    gl.glClearColor(0, 0, 0, 0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glLoadIdenreplacedy();
    gl.glRasterPos3f(0, 0, 0);
    gl.glColor3f(1, 1, 1);
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Initialized display");
    reval();
}

19 Source : EyeTarget.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Called by the drawable during the first repaint after the
 *     component has been resized. The client can update the viewport
 *     and view volume of the window appropriately, for example by a
 *     call to {@link com.jogamp.opengl.GL#glViewport}; note that for
 *     convenience the component has already called <code>glViewport(x,
 *     y, width, height)</code> when this method is called, so the
 *     client may not have to do anything in this method.
 */
/**
 * called on reshape of canvas. Sets the scaling for drawing pixels to the screen.
 */
@Override
public synchronized void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glLoadIdenreplacedy();
    gl.glViewport(0, 0, width, height);
}

19 Source : EyeTarget.java
with GNU Lesser General Public License v2.1
from SensorsINI

/**
 * Called by the drawable to initiate OpenGL rendering by the
 *     client. After all GLEventListeners have been notified of a
 *     display event, the drawable will swap its buffers if {@link
 *     GLAutoDrawable#setAutoSwapBufferMode setAutoSwapBufferMode} is
 *     enabled.
 */
@Override
public void display(GLAutoDrawable drawable) {
    target.update();
    GL2 gl = drawable.getGL().getGL2();
    gl.glClearColor(0, 0, 0, 0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    // very important to load idenreplacedy matrix here so this works after first resize!!!
    gl.glLoadIdenreplacedy();
    gl.glOrtho(0, drawable.getSurfaceWidth(), 0, drawable.getSurfaceHeight(), 10000, -10000);
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glPopMatrix();
    gl.glPushMatrix();
    gl.glColor3f(1, 1, 1);
    gl.glRectf(target.x() - SIZE, target.y() - SIZE, target.x() + SIZE, target.y() + SIZE);
    // gl.glColor3f(1,1,1);
    // gl.glTranslatef(target.x(),target.y(),0);
    // if(eyeQuad==null) eyeQuad = glu.gluNewQuadric();
    // glu.gluQuadricDrawStyle(eyeQuad,GLU.GLU_FILL);
    // glu.gluDisk(eyeQuad,0,5,16,1);
    gl.glPopMatrix();
}

See More Examples