TrackingFilter Class Reference

Dtrack packets filter. More...

#include <filter.h>

List of all members.

Public Member Functions

 TrackingFilter (float angle=0.1, float shift=5)
 Constructor.
bool UpdateFilter (Body::BodyType type, int id, float angle, float shift)
 Updates filter treshold values.
 ~TrackingFilter ()
 Destructor.
bool Filter (Body *body)
 returns true if specified body should be filtered
wxString GetAsString (const char *lineSeparator="\n", const char *atributeSeparator="\t")
 returns table as string
 TrackingFilter (float angle=0.1, float shift=5)
 Constructor.
bool UpdateFilter (Body::BodyType type, int id, float angle, float shift)
 Updates filter treshold values.
 ~TrackingFilter ()
 Destructor.
bool Filter (Body *body)
 returns true if specified body should be filtered
wxString GetAsString (const char *lineSeparator="\n", const char *atributeSeparator="\t")
 returns table as string
void WriteToLog ()

Private Member Functions

TFilterEntryfindEntry (Body::BodyType btype, int bid)
 Returns a line from filter table.
bool checkTranslation (MATRIX currMatrix, MATRIX prevMatrix, float shift)
 Check if translation distances (in any of the axes) is at least equal to treshold.
bool checkRotation (MATRIX currMatrix, MATRIX prevMatrix, float angle)
 Check if relative Euler's angles is at least equal to treshold.
TFilterEntryfindEntry (Body::BodyType btype, int bid)
 Returns a line from filter table.
bool checkTranslation (MATRIX currMatrix, MATRIX prevMatrix, float shift)
 Check if translation distances (in any of the axes) is at least equal to treshold.
bool checkRotation (MATRIX currMatrix, MATRIX prevMatrix, float angle)
 Check if relative Euler's angles is at least equal to treshold.

Private Attributes

float angleFilter
 implicit value
float distFilter
 implicit value
std::list< TFilterEntrytable
 The table with history of packets.
std::list< TFilterEntrytable
 The table with history of packets.

Classes

struct  TFilterEntry
 One line of the filter table. More...


Detailed Description

Dtrack packets filter.

Tracking filter enables to separate noise packets by setting noise treshold parameters. Please note that by using this filter, matrix of body passed to some methods can be modified!

Definition at line 13 of file filter.h.


Constructor & Destructor Documentation

TrackingFilter::TrackingFilter ( float  angle = 0.1,
float  shift = 5 
)

Constructor.

Parameters:
angle - Treshold value (radians) of angle. All relative angles smaller then treshold will be removed.
shift - Treshold value (mm) of distance. All relative translations smaller then treshold will be removed.

Definition at line 3 of file filter.cpp.

00004 {
00005        this->angleFilter = angle;
00006        this->distFilter  = shift;
00007 }

TrackingFilter::~TrackingFilter (  )  [inline]

Destructor.

Definition at line 75 of file filter.h.

00075 {}

TrackingFilter::TrackingFilter ( float  angle = 0.1,
float  shift = 5 
)

Constructor.

Parameters:
angle - Treshold value (radians) of angle. All relative angles smaller then treshold will be removed.
shift - Treshold value (mm) of distance. All relative translations smaller then treshold will be removed.

TrackingFilter::~TrackingFilter (  )  [inline]

Destructor.

Definition at line 75 of file filter.h.

00075 {}


Member Function Documentation

TrackingFilter::TFilterEntry * TrackingFilter::findEntry ( Body::BodyType  btype,
int  bid 
) [private]

Returns a line from filter table.

Parameters:
btype The type of body
bid ID of the body of given type. If no entry in table with this paramteres is found 0 is returned!

Definition at line 9 of file filter.cpp.

00010 {
00011        std::list<TFilterEntry>::iterator i;
00012        for (i = table.begin(); i!= table.end(); i++)
00013        {
00014               if (((*i).id == bid) && ((*i).type == btype)) return &(*i);
00015        }
00016        return NULL;
00017 }

bool TrackingFilter::checkTranslation ( MATRIX  currMatrix,
MATRIX  prevMatrix,
float  shift 
) [inline, private]

Check if translation distances (in any of the axes) is at least equal to treshold.

Returns true if distances are at least equal to treshold value

Parameters:
body Body to be checked.
prevMatrix Matrix to be compared with Body matrix. ( Use previous transformation matrix of body!)

Definition at line 18 of file filter.cpp.

00019 {
00020        if (absolute(currMatrix._m41 - prevMatrix._m41) >= shift
00021               || absolute(currMatrix._m42 - prevMatrix._m42) >= shift
00022               || absolute(currMatrix._m43 - prevMatrix._m43) >= shift)
00023        {
00024               //LOG(wxT("TRANSLATION FALSE"));
00025               return true;
00026        }
00027        else
00028        {
00029               //LOG(wxT("TRANSLATION FALSE"));
00030               return false;
00031        }
00032 }

bool TrackingFilter::checkRotation ( MATRIX  currMatrix,
MATRIX  prevMatrix,
float  angle 
) [inline, private]

Check if relative Euler's angles is at least equal to treshold.

Returns true if angles are at least equal to treshold.

Parameters:
body Body to be checked.
prevMatrix Matrix to be compared with Body matrix. ( Use previous transformation matrix of body!)

Definition at line 33 of file filter.cpp.

00034 {
00035        float cosA = cos(angle);
00036        float cy2 = cosf(asinf(currMatrix._m13));
00037        float cy1 = cosf(asinf(prevMatrix._m13));
00038        float cosX = (currMatrix._m33 / cy2)*(prevMatrix._m33 / cy1) + (currMatrix._m23 / (-1 * cy2)) * (prevMatrix._m23 / (-1 * cy1));
00039        float cosY = (cy2 * cy1) + (currMatrix._m13 * prevMatrix._m13);
00040        float cosZ = ((currMatrix._m11 / cy2) * (prevMatrix._m11 / cy1)) + ((currMatrix._m12 / (-1 * cy2)) * (prevMatrix._m12 / (-1 * cy1)));
00041        if (cosA >= cosX || cosA >= cosY || cosA >= cosZ)
00042        {
00043        //     LOG(wxT("ROTATION TRUE"));
00044               return true;
00045        }
00046        else
00047        {
00048               //LOG(wxT("ROTATION FALSE"));
00049               return false;
00050        }
00051 }

bool TrackingFilter::UpdateFilter ( Body::BodyType  type,
int  id,
float  angle,
float  shift 
)

Updates filter treshold values.

Parameters:
angle - Treshold value (radians) of angle. All relative angles smaller then treshold will be removed.
shift - Treshold value (mm) of distance. All relative translations smaller then treshold will be removed. returns true if entry found and updated

Definition at line 123 of file filter.cpp.

00124 {
00125        TrackingFilter::TFilterEntry * entry = this->findEntry(type, id);
00126        if (entry == NULL)
00127        {
00128               TFilterEntry new_entry;
00129               new_entry.angleFilter = angle;
00130               new_entry.distFilter = shift;
00131               new_entry.id = id;
00132               new_entry.type = type;
00133               new_entry.validMatrix = false;
00134               table.push_back(new_entry);
00135               return false;
00136        }
00137        else
00138        {
00139               entry->angleFilter = angle;
00140               entry->distFilter  = shift;
00141               return true;
00142        }
00143 }

bool TrackingFilter::Filter ( Body body  ) 

returns true if specified body should be filtered

Parameters:
body - a body specification note that this method can change transformation matrix of body

if rotation is at least equal to treshold

Definition at line 52 of file filter.cpp.

00053 {
00054        TrackingFilter::TFilterEntry * entry = findEntry(body->GetType(), body->GetID());
00055        if (entry == NULL) // if no entry. add new entry and
00056        {
00057        //     LOG(wxT("NO ENTRY"));
00058               TrackingFilter::TFilterEntry  newEntry;
00059               newEntry.id         = body->GetID();
00060               newEntry.type       = body->GetType();
00061               newEntry.prevMatrix = body->Matrix();
00062               newEntry.angleFilter = this->angleFilter;
00063               newEntry.distFilter  = this->distFilter;
00064               newEntry.validMatrix = true;
00065               table.push_back(newEntry);
00066        //     LOG(wxT("FIRST ENTRY NO FILTER"));
00067               return false; // body shouldn't be filtered
00068        }
00069        else if (entry->validMatrix)
00070        {
00071               //LOG(wxT("VALID ENTRY"));
00072               
00073               if (body->GetQuality() != 1)
00074               {
00075                      // if device is not visible, set matrix to previous (to not be the dummy)
00076                      // but not filter out the body because of the buttons.
00077        //            LOG(wxT("FILTER_TRANSFORMATION_NOT BUTTONS"));
00078                      body->SetMatrix(entry->prevMatrix);
00079                      return false;
00080               }
00081               else
00082               {
00083                      bool filt1 = false;
00084                      MATRIX filterM;
00085                      if (!checkRotation(body->Matrix(), entry->prevMatrix, entry->angleFilter))
00086                      {
00087                             // if rotation is smaller then treshold
00088                             //LOG(wxT("FILTERED ROTATION"));
00089                             filterM = entry->prevMatrix.ExtractRotation();
00090                             filt1 = true;
00091                      }
00092                      else
00093                      {
00094                             //LOG(wxT("ROTATION"));
00096                             filterM = body->Matrix().ExtractRotation();
00097                      }
00098                      if (!checkTranslation(body->Matrix(), entry->prevMatrix, entry->distFilter))
00099                      {
00100                             //LOG(wxT("FILTERED TRANSLATION"));
00101                             filterM.Translate(entry->prevMatrix.ExtractTranslation());
00102                      }
00103                      else
00104                      {
00105                             //LOG(wxT("TRANSLATION"));
00106                             filterM.Translate(body->Matrix().ExtractTranslation());
00107                             filt1 = false;
00108                      }
00109                      entry->prevMatrix = body->Matrix() = filterM;
00110                      return filt1;
00111               }
00112               return true;
00113        }
00114        else
00115        {
00116               //LOG(wxT("INVALID ENTRY"));
00117               entry->prevMatrix = body->Matrix();
00118               entry->validMatrix = true;
00119               return false;
00120        }
00121 }

wxString TrackingFilter::GetAsString ( const char *  lineSeparator = "\n",
const char *  atributeSeparator = "\t" 
)

returns table as string

Definition at line 144 of file filter.cpp.

00145 {
00146        wxString dump = wxT("");
00147        size_t  max = this->table.size();
00148        if (max ==0) return wxT("EMPTY");
00149        std::list<TFilterEntry>::iterator i, j;
00150        for (i =table.begin(); i != table.end(); i++)
00151        {
00152               if (i != table.begin()) dump += wxString::From8BitData(lineSeparator);
00153               TFilterEntry * entry = &(*i);
00154               dump += wxString::Format(wxT("%i%s%i%s%f%s%f"),
00155                                                         entry->type, atributeSeparator,
00156                                                         entry->id, atributeSeparator,
00157                                                         entry->angleFilter, atributeSeparator,
00158                                                         entry->distFilter);
00159        }
00160        return dump;
00161 }

TFilterEntry* TrackingFilter::findEntry ( Body::BodyType  btype,
int  bid 
) [private]

Returns a line from filter table.

Parameters:
btype The type of body
bid ID of the body of given type. If no entry in table with this paramteres is found 0 is returned!

bool TrackingFilter::checkTranslation ( MATRIX  currMatrix,
MATRIX  prevMatrix,
float  shift 
) [inline, private]

Check if translation distances (in any of the axes) is at least equal to treshold.

Returns true if distances are at least equal to treshold value

Parameters:
body Body to be checked.
prevMatrix Matrix to be compared with Body matrix. ( Use previous transformation matrix of body!)

bool TrackingFilter::checkRotation ( MATRIX  currMatrix,
MATRIX  prevMatrix,
float  angle 
) [inline, private]

Check if relative Euler's angles is at least equal to treshold.

Returns true if angles are at least equal to treshold.

Parameters:
body Body to be checked.
prevMatrix Matrix to be compared with Body matrix. ( Use previous transformation matrix of body!)

bool TrackingFilter::UpdateFilter ( Body::BodyType  type,
int  id,
float  angle,
float  shift 
)

Updates filter treshold values.

Parameters:
angle - Treshold value (radians) of angle. All relative angles smaller then treshold will be removed.
shift - Treshold value (mm) of distance. All relative translations smaller then treshold will be removed. returns true if entry found and updated

bool TrackingFilter::Filter ( Body body  ) 

returns true if specified body should be filtered

Parameters:
body - a body specification note that this method can change transformation matrix of body

wxString TrackingFilter::GetAsString ( const char *  lineSeparator = "\n",
const char *  atributeSeparator = "\t" 
)

returns table as string

void TrackingFilter::WriteToLog (  ) 

Definition at line 162 of file filter.cpp.

00163 {
00164        size_t max = this->table.size();
00165        if (max == 0)
00166        {
00167               LOG(wxT("<Tracking> Table empty."));
00168               return;
00169        }
00170        else
00171        {
00172               wxString dump = wxT("<Tracking> Filter table: (type, id, angle, dist)\n");
00173               std::list<TFilterEntry>::iterator i, j;
00174               for (i =table.begin(); i != table.end(); i++)
00175               {
00176                      dump << i->type << wxT(" ") << i->id << wxT(" ") << i->angleFilter << wxT(" ") << i->distFilter << wxT("\n");
00177               }
00178               LOG(dump);
00179        }
00180 }


Member Data Documentation

float TrackingFilter::angleFilter [private]

implicit value

Definition at line 39 of file filter.h.

float TrackingFilter::distFilter [private]

implicit value

Definition at line 41 of file filter.h.

std::list<TFilterEntry> TrackingFilter::table [private]

The table with history of packets.

Definition at line 43 of file filter.h.

std::list<TFilterEntry> TrackingFilter::table [private]

The table with history of packets.

Definition at line 43 of file filter.h.


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

Generated on Tue Mar 10 14:41:38 2009 for VRUT by  doxygen 1.5.5