jAER project on SourceForge

net.sf.jaer.eventprocessing
Class FilterChain

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<E>
              extended by java.util.LinkedList<EventFilter2D>
                  extended by net.sf.jaer.eventprocessing.FilterChain
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<EventFilter2D>, java.util.Collection<EventFilter2D>, java.util.Deque<EventFilter2D>, java.util.List<EventFilter2D>, java.util.Queue<EventFilter2D>

public class FilterChain
extends java.util.LinkedList<EventFilter2D>

A chain of EventFilter that serially filters or processes packets of AEPacket2D. An instance of this object can be passed to FilterFrame and is an instance field of e.g. AERetina. Filters know which chain they are part of and can find out what filters come before and afterwards, allowing them to enable or disable them according to their needs, e.g. NearestEventMotionFilter needs SimpleOrientationFilter to be enabled.

FilterChain fires the following PropertyChangeEvents

FilterChains should be constructed as in the following example taken from a filter:
         //build hierarchy
        FilterChain trackingFilterChain = new FilterChain(chip);
        EventFilter tracker=new RectangularClusterTracker(chip);
        EventFilter servoArm = new ServoArm(chip);
        EventFilter xYFilter = new XYTypeFilter(chip);
        EventFilter tableFilter=new GoalieTableFilter(chip);

        trackingFilterChain.add(new BackgroundActivityFilter(chip));
        trackingFilterChain.add(tableFilter);
        trackingFilterChain.add(tracker);
        trackingFilterChain.add(servoArm);
        setEnclosedFilterChain(trackingFilterChain); // labels enclosed filters as being enclosed
        tracker.setEnclosedFilter(xYFilter); // marks xYFilter as enclosed by tracker
        tracker.setEnclosed(true, this);    // tracker is enclosed by this
        servoArm.setEnclosed(true, this);   // same for servoArm
        xYFilter.setEnclosed(true, tracker); // but xYFilter is enclosed by tracker
 
Another, simpler, example is as follows, as part of an EventFilter's constructor:
        setEnclosedFilterChain(new FilterChain(chip)); // make a new FilterChain for this EventFilter
        RefractoryFilter rf=new RefractoryFilter(chip); // make a filter to go in the chain
        rf.setEnclosed(true, this);                     // set rf to be enclosed and inside this filter
        getEnclosedFilterChain().add(rf);               // add rf to this EventFilter's FilterChain
 

Author:
tobi
See Also:
Serialized Form

Nested Class Summary
static class FilterChain.ProcessingMode
          Filters can either be processed in the rendering or the data acquisition cycle.
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FilterChain(AEChip chip)
          Creates a new instance of FilterChain.
 
Method Summary
 boolean add(EventFilter2D filter)
          Adds a filter to the end of the chain.
 void contructPreferredFilters()
          Constructs the preferred filters for the FilterChain as stored in user Preferences.
 EventPacket filterPacket(EventPacket in)
          applies all the filters in the chain to the packet in the order of the enabled filters.
 EventFilter2D findFilter(java.lang.Class filterClass)
           
 FilterChain.ProcessingMode getProcessingMode()
           
 java.beans.PropertyChangeSupport getSupport()
          FilterChain fires the following PropertyChangeEvents processingmode - when the processing mode is changed
 int getTimeLimitMs()
           
 boolean isAnyFilterEnabled()
          Iterates over all filters and returns true if any filter is enabled.
 boolean isEnclosed()
          Is filter enclosed inside another filter?
 boolean isFilteringEnabled()
           
 boolean isMeasurePerformanceEnabled()
           
 boolean isTimedOut()
          Returns status of timeout of event processing time limit during filter processing.
 boolean isTimeLimitEnabled()
           
 boolean remove(EventFilter2D filter)
          remove the filter
 void reset()
          resets all the filters
 void setEnclosed(boolean enclosed, EventFilter enclosingFilter)
          Sets flag to show this instance is enclosed.
 void setFilteringEnabled(boolean b)
          Globally sets whether filters are applied in this FilterChain.
 void setMeasurePerformanceEnabled(boolean measurePerformanceEnabled)
           
 void setProcessingMode(FilterChain.ProcessingMode processingMode)
          Sets whether this chain is procesed in the acquisition or rendering thread.
 void setTimeLimitEnabled(boolean timeLimitEnabled)
          Enables/disables limit on processing time for packets.
 void setTimeLimitMs(int timeLimitMs)
          Set the time limit in ms for packet processing if time limiting is enabled.
 
Methods inherited from class java.util.LinkedList
add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, toArray, toArray
 
Methods inherited from class java.util.AbstractSequentialList
iterator
 
Methods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
 
Methods inherited from interface java.util.Deque
iterator
 

Constructor Detail

FilterChain

public FilterChain(AEChip chip)
Creates a new instance of FilterChain. Use <@link #contructPreferredFilters> to build the stored preferences for filters.

Parameters:
chip - the chip that uses this filter chain
Method Detail

reset

public void reset()
resets all the filters


filterPacket

public EventPacket filterPacket(EventPacket in)
applies all the filters in the chain to the packet in the order of the enabled filters. If timeLimitEnabled=true then the timeLimiter is started on the first packet. Any subsequent input iterator for events will then timeout when the time limit has been reached.

Parameters:
in - the input packet of events
Returns:
the resulting output.

findFilter

public EventFilter2D findFilter(java.lang.Class filterClass)
Parameters:
filterClass - the class to search for
Returns:
the first filter with class filterClass, or null if there is none

add

public boolean add(EventFilter2D filter)
Adds a filter to the end of the chain. Filters also need to have their enclosing state set manually: whether they are flagged as "enclosed" and who encloses them.

Specified by:
add in interface java.util.Collection<EventFilter2D>
Specified by:
add in interface java.util.Deque<EventFilter2D>
Specified by:
add in interface java.util.List<EventFilter2D>
Specified by:
add in interface java.util.Queue<EventFilter2D>
Overrides:
add in class java.util.LinkedList<EventFilter2D>
Parameters:
filter - the filter to add
Returns:
true
See Also:
)

remove

public boolean remove(EventFilter2D filter)
remove the filter

Returns:
true if successful

isTimeLimitEnabled

public boolean isTimeLimitEnabled()

setTimeLimitEnabled

public void setTimeLimitEnabled(boolean timeLimitEnabled)
Enables/disables limit on processing time for packets.


getTimeLimitMs

public int getTimeLimitMs()

setTimeLimitMs

public void setTimeLimitMs(int timeLimitMs)
Set the time limit in ms for packet processing if time limiting is enabled.


getProcessingMode

public FilterChain.ProcessingMode getProcessingMode()

setProcessingMode

public void setProcessingMode(FilterChain.ProcessingMode processingMode)
Sets whether this chain is procesed in the acquisition or rendering thread. For more real-time performance the data should be processed as it is acquired, not later when it is rendered.

Fires PropertyChangeEvent "processingmode"

See Also:
processingMode

isAnyFilterEnabled

public boolean isAnyFilterEnabled()
Iterates over all filters and returns true if any filter is enabled.

Returns:
true if any filter is enabled, false otherwise.

isMeasurePerformanceEnabled

public boolean isMeasurePerformanceEnabled()

setMeasurePerformanceEnabled

public void setMeasurePerformanceEnabled(boolean measurePerformanceEnabled)

setFilteringEnabled

public void setFilteringEnabled(boolean b)
Globally sets whether filters are applied in this FilterChain.

Parameters:
b - true to enable (default) or false to disable all filters

isFilteringEnabled

public boolean isFilteringEnabled()

contructPreferredFilters

public void contructPreferredFilters()
Constructs the preferred filters for the FilterChain as stored in user Preferences.


isTimedOut

public boolean isTimedOut()
Returns status of timeout of event processing time limit during filter processing.

Returns:
true if time limit is enabled and timeout occured during processing of last packet, false otherwise

isEnclosed

public boolean isEnclosed()
Is filter enclosed inside another filter?

Returns:
true if this filter is enclosed inside another

setEnclosed

public void setEnclosed(boolean enclosed,
                        EventFilter enclosingFilter)
Sets flag to show this instance is enclosed. If this flag is set to true, then preferences node is changed to a node unique for the enclosing filter class.

Parameters:
enclosingFilter - the filter that is enclosing this
enclosed - true if this filter is enclosed

getSupport

public java.beans.PropertyChangeSupport getSupport()
FilterChain fires the following PropertyChangeEvents


jAER project on SourceForge