From 4acd072afb9cc76231b1d666d933f3dbbb4b3baa Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Fri, 4 Feb 2011 15:07:16 +0000 Subject: Testing Client/Server configuration. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@47 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp | 12 +-- FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.vcproj | 4 +- FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp | 117 ++++++++++++++++++++------- FaceTrackNoIR.suo | Bin 334848 -> 343552 bytes FaceTrackNoIR/FTNoIR_FGcontrols.ui | 10 +++ FaceTrackNoIR/FaceTrackNoIR.ui | 3 + bin/FaceTrackNoIR.exe | Bin 757760 -> 757760 bytes 7 files changed, 107 insertions(+), 39 deletions(-) diff --git a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp index 4748f879..957f5aec 100644 --- a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp +++ b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp @@ -186,16 +186,16 @@ void FTNoIR_Filter_EWMA2::FilterHeadPoseData(THeadPoseData *current_camera_posit //calculate the alphas //work out the dynamic smoothing factors - if (newTarget) { +// if (newTarget) { for (i=0;i<6;i++) { alpha[i]=1.0f/(parameterValueAsFloat[kMinSmoothing]+((1.0f-pow(norm_output_delta[i],parameterValueAsFloat[kSmoothingScaleCurve]))*smoothing_frames_range)); smoothed_alpha[i]=(alpha_smoothing*alpha[i])+((1.0f-alpha_smoothing)*prev_alpha[i]); } - } +// } - qDebug() << "FTNoIR_Filter_EWMA2::FilterHeadPoseData() smoothing frames = " << smoothing_frames_range; - qDebug() << "FTNoIR_Filter_EWMA2::FilterHeadPoseData() alpha[3] = " << alpha[3]; + //qDebug() << "FTNoIR_Filter_EWMA2::FilterHeadPoseData() smoothing frames = " << smoothing_frames_range; + //qDebug() << "FTNoIR_Filter_EWMA2::FilterHeadPoseData() alpha[3] = " << alpha[3]; //use the same (largest) smoothed alpha for each channel //NB: larger alpha = *less* lag (opposite to what you'd expect) @@ -211,8 +211,8 @@ void FTNoIR_Filter_EWMA2::FilterHeadPoseData(THeadPoseData *current_camera_posit //move the camera for (i=0;i<6;i++) { -// output[i]=(largest_alpha*target[i])+((1.0f-largest_alpha)*prev_output[i]); - output[i]=(smoothed_alpha[i]*target[i])+((1.0f-smoothed_alpha[i])*prev_output[i]); + output[i]=(largest_alpha*target[i])+((1.0f-largest_alpha)*prev_output[i]); +// output[i]=(smoothed_alpha[i]*target[i])+((1.0f-smoothed_alpha[i])*prev_output[i]); } new_camera_position->x=output[0]; 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 @@ /> #include +#include #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> parameterRange; + QList 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(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() @@ -82,17 +122,6 @@ int no_bytes; 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. // @@ -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. diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo index d5744f58..ff1e1575 100644 Binary files a/FaceTrackNoIR.suo and b/FaceTrackNoIR.suo differ diff --git a/FaceTrackNoIR/FTNoIR_FGcontrols.ui b/FaceTrackNoIR/FTNoIR_FGcontrols.ui index 270a0ee5..5f5d1563 100644 --- a/FaceTrackNoIR/FTNoIR_FGcontrols.ui +++ b/FaceTrackNoIR/FTNoIR_FGcontrols.ui @@ -259,6 +259,16 @@ + + spinIPFirstNibble + spinIPSecondNibble + spinIPThirdNibble + spinIPFourthNibble + spinPortNumber + btnOK + btnCancel + chkLocalPC + diff --git a/FaceTrackNoIR/FaceTrackNoIR.ui b/FaceTrackNoIR/FaceTrackNoIR.ui index 698929cb..25adf15f 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.ui +++ b/FaceTrackNoIR/FaceTrackNoIR.ui @@ -1191,6 +1191,9 @@ background:none; background:none; + + 1 + 50 diff --git a/bin/FaceTrackNoIR.exe b/bin/FaceTrackNoIR.exe index 191feaa9..e98c084a 100644 Binary files a/bin/FaceTrackNoIR.exe and b/bin/FaceTrackNoIR.exe differ -- cgit v1.2.3