public class SpotCollection extends Object implements MultiThreaded
SortedMap
we use to store the
spots contained in each frame with a few utility methods.
Internally we rely on ConcurrentSkipListMap to allow concurrent access without clashes.
This class is MultiThreaded
. There are a few processes that can
benefit from multithreaded computation (filter(Collection)
,
filter(FeatureFilter)
Modifier and Type | Field and Description |
---|---|
static Double |
ONE |
static String |
VISIBILITY |
static Double |
ZERO |
Constructor and Description |
---|
SpotCollection()
Construct a new empty spot collection.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Spot spot,
Integer frame)
Adds the given spot to this collection, at the specified frame, and mark
it as visible.
|
void |
clear()
Removes all the content from this collection.
|
void |
crop()
Remove all the non-visible spots of this collection.
|
void |
filter(Collection<FeatureFilter> filters)
Filters out the content of this collection using the specified
FeatureFilter collection. |
void |
filter(FeatureFilter featurefilter)
Filters out the content of this collection using the specified
FeatureFilter . |
Integer |
firstKey()
Returns the first (lowest) frame currently in this collection.
|
static SpotCollection |
fromCollection(Iterable<Spot> spots)
Creates a new
SpotCollection containing only the specified spots. |
static SpotCollection |
fromMap(Map<Integer,Set<Spot>> source)
Creates a new
SpotCollection from a copy of the specified map of
sets. |
Spot |
getClosestSpot(Spot location,
int frame,
boolean visibleSpotsOnly)
Returns the closest
Spot to the given location (encoded as a
Spot), contained in the frame frame . |
int |
getNSpots(boolean visibleSpotsOnly)
Returns the total number of spots in this collection, over all frames.
|
int |
getNSpots(int frame,
boolean visibleSpotsOnly)
Returns the number of spots at the given frame.
|
int |
getNumThreads() |
Spot |
getSpotAt(Spot location,
int frame,
boolean visibleSpotsOnly)
Returns the
Spot at the given location (encoded as a Spot),
contained in the frame frame . |
Iterable<Spot> |
iterable(boolean visibleSpotsOnly)
A convenience methods that returns an
Iterable wrapper for this
collection as a whole. |
Iterable<Spot> |
iterable(int frame,
boolean visibleSpotsOnly)
A convenience methods that returns an
Iterable wrapper for a
specific frame of this spot collection. |
Iterator<Spot> |
iterator(boolean visibleSpotsOnly)
Return an iterator that iterates over all the spots contained in this
collection.
|
Iterator<Spot> |
iterator(Integer frame,
boolean visibleSpotsOnly)
Return an iterator that iterates over the spots in the specified frame.
|
NavigableSet<Integer> |
keySet()
Returns a NavigableSet view of the frames contained in this collection.
|
Integer |
lastKey()
Returns the last (highest) frame currently in this collection.
|
void |
put(int frame,
Collection<Spot> spots)
Stores the specified spots as the content of the specified frame.
|
boolean |
remove(Spot spot,
Integer frame)
Removes the given spot from this collection, at the specified frame.
|
Spot |
search(int ID)
Retrieves and returns the
Spot object in this collection with the
specified ID. |
void |
setNumThreads() |
void |
setNumThreads(int numThreads) |
void |
setVisible(boolean visible)
Marks all the content of this collection as visible or invisible.
|
String |
toString() |
public static final Double ZERO
public static final Double ONE
public static final String VISIBILITY
public Spot search(int ID)
Spot
object in this collection with the
specified ID. Returns null
if the spot cannot be found. All
spots, visible or not, are searched for.ID
- the ID to look for.null
if this spot
does not exist or does not belong to this collection.public void add(Spot spot, Integer frame)
If the frame does not exist yet in the collection, it is created and
added. Upon adding, the added spot has its feature Spot.FRAME
updated with the passed frame value.
spot
- the spot to add.frame
- the frame to add it to.public boolean remove(Spot spot, Integer frame)
If the spot frame collection does not exist yet, nothing is done and
false
is returned. If the spot cannot be found in the frame
content, nothing is done and false
is returned.
spot
- the spot to remove.frame
- the frame to remove it from.true
if the spot was succesfully removed.public void setVisible(boolean visible)
visible
- if true, all spots will be marked as visible.public final void filter(FeatureFilter featurefilter)
FeatureFilter
. Spots that are filtered out are marked as
invisible, and visible otherwise.featurefilter
- the filter to use.public final void filter(Collection<FeatureFilter> filters)
FeatureFilter
collection. Spots that are filtered out are marked
as invisible, and visible otherwise. To be marked as visible, a spot must
pass all of the specified filters (AND chaining).filters
- the filter collection to use.public final Spot getClosestSpot(Spot location, int frame, boolean visibleSpotsOnly)
Spot
to the given location (encoded as a
Spot), contained in the frame frame
. If the frame has no
spot, return null
.location
- the location to search for.frame
- the frame to inspect.visibleSpotsOnly
- if true, will only search though visible spots. If false, will
search through all spots.public final Spot getSpotAt(Spot location, int frame, boolean visibleSpotsOnly)
Spot
at the given location (encoded as a Spot),
contained in the frame frame
. A spot is returned only
if there exists a spot such that the given location is within the spot
radius. Otherwise null
is returned.location
- the location to search for.frame
- the frame to inspect.visibleSpotsOnly
- if true, will only search though visible spots. If false, will
search through all spots.null
is such a
spots cannot be found.public final int getNSpots(boolean visibleSpotsOnly)
visibleSpotsOnly
- if true, will only count visible spots. If false count all
spots.public int getNSpots(int frame, boolean visibleSpotsOnly)
frame
- the frame.visibleSpotsOnly
- if true, will only count visible spots. If false count all
spots.public Iterator<Spot> iterator(boolean visibleSpotsOnly)
visibleSpotsOnly
- if true, the returned iterator will only iterate through
visible spots. If false, it will iterate over all spots.public Iterator<Spot> iterator(Integer frame, boolean visibleSpotsOnly)
visibleSpotsOnly
- if true, the returned iterator will only iterate through
visible spots. If false, it will iterate over all spots.frame
- the frame to iterate over.public Iterable<Spot> iterable(boolean visibleSpotsOnly)
Iterable
wrapper for this
collection as a whole.visibleSpotsOnly
- if true, the iterable will contains only visible spots.
Otherwise, it will contain all the spots.public Iterable<Spot> iterable(int frame, boolean visibleSpotsOnly)
Iterable
wrapper for a
specific frame of this spot collection. The iterable is backed-up by the
actual collection content, so modifying it can have unexpected results.visibleSpotsOnly
- if true, the iterable will contains only visible spots of the
specified frame. Otherwise, it will contain all the spots of
the specified frame.frame
- the frame of the content the returned iterable will wrap.public void put(int frame, Collection<Spot> spots)
Spot.FRAME
is
updated to be the specified frame.frame
- the frame to store these spots at. The specified spots replace
the previous content of this frame, if any.spots
- the spots to store.public Integer firstKey()
public Integer lastKey()
public NavigableSet<Integer> keySet()
The view's iterator is a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
public void clear()
public void setNumThreads()
setNumThreads
in interface MultiThreaded
public void setNumThreads(int numThreads)
setNumThreads
in interface MultiThreaded
public int getNumThreads()
getNumThreads
in interface MultiThreaded
public void crop()
public static SpotCollection fromCollection(Iterable<Spot> spots)
SpotCollection
containing only the specified spots.
Their frame origin is retrieved from their Spot.FRAME
feature, so
it must be set properly for all spots. All the spots of the new
collection have the same visibility that the one they carry.spots
- the spot collection to build from.SpotCollection
instance.public static SpotCollection fromMap(Map<Integer,Set<Spot>> source)
SpotCollection
from a copy of the specified map of
sets. The spots added this way are completely untouched. In particular,
their VISIBILITY
feature is left untouched, which makes this
method suitable to de-serialize a SpotCollection
.source
- the map to buidl the spot collection from.Copyright © 2015–2021 Fiji. All rights reserved.