Skip to content
Snippets Groups Projects
Commit 768196c1 authored by POLITO Guillermo Andres's avatar POLITO Guillermo Andres
Browse files

Adding Scaladocs to AER files

parent 6360fb25
Branches
No related tags found
No related merge requests found
......@@ -4,26 +4,31 @@ package fr.univ_lille.cristal.emeraude.n2s3.features.io.input
* Created by falezp on 26/07/16.
*/
import java.io.File
import java.io.FileInputStream
import java.io.EOFException
import java.io.FileOutputStream
import java.io.{EOFException, File, FileInputStream}
import java.nio.ByteBuffer
/**
* Represents an event of an AER input (e.g., a camera).
* An AER event possess the address where the event occurred (e.g., which pixel in the image) and the timestamp when this happened.
*/
case class AEREvent(address : Short, Timestamp : Int)
/**
* Reader of files in AER format.
* This reader assumes that events inside the file are 6 bytes long.
* Events are read in a buffered way in chunks of 64 events.
*
* Read events are returned as [[AEREvent]] objects with the address of the event in the file and the timestamp where it occurred.
*/
class AERFileReader(filename : String) {
private val eventSize = 6
private val chunkSize = 64
private val file = new File(filename)
private val eventNumber = file.length()/eventSize.toLong
private val reader = new FileInputStream(file).getChannel
private var cursor : Long = 0L
private val currentChunk = ByteBuffer.allocate(chunkSize*eventSize)
private var currentChunkSize = 0
......
......@@ -8,11 +8,17 @@ import java.io.File
import java.io.FileOutputStream
import java.nio.ByteBuffer
/**
* Writes [[AEREvent]]-like information to a file.
* @param filename
*/
class AERFileWriter(filename : String) {
private val file = new File(filename)
private val writer = new FileOutputStream(file, false).getChannel
def appendEvent(aEREvent: AEREvent) : Unit = this.appendEvent(aEREvent.address, aEREvent.Timestamp)
def appendEvent(address : Short, timestamp : Int) : Unit = {
val buffer = ByteBuffer.allocate(6)
buffer.putShort(address)
......
......@@ -71,6 +71,9 @@ class AERCochlea extends AERFormat {
}
}
/**
* Represents the input of an AER file to send to the simulation.
*/
case class AERInput(timestamp: Timestamp, address : Int) extends Input {
override def prefixTimestamp(prefix: Timestamp): this.type = {
AERInput(prefix+timestamp, address).asInstanceOf[this.type]
......@@ -80,16 +83,6 @@ case class AERInput(timestamp: Timestamp, address : Int) extends Input {
}
/*object FreeWay {
def input(filename: String, enableSpikeSign: Boolean = false) = {
new AERInputStream("data/aerdata/freeway.mat.dat")
.groupBy(x => x.timestamp)
.map(events => events.map{ event => Input(ShapelessSpike, event.timestamp, AERRetinaInputTransformation.transformAddress(event.destinationIndex, enableSpikeSign)) })
.repeat(8)
}
}*/
/**
* Reads AER files using jAER (jar file in lib directory).
* All the methods return an IndexedSeq[Event]. The timestamps are
......@@ -98,8 +91,7 @@ case class AERInput(timestamp: Timestamp, address : Int) extends Input {
* @author boulet
* @param filename: String, the name of the file to read from
*/
//TODO expliquer la relation entre AERInputStream AERInput
//TODO: expliquer la relation entre AERInputStream AERInput
class AERInputStream(filename: String, s : Shape, chunkSize : Int = 64) extends N2S3InputStream[InputSeq[AERInput]] with StreamTimestampsManager {
val aeis = new AEFileInputStream(new File(filename))
......@@ -137,15 +129,6 @@ class AERInputStream(filename: String, s : Shape, chunkSize : Int = 64) extends
}
}
/**
* @param n, the number of events to read
* @return sequence of events
*/
private def readEventsByNumber(n: Int) = {
eventsFromAEPacket(aeis.readPacketByNumber(n))
}
/**
* @param dt, the time interval in µs to read events from the last read event
* @return sequence of events
......@@ -206,20 +189,6 @@ class AERInputStream(filename: String, s : Shape, chunkSize : Int = 64) extends
}
}
private def peek() = {
if (this.peekEvent.isEmpty && aeis.position() < aeis.size() - 1 ){
try{
val read = eventsFromAEPacket(aeis.readPacketByNumber(1))
if (read.nonEmpty){
this.peekEvent = Some(read)
}
} catch {
case e: EOFException =>
}
}
this.peekEvent
}
/**
* return if we reach the end of the file
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment