Skip to content

Commit

Permalink
Refactored AU/SU mapping to use names, should make it a bit more flex…
Browse files Browse the repository at this point in the history
…ible.
  • Loading branch information
jorticus committed Jun 21, 2014
1 parent 64504d2 commit 2b67af6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
7 changes: 7 additions & 0 deletions include/eru/Model.h
@@ -1,6 +1,8 @@
#ifndef ERUFACE_MODEL_H
#define ERUFACE_MODEL_H

#include <vector>
#include <unordered_map>
#include "eruFace/VertexSet.h"
#include "eruFace/Deformation.h"

Expand Down Expand Up @@ -50,6 +52,9 @@ namespace eruFace
inline const Deformation& staticDeformation( int n ) const { return _staticDeformations[n]; }
inline Deformation& staticDeformation( int n ) { return _staticDeformations[n]; }

inline const int dynamicDeformationIndex(std::string name) { return _dynamicIndices.at(name); }
inline const int staticDeformationIndex(std::string name) { return _staticIndices.at(name); }

void setDynamicParam( int, double );
double getDynamicParam( int ) const;
int nDynamicDeformations() const;
Expand Down Expand Up @@ -135,9 +140,11 @@ namespace eruFace

std::vector<Deformation> _dynamicDeformations;
std::vector<double> _dynamicParams;
std::unordered_map<std::string, int> _dynamicIndices;

std::vector<Deformation> _staticDeformations;
std::vector<double> _staticParams;
std::unordered_map<std::string, int> _staticIndices;

eruMath::Vector3d _rotation;
eruMath::Vector3d _scale;
Expand Down
3 changes: 3 additions & 0 deletions include/models/CustomFaceModel.h
Expand Up @@ -28,6 +28,9 @@ class CustomFaceModel : public FaceModel
private:
bool hasModel;

std::vector<int> su_map;
std::vector<int> au_map;

IFTModel* pModel;
IFTFaceTracker* pFaceTracker;

Expand Down
15 changes: 15 additions & 0 deletions src/eru/Model.cpp
Expand Up @@ -6,6 +6,7 @@
#include <fstream>
#include <exception>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>

#include "eru/Model.h"
#include "eru/StringStreamUtils.h"
Expand Down Expand Up @@ -729,13 +730,27 @@ Model::readDynamicDeformations(std::istream& is)
{
readDeformations(_dynamicDeformations, "Action Unit", is);
_dynamicParams.assign(nDynamicDeformations(), 0.0);

_dynamicIndices.clear();
for (int i = 0; i < _dynamicDeformations.size(); i++) {
auto name = _dynamicDeformations[i].getName();
boost::algorithm::to_lower(name);
_dynamicIndices[name] = i;
}
}

void
Model::readStaticDeformations(std::istream& is)
{
readDeformations(_staticDeformations, "Shape Unit", is);
_staticParams.assign(nStaticDeformations(), 0.0);

_staticIndices.clear();
for (int i = 0; i < _staticDeformations.size(); i++) {
auto name = _staticDeformations[i].getName();
boost::algorithm::to_lower(name);
_staticIndices[name] = i;
}
}

//////////////////////////////////////////////////////////////////////
Expand Down
76 changes: 51 additions & 25 deletions src/models/CustomFaceModel.cpp
Expand Up @@ -8,27 +8,29 @@

using namespace std;

static const int su_map[] = {
0, // Head height
1, // Eyebrows vertical position
2, // Eyes vertical position
3, // Eyes width
4, // Eyes height
5, // Eye separation distance
8, // Nose vertical position
10, // Mouth vertical position
11, // Mouth width
-1, // Eyes vertical difference
-1, // Chin width
#define NUM_KINECT_SU 11
static const string kinect_su_map[NUM_KINECT_SU] = {
"head height",
"eyebrows vertical position",
"eyes vertical position",
"eyes, width",
"eyes, height",
"eye separation distance",
"nose vertical position",
"mouth vertical position",
"mouth width",
"", // Eyes vertical distance // Not specified in candide-3
"", // Chin width // Not specified in candide-3
};

static const int au_map[] = {
0, // Upper lip raiser
1, // Jaw lowerer
2, // Lip stretcher
3, // Brow lowerer
4, // Lip corner depressor
5, // Outer brow raiser
#define NUM_KINECT_AU 6
static const string kinect_au_map[NUM_KINECT_AU] = {
"auv0 upper lip raiser (au10)",
"auv11 jaw drop (au26/27)",
"auv2 lip stretcher (au20)",
"auv3 brow lowerer (au4)",
"auv14 lip corner depressor (au13/15)",
"auv5 outer brow raiser (au2)",
};

CustomFaceModel::CustomFaceModel() : FaceModel()
Expand All @@ -52,6 +54,30 @@ bool CustomFaceModel::LoadMesh(std::string filename) {
}
}

// Look up kinect to wfm parameter mappings and store for later use
su_map.clear();
for (int i = 0; i < NUM_KINECT_SU; i++) {
const string name = kinect_su_map[i];
try {
int map_idx = (!name.empty()) ? mesh.staticDeformationIndex(name) : -1;
su_map.push_back(map_idx);
}
catch (exception& e) {
throw runtime_error((boost::format("Kinect SU '%s' not found in the provided model") % name).str());
}
}
au_map.clear();
for (int i = 0; i < NUM_KINECT_AU; i++) {
const string name = kinect_au_map[i];
try {
int map_idx = (!name.empty()) ? mesh.dynamicDeformationIndex(name) : -1;
au_map.push_back(map_idx);
}
catch (exception& e) {
throw runtime_error((boost::format("Kinect AU '%s' not found in the provided model") % name).str());
}
}

return true;
}

Expand Down Expand Up @@ -84,9 +110,9 @@ void CustomFaceModel::UpdateModel(IFTResult* pFTResult, FT_CAMERA_CONFIG* pCamer
if (nSD > 0) {
for (int i = 0; i < suCount; i++) {
// Map kinect shape units to candide-3 shape units
int su_idx = su_map[i];
if (su_idx >= 0) {
mesh.setStaticParam(su_idx, static_cast<double>(shapeUnits[i]));
int idx = su_map[i];
if (idx >= 0) {
mesh.setStaticParam(i, shapeUnits[i]);
}
}
mesh.updateStatic();
Expand All @@ -103,9 +129,9 @@ void CustomFaceModel::UpdateModel(IFTResult* pFTResult, FT_CAMERA_CONFIG* pCamer
if (nDD > 0) {
for (int i = 0; i < auCount; i++) {
// Map kinect shape units to candide-3 action units
int au_idx = au_map[i];
if (au_idx >= 0) {
mesh.setDynamicParam(au_idx, static_cast<double>(actionUnits[i]));
int idx = au_map[i];
if (idx >= 0) {
mesh.setDynamicParam(i, actionUnits[i]);
}
}
}
Expand Down

0 comments on commit 2b67af6

Please sign in to comment.