SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AveragedQuat4f Class Reference

#include <CVTrackedArucoCube.h>

Public Member Functions

 AveragedQuat4f (int numValues, SLQuat4f initValue)
 
void init (int numValues, SLQuat4f initValue)
 Initializes the average value array to a given value. More...
 
void set (SLQuat4f value)
 Sets the current value in the value array and builds the average. More...
 
SLQuat4f average ()
 
size_t size ()
 

Private Attributes

float _oneOverNumValues {}
 multiplier instead of divider More...
 
vector< SLQuat4f_values
 value array More...
 
int _currentValueIndex {}
 current value index within _values More...
 
SLQuat4f _average
 average value More...
 

Detailed Description

Definition at line 20 of file CVTrackedArucoCube.h.

Constructor & Destructor Documentation

◆ AveragedQuat4f()

AveragedQuat4f::AveragedQuat4f ( int  numValues,
SLQuat4f  initValue 
)
inline

Definition at line 23 of file CVTrackedArucoCube.h.

24  {
25  init(numValues, initValue);
26  }
void init(int numValues, SLQuat4f initValue)
Initializes the average value array to a given value.

Member Function Documentation

◆ average()

SLQuat4f AveragedQuat4f::average ( )
inline

Definition at line 76 of file CVTrackedArucoCube.h.

76 { return _average; }
SLQuat4f _average
average value

◆ init()

void AveragedQuat4f::init ( int  numValues,
SLQuat4f  initValue 
)
inline

Initializes the average value array to a given value.

Definition at line 29 of file CVTrackedArucoCube.h.

30  {
31  assert(numValues > 0 && "Num. of values must be greater than zero");
32  _values.clear();
33  _values.resize(numValues, initValue);
34  _oneOverNumValues = 1.0f / (float)_values.size();
35  _average = initValue;
37  }
vector< SLQuat4f > _values
value array
int _currentValueIndex
current value index within _values
float _oneOverNumValues
multiplier instead of divider

◆ set()

void AveragedQuat4f::set ( SLQuat4f  value)
inline

Sets the current value in the value array and builds the average.

Definition at line 40 of file CVTrackedArucoCube.h.

41  {
42  assert(_values.size() > 0 && "_value vector not initialized");
43 
44  // Short cut for no averaging
45  if (_values.size() == 1)
46  _average = value;
47  else
48  {
49  if (_currentValueIndex == _values.size())
51 
52  // Correct the sum continuously
53  _values[_currentValueIndex] = value;
54 
55  _average.set(0.0f, 0.0f, 0.0f, 0.0f);
56  for (int i = 0; i < _values.size(); i++)
57  {
58  SLQuat4f current = _values[i];
59  float weight = _oneOverNumValues;
60 
61  if (i > 0 && current.dot(_values[0]) < -0.001)
62  weight = -weight;
63 
64  _average.set(_average.x() + current.x() * weight,
65  _average.y() + current.y() * weight,
66  _average.z() + current.z() * weight,
67  _average.w() + current.w() * weight);
68  }
69 
71 
73  }
74  }
T w() const
Definition: SLQuat4.h:39
void set(T x, T y, T z, T w)
Definition: SLQuat4.h:140
T z() const
Definition: SLQuat4.h:38
T dot(const SLQuat4< T > &q) const
Definition: SLQuat4.h:536
T y() const
Definition: SLQuat4.h:37
T x() const
Definition: SLQuat4.h:36
T normalize()
Definition: SLQuat4.h:575

◆ size()

size_t AveragedQuat4f::size ( )
inline

Definition at line 77 of file CVTrackedArucoCube.h.

77 { return _values.size(); }

Member Data Documentation

◆ _average

SLQuat4f AveragedQuat4f::_average
private

average value

Definition at line 83 of file CVTrackedArucoCube.h.

◆ _currentValueIndex

int AveragedQuat4f::_currentValueIndex {}
private

current value index within _values

Definition at line 82 of file CVTrackedArucoCube.h.

◆ _oneOverNumValues

float AveragedQuat4f::_oneOverNumValues {}
private

multiplier instead of divider

Definition at line 80 of file CVTrackedArucoCube.h.

◆ _values

vector<SLQuat4f> AveragedQuat4f::_values
private

value array

Definition at line 81 of file CVTrackedArucoCube.h.


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