Skip to content

Commit

Permalink
Merge master into jogl2.5
Browse files Browse the repository at this point in the history
Conflicts:
	nbproject/project.properties
  • Loading branch information
Tobi Delbruck authored and Tobi Delbruck committed Dec 19, 2023
2 parents 50c6fe5 + 1ae147e commit f30f58a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue, 19 Dec 2023 09:35:21 -0800
#Tue, 19 Dec 2023 10:16:15 -0800
annotation.processing.enabled=false
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
Expand Down
45 changes: 44 additions & 1 deletion src/net/sf/jaer/eventprocessing/filter/EventRateEstimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*/
package net.sf.jaer.eventprocessing.filter;

import java.beans.PropertyChangeEvent;
import net.sf.jaer.Description;
import net.sf.jaer.DevelopmentStatus;
import net.sf.jaer.aemonitor.AEConstants;
import net.sf.jaer.chip.AEChip;
import net.sf.jaer.event.BasicEvent;
import net.sf.jaer.event.EventPacket;
import net.sf.jaer.eventprocessing.EventFilter2D;
import net.sf.jaer.util.filter.LowpassFilter;
import net.sf.jaer.graphics.AEViewer;

/**
* Estimates event rate from the input stream.
Expand Down Expand Up @@ -39,23 +40,37 @@ public class EventRateEstimator extends EventFilter2D {
private float maxRate = getFloat("maxRate", 10e6f);
private float filteredRate = 0, instantaneousRate = 0;
private float eventRateTauMs = getFloat("eventRateTauMs", 100);
private float biasChangePauseS = getFloat("biasChangePauseS", .5f);
/* Event rate estimates are sent to observers this many times per tau */
protected int UPDATE_RATE_TAU_DIVIDER = 1;
private int numEventsSinceLastUpdate = 0;
private int numEventsInLastPacket = 0;
private boolean biasChanged=false;
private long biasChangedTimeMs=0;

public EventRateEstimator(AEChip chip) {
super(chip);
// filter.setTauMs(eventRateTauMs);
setPropertyTooltip("eventRateTauMs", "lowpass filter time constant in ms for measuring event rate");
setPropertyTooltip("maxRate", "maximum estimated rate, which is used for zero ISIs between packets");
setPropertyTooltip("biasChangePauseS", "time in seconds to pause measurement after detected change of any bias (0 to disable)");
}

@Override
synchronized public EventPacket<? extends BasicEvent> filterPacket(EventPacket<? extends BasicEvent> in) {
if (in == null || in.getSize() == 0) {
return in; // if there are no events, don't touch values since we don't have a new update time
}
if (biasChanged && this.biasChangePauseS>0) {
final long timeSinceBiasChangeMs = System.currentTimeMillis() - biasChangedTimeMs;
if (timeSinceBiasChangeMs < 1000 * this.biasChangePauseS) {
lastComputeTimestamp = in.getLastTimestamp();
// System.out.println(String.format("timeSinceBiasChangeMs=%d < %.0f",timeSinceBiasChangeMs,1000*this.biasChangePauseS));
return in;
} else {
biasChanged = false;
}
}
numEventsInLastPacket = 0;
for (BasicEvent e : in) {
addEvent(e, in);
Expand Down Expand Up @@ -115,13 +130,25 @@ public void resetFilter() {
@Override
public void initFilter() {
resetFilter();
if (chip.getAeViewer() != null) {
chip.getAeViewer().getSupport().addPropertyChangeListener(AEViewer.EVENT_CHIP, this);
chip.getBiasgen().getSupport().addPropertyChangeListener(this);
}
}

@Override
public String toString() {
return super.toString() + " rate=" + filteredRate;
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() instanceof AEChip) {
biasChanged = true;
biasChangedTimeMs=System.currentTimeMillis();
}
}

public float getEventRateTauMs() {
return eventRateTauMs;
}
Expand Down Expand Up @@ -183,4 +210,20 @@ public void setMaxRate(float maxRate) {
public int getNumEventsInLastPacket() {
return numEventsInLastPacket;
}

/**
* @return the biasChangePauseS
*/
public float getBiasChangePauseS() {
return biasChangePauseS;
}

/**
* @param biasChangePauseS the biasChangePauseS to set
*/
synchronized public void setBiasChangePauseS(float biasChangePauseS) {
this.biasChangePauseS = biasChangePauseS;
putFloat("biasChangePauseS",biasChangePauseS);
// log.info(String.format("Set biasChangePauseS=%.3fs",this.biasChangePauseS));
}
}
20 changes: 19 additions & 1 deletion src/net/sf/jaer/eventprocessing/filter/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class Info extends EventFilter2D implements FrameAnnotater, PropertyChang
// volatile private float eventRateMeasured = 0; // volatile, also shared
private boolean addedViewerPropertyChangeListener = false; // need flag because viewer doesn't exist on creation
private boolean eventRate = getBoolean("eventRate", true);
private boolean eventRatePerPixel = getBoolean("eventRatePerPixel", false);
private volatile boolean resetTimeEnabled = false; // user for doResetTime
private boolean resetTimeOnRewind = getBoolean("resetTimeOnRewind", false);

Expand Down Expand Up @@ -391,6 +392,7 @@ public Info(AEChip chip) {
setPropertyTooltip("eventRateScaleMax", "scale event rates to this maximum");
setPropertyTooltip("timeScaling", "shows time scaling relative to real time");
setPropertyTooltip("eventRate", "shows average event rate");
setPropertyTooltip("eventRatePerPixel", "shows average event rate per pixel (selected) or total (unselected). Set eventRateScaleMax to scale bars.");
setPropertyTooltip("eventRateSigned", "uses signed event rate for ON positive and OFF negative");
setPropertyTooltip("eventRateTauMs", "lowpass time constant in ms for filtering event rate");
setPropertyTooltip("showRateTrace", "shows a historical trace of event rate");
Expand Down Expand Up @@ -798,7 +800,8 @@ private void drawEventRateBars(GLAutoDrawable drawable) {
// and multiply by number of pixels to get string length in screen pixels.
float sw = (glut.glutBitmapLength(font, s) / w) * sx;
glut.glutBitmapString(font, s);
gl.glRectf(xpos + sw, bary + barh, xpos + sw + ((totalRate * sx) / getEventRateScaleMax()), bary);
float rate=isEventRatePerPixel()? perPixelRate:totalRate;
gl.glRectf(xpos + sw, bary + barh, xpos + sw + ((rate * sx) / getEventRateScaleMax()), bary);
}
gl.glPopMatrix();

Expand Down Expand Up @@ -1059,4 +1062,19 @@ public void setMeasureSparsity(boolean measureSparsity) {
putBoolean("measureSparsity", measureSparsity);
}

/**
* @return the eventRatePerPixel
*/
public boolean isEventRatePerPixel() {
return eventRatePerPixel;
}

/**
* @param eventRatePerPixel the eventRatePerPixel to set
*/
public void setEventRatePerPixel(boolean eventRatePerPixel) {
this.eventRatePerPixel = eventRatePerPixel;
putBoolean("eventRatePerPixel", eventRatePerPixel);
}

}

0 comments on commit f30f58a

Please sign in to comment.