Update DDE face tracker to work with menu item

This commit is contained in:
David Rowe 2015-02-18 12:40:59 -08:00
parent c446e72226
commit a66af77b23
3 changed files with 41 additions and 55 deletions

View file

@ -1728,6 +1728,7 @@ void Application::init() {
// initialize our face trackers after loading the menu settings // initialize our face trackers after loading the menu settings
DependencyManager::get<Faceshift>()->init(); DependencyManager::get<Faceshift>()->init();
DependencyManager::get<DdeFaceTracker>()->init();
DependencyManager::get<Visage>()->init(); DependencyManager::get<Visage>()->init();
Leapmotion::init(); Leapmotion::init();

View file

@ -44,58 +44,40 @@ struct Packet{
}; };
DdeFaceTracker::DdeFaceTracker() : DdeFaceTracker::DdeFaceTracker() :
_lastReceiveTimestamp(0), DdeFaceTracker(QHostAddress::Any, DDE_FEATURE_POINT_SERVER_PORT)
_reset(false), {
_leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
_rightBlinkIndex(1), }
_leftEyeOpenIndex(8),
_rightEyeOpenIndex(9), DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 port) :
_browDownLeftIndex(14), _lastReceiveTimestamp(0),
_browDownRightIndex(15), _reset(false),
_browUpCenterIndex(16), _leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
_browUpLeftIndex(17), _rightBlinkIndex(1),
_browUpRightIndex(18), _leftEyeOpenIndex(8),
_mouthSmileLeftIndex(28), _rightEyeOpenIndex(9),
_mouthSmileRightIndex(29), _browDownLeftIndex(14),
_jawOpenIndex(21) _browDownRightIndex(15),
_browUpCenterIndex(16),
_browUpLeftIndex(17),
_browUpRightIndex(18),
_mouthSmileLeftIndex(28),
_mouthSmileRightIndex(29),
_jawOpenIndex(21),
_host(host),
_port(port)
{ {
_blendshapeCoefficients.resize(NUM_EXPRESSION); _blendshapeCoefficients.resize(NUM_EXPRESSION);
connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams())); connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams()));
connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketErrorOccurred(QAbstractSocket::SocketError))); connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketErrorOccurred(QAbstractSocket::SocketError)));
connect(&_udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(socketStateChanged(QAbstractSocket::SocketState))); connect(&_udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(socketStateChanged(QAbstractSocket::SocketState)));
bindTo(DDE_FEATURE_POINT_SERVER_PORT);
}
DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 port) :
_lastReceiveTimestamp(0),
_reset(false),
_leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
_rightBlinkIndex(1),
_leftEyeOpenIndex(8),
_rightEyeOpenIndex(9),
_browDownLeftIndex(14),
_browDownRightIndex(15),
_browUpCenterIndex(16),
_browUpLeftIndex(17),
_browUpRightIndex(18),
_mouthSmileLeftIndex(28),
_mouthSmileRightIndex(29),
_jawOpenIndex(21)
{
_blendshapeCoefficients.resize(NUM_EXPRESSION);
connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams()));
connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketErrorOccurred(QAbstractSocket::SocketError)));
connect(&_udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState)));
bindTo(host, port);
} }
DdeFaceTracker::~DdeFaceTracker() { DdeFaceTracker::~DdeFaceTracker() {
if(_udpSocket.isOpen()) if (_udpSocket.isOpen()) {
_udpSocket.close(); _udpSocket.close();
}
} }
void DdeFaceTracker::init() { void DdeFaceTracker::init() {
@ -110,15 +92,15 @@ void DdeFaceTracker::update() {
} }
void DdeFaceTracker::bindTo(quint16 port) { void DdeFaceTracker::setEnabled(bool enabled) {
bindTo(QHostAddress::Any, port); if (enabled) {
} if (_udpSocket.isOpen()) {
_udpSocket.close();
void DdeFaceTracker::bindTo(const QHostAddress& host, quint16 port) { }
if(_udpSocket.isOpen()) { _udpSocket.bind(_host, _port);
} else {
_udpSocket.close(); _udpSocket.close();
} }
_udpSocket.bind(host, port);
} }
bool DdeFaceTracker::isActive() const { bool DdeFaceTracker::isActive() const {
@ -135,7 +117,7 @@ void DdeFaceTracker::socketStateChanged(QAbstractSocket::SocketState socketState
QString state; QString state;
switch(socketState) { switch(socketState) {
case QAbstractSocket::BoundState: case QAbstractSocket::BoundState:
state = "Bounded"; state = "Bound";
break; break;
case QAbstractSocket::ClosingState: case QAbstractSocket::ClosingState:
state = "Closing"; state = "Closing";
@ -156,7 +138,7 @@ void DdeFaceTracker::socketStateChanged(QAbstractSocket::SocketState socketState
state = "Unconnected"; state = "Unconnected";
break; break;
} }
qDebug() << "[Info] DDE Face Tracker Socket: " << socketState; qDebug() << "[Info] DDE Face Tracker Socket: " << state;
} }
void DdeFaceTracker::readPendingDatagrams() { void DdeFaceTracker::readPendingDatagrams() {

View file

@ -28,9 +28,6 @@ public:
void reset(); void reset();
void update(); void update();
//sockets
void bindTo(quint16 port);
void bindTo(const QHostAddress& host, quint16 port);
bool isActive() const; bool isActive() const;
float getLeftBlink() const { return getBlendshapeCoefficient(_leftBlinkIndex); } float getLeftBlink() const { return getBlendshapeCoefficient(_leftBlinkIndex); }
@ -47,7 +44,10 @@ public:
float getMouthSize() const { return getBlendshapeCoefficient(_jawOpenIndex); } float getMouthSize() const { return getBlendshapeCoefficient(_jawOpenIndex); }
float getMouthSmileLeft() const { return getBlendshapeCoefficient(_mouthSmileLeftIndex); } float getMouthSmileLeft() const { return getBlendshapeCoefficient(_mouthSmileLeftIndex); }
float getMouthSmileRight() const { return getBlendshapeCoefficient(_mouthSmileRightIndex); } float getMouthSmileRight() const { return getBlendshapeCoefficient(_mouthSmileRightIndex); }
public slots:
void setEnabled(bool enabled);
private slots: private slots:
//sockets //sockets
@ -59,6 +59,9 @@ private:
DdeFaceTracker(); DdeFaceTracker();
DdeFaceTracker(const QHostAddress& host, quint16 port); DdeFaceTracker(const QHostAddress& host, quint16 port);
~DdeFaceTracker(); ~DdeFaceTracker();
QHostAddress _host;
quint16 _port;
float getBlendshapeCoefficient(int index) const; float getBlendshapeCoefficient(int index) const;
void decodePacket(const QByteArray& buffer); void decodePacket(const QByteArray& buffer);