Browse files

Changed the code so only markers not attached to a rigid body are add…

…ed to the labeledMarkers map. Also labeledMarkers are saved during the recording.
  • Loading branch information...
1 parent 3a46a01 commit 249d4d4569f9e7d74654e5c15ac1eab11657781d @mdfeist committed Jun 21, 2013
View
2 BlinkAnalysis/AppViewer.cpp
@@ -37,7 +37,7 @@ osg::Vec3 lastRay;
bool running = false;
bool visible = false;
-bool localMarkers = false;
+bool localMarkers = true;
float VIEWER_SCALE = 1.f;
View
39 BlinkAnalysis/ClientHandler.cpp
@@ -57,6 +57,30 @@ ClientHandler::~ClientHandler(void)
if (this->dikablisEyeVectorArray != NULL)
free(this->dikablisEyeVectorArray);
}
+bool ClientHandler::lock() {
+ // Request ownership of mutex
+ DWORD dwWaitResult;
+ while(true)
+ {
+ // Wait for Mutex to be free
+ dwWaitResult = WaitForSingleObject(g_hMutex, INFINITE);
+ switch (dwWaitResult)
+ {
+ // The thread got ownership of the mutex
+ case WAIT_OBJECT_0:
+ return true;
+ break;
+
+ // The thread got ownership of an abandoned mutex
+ // The database is in an indeterminate state
+ case WAIT_ABANDONED:
+ return false;
+ break;
+ }
+ }
+
+ return false;
+}
void ClientHandler::setRayCalibration(float *vectorArray) {
if (this->dikablisEyeVectorArray != NULL &&
@@ -195,3 +219,18 @@ void ClientHandler::clearStaleMarkers()
}
}
+void ClientHandler::addRigidBodyMarker(Marker marker) {
+ rigidBodyMarkers.insert(marker);
+}
+
+bool ClientHandler::doesRigidBodyMarkerExist(Marker* marker) {
+ std::set<Marker>::iterator ret;
+ ret = rigidBodyMarkers.find((*marker));
+
+ return (ret != rigidBodyMarkers.end());
+}
+
+void ClientHandler::clearRigidBodyMarkers() {
+ rigidBodyMarkers.clear();
+}
+
View
39 BlinkAnalysis/ClientHandler.h
@@ -8,13 +8,15 @@
#include <process.h>
#include <map>
+#include <set>
#include "RigidBody.h"
#include "NatNetTypes.h"
#include "NatNetClient.h"
+typedef std::map<int, RigidBody*>::iterator RigidBody_iterator;
typedef std::map<int, Marker*>::iterator labeledmarker_iterator;
/*
@@ -40,6 +42,8 @@ class ClientHandler
int rigidBodyTool;
// map to store all other markers
std::map<int, Marker*> labeledMarkers;
+ // Used to make sure we are not duplicating markers
+ std::set<Marker> rigidBodyMarkers;
// OptiTrack Server Settings
char cLocalIPAddress[128]; // Your local IP Address
@@ -67,36 +71,10 @@ class ClientHandler
~ClientHandler(void); // Destructor
// Lock the client so data cannot be changed while doing updates
- bool lock() {
- // Request ownership of mutex
- DWORD dwWaitResult;
- while(true)
- {
- // Wait for Mutex to be free
- dwWaitResult = WaitForSingleObject(g_hMutex, INFINITE);
- switch (dwWaitResult)
- {
- // The thread got ownership of the mutex
- case WAIT_OBJECT_0:
- return true;
- break;
-
- // The thread got ownership of an abandoned mutex
- // The database is in an indeterminate state
- case WAIT_ABANDONED:
- return false;
- break;
- }
- }
-
- return false;
- }
+ bool lock();
// Unlocks the client allowing threads to change its data
- void unlock() {
- // Release the utex
- ReleaseMutex(g_hMutex);
- }
+ void unlock() { ReleaseMutex(g_hMutex); }
// Set/Get the NatNetClient
void setClient(NatNetClient* client) { this->client = client; }
@@ -144,6 +122,11 @@ class ClientHandler
void clearLabeledMarkers();
void clearStaleMarkers();
+ // Rigid Body Markers
+ void addRigidBodyMarker(Marker marker);
+ bool doesRigidBodyMarkerExist(Marker* marker);
+ void clearRigidBodyMarkers();
+
// Rigid Body Tool for defining objects
void setRigidBodyTool(int id) { rigidBodyTool = id; }
int getRigidBodyTool() { return rigidBodyTool; }
View
15 BlinkAnalysis/Marker.h
@@ -35,6 +35,21 @@ class Marker {
this->selected = false;
}
+ inline bool operator == (const Marker& rhs) const
+ {
+ return position == rhs.position;
+ }
+
+ inline bool operator != (const Marker& rhs) const
+ {
+ return position != rhs.position;
+ }
+
+ inline bool operator < (const Marker& rhs) const
+ {
+ return position < rhs.position;
+ }
+
void setID(int id) { this->id = id; }
int getID() { return this->id; }
View
16 BlinkAnalysis/NatNetClientSetup.cpp
@@ -325,6 +325,16 @@ void __cdecl DataHandler(sFrameOfMocapData* data, void* pUserData)
// Cast user data as ClientHandler
ClientHandler* pClient = (ClientHandler*) pUserData;
+ // Lock the ClientHandler so data isn't changed
+ // by another thread.
+ if (!pClient->lock())
+ return;
+
+ pClient->clearRigidBodyMarkers();
+
+ // Unlock the ClientHandler
+ pClient->unlock();
+
// Rigid Bodies
for(int i = 0; i < data->nRigidBodies; i++)
{
@@ -377,6 +387,7 @@ void __cdecl DataHandler(sFrameOfMocapData* data, void* pUserData)
// Add the marker to the Rigid Body
body->addMarker(marker);
+ pClient->addRigidBodyMarker(marker);
}
// Unlock the ClientHandler
@@ -407,7 +418,10 @@ void __cdecl DataHandler(sFrameOfMocapData* data, void* pUserData)
marker = new Marker(data->LabeledMarkers[i].ID, x, y, z, data->LabeledMarkers[i].size);
marker->update();
marker->setColor(osg::Vec4(0, 0, 1, 1));
- pClient->addLabeledMarker(marker->getID(), marker);
+
+ if (!pClient->doesRigidBodyMarkerExist(marker)) {
+ pClient->addLabeledMarker(marker->getID(), marker);
+ }
}
pClient->unlock();
View
15 BlinkAnalysis/Recording.cpp
@@ -6,8 +6,6 @@
#include "RecordingManager.h"
#include "Settings.h"
-typedef std::map<int, RigidBody*>::iterator RigidBody_iterator;
-
Recording::Recording(void)
{
this->readyForRecording = false;
@@ -237,6 +235,19 @@ void Recording:: addFrame() {
fileStream << "</RigidBody>\n";
}
+ std::map<int, Marker*>* markerMap = client->getLabeledMarkerMap();
+ for (labeledmarker_iterator it_marker = markerMap->begin(); it_marker != markerMap->end(); ++it_marker)
+ {
+ // Get Pointer to marker
+ Marker* marker = it_marker->second;
+
+ fileStream << "<Marker ";
+ fileStream << "x=\"" << (*marker).x() << "\" ";
+ fileStream << "y=\"" << (*marker).y() << "\" ";
+ fileStream << "z=\"" << (*marker).z() << "\" ";
+ fileStream << "/>\n";
+ }
+
// Unlock the ClientHandler
client->unlock();

0 comments on commit 249d4d4

Please sign in to comment.