summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp
diff options
context:
space:
mode:
authorWim Vriend <facetracknoir@gmail.com>2011-02-04 15:07:16 +0000
committerWim Vriend <facetracknoir@gmail.com>2011-02-04 15:07:16 +0000
commit4acd072afb9cc76231b1d666d933f3dbbb4b3baa (patch)
tree3b3464d8a81c990bf6446af4d7e850a001a2c2b1 /FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp
parent6a168be69e38cbfba522666ced2fb3f6579b0f29 (diff)
Testing Client/Server configuration.
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@47 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp')
-rw-r--r--FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp117
1 files changed, 86 insertions, 31 deletions
diff --git a/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp b/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp
index d3c67d71..9dfb26a7 100644
--- a/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp
+++ b/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp
@@ -1,7 +1,9 @@
#include "ftnoir_tracker_base.h"
#include <QThread>
#include <QUdpSocket>
+#include <QMessageBox>
#include "Windows.h"
+#include "math.h"
class FTNoIR_Tracker_UDP : public ITracker, QThread
{
@@ -14,6 +16,8 @@ public:
void StartTracker();
void GiveHeadPoseData(THeadPoseData *data);
+ bool setParameterValue(const int index, const float newvalue);
+
protected:
void run(); // qthread override run method
@@ -31,6 +35,16 @@ private:
int srcPort; // Source port-number
THeadPoseData newHeadPose; // Structure with new headpose
+
+ //parameter list for the filter-function(s)
+ enum
+ {
+ kPortAddress=0, // Index in QList
+ kNumFilterParameters // Indicate number of parameters used
+ };
+ QList<std::pair<float,float>> parameterRange;
+ QList<float> parameterValueAsFloat;
+
};
FTNoIR_Tracker_UDP::FTNoIR_Tracker_UDP()
@@ -42,12 +56,38 @@ FTNoIR_Tracker_UDP::FTNoIR_Tracker_UDP()
m_StopThread = CreateEvent(0, TRUE, FALSE, 0);
m_WaitThread = CreateEvent(0, TRUE, FALSE, 0);
- newHeadPose.x = 1.0f;
- newHeadPose.y = 2.0f;
- newHeadPose.z = 3.0f;
- newHeadPose.yaw = 4.0f;
- newHeadPose.pitch = 5.0f;
- newHeadPose.roll = 6.0f;
+ //allocate memory for the parameters
+ parameterValueAsFloat.clear();
+ parameterRange.clear();
+
+ // Add the parameters to the list
+ parameterRange.append(std::pair<float,float>(1000.0f,9999.0f));
+ parameterValueAsFloat.append(0.0f);
+ setParameterValue(kPortAddress,5551.0f);
+
+ newHeadPose.x = 0.0f;
+ newHeadPose.y = 0.0f;
+ newHeadPose.z = 0.0f;
+ newHeadPose.yaw = 0.0f;
+ newHeadPose.pitch = 0.0f;
+ newHeadPose.roll = 0.0f;
+
+ //
+ // Create UDP-sockets if they don't exist already.
+ // They must be created here, because they must be in the new thread (FTNoIR_Tracker_UDP::run())
+ //
+ if (inSocket == 0) {
+ qDebug() << "FTNoIR_Tracker_UDP::run() creating insocket";
+ inSocket = new QUdpSocket();
+ // Connect the inSocket to the port, to receive messages
+
+ if (!inSocket->bind(QHostAddress::Any, (int) parameterValueAsFloat[kPortAddress], QUdpSocket::ShareAddress )) {
+ QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to bind UDP-port",QMessageBox::Ok,QMessageBox::NoButton);
+ delete inSocket;
+ inSocket = 0;
+ }
+ }
+
}
FTNoIR_Tracker_UDP::~FTNoIR_Tracker_UDP()
@@ -83,17 +123,6 @@ QHostAddress sender;
quint16 senderPort;
//
- // Create UDP-sockets if they don't exist already.
- // They must be created here, because they must be in the new thread (FTNoIR_Tracker_UDP::run())
- //
- if (inSocket == 0) {
- qDebug() << "FTNoIR_Tracker_UDP::run() creating insocket";
- inSocket = new QUdpSocket();
- // Connect the inSocket to the port, to receive messages
- inSocket->bind(QHostAddress::Any, destPort+1);
- }
-
- //
// Read the data that was received.
//
forever {
@@ -107,18 +136,23 @@ quint16 senderPort;
return;
}
- while (inSocket->hasPendingDatagrams()) {
+ if (inSocket != 0) {
+ while (inSocket->hasPendingDatagrams()) {
- QByteArray datagram;
- datagram.resize(inSocket->pendingDatagramSize());
+ QByteArray datagram;
+ datagram.resize(inSocket->pendingDatagramSize());
- inSocket->readDatagram( (char * ) &newHeadPose, sizeof(newHeadPose), &sender, &senderPort);
+ inSocket->readDatagram( (char * ) &newHeadPose, sizeof(newHeadPose), &sender, &senderPort);
+ }
+ }
+ else {
+ qDebug() << "FTNoIR_Tracker_UDP::run() insocket not ready: exit run()";
+ return;
}
//for lower cpu load
- usleep(5000);
+ usleep(10000);
yieldCurrentThread();
-
}
}
@@ -140,14 +174,6 @@ void FTNoIR_Tracker_UDP::StartTracker()
void FTNoIR_Tracker_UDP::GiveHeadPoseData(THeadPoseData *data)
{
-
- //newHeadPose.x += 1.0f;
- //newHeadPose.y += 2.0f;
- //newHeadPose.z += 3.0f;
- //newHeadPose.yaw += 4.0f;
- //newHeadPose.pitch += 5.0f;
- //newHeadPose.roll += 6.0f;
-
data->x = newHeadPose.x;
data->y = newHeadPose.y;
data->z = newHeadPose.z;
@@ -157,6 +183,35 @@ void FTNoIR_Tracker_UDP::GiveHeadPoseData(THeadPoseData *data)
return;
}
+bool FTNoIR_Tracker_UDP::setParameterValue(const int index, const float newvalue)
+{
+ if ((index >= 0) && (index < parameterValueAsFloat.size()))
+ {
+ //
+ // Limit the new value, using the defined range.
+ //
+ if (newvalue < parameterRange[index].first) {
+ parameterValueAsFloat[index] = parameterRange[index].first;
+ }
+ else {
+ if (newvalue > parameterRange[index].second) {
+ parameterValueAsFloat[index] = parameterRange[index].second;
+ }
+ else {
+ parameterValueAsFloat[index] = newvalue;
+ }
+ }
+
+// updateParameterString(index);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+};
+
+
////////////////////////////////////////////////////////////////////////////////
// Factory function that creates instances if the Tracker object.