OSVR-Core
Classes | Public Types | Public Member Functions | List of all members
osvr::vbtracker::AssignMeasurementsToLeds Class Reference

Public Types

using LedAndMeasurement = std::pair< Led &, LedMeasurement const & >
 
using LedMeasDistance = std::tuple< std::size_t, std::size_t, float >
 
using HeapValueType = LedMeasDistance
 
using HeapType = std::vector< HeapValueType >
 
using size_type = HeapType::size_type
 

Public Member Functions

 AssignMeasurementsToLeds (LedGroup &leds, LedMeasurementVec const &measurements, const std::size_t numBeacons, float blobMoveThresh, bool verbose=false)
 
void populateStructures ()
 Must call first, and only once. More...
 
size_type discardInvalidEntries (bool verbose=false)
 Discards invalid entries (those where either the LED or the measurement, or both, have already been assigned) from the heap, and returns the count of entries so discarded. More...
 
bool resumbitMeasurement (LedMeasurement const &meas)
 In case a measurement update goes bad, we can try to "un-mark" a measurement as consumed. More...
 
bool hasMoreMatches (bool verbose=false)
 Searches the heap, discarding now-invalid entries, until it finds an entry where both the LED and the measurement are unclaimed, or it runs out of entries. More...
 
LedAndMeasurement getMatch (bool verbose=false)
 Requires that hasMoreMatches() has been run and returns true. More...
 
bool haveMadeMaxMatches () const
 Have we made as many matches as we possibly can? (that is, the minimum of the number of LED objects and the number of measurements) More...
 
size_type maxMatches () const
 The maximum number of matches theoretically achievable with this input: the minimum of the number of LED objects and the number of measurements.
 
bool empty () const
 Is our heap of possibilities empty? More...
 
size_type size () const
 Entries in the heap of possibilities. More...
 
size_type theoreticalMaxSize () const
 This is the size it could have potentially been, had all LEDs been within the distance threshold. More...
 
double heapSizeFraction () const
 The fraction of the theoretical max that the size is. More...
 
size_type numUnclaimedLedObjects () const
 
void eraseUnclaimedLedObjects (bool verbose=false)
 
size_type numUnclaimedMeasurements () const
 
template<typename F >
void forEachUnclaimedMeasurement (F &&op)
 
size_type numCompletedMatches () const
 

Member Function Documentation

§ discardInvalidEntries()

size_type osvr::vbtracker::AssignMeasurementsToLeds::discardInvalidEntries ( bool  verbose = false)
inline

Discards invalid entries (those where either the LED or the measurement, or both, have already been assigned) from the heap, and returns the count of entries so discarded.

Great, we found one!

§ empty()

bool osvr::vbtracker::AssignMeasurementsToLeds::empty ( ) const
inline

Is our heap of possibilities empty?

Not terribly harmful here, just illogical, so assert instead of unconditional check and throw.

§ eraseUnclaimedLedObjects()

void osvr::vbtracker::AssignMeasurementsToLeds::eraseUnclaimedLedObjects ( bool  verbose = false)
inline

already used

§ forEachUnclaimedMeasurement()

template<typename F >
void osvr::vbtracker::AssignMeasurementsToLeds::forEachUnclaimedMeasurement ( F &&  op)
inline

already used

Apply the operation.

§ getMatch()

LedAndMeasurement osvr::vbtracker::AssignMeasurementsToLeds::getMatch ( bool  verbose = false)
inline

Requires that hasMoreMatches() has been run and returns true.

Mark that we've used this LED and measurement.

Postcondition check - shouldn't be valid anymore, we just consumed it.

Now, remove this entry from the heap.

Count it

and return the reward.

§ hasMoreMatches()

bool osvr::vbtracker::AssignMeasurementsToLeds::hasMoreMatches ( bool  verbose = false)
inline

Searches the heap, discarding now-invalid entries, until it finds an entry where both the LED and the measurement are unclaimed, or it runs out of entries.

Early out: We've already matched up all of one type or another.

§ haveMadeMaxMatches()

bool osvr::vbtracker::AssignMeasurementsToLeds::haveMadeMaxMatches ( ) const
inline

Have we made as many matches as we possibly can? (that is, the minimum of the number of LED objects and the number of measurements)

Not terribly harmful here, just illogical, so assert instead of unconditional check and throw.

§ heapSizeFraction()

double osvr::vbtracker::AssignMeasurementsToLeds::heapSizeFraction ( ) const
inline

The fraction of the theoretical max that the size is.

Not terribly harmful here, just illogical, so assert instead of unconditional check and throw.

§ populateStructures()

void osvr::vbtracker::AssignMeasurementsToLeds::populateStructures ( )
inline

Must call first, and only once.

Clean up LEDs and populate their ref vector.

Populate the measurement ref vector.

Do the O(n * m) distance computation to populate the vector that will become our min-heap.

WARNING: watch the order of arguments to this function, since the type of the indices is identical...

Turn that vector into our min-heap.

More efficient to do this one-time 3N=O(n) operation, than repeatedly push_heap (2log(N)=O(log n)) as we go, because:

  • we don't need the heap property until we've completed processing all the input (so push_heap gives us no benefit there)
  • the max number of comparisons, by the requirements of the standard, are lower (and linear) and stay lower for the make_heap approach for a heap size of > 5.

§ resumbitMeasurement()

bool osvr::vbtracker::AssignMeasurementsToLeds::resumbitMeasurement ( LedMeasurement const &  meas)
inline

In case a measurement update goes bad, we can try to "un-mark" a measurement as consumed.

Todo:
do we throw a logic error here?

Un-count the match.

Restore the entry in the refs table.

§ size()

size_type osvr::vbtracker::AssignMeasurementsToLeds::size ( ) const
inline

Entries in the heap of possibilities.

Not terribly harmful here, just illogical, so assert instead of nconditional check and throw.

§ theoreticalMaxSize()

size_type osvr::vbtracker::AssignMeasurementsToLeds::theoreticalMaxSize ( ) const
inline

This is the size it could have potentially been, had all LEDs been within the distance threshold.

(O(n m))


The documentation for this class was generated from the following file: