summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_UDP
diff options
context:
space:
mode:
Diffstat (limited to 'FTNoIR_Tracker_UDP')
-rw-r--r--FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.vcproj4
-rw-r--r--FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp117
2 files changed, 88 insertions, 33 deletions
diff --git a/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.vcproj b/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.vcproj
index d5df6fc0..55e6d66b 100644
--- a/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.vcproj
+++ b/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.vcproj
@@ -38,7 +38,7 @@
/>
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=".\GeneratedFiles;&quot;$(QTDIR)\include&quot;;&quot;.\GeneratedFiles\$(ConfigurationName)&quot;;&quot;$(QTDIR)\include\qtmain&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtNetwork&quot;;.\"
+ AdditionalIncludeDirectories=".\GeneratedFiles;&quot;$(QTDIR)\include&quot;;&quot;.\GeneratedFiles\$(ConfigurationName)&quot;;&quot;$(QTDIR)\include\qtmain&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtNetwork&quot;;&quot;$(QTDIR)\include\QtGui&quot;;.\"
PreprocessorDefinitions="UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_THREAD_SUPPORT;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;FTNOIR_TRACKER_BASE_LIB"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="false"
@@ -55,7 +55,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="qtmain.lib QtCore4.lib QtNetwork4.lib"
+ AdditionalDependencies="qtmain.lib QtCore4.lib QtGui4.lib QtNetwork4.lib"
OutputFile="$(OutDir)\$(ProjectName).dll"
AdditionalLibraryDirectories="$(QTDIR)\lib"
GenerateDebugInformation="false"
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.