38 for (
size_t i = 0; i < aJointOffsets.size(); i++)
40 m_aJointOffsets.push_back(aJointOffsets.at(i));
41 m_aJointAngles.push_back(0);
46 for (
size_t i = 0; i < aFingerTipCorners.size(); i++)
48 m_aFingerTipCornersInLocalCS.push_back(aFingerTipCorners.at(i));
59 Mat3d mRotLocal, mRotGlobal = Math3d::unit_mat;
60 Vec3d vTemp = Math3d::zero_vec;
63 const size_t n = (m_aJointAngles.size() <= aNewJointValues.size()) ? m_aJointAngles.size() : aNewJointValues.size();
64 for (
size_t i = 0; i < n; i++)
66 m_aJointAngles.at(i) = aNewJointValues.at(i);
67 Math3d::SetRotationMatY(mRotLocal, aNewJointValues.at(i));
68 Math3d::MulMatMat(mRotGlobal, mRotLocal, mRotGlobal);
69 vTemp.x = m_aJointOffsets.at(i);
70 Math3d::MulMatVec(mRotGlobal, vTemp, m_aFingerJointsInFingerBaseCS.at(i), m_aFingerJointsInFingerBaseCS.at(i + 1));
73 Vec3d vFingerTipPosition = m_aFingerJointsInFingerBaseCS.at(m_aJointAngles.size());
74 for (
size_t i = 0; i < m_aFingerTipCornersInLocalCS.size(); i++)
76 Math3d::MulMatVec(mRotGlobal, m_aFingerTipCornersInLocalCS.at(i), vFingerTipPosition, m_aFingerTipCornersInFingerBaseCS.at(i));
90 std::ifstream sFileStream(sConfigFileName.c_str(), std::ifstream::in);
91 if (!sFileStream.good())
93 ARMARX_WARNING_S <<
"CHandModelV2 constructor: file " << sConfigFileName <<
" could not be opened";
97 setlocale(LC_NUMERIC,
"C");
102 std::vector<std::vector<float> > aJointOffsets;
103 aJointOffsets.resize(5);
107 sscanf(sLine.c_str(),
"%f %f %f", &vTemp.x, &vTemp.y, &vTemp.z);
112 sscanf(sLine.c_str(),
"%f", &fTemp);
113 aJointOffsets.at(0).push_back(fTemp);
117 sscanf(sLine.c_str(),
"%f", &fTemp);
118 aJointOffsets.at(0).push_back(fTemp);
124 sscanf(sLine.c_str(),
"%f %f %f", &vTemp.x, &vTemp.y, &vTemp.z);
129 sscanf(sLine.c_str(),
"%f", &fTemp);
130 aJointOffsets.at(1).push_back(fTemp);
134 sscanf(sLine.c_str(),
"%f", &fTemp);
135 aJointOffsets.at(1).push_back(fTemp);
140 sscanf(sLine.c_str(),
"%f %f %f", &vTemp.x, &vTemp.y, &vTemp.z);
145 sscanf(sLine.c_str(),
"%f", &fTemp);
146 aJointOffsets.at(2).push_back(fTemp);
150 sscanf(sLine.c_str(),
"%f", &fTemp);
151 aJointOffsets.at(2).push_back(fTemp);
156 sscanf(sLine.c_str(),
"%f %f %f", &vTemp.x, &vTemp.y, &vTemp.z);
161 sscanf(sLine.c_str(),
"%f", &fTemp);
162 aJointOffsets.at(3).push_back(fTemp);
166 sscanf(sLine.c_str(),
"%f", &fTemp);
167 aJointOffsets.at(3).push_back(fTemp);
172 sscanf(sLine.c_str(),
"%f %f %f", &vTemp.x, &vTemp.y, &vTemp.z);
177 sscanf(sLine.c_str(),
"%f", &fTemp);
178 aJointOffsets.at(4).push_back(fTemp);
182 sscanf(sLine.c_str(),
"%f", &fTemp);
183 aJointOffsets.at(4).push_back(fTemp);
188 int nNumFingertipPoints;
190 sscanf(sLine.c_str(),
"%d", &nNumFingertipPoints);
192 float fFingerTipOffsetZ;
194 sscanf(sLine.c_str(),
"%f", &fFingerTipOffsetZ);
197 std::vector<Vec3d> aFingertipPoints;
199 for (
int i = 0; i < nNumFingertipPoints; i++)
201 sscanf(sLine.c_str(),
"%f %f %f", &vTemp.x, &vTemp.y, &vTemp.z);
202 vTemp.z += fFingerTipOffsetZ;
203 aFingertipPoints.push_back(vTemp);
204 std::getline(sFileStream, sLine);
221 std::vector<Vec3d> aFingertipPointsThumb;
222 aFingertipPointsThumb.resize(nNumFingertipPoints);
223 for (
int i = 0; i < nNumFingertipPoints; i++)
225 Math3d::SetVec(aFingertipPointsThumb.at(i), -aFingertipPoints.at(i).x, aFingertipPoints.at(i).y, aFingertipPoints.at(i).z);
227 CFinger* pNewFinger =
new CFinger(aJointOffsets.at(0), aFingertipPointsThumb);
231 for (
int i = 1; i <= 4; i++)
233 pNewFinger =
new CFinger(aJointOffsets.at(i), aFingertipPoints);
244 for (
int i = 0; i < 5; i++)
254 for (
int i = 0; i < 5; i++)
280 std::getline(sFileStream, sLine);
282 while (sLine.at(0) ==
'#');
297 for (
size_t i = 0; i <
m_aFingers.size(); i++)
299 m_aFingers.at(i)->UpdateJointAngles(aFingerJointAngles.at(i));
302 Vec3d vOffsetToFingerBaseRotated, vTemp;
306 for (
size_t i = 0; i <
m_aFingers.at(0)->m_aFingerJointsInFingerBaseCS.size(); i++)
311 for (
size_t i = 0; i <
m_aFingers.at(0)->m_aFingerTipCornersInFingerBaseCS.size(); i++)
318 Mat3d mPalmJointRotation, mAbsoluteRotationAfterPalmJoint;
320 Math3d::MulMatMat(
m_mHandOrientation, mPalmJointRotation, mAbsoluteRotationAfterPalmJoint);
322 for (
int j = 1; j <= 4; j++)
324 Math3d::MulMatVec(mAbsoluteRotationAfterPalmJoint,
m_aOffsetsToFingers.at(j), vOffsetToFingerBaseRotated);
325 for (
size_t i = 0; i <
m_aFingers.at(j)->m_aFingerJointsInFingerBaseCS.size(); i++)
327 Math3d::MulMatVec(mAbsoluteRotationAfterPalmJoint,
m_aFingers.at(j)->m_aFingerJointsInFingerBaseCS.at(i), vOffsetToFingerBaseRotated, vTemp);
331 for (
size_t i = 0; i <
m_aFingers.at(j)->m_aFingerTipCornersInFingerBaseCS.size(); i++)
333 Math3d::MulMatVec(mAbsoluteRotationAfterPalmJoint,
m_aFingers.at(j)->m_aFingerTipCornersInFingerBaseCS.at(i), vOffsetToFingerBaseRotated, vTemp);
344 Vec3d vTrackingBallPositionInWorldCS;
348 float fFocalLengthLeft = 0.5f * (
m_pStereoCalibration->GetLeftCalibration()->GetCameraParameters().focalLength.x +
m_pStereoCalibration->GetLeftCalibration()->GetCameraParameters().focalLength.y);
352 float fFocalLengthRight = 0.5f * (
m_pStereoCalibration->GetRightCalibration()->GetCameraParameters().focalLength.x +
m_pStereoCalibration->GetRightCalibration()->GetCameraParameters().focalLength.y);
360 Vec3d vHandPosition = {(
float)pConfig[0], (
float)pConfig[1], (
float) pConfig[2]};
361 Mat3d mHandOrientation;
362 Math3d::SetRotationMat(mHandOrientation, pConfig[3], pConfig[4], pConfig[5]);
364 float fPalmJointAngle = -pConfig[6];
366 std::vector<std::vector<float> > aFingerJointAngles;
367 aFingerJointAngles.resize(5);
368 aFingerJointAngles.at(0).push_back(pConfig[7]);
369 aFingerJointAngles.at(0).push_back(pConfig[8]);
370 aFingerJointAngles.at(1).push_back(-pConfig[9]);
371 aFingerJointAngles.at(1).push_back(-pConfig[9]);
372 aFingerJointAngles.at(2).push_back(-pConfig[10]);
373 aFingerJointAngles.at(2).push_back(-pConfig[10]);
374 aFingerJointAngles.at(3).push_back(-pConfig[11]);
375 aFingerJointAngles.at(3).push_back(-pConfig[11]);
376 aFingerJointAngles.at(4).push_back(-pConfig[11]);
377 aFingerJointAngles.at(4).push_back(-pConfig[11]);
379 UpdateHand(vHandPosition, mHandOrientation, fPalmJointAngle, aFingerJointAngles);