<commit_before>/*
 * RetinaCanvas.java
 *
 * Created on January 9, 2006, 6:50 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ch.unizh.ini.jaer.chip.cochlea;


import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;

import net.sf.jaer.chip.AEChip;
import net.sf.jaer.event.EventPacket;
import net.sf.jaer.event.TypedEvent;
import net.sf.jaer.graphics.AEChipRenderer;
import net.sf.jaer.graphics.ChipCanvas;
import net.sf.jaer.graphics.DisplayMethod;
import net.sf.jaer.graphics.DisplayMethod2D;

import com.jogamp.opengl.util.gl2.GLUT;

/**
 * Shows events from stereo cochlea as a rastergram. Each packet is painted to the right of previous ones. The screen is used as the memory.
 *When the time reaches the right side, it resets to the left and the screen is cleared. The timescale is set by the ChipRenderer colorScale, which the user
 *can set with the UP/DOWN arrows buttons. It is set so that the entire width of the screen is a certain number of seconds.
 * @author tobi
 */
public class RollingCochleaGramDisplayMethod extends DisplayMethod implements DisplayMethod2D, HasSelectedCochleaChannel {

        public static final String EVENT_SCREEN_CLEARED="RollingCochleaGramDisplayMethod.EVENT_SCREEN_CLEARED";

	/**
	 * Creates a new instance of CochleaGramDisplayMethod
	 *
	 * @param c the canvas we are drawing on
	 */
	public RollingCochleaGramDisplayMethod(ChipCanvas c) {
		super(c);
	}
	final float rasterWidth = 0.003f; // width of screen;
	final int BORDER = 50; // pixels
	protected int startTime = 0; // the time (in timestamp units) that the strip starts at currently; is updated when chart reaches timeWidthUs
	protected boolean clearScreenEnabled = true; // set by rendering when it is time to resetart the strip chart because time has passed right edge
	int font = GLUT.BITMAP_HELVETICA_18;
	int oldColorScale = 0;
	boolean hasBlend = false;
	boolean hasBlendChecked = false;
	/** Set by rendering to total width in us time of current strip chart */
	protected float timeWidthUs; // set horizontal scale so that we can just use relative timestamp for x
	/** The selected channel is displayed by a marker line in the display. This feature is used to select channels in the Equalizer. */
	protected int selectedChannel=-1;

	private int prevSelectedChannel=-1;
	/** set by rendering so that 1 unit drawing scale draws to right side, 0 to left during rendering, using scaling as in
    <pre>
    drawTimeScale = (drawable.getWidth() / timeWidthUs); // scale horizontal is draw
    gl.glScalef(drawTimeScale, yScale, 1);
    </pre>
	 */
	protected float drawTimeScale;

	/** displays individual events as cochleagram
	 * @param drawable the drawable passed in by OpenGL
	 */
	@Override
	public void display(GLAutoDrawable drawable) {
		AEChipRenderer renderer = (AEChipRenderer) getChipCanvas().getRenderer();
		int ntaps = chip.getSizeX();
		EventPacket ae = (EventPacket) chip.getLastData();
		if ((ae == null) || ae.isEmpty()) {
			return;
		}
		int t0 = ae.getFirstTimestamp();

		GL2 gl = drawable.getGL().getGL2();
		gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
		gl.glLoadIdentity(); // very important to load identity matrix here so this works after first resize!!!
		gl.glOrtho(-BORDER, drawable.getSurfaceWidth() + BORDER, -BORDER, drawable.getSurfaceHeight() + BORDER, 10000, -10000);
		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
		// blend may not be available depending on graphics mode or opengl version.
		if (!hasBlendChecked) {
			hasBlendChecked = true;
			String glExt = gl.glGetString(GL.GL_EXTENSIONS);
			if (glExt.indexOf("GL_EXT_blend_color") != -1) {
				hasBlend = true;
			}
		}
		if (hasBlend) {
			try {
				gl.glEnable(GL.GL_BLEND);
				gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
				gl.glBlendEquation(GL.GL_FUNC_ADD);
			} catch (GLException e) {
				log.warning("tried to use glBlend which is supposed to be available but got following exception");
				gl.glDisable(GL.GL_BLEND);
				e.printStackTrace();
				hasBlend = false;
			}
		}
		gl.glLoadIdentity();
		// translate origin to this point
		gl.glTranslatef(0, 0, 0);
		// scale everything by rastergram scale
		float yScale = (drawable.getSurfaceHeight()) / (float) ntaps;// scale vertical is draableHeight/numPixels
		// timewidth comes from render contrast setting
		// width starts with colorScale=1 to be the standard refresh rate
		// so that a raster will refresh every frame and reduces by powers of two
		int colorScale = getRenderer().getColorScale();
		if (colorScale != oldColorScale) {
			clearScreenEnabled = true;
		}
		oldColorScale = colorScale;
		int frameRate = 60; // hz
		if (chip instanceof AEChip) {
			frameRate = ((AEChip) chip).getAeViewer().getFrameRate();
		}
		timeWidthUs = (1e6f / frameRate) * (1 << colorScale); // set horizontal scale so that we can just use relative timestamp for x
		drawTimeScale = (drawable.getSurfaceWidth() / timeWidthUs); // scale horizontal is draw<commit_msg>refactored for getDesiredFrameRate in AEViewer<commit_after>/*
 * RetinaCanvas.java
 *
 * Created on January 9, 2006, 6:50 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ch.unizh.ini.jaer.chip.cochlea;


import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;

import net.sf.jaer.chip.AEChip;
import net.sf.jaer.event.EventPacket;
import net.sf.jaer.event.TypedEvent;
import net.sf.jaer.graphics.AEChipRenderer;
import net.sf.jaer.graphics.ChipCanvas;
import net.sf.jaer.graphics.DisplayMethod;
import net.sf.jaer.graphics.DisplayMethod2D;

import com.jogamp.opengl.util.gl2.GLUT;

/**
 * Shows events from stereo cochlea as a rastergram. Each packet is painted to the right of previous ones. The screen is used as the memory.
 *When the time reaches the right side, it resets to the left and the screen is cleared. The timescale is set by the ChipRenderer colorScale, which the user
 *can set with the UP/DOWN arrows buttons. It is set so that the entire width of the screen is a certain number of seconds.
 * @author tobi
 */
public class RollingCochleaGramDisplayMethod extends DisplayMethod implements DisplayMethod2D, HasSelectedCochleaChannel {

        public static final String EVENT_SCREEN_CLEARED="RollingCochleaGramDisplayMethod.EVENT_SCREEN_CLEARED";

	/**
	 * Creates a new instance of CochleaGramDisplayMethod
	 *
	 * @param c the canvas we are drawing on
	 */
	public RollingCochleaGramDisplayMethod(ChipCanvas c) {
		super(c);
	}
	final float rasterWidth = 0.003f; // width of screen;
	final int BORDER = 50; // pixels
	protected int startTime = 0; // the time (in timestamp units) that the strip starts at currently; is updated when chart reaches timeWidthUs
	protected boolean clearScreenEnabled = true; // set by rendering when it is time to resetart the strip chart because time has passed right edge
	int font = GLUT.BITMAP_HELVETICA_18;
	int oldColorScale = 0;
	boolean hasBlend = false;
	boolean hasBlendChecked = false;
	/** Set by rendering to total width in us time of current strip chart */
	protected float timeWidthUs; // set horizontal scale so that we can just use relative timestamp for x
	/** The selected channel is displayed by a marker line in the display. This feature is used to select channels in the Equalizer. */
	protected int selectedChannel=-1;

	private int prevSelectedChannel=-1;
	/** set by rendering so that 1 unit drawing scale draws to right side, 0 to left during rendering, using scaling as in
    <pre>
    drawTimeScale = (drawable.getWidth() / timeWidthUs); // scale horizontal is draw
    gl.glScalef(drawTimeScale, yScale, 1);
    </pre>
	 */
	protected float drawTimeScale;

	/** displays individual events as cochleagram
	 * @param drawable the drawable passed in by OpenGL
	 */
	@Override
	public void display(GLAutoDrawable drawable) {
		AEChipRenderer renderer = (AEChipRenderer) getChipCanvas().getRenderer();
		int ntaps = chip.getSizeX();
		EventPacket ae = (EventPacket) chip.getLastData();
		if ((ae == null) || ae.isEmpty()) {
			return;
		}
		int t0 = ae.getFirstTimestamp();

		GL2 gl = drawable.getGL().getGL2();
		gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
		gl.glLoadIdentity(); // very important to load identity matrix here so this works after first resize!!!
		gl.glOrtho(-BORDER, drawable.getSurfaceWidth() + BORDER, -BORDER, drawable.getSurfaceHeight() + BORDER, 10000, -10000);
		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
		// blend may not be available depending on graphics mode or opengl version.
		if (!hasBlendChecked) {
			hasBlendChecked = true;
			String glExt = gl.glGetString(GL.GL_EXTENSIONS);
			if (glExt.indexOf("GL_EXT_blend_color") != -1) {
				hasBlend = true;
			}
		}
		if (hasBlend) {
			try {
				gl.glEnable(GL.GL_BLEND);
				gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
				gl.glBlendEquation(GL.GL_FUNC_ADD);
			} catch (GLException e) {
				log.warning("tried to use glBlend which is supposed to be available but got following exception");
				gl.glDisable(GL.GL_BLEND);
				e.printStackTrace();
				hasBlend = false;
			}
		}
		gl.glLoadIdentity();
		// translate origin to this point
		gl.glTranslatef(0, 0, 0);
		// scale everything by rastergram scale
		float yScale = (drawable.getSurfaceHeight()) / (float) ntaps;// scale vertical is draableHeight/numPixels
		// timewidth comes from render contrast setting
		// width starts with colorScale=1 to be the standard refresh rate
		// so that a raster will refresh every frame and reduces by powers of two
		int colorScale = getRenderer().getColorScale();
		if (colorScale != oldColorScale) {
			clearScreenEnabled = true;
		}
		oldColorScale = colorScale;
		int frameRate = 60; // hz
		if (chip instanceof AEChip) {
			frameRate = ((AEChip) chip).getAeViewer().getDesiredFrameRate();
		}
		timeWidthUs = (1e6f / frameRate) * (1 << colorScale); // set horizontal scale so that we can just use relative timestamp for x
		drawTimeScale = (drawable.getSurfaceWidth() / timeWidthUs); // scale horizontal is draw
{'fraction_non_alphanumeric': 0.09234059097978227, 'fraction_numerical': 0.009720062208398134, 'mean_word_length': 4.056019656019656, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6721980', 'n_tokens_mistral': 3448, 'n_tokens_neox': 3158, 'n_words': 1079}