├── CMUMAD_example_segmentation.png ├── ActionSegmentation_Pose ├── HDM05-Parser │ ├── quaternions │ │ ├── quatCommutator.m │ │ ├── matrix2quat.m │ │ ├── directedAngle.m │ │ ├── plotcoeffs.m │ │ ├── spheric4d2euclid4d.m │ │ ├── quatexp.m │ │ ├── quatnormsq.m │ │ ├── quatconj.m │ │ ├── quatinv.m │ │ ├── quatnormalize.m │ │ ├── proj2hyperplane.m │ │ ├── matrix2angle_axis.m │ │ ├── gramschmidt.m │ │ ├── quatmult.m │ │ ├── filterMot.m │ │ ├── rotmatrix.m │ │ ├── rotquat.m │ │ ├── quatnormalizeSign.m │ │ ├── sphericalAverage_incremental_approx.m │ │ ├── resampleQuats.m │ │ ├── quatexp_rot.m │ │ ├── quatlog.m │ │ ├── quatrot.m │ │ ├── quat2matrix.m │ │ ├── orientationFilter.m │ │ ├── euler2matrixSymb.m │ │ ├── distRP3.m │ │ ├── angularVelocity.m │ │ ├── filterS3.m │ │ ├── bisectS3.m │ │ ├── doubleS3.m │ │ ├── distS3.m │ │ ├── filterR4.m │ │ ├── sphericalAverageA1.m │ │ ├── slerp.m │ │ ├── quatlog_rot.m │ │ ├── filterSphericalAverageA1.m │ │ ├── distS3_log.m │ │ └── slerpNQuats.m │ ├── animate │ │ ├── animateGUI.fig │ │ ├── params_point.m │ │ ├── pauseAnimation.m │ │ ├── updateAnimationSlider.m │ │ ├── animatedPatchStruct.m │ │ ├── old_createPlaneNormal.m │ │ ├── params_cappedCylinder.m │ │ ├── animateD.m │ │ ├── gramschmidt.m │ │ ├── test_multiple.m │ │ ├── clearTracePoses.m │ │ ├── test_getframe.m │ │ ├── params_planePointNormal_yAxis.m │ │ ├── saveCamera.m │ │ ├── showTrajectory.m │ │ ├── params_planePointNormal_hipMiddle.m │ │ ├── addAnimatedPatches.m │ │ ├── showTracePoses.m │ │ ├── resumeAnimation.m │ │ └── createGroundPlane.m │ ├── data │ │ ├── HDM_dg_06-03_03_120.amc │ │ └── HDM_dg_06-03_03_120.c3d │ ├── parser │ │ ├── C3Dparser │ │ │ ├── buildSkelPathsForPointCloud.m │ │ │ ├── getLabelIndex.m │ │ │ ├── LCS │ │ │ │ ├── callbackFunctions │ │ │ │ │ ├── neck_default.m │ │ │ │ │ ├── lclavicle_default.m │ │ │ │ │ ├── lelbow_default.m │ │ │ │ │ ├── lfingers_default.m │ │ │ │ │ ├── rclavicle_default.m │ │ │ │ │ ├── relbow_default.m │ │ │ │ │ ├── rwrist_default.m │ │ │ │ │ ├── lshoulder_default.m │ │ │ │ │ ├── ltoes_default.m │ │ │ │ │ ├── lwrist_default.m │ │ │ │ │ ├── rshoulder_default.m │ │ │ │ │ ├── rtoes_default.m │ │ │ │ │ ├── root_default.m │ │ │ │ │ ├── headtop_default.m │ │ │ │ │ ├── rankle_default.m │ │ │ │ │ ├── lankle_default.m │ │ │ │ │ ├── lknee_default.m │ │ │ │ │ ├── rknee_default.m │ │ │ │ │ ├── head_default.m │ │ │ │ │ ├── belly_default.m │ │ │ │ │ ├── chest_default.m │ │ │ │ │ ├── generateDefaultFunctionNames.m │ │ │ │ │ ├── lhip_default.m │ │ │ │ │ ├── rhip_default.m │ │ │ │ │ └── rfingers_default.m │ │ │ │ ├── skelfitATSrek.m │ │ │ │ ├── refitBone.m │ │ │ │ ├── calculateBoneLengths.m │ │ │ │ ├── moveSkelSegment.m │ │ │ │ ├── skelfitATS.m │ │ │ │ ├── extractSkelBones.m │ │ │ │ ├── generateLCS.m │ │ │ │ └── readMocapSmartLCS.m │ │ │ ├── callbackFunctions │ │ │ │ ├── neck_default.m │ │ │ │ ├── lelbow_default.m │ │ │ │ ├── relbow_default.m │ │ │ │ ├── chest_default.m │ │ │ │ ├── lfingers_default.m │ │ │ │ ├── lhip_default.m │ │ │ │ ├── lshoulder_default.m │ │ │ │ ├── ltoes_default.m │ │ │ │ ├── lwrist_default.m │ │ │ │ ├── rfingers_default.m │ │ │ │ ├── rhip_default.m │ │ │ │ ├── rshoulder_default.m │ │ │ │ ├── rtoes_default.m │ │ │ │ ├── rwrist_default.m │ │ │ │ ├── root_default.m │ │ │ │ ├── lclavicle_default.m │ │ │ │ ├── rclavicle_default.m │ │ │ │ ├── rankle_default.m │ │ │ │ ├── rknee_default.m │ │ │ │ ├── lankle_default.m │ │ │ │ ├── lknee_default.m │ │ │ │ ├── head_default.m │ │ │ │ ├── headtop_default.m │ │ │ │ ├── belly_default.m │ │ │ │ └── generateDefaultFunctionNames.m │ │ │ ├── buildSkelPathsFromMot.m │ │ │ ├── generateSkel.m │ │ │ ├── mapCoordinates.m │ │ │ ├── mapLabelNamesToVicon.m │ │ │ └── convert.m │ │ ├── ASFAMCparser │ │ │ ├── beginsWithColon.m │ │ │ ├── readName.m │ │ │ ├── readVersion.m │ │ │ ├── eatWhitespace.m │ │ │ ├── readSamplesPerSecond.m │ │ │ ├── readNumFramesBIN.m │ │ │ ├── findNextASFSection.m │ │ │ ├── readDocumentation.m │ │ │ ├── readSkin.m │ │ │ ├── readBonedata.m │ │ │ ├── readUnits.m │ │ │ ├── readHierarchyASF.m │ │ │ ├── constructAuxiliaryArrays.m │ │ │ ├── constructPaths.m │ │ │ ├── readNumFrames.m │ │ │ ├── constructSkeleton.m │ │ │ ├── getAMCLengthInSeconds.m │ │ │ ├── readRootASF.m │ │ │ ├── convert2quat.m │ │ │ ├── matrix_to_amc.m │ │ │ ├── readBone.m │ │ │ └── readASF.m │ │ ├── BVHparser │ │ │ ├── readRootBVH.m │ │ │ ├── extractRootTranslation.m │ │ │ ├── readOffset.m │ │ │ ├── readHierarchyBVH.m │ │ │ ├── readChannels.m │ │ │ ├── readBVH.m │ │ │ └── readMotion.m │ │ ├── escapeUnderscore.m │ │ ├── moveMotToXZ.m │ │ ├── DOFID.m │ │ ├── eatWhitespace.m │ │ ├── trajectoryID.m │ │ ├── findNextToken.m │ │ ├── rotateMotY.m │ │ ├── forwardKinematicsQuat.m │ │ ├── reflectMotYZ.m │ │ ├── averageFrontVector.m │ │ ├── scaleSkelMot.m │ │ ├── computeBoundingBox.m │ │ ├── findKeyword.m │ │ ├── readMocapD.m │ │ ├── emptySkeletonNode.m │ │ ├── readMocapSmart.m │ │ ├── readMocapGUI.m │ │ ├── recursive_forwardKinematicsQuat.m │ │ ├── forwardKinematicsEuler.m │ │ └── cropMot.m │ └── usage.m └── readTUMKitchenAnnotation.m ├── eval_package ├── extractGTFormat.m ├── calLocalFeatureAggregationWithEncodedFeatures_TUMKitchen.m ├── calLocalFeatureAggregationAndClustering_TUMKitchen.m ├── calLocalFeatureAggregationAndClusteringWithEncodedFeatures.m └── calLocalFeatureAggregationAndClustering.m ├── mex_dynamic_clustering └── compile.m └── python_dynamic_clustering ├── util_visualize.py └── run_dc.py /CMUMAD_example_segmentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yz-cnsdqz/dynamic_clustering/HEAD/CMUMAD_example_segmentation.png -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatCommutator.m: -------------------------------------------------------------------------------- 1 | function q=quatCommutator(q1,q2) 2 | 3 | q = quatmult(q1,quatmult(q2,quatmult(quatinv(q1),quatinv(q2)))); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/animateGUI.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yz-cnsdqz/dynamic_clustering/HEAD/ActionSegmentation_Pose/HDM05-Parser/animate/animateGUI.fig -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/matrix2quat.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yz-cnsdqz/dynamic_clustering/HEAD/ActionSegmentation_Pose/HDM05-Parser/quaternions/matrix2quat.m -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/directedAngle.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yz-cnsdqz/dynamic_clustering/HEAD/ActionSegmentation_Pose/HDM05-Parser/quaternions/directedAngle.m -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/data/HDM_dg_06-03_03_120.amc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yz-cnsdqz/dynamic_clustering/HEAD/ActionSegmentation_Pose/HDM05-Parser/data/HDM_dg_06-03_03_120.amc -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/data/HDM_dg_06-03_03_120.c3d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yz-cnsdqz/dynamic_clustering/HEAD/ActionSegmentation_Pose/HDM05-Parser/data/HDM_dg_06-03_03_120.c3d -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/buildSkelPathsForPointCloud.m: -------------------------------------------------------------------------------- 1 | function paths = buildSkelPathsForPointCloud(skel) 2 | 3 | for i = 1:skel.njoints 4 | paths{i,1} = [i;i]; 5 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/beginsWithColon.m: -------------------------------------------------------------------------------- 1 | function result = beginsWithColon(lin) 2 | 3 | result = false; 4 | if (length(lin)>0) 5 | if (lin(1) == ':') 6 | result = true; 7 | end 8 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/plotcoeffs.m: -------------------------------------------------------------------------------- 1 | function plotcoeffs(Q) 2 | 3 | N = size(Q,2); 4 | plot([1:N],Q); 5 | set(gca,'xlim',[1 N]); 6 | set(gca,'ylim',1.1*[min(min(Q)) max(max(Q))]); 7 | 8 | %axis([1,N,-1.1,1.1]); -------------------------------------------------------------------------------- /eval_package/extractGTFormat.m: -------------------------------------------------------------------------------- 1 | function dst = extractGTFormat(src) 2 | 3 | src(src(:,1)>=1000,1) = 36; 4 | 5 | act_label = src(:,1); 6 | n_frames = [src(1,3); diff(src(:,3))]; 7 | meaning1 = src(:,4); 8 | meaning2 = src(:,5); 9 | 10 | dst = [act_label n_frames meaning1 meaning2]; 11 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/BVHparser/readRootBVH.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readRoot(skel,fid) 2 | 3 | global currentPath; 4 | 5 | currentPath = 1; 6 | 7 | [result,skel,newnode_id] = readJoint(skel,0,fid); 8 | if ~result 9 | error('Error while parsing root.'); 10 | end 11 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/spheric4d2euclid4d.m: -------------------------------------------------------------------------------- 1 | function x = spheric4d2euclid4d(r,alpha,beta,gamma) 2 | 3 | x=zeros(4,size(r,2)); 4 | x(1,:) = r.*cos(alpha).*cos(beta).*cos(gamma); 5 | x(2,:) = r.*sin(alpha).*cos(beta).*cos(gamma); 6 | x(3,:) = r.*sin(beta).*cos(gamma); 7 | x(4,:) = r.*sin(gamma); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/BVHparser/extractRootTranslation.m: -------------------------------------------------------------------------------- 1 | function rootTranslation = extractRootTranslation(skel,data) 2 | 3 | itx = strmatch('tx',skel.nodes(1).DOF); 4 | ity = strmatch('ty',skel.nodes(1).DOF); 5 | itz = strmatch('tz',skel.nodes(1).DOF); 6 | 7 | rootTranslation = data([itx,ity,itz],:); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/getLabelIndex.m: -------------------------------------------------------------------------------- 1 | function labelIndex = getLabelIndex(nameMap, listOfLabels) 2 | 3 | for i = 1:size(listOfLabels,2) 4 | for j = 1:size(nameMap,1) 5 | if strcmp( listOfLabels(i), nameMap{j,1} ) 6 | labelIndex(i) = nameMap{j,3}; 7 | end 8 | end 9 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatexp.m: -------------------------------------------------------------------------------- 1 | function Q = quatexp(V) 2 | % Q = quatexp(V) 3 | % Quaternionic exponential without (Grassia's) scaling factor of 0.5 in the 4 | % argument 5 | % 6 | % input: V is a 3xn array of 3-vectors 7 | % output: Q(:,i) is the quaternionic exponential of V(:,i), 8 | 9 | Q = quatexp_rot(2*V); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatnormsq.m: -------------------------------------------------------------------------------- 1 | function P = quatnormsq(Q) 2 | % input: Q is a 4xn array of quaternions represented as column vectors 3 | % output: P(i) is the squared magnitude of the quaternion Q(:,i), 4 | 5 | if (size(Q,1)~=4) 6 | error('Input array: number of rows must be 4!'); 7 | end 8 | 9 | P = sum(Q.^2); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatconj.m: -------------------------------------------------------------------------------- 1 | function P = quatconj(Q) 2 | % input: Q is a 4xn array of quaternions represented as column vectors 3 | % output: P(:,i) is the conjugate quaternion of Q(:,i) 4 | 5 | if (size(Q,1)~=4) 6 | error('Input array: number of rows must be 4!'); 7 | end 8 | n = size(Q,2); 9 | 10 | P = Q .* [ones(1, n);-ones(3,n)]; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatinv.m: -------------------------------------------------------------------------------- 1 | function P = quatinv(Q) 2 | % input: Q is a 4xn array of quaternions represented as column vectors 3 | % output: P(:,i) is the inverse quaternion of invertible Q(:,i), else repmat(NaN,4,1) 4 | 5 | if (size(Q,1)~=4) 6 | error('Input array: number of rows must be 4!'); 7 | end 8 | 9 | P = quatconj(Q)./ (ones(4, 1)*quatnormsq(Q)); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatnormalize.m: -------------------------------------------------------------------------------- 1 | function P = quatnormalize(Q) 2 | % input: Q is a 4xn array of quaternions represented as column vectors 3 | % output: P(:,i) is a unit quaternion in the direction of Q(:,i), 4 | 5 | if (size(Q,1)~=4) 6 | error('Input array: number of rows must be 4!'); 7 | end 8 | 9 | nsq = sum(Q.^2); 10 | P = Q./repmat(sqrt(nsq),4,1); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/neck_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = neck_default( mot ) 2 | 3 | viconNames = {'C7', 'STRN', 'T10'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0.7 * mot.jointTrajectories{idx(1)} + 0.15 * mot.jointTrajectories{idx(2)} + 0.15 * mot.jointTrajectories{idx(3)}; 10 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/neck_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = neck_default( mot ) 2 | 3 | viconNames = {'C7'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lelbow_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lelbow_default( mot ) 2 | 3 | viconNames = {'LELB'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/relbow_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = relbow_default( mot ) 2 | 3 | viconNames = {'RELB'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lclavicle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lclavicle_default( mot ) 2 | 3 | viconNames = {'C7', 'STRN', 'T10'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0.7 * mot.jointTrajectories{idx(1)} + 0.15 * mot.jointTrajectories{idx(2)} + 0.15 * mot.jointTrajectories{idx(3)}; 10 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lelbow_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lelbow_default( mot ) 2 | 3 | viconNames = {'LELB'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lfingers_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lfingers_default( mot ) 2 | 3 | viconNames = {'LFIN'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rclavicle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rclavicle_default( mot ) 2 | 3 | viconNames = {'C7', 'STRN', 'T10'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0.7 * mot.jointTrajectories{idx(1)} + 0.15 * mot.jointTrajectories{idx(2)} + 0.15 * mot.jointTrajectories{idx(3)}; 10 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/relbow_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = relbow_default( mot ) 2 | 3 | viconNames = {'RELB'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rwrist_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rwrist_default( mot ) 2 | 3 | viconNames = {'RWRB', 'RWRA'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/skelfitATSrek.m: -------------------------------------------------------------------------------- 1 | function mot = skelfitATSrek( mot, jointIdx, skelTree, parentJoints ) 2 | 3 | childIdx = skelTree{jointIdx,2}; 4 | 5 | for i=1:length(childIdx) 6 | if not(ismember(childIdx(i), parentJoints)) 7 | mot = refitBone(mot, jointIdx, childIdx(i)); 8 | mot = skelfitATSrek(mot, childIdx(i), skelTree, [parentJoints jointIdx]); 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/chest_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = chest_default( mot ) 2 | 3 | viconNames = {'C7', 'STRN', 'T10'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lfingers_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lfingers_default( mot ) 2 | 3 | viconNames = {'LFIN'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lhip_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lhip_default( mot ) 2 | 3 | viconNames = {'LFWT', 'LBWT'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lshoulder_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lshoulder_default( mot ) 2 | 3 | viconNames = {'LSHO'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/ltoes_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = ltoes_default( mot ) 2 | 3 | viconNames = {'LTOE', 'LMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lwrist_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lwrist_default( mot ) 2 | 3 | viconNames = {'LWRB', 'LWRA'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rfingers_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rfingers_default( mot ) 2 | 3 | viconNames = {'RFIN'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rhip_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rhip_default( mot ) 2 | 3 | viconNames = {'RFWT', 'RBWT'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rshoulder_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rshoulder_default( mot ) 2 | 3 | viconNames = {'RSHO'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rtoes_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rtoes_default( mot ) 2 | 3 | viconNames = {'RTOE', 'RMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rwrist_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rwrist_default( mot ) 2 | 3 | viconNames = {'RWRB', 'RWRA'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lshoulder_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lshoulder_default( mot ) 2 | 3 | viconNames = {'LSHO'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/ltoes_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = ltoes_default( mot ) 2 | 3 | viconNames = {'LTOE', 'LMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lwrist_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lwrist_default( mot ) 2 | 3 | viconNames = {'LWRB', 'LWRA'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rshoulder_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rshoulder_default( mot ) 2 | 3 | viconNames = {'RSHO'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rtoes_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rtoes_default( mot ) 2 | 3 | viconNames = {'RTOE', 'RMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/root_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = root_default( mot ) 2 | 3 | viconNames = {'RFWT', 'LFWT', 'LBWT', 'RBWT'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/root_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = root_default( mot ) 2 | 3 | viconNames = {'STRN', 'RFWT', 'LFWT', 'LBWT', 'RBWT'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0; 10 | for i = 1:length(idx) 11 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 12 | end 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/headtop_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = headtop_default( mot ) 2 | 3 | viconNames = {'RFHD', 'LFHD', 'RBHD', 'LBHD'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strmatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0.15 * mot.jointTrajectories{idx(1)} + 0.15 * mot.jointTrajectories{idx(2)} + 0.35 * mot.jointTrajectories{idx(3)} + 0.35 * mot.jointTrajectories{idx(4)}; 10 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lclavicle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lclavicle_default( mot ) 2 | 3 | viconNames = {'C7', 'LSHO'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % can be adjusted to slide over to shoulder if needed: alpha \in [0:1] 10 | alpha = 1.0; 11 | trajectories = alpha * mot.jointTrajectories{idx(1)} + (1-alpha) * mot.jointTrajectories{idx(2)}; 12 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rclavicle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rclavicle_default( mot ) 2 | 3 | viconNames = {'C7', 'RSHO'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % can be adjusted to slide over to shoulder if needed: alpha \in [0:1] 10 | alpha = 1.0; 11 | trajectories = alpha * mot.jointTrajectories{idx(1)} + (1-alpha) * mot.jointTrajectories{idx(2)}; 12 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readName.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readName(skel,fid) 2 | 3 | [result,lin] = findNextASFSection(fid); 4 | if (~result) 5 | error(['Could not find NAME in ' skel.filename '!']); 6 | end 7 | 8 | [token,lin] = strtok(lin); 9 | token = token(2:end); % remove leading colon 10 | if ~strcmpi(token,'name') 11 | error(['Expected NAME in ' skel.filename '!']); 12 | end 13 | 14 | [token,lin] = strtok(lin); 15 | skel.name = token; 16 | 17 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rankle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rankle_default( mot ) 2 | 3 | viconNames = {'RANK', 'RTOE', 'RMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % Approximation: ankle joint is located 0.3 foot-widths from surface 10 | dist = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.3 * dist; 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/rknee_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rknee_default( mot ) 2 | 3 | viconNames = {'RKNE', 'RTOE', 'RMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % Approximation: knee joint is located 2/5 foot-width from surface 10 | dist = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.4 * dist; 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rankle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rankle_default( mot ) 2 | 3 | viconNames = {'RANK', 'RTOE', 'RMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % Approximation: ankle joint is located 0.3 foot-widths from surface 10 | dist = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.3 * dist; 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lankle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lankle_default( mot ) 2 | 3 | viconNames = {'LANK', 'LTOE', 'LMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % Approximation: ankle joint is located 0.3 foot-widths from surface 10 | dist = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.3 * dist; 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/lknee_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lknee_default( mot ) 2 | 3 | viconNames = {'LKNE', 'LTOE', 'LMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % Approximation: knee joint is located 2/5 foot-width from surface 10 | dist = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.4 * dist; 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lankle_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lankle_default( mot ) 2 | 3 | viconNames = {'LANK', 'LTOE', 'LMT5'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | % Approximation: ankle joint is located 0.3 foot-widths from surface 10 | dist = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.3 * dist; 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readVersion.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readVersion(skel,fid) 2 | 3 | [result,lin] = findNextASFSection(fid); 4 | if (~result) 5 | error(['Could not find VERSION in ' skel.filename '!']); 6 | end 7 | 8 | [token,lin] = strtok(lin); 9 | token = token(2:end); % remove leading colon 10 | if ~strcmpi(token,'version') 11 | error(['Expected VERSION in ' skel.filename '!']); 12 | end 13 | 14 | [token,lin] = strtok(lin); 15 | skel.version = token; 16 | 17 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/eatWhitespace.m: -------------------------------------------------------------------------------- 1 | function l_out = eatWhitespace(l_in) 2 | % fast forward in file, skipping whitespace and #-comments 3 | n = 1; % begin pointer 4 | m = length(l_in); % end pointer 5 | for i = 1:length(l_in) 6 | c = double(l_in(i)); 7 | if (c == 9) | (c == 10) | (c == 13) | (c == 32) % TAB, CR, LF, SPC 8 | n = n+1; 9 | elseif (c=='#') % ASF comment 10 | m = i-1; 11 | else 12 | break; 13 | end 14 | end 15 | l_out = l_in(n:m); 16 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lknee_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lknee_default( mot ) 2 | 3 | viconNames = {'LKNE', 'LTOE', 'LMT5', 'LANK'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | distX = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 10 | distY = mot.jointTrajectories{idx(3)} - mot.jointTrajectories{idx(4)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.6 * distX + 0.2 * distY; 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rknee_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rknee_default( mot ) 2 | 3 | viconNames = {'RKNE', 'RTOE', 'RMT5', 'RANK'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | distX = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 10 | distY = mot.jointTrajectories{idx(3)} - mot.jointTrajectories{idx(4)}; 11 | 12 | trajectories = mot.jointTrajectories{idx(1)} + 0.6 * distX + 0.2 * distY; 13 | 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/refitBone.m: -------------------------------------------------------------------------------- 1 | function mot = refitBone( mot, jointIdx1, jointIdx2 ) 2 | % enforces fixed bone length for this bone over all frames of the animation 3 | 4 | % determine desired length 5 | % crop to length 6 | 7 | diffVect = mot.jointTrajectories{jointIdx2} - mot.jointTrajectories{jointIdx1}; 8 | diffLen = sqrt(dot(diffVect,diffVect)); 9 | targetLength = mean(diffLen); 10 | 11 | mot.jointTrajectories{jointIdx2} = mot.jointTrajectories{jointIdx1} + targetLength * (diffVect ./ [diffLen;diffLen;diffLen]); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/proj2hyperplane.m: -------------------------------------------------------------------------------- 1 | function y = proj2hyperplane(n,c,x) 2 | dim = size(x,1); 3 | 4 | i = find(n); % find first nonzero component of n 5 | if (size(i) == 0) 6 | return; 7 | end; 8 | i = i(1); 9 | 10 | B = zeros(dim,dim); 11 | B(1:dim,1) = n; 12 | 13 | E = eye(dim); 14 | B(:,2:dim) = [E(:,1:i-1) E(:,i+1:dim)]; 15 | B = gramschmidt(B); 16 | x = B * x; % change of basis such that n = e1 17 | 18 | % projection of x onto (affine) plane defined by n 19 | y = x(setdiff([1:dim],i),:); 20 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/head_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = head_default( mot ) 2 | 3 | viconNames = {'RFHD', 'LFHD', 'RBHD', 'LBHD', 'C7'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | mid1 = 0.25 * mot.jointTrajectories{idx(1)} + 0.25 * mot.jointTrajectories{idx(2)} + 0.25 * mot.jointTrajectories{idx(3)} + 0.25 * mot.jointTrajectories{idx(4)}; 10 | mid2 = mot.jointTrajectories{idx(5)}; 11 | 12 | trajectories = 0.5 * mid1 + 0.5 * mid2; 13 | -------------------------------------------------------------------------------- /mex_dynamic_clustering/compile.m: -------------------------------------------------------------------------------- 1 | delete *.mexa64 2 | mexOpenCV dynamic_clustering.cpp -I/usr/local/include -L/usr/local/lib -L/usr/local/cuda-8.0/lib64 -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lcufft -lnpps -lnppi -lnppc -lcudart -lrt -lpthread -lm -ldl -lboost_system -lboost_filesystem -lboost_timer 3 | 4 | 5 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/BVHparser/readOffset.m: -------------------------------------------------------------------------------- 1 | function [result,newnode] = readOffset(newnode,fid) 2 | 3 | [result, lin] = findKeyword(fid,'OFFSET'); 4 | if ~result 5 | error(['BVH section OFFSET not found for node ' newnode.name '!']); 6 | return; 7 | end 8 | lin = deblank(lin(8:size(lin,2))); % remove 'OFFSET' at beginning of line, trim 9 | newnode.offset = sscanf(lin,'%f%f%f'); 10 | newnode.length = norm(newnode.offset); 11 | if (newnode.length > eps) 12 | newnode.direction = (1/newnode.length)*newnode.offset; 13 | end 14 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/head_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = head_default( mot ) 2 | 3 | viconNames = {'RFHD', 'LFHD', 'RBHD', 'LBHD', 'C7'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strmatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | mid1 = 0.25 * mot.jointTrajectories{idx(1)} + 0.25 * mot.jointTrajectories{idx(2)} + 0.25 * mot.jointTrajectories{idx(3)} + 0.25 * mot.jointTrajectories{idx(4)}; 10 | mid2 = mot.jointTrajectories{idx(5)}; 11 | 12 | trajectories = 0.4 * mid1 + 0.6 * mid2; 13 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/headtop_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = headtop_default( mot ) 2 | 3 | viconNames = {'RFHD', 'LFHD', 'RBHD', 'LBHD', 'C7'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | mid1 = 0.25 * mot.jointTrajectories{idx(1)} + 0.25 * mot.jointTrajectories{idx(2)} + 0.25 * mot.jointTrajectories{idx(3)} + 0.25 * mot.jointTrajectories{idx(4)}; 10 | mid2 = mot.jointTrajectories{idx(5)}; 11 | 12 | trajectories = mid1 + 0.3 * (mid1 - mid2); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/callbackFunctions/belly_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = belly_default( mot ) 2 | 3 | viconNames = {'STRN', 'T10', 'RFWT', 'LFWT', 'LBWT', 'RBWT'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0.4 * mot.jointTrajectories{idx(1)} + 0.4 * mot.jointTrajectories{idx(2)} + 0.05 * mot.jointTrajectories{idx(3)} ... 10 | + 0.05 * mot.jointTrajectories{idx(4)} + 0.05 * mot.jointTrajectories{idx(5)} + 0.05*mot.jointTrajectories{idx(6)}; 11 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/belly_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = belly_default( mot ) 2 | 3 | viconNames = {'STRN', 'T10', 'RFWT', 'LFWT', 'LBWT', 'RBWT'}; 4 | 5 | for i = 1:length(viconNames) 6 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 7 | end 8 | 9 | trajectories = 0.1 * mot.jointTrajectories{idx(1)} + 0.3 * mot.jointTrajectories{idx(2)} + 0.1 * mot.jointTrajectories{idx(3)} ... 10 | + 0.1 * mot.jointTrajectories{idx(4)} + 0.2 * mot.jointTrajectories{idx(5)} + 0.2 * mot.jointTrajectories{idx(6)}; 11 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readSamplesPerSecond.m: -------------------------------------------------------------------------------- 1 | function mot = readSamplesPerSecond(mot,fid) 2 | 3 | pos = ftell(fid); 4 | [result,lin] = findNextASFSection(fid); 5 | if (~result) 6 | return; % SAMPLES-PER-SECOND is optional! 7 | end 8 | 9 | [token,lin] = strtok(lin); 10 | token = token(2:end); % remove leading colon 11 | if ~strcmpi(token,'SAMPLES-PER-SECOND') 12 | fseek(fid,pos,'bof'); 13 | return; % UNITS are optional! 14 | end 15 | 16 | [token,lin] = strtok(lin); 17 | mot.samplingRate = str2num(token); 18 | mot.frameTime = 1/mot.samplingRate; 19 | 20 | fseek(fid,pos,'bof'); 21 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/matrix2angle_axis.m: -------------------------------------------------------------------------------- 1 | function [phi,A] = matrix2angle_axis(M) 2 | 3 | M11 = squeeze(M(1,1,:))'; 4 | M12 = squeeze(M(1,2,:))'; 5 | M13 = squeeze(M(1,3,:))'; 6 | M21 = squeeze(M(2,1,:))'; 7 | M22 = squeeze(M(2,2,:))'; 8 | M23 = squeeze(M(2,3,:))'; 9 | M31 = squeeze(M(3,1,:))'; 10 | M32 = squeeze(M(3,2,:))'; 11 | M33 = squeeze(M(3,3,:))'; 12 | 13 | S1 = M32 - M23; 14 | S2 = M13 - M31; 15 | S3 = M21 - M12; 16 | 17 | TR = M11 + M22 + M33; 18 | 19 | lengths = sqrt(S1.^2+S2.^2+S3.^2); 20 | A = [S1;S2;S3]./repmat(lengths,3,1); 21 | S = lengths/2; 22 | C = 0.5*(TR-1); 23 | phi = atan2(S,C); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readNumFramesBIN.m: -------------------------------------------------------------------------------- 1 | function n = readNumFramesBIN(fid) 2 | 3 | numDOF = []; % auxiliary array containing the respective numbers of DOFs 4 | while (~feof(fid)) 5 | token = fscanf(fid,'%s ',1); % read bone label 6 | h = fscanf(fid,'%d\n',1); % read nDOF and newline 7 | if (~isnan(str2double(token))) % reached beginning of frame data! 8 | break; 9 | end 10 | numDOF = [numDOF; h]; 11 | end 12 | 13 | totalNumDOF = sum(numDOF); 14 | pos1 = ftell(fid); 15 | fseek(fid,0,'eof'); 16 | pos2 = ftell(fid); 17 | fclose(fid); 18 | 19 | n = (pos2 - pos1 + 1)/(8*totalNumDOF); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/calculateBoneLengths.m: -------------------------------------------------------------------------------- 1 | function boneLengths = calculateBoneLengths( mot ) 2 | 3 | nJoints = length(mot.jointTrajectories); 4 | nFrames = length(mot.jointTrajectories{1}); 5 | 6 | skelBones = extractSkelBones(mot.nameMap); 7 | 8 | for i=1:length(skelBones) 9 | idx1 = skelBones{i}(1); 10 | idx2 = skelBones{i}(2); 11 | traj1 = mot.jointTrajectories{idx1}; 12 | traj2 = mot.jointTrajectories{idx2}; 13 | 14 | diff = traj1-traj2; 15 | diff = sqrt(dot(diff,diff)); 16 | 17 | boneLengths(i,1) = idx1; 18 | boneLengths(i,2) = idx2; 19 | boneLengths(i,3) = mean(diff); 20 | end 21 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/gramschmidt.m: -------------------------------------------------------------------------------- 1 | function B = gramschmidt(A) 2 | n = size(A,1); 3 | if (size(A,2) ~= n) 4 | return; 5 | end; 6 | B = zeros(n,n); 7 | 8 | B(:,1) = (1/norm(A(:,1)))*A(:,1); 9 | 10 | for i=2:n 11 | v = A(:,i); 12 | U = B(:,1:i-1); % subspace basis which has already been orthonormalized 13 | pc = transpose(U)*v; % orthogonal projection coefficients of v onto U 14 | p = U * pc; % orthogonal projection vector of v onto U 15 | v = v - p; 16 | if (norm(v) 0, lower 21 | % % hemisphere, s < 0) 22 | % s = [1 dot(q(:, 1:numFrames-1), q(:, 2:numFrames))]; 23 | % s(s<0) = -1; 24 | % s(s>0) = 1; 25 | % sDiff = [0 diff(s)]; 26 | % 27 | % 28 | % % change the sign of the quats that lie in the lower hemisphere. 29 | % q(:, s<0) = -1*q(:, s<0); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readSkin.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readSkin(skel,fid) 2 | 3 | pos = ftell(fid); 4 | [result,lin] = findNextASFSection(fid); 5 | if (~result) 6 | return; % SKIN is optional! 7 | end 8 | 9 | [token,lin] = strtok(lin); 10 | token = token(2:end); % remove leading colon 11 | if ~strcmpi(token,'skin') 12 | fseek(fid,pos,'bof'); 13 | return; % SKIN is optional! 14 | end 15 | 16 | % read first skin filename 17 | n = 1; 18 | [token,lin] = strtok(lin); 19 | if (~isempty(token)) 20 | skel.skin{n,1} = token; 21 | n = n+1; 22 | end 23 | 24 | % read remaining skin filenames 25 | while (~feof(fid)) 26 | lin = eatWhitespace(fgetl(fid)); 27 | if (length(lin)<1) 28 | continue; 29 | end 30 | if (beginsWithColon(lin)) 31 | break; 32 | end 33 | 34 | skel.skin{n,1} = lin; 35 | n = n+1; 36 | end 37 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/lhip_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = lhip_default( mot ) 2 | 3 | % REMARK: unfortunately the 'LTHI' marker is not available in all takes, 4 | % so we can not use it for estimation. 5 | 6 | viconNames = {'LFWT', 'LBWT', 'RBWT'}; 7 | 8 | for i = 1:length(viconNames) 9 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 10 | end 11 | 12 | % compute vector orthogonal to ('LFWT', 'LBWT', 'RBWT') - plane 13 | v1 = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(1)}; 14 | v2 = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 15 | orth = cross(v1,v2); 16 | normOrth = sqrt(dot(orth,orth)); 17 | 18 | % scale length to 'LFWT'-'LBWT' distance 19 | orth = orth ./ [normOrth;normOrth;normOrth] * mean(sqrt(dot(v1,v1))); 20 | 21 | % estimate position 22 | trajectories = 0.7 * mot.jointTrajectories{idx(1)} + 0.3 * mot.jointTrajectories{idx(2)} + 0.4 * orth; 23 | 24 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rhip_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rhip_default( mot ) 2 | 3 | % REMARK: unfortunately the 'RTHI' marker is not available in all takes, 4 | % so we can not use it for estimation. 5 | 6 | viconNames = {'RFWT', 'RBWT', 'LBWT'}; 7 | 8 | for i = 1:length(viconNames) 9 | idx(i) = strMatch(viconNames(i), mot.nameMap(:,1)); 10 | end 11 | 12 | % compute vector orthogonal to ('LFWT', 'LBWT', 'RBWT') - plane 13 | v1 = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(1)}; 14 | v2 = mot.jointTrajectories{idx(2)} - mot.jointTrajectories{idx(3)}; 15 | orth = cross(v2,v1); 16 | normOrth = sqrt(dot(orth,orth)); 17 | 18 | % scale length to 'LFWT'-'LBWT' distance 19 | orth = orth ./ [normOrth;normOrth;normOrth] * mean(sqrt(dot(v1,v1))); 20 | 21 | % estimate position 22 | trajectories = 0.7 * mot.jointTrajectories{idx(1)} + 0.3 * mot.jointTrajectories{idx(2)} + 0.4 * orth; 23 | 24 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/sphericalAverage_incremental_approx.m: -------------------------------------------------------------------------------- 1 | function [q,Q] = sphericalAverage_incremental_approx(P,varargin) 2 | 3 | w = 1/(size(P,2))*ones(1,size(P,2)); 4 | if (nargin>1) 5 | w = varargin{1}; 6 | end 7 | 8 | if (size(P,1)~=4) 9 | error('P must be a 4xn array!'); 10 | end 11 | n = size(P,2); 12 | if (size(w,1)~=1) 13 | error('Weights must be a row vector!'); 14 | end 15 | if (size(w,2)~=n) 16 | error('#quaternions = #weights required!'); 17 | end 18 | if (abs(sum(w)-1)>1000*eps) 19 | error('Sum of weights must be 1!'); 20 | end 21 | 22 | Q = zeros(4,n); 23 | Q(:,1) = P(:,1); 24 | 25 | w_sum = w(1); 26 | for i = 2:n 27 | w_sum = w_sum+w(i); 28 | v = w(i)/w_sum; 29 | Q(:,i) = quatmult(Q(:,i-1),quatexp((1-v)*quatlog(quatmult(quatinv(Q(:,i-1)),P(:,i))))); 30 | %Q(:,i) = quatexp((1-v)*quatlog(Q(:,i-1)) + v*quatlog(P(:,i))); 31 | end 32 | 33 | q = Q(:,n); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readBonedata.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readBonedata(skel,fid) 2 | 3 | [result,lin] = findNextASFSection(fid); 4 | if (~result) 5 | error(['ASF: Could not find BONEDATA in ' skel.filename '!']); 6 | end 7 | 8 | [token,lin] = strtok(lin); 9 | token = token(2:end); % remove leading colon 10 | if ~strcmpi(token,'BONEDATA') 11 | error(['ASF: Expected BONEDATA in ' skel.filename '!']); 12 | end 13 | 14 | bonedata = emptySkeletonNode; 15 | k = 2; 16 | while (~feof(fid)) 17 | pos = ftell(fid); 18 | lin = eatWhitespace(fgetl(fid)); 19 | if (length(lin)<1) 20 | continue; 21 | end 22 | if (beginsWithColon(lin)) 23 | fseek(fid,pos,'bof'); 24 | break; % we have passed the end of the bonedata section 25 | end 26 | fseek(fid,pos,'bof'); 27 | 28 | [result, skel.nodes(k,1)] = readBone(skel,fid); 29 | skel.njoints = skel.njoints + 1; 30 | k = k+1; 31 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/callbackFunctions/rfingers_default.m: -------------------------------------------------------------------------------- 1 | function trajectories = rfingers_default( mot ) 2 | 3 | viconNames = {'RFIN'}; 4 | idx = []; 5 | 6 | for i = 1:length(viconNames) 7 | temp = strMatch(viconNames(i), mot.nameMap(:,1)); 8 | if not(isempty(temp)) 9 | idx(i) = temp; 10 | end 11 | end 12 | 13 | trajectories = 0; 14 | idx = idx(find(idx)); 15 | 16 | for i = 1:length(idx) 17 | trajectories = trajectories + 1/length(idx) * mot.jointTrajectories{idx(i)}; 18 | end 19 | 20 | if isempty(idx) 21 | viconNames = {'LFIN', 'RWRA', 'RWRB', 'LWRA'}; 22 | idx = []; 23 | 24 | for i = 1:length(viconNames) 25 | temp = strMatch(viconNames(i), mot.nameMap(:,1)); 26 | if not(isempty(temp)) 27 | idx(i) = temp; 28 | end 29 | end 30 | 31 | trajectories = 0.5*(mot.jointTrajectories{idx(2)} + mot.jointTrajectories{idx(3)}) + mot.jointTrajectories{idx(1)} - mot.jointTrajectories{idx(4)}; 32 | end 33 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/mapCoordinates.m: -------------------------------------------------------------------------------- 1 | function coordinateMapping = mapCoordinates(xScreen, yScreen); 2 | x = char(xScreen); 3 | y = char(yScreen); 4 | 5 | if strfind(x, 'X') ~= 0 6 | coordinateMapping(1) = 1; 7 | if strfind(y, 'Y') ~= 0 8 | coordinateMapping(2) = 2; 9 | coordinateMapping(3) = 3; 10 | else 11 | coordinateMapping(2) = 3; 12 | coordinateMapping(3) = 2; 13 | end 14 | elseif strfind(x, 'Y') ~= 0 15 | coordinateMapping(1) = 2; 16 | if strfind(y, 'X') ~= 0 17 | coordinateMapping(2) = 1; 18 | coordinateMapping(3) = 3; 19 | else 20 | coordinateMapping(2) = 3; 21 | coordinateMapping(3) = 1; 22 | end 23 | elseif strfind(x, 'Z') ~= 0 24 | coordinateMapping(1) = 3; 25 | if strfind(y, 'X') ~= 0 26 | coordinateMapping(2) = 1; 27 | coordinateMapping(3) = 2; 28 | else 29 | coordinateMapping(2) = 2; 30 | coordinateMapping(3) = 1; 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/BVHparser/readHierarchyBVH.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readHierarchy(skel,fid) 2 | 3 | [result, line] = findKeyword(fid,'HIERARCHY'); 4 | if ~result 5 | error(['BVH section HIERARCHY not found in file ' skel.filename '!']); 6 | return; 7 | end 8 | 9 | tic; 10 | [result, skel] = readRootBVH(skel,fid); 11 | t=toc; 12 | disp(['Read skeleton data from ' skel.filename ' in ' num2str(t) ' seconds.']); 13 | 14 | 15 | %%%%%%%%% fill in joint names, bone names and animated/unanimated arrays 16 | skel.jointNames = cell(skel.njoints,1); 17 | skel.boneNames = cell(skel.njoints,1); 18 | for k=1:length(skel.nodes) 19 | if ~isempty(skel.nodes(k).DOF{1}) 20 | skel.animated = [skel.animated; k]; 21 | else 22 | skel.unanimated = [skel.unanimated; k]; 23 | end 24 | 25 | skel.jointNames{k,1} = skel.nodes(k).jointName; 26 | skel.boneNames{k,1} = skel.nodes(k).boneName; 27 | end 28 | 29 | skel.nameMap = constructNameMap(skel); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/resampleQuats.m: -------------------------------------------------------------------------------- 1 | function quatTarget = resampleQuats(quatSource, fsSource, fsTarget) 2 | % FUNCTION resampleQuats(quatSource, fsSource, fsTarget) resamples 3 | % quaternions according to arbitrary (floating point) sampling rates. It 4 | % does NOT filter the quaternions before resampling. 5 | % 6 | % Author: Andreas Baak 7 | % Date: 20.05.09 8 | % 9 | % 10 | % INPUT: quatSource: (4xN double array) 11 | % fsSource: sampling rate of the quats 12 | % fsTarget: desired target sampling rate 13 | 14 | if size(quatSource, 1) ~= 4 15 | error('input quaternions should be a 4xN matrix.'); 16 | end 17 | 18 | nframes = size(quatSource, 2); 19 | slope = fsSource/fsTarget; 20 | samples = 1:slope:nframes; 21 | interpCoeff = samples - floor(samples); 22 | samples = floor(samples); 23 | 24 | % interpolate between the right samples of the source signal. 25 | 26 | quatTarget = slerpNQuats(quatSource(:,samples), quatSource(:,samples+1), interpCoeff, 10^-6); 27 | 28 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatexp_rot.m: -------------------------------------------------------------------------------- 1 | function P = quatexp_rot(Q) 2 | % P = quatexp_rot(Q) 3 | % Implementation according to Grassia (1998) 4 | % 5 | % input: Q is a 3xn array of 3-vectors 6 | % output: P(:,i) is the quaternionic exponential of Q(:,i) 7 | 8 | if (size(Q,1)~=3) 9 | error('Input array: number of rows must be 3!'); 10 | end 11 | n = size(Q,2); 12 | 13 | thresh = eps^(1/4); 14 | 15 | theta = sqrt(sum(Q(:,:).^2)); % euclidean length of the vector part 16 | zero = theta0) 21 | vector_parts(:,zero) = repmat((0.5 + (1/48)*theta(:, zero).^2),3,1) .* Q(:,zero); % use first two terms of sinc taylor expansion 22 | %end 23 | %if length(nonzero>0) 24 | vector_parts(:,nonzero) = repmat(sin(0.5*theta(:, nonzero)),3,1).*(Q(:,nonzero)./repmat(theta(:, nonzero),3,1)); 25 | %end 26 | 27 | real_parts = cos(0.5*theta); 28 | 29 | P = [real_parts;vector_parts]; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatlog.m: -------------------------------------------------------------------------------- 1 | function P = quatlog(varargin) 2 | % P = quatlog(Q, tol) 3 | % Quaternionic logarithm, without (Grassia's) scaling factor of 2. 4 | % 5 | % input: Q is a 4xn array of quaternions represented as column vectors. 6 | % If tol is specified, it denotes the allowable deviation from unit 7 | % length for the input quaternions. Deviations less than tol will 8 | % lead to re-normalization, deviations larger than tol will lead 9 | % to re-normalization and a warning. If tol is not specified, 10 | % all deviations larger than the machine precision will lead to 11 | % an error. 12 | % 13 | % output: P(:,i) is a 3-vector, the quaternionic logarithm of the 14 | % quaternion Q(:,i) 15 | 16 | switch (nargin) 17 | case 1 18 | Q = varargin{1}; 19 | tol = 1000 * eps; 20 | case 2 21 | Q = varargin{1}; 22 | tol = varargin{2}; 23 | otherwise 24 | error('Wrong number of arguments.'); 25 | end 26 | 27 | P = quatlog_rot(Q,tol)/2; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatrot.m: -------------------------------------------------------------------------------- 1 | function Y = quatrot(X,Q) 2 | % Y = quatrot(X,Q) 3 | % Rotate vectors in 3xN matrix X by quaternions in Q. 4 | % If Q is 4xN, "point-wise" rotation will be performed. 5 | % If Q is 4x1, all vectors in X will be rotated by Q. 6 | % 7 | % Remark: To concatenate rotations in quaternion representation, multiply them from left to right, 8 | % just like rotation matrices. 9 | % Example: First rotating by q1, then by q2 is equivalent to rotating by quatmult(q2,q1). 10 | 11 | if (size(X,1)~=3) 12 | error('X has to be 3xN.'); 13 | end 14 | if (size(Q,1)~=4) 15 | error('Q has to have 4 rows (quaternions!).'); 16 | end 17 | 18 | N = size(X,2); 19 | M = size(Q,2); 20 | if (M==1 && N>=1) 21 | Q = Q(:, ones(1, N)); 22 | M = size(Q,2); 23 | end 24 | 25 | if (M>=1 && N==1) 26 | X = X(:, ones(1, M)); 27 | N = size(X,2); 28 | end 29 | 30 | if (M==N) 31 | Y = quatmult(quatmult(Q,[zeros(1,N);X]),quatinv(Q)); 32 | Y = Y(2:4,:); 33 | else 34 | error('Size mismatch between X and Q!'); 35 | end 36 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/escapeUnderscore.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [ escapedString ] = escapeUnderscore( string ) 22 | %ESCAPEUNDERSCORE Escapes all underscores _ of string to \_ . 23 | 24 | escapedString = strrep(string, '_', '\_'); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quat2matrix.m: -------------------------------------------------------------------------------- 1 | function R = quat2matrix(Q) 2 | % R = quat2matrix(Q) 3 | % Converts quaternions to the corresponding rotation matrix 4 | % representations. 5 | % 6 | % Input: Q, 4xn array of quaterions 7 | % 8 | % Output: R, 3x3xn array of rotation matrices 9 | % 10 | % Reference: Shoemake(1985) 11 | % 12 | % Remark: Shoemake uses the quaternion rotation formula x' = q^{-1}xq. 13 | % We use the more common convention x' = qxq^{-1}. This leads to 14 | % transposed matrices (opposed to Shoemake's formulas), or, 15 | % equivalently, inverted quaternion representations. 16 | 17 | n = size(Q,2); 18 | 19 | Q = quatnormalize(Q); 20 | 21 | R = zeros(3,3,n); 22 | w = Q(1,:); 23 | x = Q(2,:); 24 | y = Q(3,:); 25 | z = Q(4,:); 26 | 27 | R(1,1,:) = 1 - 2*y.^2 - 2*z.^2; 28 | R(2,1,:) = 2*x.*y + 2*w.*z; 29 | R(3,1,:) = 2*x.*z - 2*w.*y; 30 | R(1,2,:) = 2*x.*y - 2*w.*z; 31 | R(2,2,:) = 1 - 2*x.^2 - 2*z.^2; 32 | R(3,2,:) = 2*y.*z + 2*w.*x; 33 | R(1,3,:) = 2*x.*z + 2*w.*y; 34 | R(2,3,:) = 2*y.*z - 2*w.*x; 35 | R(3,3,:) = 1 - 2*x.^2 - 2*y.^2; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/orientationFilter.m: -------------------------------------------------------------------------------- 1 | function b = orientationFilter(a) 2 | % b = orientationFilter(a) 3 | % Constructs a filter for orientation data filtering from a standard 4 | % symmetric convolution filter. 5 | % 6 | % Input: symmetric row vector, odd length, sum = 1 7 | % Output: corresponding orientation filter 8 | % 9 | % Reference: J. Lee and S. Shin: General Construction of Time-Domain Filters for Orientation Data, 10 | % Trans. IEEE Vis. and Comp. Graph., 2002 11 | 12 | 13 | if (size(a,1)~=1) 14 | error('Filter must be a row vector!'); 15 | end 16 | 17 | if (abs(sum(a)-1)>1000*eps) 18 | error('Sum of filter coefficients must be 1!'); 19 | end 20 | 21 | if (mod(length(a),2)==1) 22 | k = (length(a)-1)/2; 23 | if (abs(sum(a(1:k) - fliplr(a(k+2:2*k+1))))>1000*eps) 24 | error('Filter must be symmetric!'); 25 | end 26 | else 27 | error('Filter length must be odd!'); 28 | end 29 | 30 | b = zeros(1,2*k); 31 | for m = 1:k 32 | b(m) = -sum(a(1:m)); 33 | end 34 | for m = k+1:2*k 35 | b(m) = sum(a(m+1:2*k+1)); 36 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readUnits.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readUnits(skel,fid) 2 | 3 | pos = ftell(fid); 4 | [result,lin] = findNextASFSection(fid); 5 | if (~result) 6 | return; % UNITS are optional! 7 | end 8 | 9 | [token,lin] = strtok(lin); 10 | token = token(2:end); % remove leading colon 11 | if ~strcmpi(token,'units') 12 | fseek(fid,pos,'bof'); 13 | return; % UNITS are optional! 14 | end 15 | 16 | while (~feof(fid)) 17 | pos = ftell(fid); 18 | lin = eatWhitespace(fgetl(fid)); 19 | if (length(lin)<1) 20 | continue; 21 | end 22 | if (beginsWithColon(lin)) 23 | break; 24 | end 25 | 26 | [token,lin] = strtok(lin); 27 | [token2,lin] = strtok(lin); 28 | switch (upper(token)) 29 | case 'MASS' 30 | skel.massUnit = str2num(token2); 31 | case 'LENGTH' 32 | skel.lengthUnit = str2num(token2); 33 | case 'ANGLE' 34 | skel.angleUnit = token2; 35 | otherwise 36 | warning(['Unknown UNIT: ' token '!']); 37 | end 38 | end 39 | fseek(fid,pos,'bof'); 40 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/params_point.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function points = params_point(mot,p1_name) 22 | 23 | if (ischar(p1_name)) 24 | p1 = trajectoryID(mot,p1_name); 25 | else 26 | p1 = mot.nameMap{p1_name,3}; 27 | end 28 | 29 | points = mot.jointTrajectories{p1}; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/pauseAnimation.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function pauseAnimation 22 | global VARS_GLOBAL_ANIM 23 | 24 | t = timerfind('Name','AnimationTimer'); 25 | if(~isempty(t)) 26 | t = t(1); 27 | stop(t); 28 | wait(t); 29 | 30 | VARS_GLOBAL_ANIM.animation_paused = true; 31 | end 32 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/updateAnimationSlider.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function updateAnimationSlider(current_frame,slider_handle); 22 | 23 | minimum = get(slider_handle, 'Min'); 24 | maximum = get(slider_handle, 'Max'); 25 | 26 | if (current_frame>=minimum & current_frame<=maximum) 27 | set(slider_handle, 'Value', current_frame); 28 | end 29 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/extractSkelBones.m: -------------------------------------------------------------------------------- 1 | function skelBones = extractSkelBones( nameMap ) 2 | 3 | % bones = { {'LSHO', 'LELB'}, {'LKNE', 'LANK'}, {'LFWT', 'LKNE'}, {'LELB', 'LFRM'}, {'LFRM', 'LWRB'}, {'LSHO', 'CLAV'}, ... 4 | % {'RSHO', 'RELB'}, {'RKNE', 'RANK'}, {'RFWT', 'RKNE'}, {'RELB', 'RFRM'}, {'RFRM', 'RWRB'}, {'RSHO', 'CLAV'} }; 5 | bones = { {'neck', 'lclavicle'}, {'lclavicle', 'lshoulder'}, {'lshoulder', 'lelbow'}, {'lelbow', 'lwrist'}, {'lwrist', 'lfingers'}, ... 6 | {'neck', 'rclavicle'}, {'rclavicle', 'rshoulder'}, {'rshoulder', 'relbow'}, {'relbow', 'rwrist'}, {'rwrist', 'rfingers'}, ... 7 | {'root', 'lhip'}, {'lhip', 'lknee'}, {'lknee', 'lankle'}, {'lankle', 'ltoes'}, ... 8 | {'root', 'rhip'}, {'rhip', 'rknee'}, {'rknee', 'rankle'}, {'rankle', 'rtoes'}, ... 9 | {'root', 'belly'}, {'belly', 'chest'}, {'chest', 'neck'}, {'neck', 'head'}, {'head', 'headtop'} }; 10 | 11 | 12 | for i=1:length(bones) 13 | j1 = bones{i}(1); 14 | j2 = bones{i}(2); 15 | 16 | idx1 = strmatch(j1, nameMap(:,1), 'exact'); 17 | idx2 = strmatch(j2, nameMap(:,1), 'exact'); 18 | 19 | skelBones{i}(1) = nameMap{idx1(1,1),3}; 20 | skelBones{i}(2) = nameMap{idx2(1,1),3}; 21 | end 22 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readHierarchyASF.m: -------------------------------------------------------------------------------- 1 | function [result,hierarchy] = readHierarchy(fid) 2 | 3 | [result,lin] = findNextASFSection(fid); 4 | if (~result) 5 | error(['ASF: Could not find HIERARCHY in ' skel.filename '!']); 6 | end 7 | 8 | [token,lin] = strtok(lin); 9 | token = token(2:end); % remove leading colon 10 | if ~strcmpi(token,'HIERARCHY') 11 | error(['ASF: Expected HIERARCHY in ' skel.filename '!']); 12 | end 13 | 14 | [result, lin] = findKeyword(fid,'begin'); 15 | if ~result 16 | error('ASF: Expected BEGIN while reading hierarchy!'); 17 | end 18 | 19 | hierarchy = cell(1,1); 20 | k = 1; 21 | while (~feof(fid)) 22 | pos = ftell(fid); 23 | lin = eatWhitespace(fgetl(fid)); 24 | if (length(lin)<1) 25 | continue; 26 | end 27 | if (strcmpi(lin(1:3),'end')) 28 | break; % passed end of hierarchy! 29 | end 30 | 31 | n = 1; 32 | while ~isempty(lin) 33 | [token,lin] = strtok(lin); 34 | hierarchy{k,n} = token; 35 | n = n+1; 36 | end 37 | k = k+1; 38 | end 39 | fseek(fid,pos,'bof'); 40 | 41 | [result, lin] = findKeyword(fid,'end'); 42 | if ~result 43 | error('ASF: Expected END while reading hierarchy!'); 44 | end 45 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/constructAuxiliaryArrays.m: -------------------------------------------------------------------------------- 1 | function skel = constructAuxiliaryArrays(skel, currentNode_id) 2 | % traverse kinematic chain filling in skel's "name" and "animated/unanimated" arrays 3 | 4 | if (size(skel.nodes(currentNode_id).DOF)>0) 5 | skel.animated = [skel.animated; currentNode_id]; 6 | else 7 | skel.unanimated = [skel.unanimated; currentNode_id]; 8 | end 9 | 10 | if (currentNode_id>1) % leave the root alone! 11 | skel.nodes(currentNode_id).jointName = [skel.nodes(skel.nodes(currentNode_id).parentID).boneName '_@_' skel.nodes(currentNode_id).boneName]; 12 | end 13 | 14 | childCount = size(skel.nodes(currentNode_id).children,1); 15 | if (childCount <= 0) % for childless nodes, simply copy the existing joint/bone names into name arrays 16 | skel.jointNames{currentNode_id,1} = skel.nodes(currentNode_id).jointName; 17 | skel.boneNames{currentNode_id,1} = skel.nodes(currentNode_id).boneName; 18 | return; 19 | end 20 | 21 | for k = 1:childCount 22 | skel = constructAuxiliaryArrays(skel, skel.nodes(currentNode_id).children(k)); 23 | end 24 | 25 | skel.jointNames{currentNode_id,1} = skel.nodes(currentNode_id).jointName; 26 | skel.boneNames{currentNode_id,1} = skel.nodes(currentNode_id).boneName; 27 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/moveMotToXZ.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function mot = moveMotToXZ(mot,p) 22 | 23 | v = p - mot.rootTranslation([1 3],1); 24 | 25 | for k=1:length(mot.jointTrajectories) 26 | mot.jointTrajectories{k}([1 3],:) = mot.jointTrajectories{k}([1 3],:) + repmat(v,1,mot.nframes); 27 | end 28 | mot.rootTranslation([1 3],:) = mot.rootTranslation([1 3],:) + repmat(v,1,mot.nframes); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/DOFID.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function ID = DOFID(skel,jointname) 22 | 23 | i = strmatch(upper(jointname),upper(skel.nameMap(:,1)),'exact'); 24 | 25 | if (isempty(i)) 26 | error(['Unknown standard joint name "' jointname '"!']); 27 | end 28 | 29 | if (length(i)>1) 30 | error(['Ambiguous standard joint name "' jointname '"!']); 31 | end 32 | 33 | ID = skel.nameMap{i,2}; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/eatWhitespace.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function l_out = eatWhitespace(l_in) 22 | % fast forward in file, skipping whitespace 23 | n = 1; 24 | for i = 1:size(l_in,2) 25 | c = double(l_in(i)); 26 | if (c == 9) | (c == 10) | (c == 13) | (c == 32) % TAB, CR, LF, SPC 27 | n = n+1; 28 | else 29 | break; 30 | end 31 | end 32 | l_out = l_in(n:size(l_in,2)); 33 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/trajectoryID.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function ID = trajectoryID(skel,jointname) 22 | 23 | i = strmatch(upper(jointname),upper(skel.nameMap(:,1)),'exact'); 24 | 25 | if (isempty(i)) 26 | error(['Unknown standard joint name "' jointname '"!']); 27 | end 28 | 29 | if (length(i)>1) 30 | error(['Ambiguous standard joint name "' jointname '"!']); 31 | end 32 | 33 | ID = skel.nameMap{i,3}; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/generateLCS.m: -------------------------------------------------------------------------------- 1 | function [ skel_new, mot_new ] = generateLCS( skel, mot, callbackFunctionNames) 2 | % [ skel_new, mot_new ] = generateLCS( skel, mot, callbackFunctionNames) 3 | % 4 | % callbackFunctionNames is an optional parameter. 5 | 6 | if nargin < 1 7 | help generateLCS; 8 | return; 9 | end 10 | 11 | if nargin < 3 12 | callbackFunctionNames = generateDefaultFunctionNames; 13 | end 14 | 15 | skel_new = skel; 16 | skel_new.nameMap = []; 17 | mot_new = mot; 18 | mot_new.nameMap = []; 19 | mot_new.jointTrajectories = []; 20 | emptyTrajectories = 0; 21 | 22 | for i = 1:size(callbackFunctionNames,2) 23 | traj = feval(char(callbackFunctionNames(2,i)), mot); 24 | if traj==0 25 | emptyTrajectories = emptyTrajectories + 1; 26 | else 27 | mot_new.jointTrajectories{i - emptyTrajectories,1} = traj; 28 | mot_new.nameMap{i - emptyTrajectories,1} = char(callbackFunctionNames(1,i)); 29 | mot_new.nameMap{i - emptyTrajectories,2} = 0; 30 | mot_new.nameMap{i - emptyTrajectories,3} = i - emptyTrajectories; 31 | end 32 | end 33 | 34 | skel_new.njoints = 24 - emptyTrajectories; 35 | mot_new.njoints = 24 - emptyTrajectories; 36 | skel_new.nameMap = mot_new.nameMap; 37 | skel_new.paths = buildSkelPathsFromMot(mot_new); 38 | 39 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/constructPaths.m: -------------------------------------------------------------------------------- 1 | function [skel,currentPath] = constructPaths(skel, currentNode_id, currentPath) 2 | % traverse kinematic chain to generate a minimal edge-disjoint path covering used in the rendering process 3 | 4 | %%%%%%%%%%%%% append current node to current path 5 | if isempty(skel.paths) 6 | p = []; 7 | else 8 | p = skel.paths{currentPath,1}; 9 | end 10 | skel.paths{currentPath,1} = [p; currentNode_id]; 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | 13 | childCount = length(skel.nodes(currentNode_id).children); 14 | 15 | if (childCount == 0) % this is a childless bone 16 | if (size(skel.paths,1)==currentPath) % no children at all AND current path nonempty => start new current path 17 | currentPath = currentPath + 1; 18 | end 19 | return; 20 | end 21 | 22 | childCount = length(skel.nodes(currentNode_id).children); 23 | 24 | for k = 1:childCount 25 | if (k > 1) % start a new path at a joint with more than one child 26 | if (size(skel.paths,1)==currentPath) % current path is nonempty 27 | currentPath = currentPath + 1; 28 | end 29 | skel.paths{currentPath,1}(1) = currentNode_id; 30 | end 31 | [skel,currentPath] = constructPaths(skel, skel.nodes(currentNode_id).children(k), currentPath); 32 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/usage.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | addpath(genpath('parser')) 22 | addpath(genpath('animate')) 23 | addpath('quaternions') 24 | %% load input files 25 | [skel,mot] = readMocap('data/HDM_dg.asf', 'data/HDM_dg_06-03_03_120.amc'); 26 | [skelC3D,motC3D] = readMocap('data/HDM_dg_06-03_03_120.c3d', [], false); 27 | 28 | %% animate asf/amc file 29 | animate(skel, mot); 30 | 31 | %% animate C3D file 32 | animate(skelC3D, motC3D) 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/animatedPatchStruct.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function s = animatedPatchStruct(varargin) 22 | n = 1; 23 | if (nargin>0) 24 | n = varargin{1}; 25 | end 26 | 27 | s = struct('function_name',cell(n,1),... 28 | 'function_params',cell(n,1),... 29 | 'color','blue',... 30 | 'alpha',1,... 31 | 'nsteps',64,... 32 | 'type','disc',... 33 | 'X',[],... 34 | 'Y',[],... 35 | 'Z',[]); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/findNextToken.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [result, token] = findNextToken(fid) 22 | % stops at first occurence of any non-whitespace word and returns the entire line as token. 23 | 24 | line_count = 0; 25 | while ~feof(fid) 26 | line = fgetl(fid); 27 | line_count = line_count + 1; 28 | line = strtok(line); 29 | if (length(line)>0) 30 | token = line; 31 | result = true; 32 | return; 33 | end 34 | end 35 | result = false; 36 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/BVHparser/readChannels.m: -------------------------------------------------------------------------------- 1 | function [result,newnode,is_animated] = readChannels(newnode,fid) 2 | 3 | [result, lin] = findKeyword(fid,'CHANNELS'); 4 | if ~result 5 | error(['BVH section CHANNELS not found for node ' newnode.name '!']); 6 | return; 7 | end 8 | lin = deblank(lin(10:size(lin,2))); % remove 'CHANNELS' at beginning of line, trim 9 | [str_num_channels,lin] = strtok(lin); 10 | num_channels = sscanf(str_num_channels,'%d'); 11 | 12 | newnode.DOF = cell(num_channels,1); 13 | for k=1:num_channels 14 | [channel,lin] = strtok(lin); 15 | switch upper(channel) 16 | case 'XROTATION' 17 | channel = 'rx'; 18 | newnode.rotationOrder = [newnode.rotationOrder 'x']; 19 | case 'YROTATION' 20 | channel = 'ry'; 21 | newnode.rotationOrder = [newnode.rotationOrder 'y']; 22 | case 'ZROTATION' 23 | channel = 'rz'; 24 | newnode.rotationOrder = [newnode.rotationOrder 'z']; 25 | case 'XPOSITION' 26 | channel = 'tx'; 27 | case 'YPOSITION' 28 | channel = 'ty'; 29 | case 'ZPOSITION' 30 | channel = 'tz'; 31 | otherwise 32 | warning(['Invalid DOF specification: ' channel '!']); 33 | end 34 | newnode.DOF{k,1} = channel; 35 | end 36 | is_animated = (num_channels > 0); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/old_createPlaneNormal.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [X,Y,Z] = createPlaneNormal(n, x0, sides_length) 22 | 23 | X = [-sides_length(1)/2 -sides_length(1)/2;sides_length(1)/2 sides_length(1)/2]; 24 | Y = [sides_length(2)/2 -sides_length(2)/2;sides_length(2)/2 -sides_length(2)/2]; 25 | Z = [0 0;0 0]; 26 | n0 = [0;0;1]; 27 | x = cross(n,n0); 28 | cphi = dot(n/norm(n),n0/norm(n0)); 29 | 30 | 31 | rotate(h,x,phi*180/pi); 32 | 33 | set(h,'facecolor','black'); 34 | alpha(h,0.25); 35 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/rotateMotY.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [mot,skel] = rotateMotY(skel,mot,desiredFrontVec,varargin) 22 | 23 | frontVec = averageFrontVector(mot,varargin{:}); 24 | phi = directedAngle(frontVec,desiredFrontVec); 25 | 26 | skel.rootRotationalOffsetQuat = euler2quat([0; -phi; 0],'xyz'); 27 | 28 | mot.rootTranslation = quatrot(mot.rootTranslation,skel.rootRotationalOffsetQuat); 29 | mot.jointTrajectories = forwardKinematicsQuat(skel,mot); 30 | mot.boundingBox = computeBoundingBox(mot); 31 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readNumFrames.m: -------------------------------------------------------------------------------- 1 | function s = readNumFrames(fid) 2 | 3 | %%%%%%%%%% find :DEGREES section 4 | found = false; 5 | while ~found 6 | [result,lin] = findNextASFSection(fid); 7 | if (~result) 8 | error(['AMC: Could not find DEGREES in ' mot.filename '!']); 9 | end 10 | 11 | [token,lin] = strtok(lin); 12 | token = token(2:end); % remove leading colon 13 | if strcmpi(token,'DEGREES') 14 | found = true; 15 | end 16 | end 17 | 18 | %%%%%%%%%%%% find out how many frames we are dealing with: seek to end and read backwards till last frame number 19 | found = false; % found last frame number 20 | fseek(fid,-1,'eof'); % jump to end of file 21 | while (ftell(fid) > 0 & ~found) % not at bof AND not found last frame number 22 | pos = ftell(fid); 23 | ch = fread(fid,1,'uchar'); % read current character 24 | if (ch == 10) % line feed 25 | l = fgetl(fid); 26 | fseek(fid,pos-1,'bof'); 27 | if (l ~= -1) % no eof encountered 28 | [frame_num, OK] = str2num(l); 29 | if (OK) 30 | found = true; 31 | end 32 | end 33 | else 34 | fseek(fid,-2,'cof'); % jump 2 characters back 35 | end 36 | end 37 | if (~found) 38 | error(['AMC: Could not find last frame number in ' mot.filename '!']); 39 | end 40 | s = frame_num; 41 | -------------------------------------------------------------------------------- /python_dynamic_clustering/run_dc.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.io as sio 3 | from lib_dynamic_clustering import * 4 | from lib_local_temporal_pooling import * 5 | import matplotlib.pyplot as plt 6 | from util_visualize import * 7 | 8 | ''' 9 | run hierarchical dynamic clustering for human motion segmentation: 10 | Given an input feature sequence, we get segments boundaries of moving actions. 11 | Dynamic clustering + motion energy-based pooling are employed. 12 | ''' 13 | 14 | 15 | ## read feature sequence 16 | data_file_path = '/is/ps2/yzhang/Pictures/DynamicClustering/CMUMAD_features/CMUMAD_jointLocs_sub05_seq01.mat' 17 | data = sio.loadmat(data_file_path) 18 | X = data['X'] 19 | 20 | ## run dynamic clustering 21 | cluster_structure = dynamic_clustering(X, delta=1e-2, verbose=False) 22 | cluster_idx = np.array(cluster_structure['idx']) 23 | 24 | 25 | ## run motion energy-based temporal pooling 26 | action_bound, action_label = motion_energy_pooling(cluster_idx, 27 | W=30, 28 | sigma=2.5, 29 | peak_distance=30, 30 | plot_me=True) 31 | 32 | print(action_bound) 33 | 34 | ## visualize segmentation 35 | # show_seg(cluster_structure['idx'], n_clusters=len(cluster_structure['centers'])) 36 | show_seg(action_label, n_clusters=2) 37 | plt.show() 38 | 39 | 40 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/euler2matrixSymb.m: -------------------------------------------------------------------------------- 1 | function [R,latx] = euler2matrixSymb(anglenames,rotorder) 2 | 3 | for k=1:length(anglenames) 4 | angles(k) = sym(anglenames{k}); 5 | end 6 | 7 | switch (lower(rotorder(1))) 8 | case 'x' 9 | R = [1 0 0; 0 cos(angles(1)) -sin(angles(1)); 0 sin(angles(1)) cos(angles(1))]; 10 | case 'y' 11 | R = [cos(angles(1)) 0 sin(angles(1)); 0 1 0; -sin(angles(1)) 0 cos(angles(1))]; 12 | case 'z' 13 | R = [cos(angles(1)) -sin(angles(1)) 0; sin(angles(1)) cos(angles(1)) 0; 0 0 1]; 14 | end 15 | 16 | for k=2:length(rotorder) 17 | switch (lower(rotorder(k))) 18 | case 'x' 19 | R = R*[1 0 0; 0 cos(angles(k)) -sin(angles(k)); 0 sin(angles(k)) cos(angles(k))]; 20 | case 'y' 21 | R = R*[cos(angles(k)) 0 sin(angles(k)); 0 1 0; -sin(angles(k)) 0 cos(angles(k))]; 22 | case 'z' 23 | R = R*[cos(angles(k)) -sin(angles(k)) 0; sin(angles(k)) cos(angles(k)) 0; 0 0 1]; 24 | end 25 | end 26 | 27 | latx = latex(R); 28 | latx = strrep(latx,'\noalign{\medskip}',''); 29 | latx = strrep(latx,'\cos(1)','\co{1}'); 30 | latx = strrep(latx,'\cos(2)','\co{2}'); 31 | latx = strrep(latx,'\cos(3)','\co{3}'); 32 | latx = strrep(latx,'\sin(1)','\si{1}'); 33 | latx = strrep(latx,'\sin(2)','\si{2}'); 34 | latx = strrep(latx,'\sin(3)','\si{3}'); 35 | latx = strrep(latx,'\left [','\left('); 36 | latx = strrep(latx,'\right [','\right)'); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/params_cappedCylinder.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [points1,points2] = params_cappedCylinder(mot,p1_name,p2_name,varargin) 22 | % p1 and p2 define a line segment p1p2. 23 | % 24 | % function returns the two endpoints of the line segment 25 | 26 | if (ischar(p1_name)) 27 | p1 = trajectoryID(mot,p1_name); 28 | else 29 | p1 = mot.nameMap{p1_name,3}; 30 | end 31 | if (ischar(p2_name)) 32 | p2 = trajectoryID(mot,p2_name); 33 | else 34 | p2 = mot.nameMap{p2_name,3}; 35 | end 36 | 37 | points1 = mot.jointTrajectories{p1}; 38 | points2 = mot.jointTrajectories{p2}; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/animateD.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function animateD(doc_id,varargin) 22 | 23 | global VARS_GLOBAL; 24 | 25 | repeat_num = 1; 26 | speed = 1; 27 | frames = 0; 28 | if nargin > 3 29 | repeat_num = varargin{3}; 30 | end 31 | if nargin > 2 32 | speed = varargin{2}; 33 | end 34 | if nargin > 1 35 | frames = varargin{1}; 36 | end 37 | 38 | [skel,mot] = readMocapD(doc_id); 39 | if (frames == 0) 40 | frames = 1:mot.nframes; 41 | end 42 | %animate_initGraphics; 43 | figure(100); 44 | set(gcf, 'name', [num2str(doc_id), ': ' mot.filename]); 45 | animate(skel,mot,repeat_num,speed,frames); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/constructSkeleton.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = constructSkeleton(skel, currentNode_id, hierarchy, currentHierarchyIndex) 2 | 3 | result = false; 4 | 5 | k = 2; % in an ASF file, k = 1 should be referring to currentNode, the parent of the child nodes to be inserted 6 | while ((k<=size(hierarchy,2)) & (~isempty(hierarchy{currentHierarchyIndex,k}))) % insert all child nodes 7 | childBoneName = hierarchy{currentHierarchyIndex,k}; 8 | childBoneIndex = strmatch(upper(childBoneName),upper({skel.nodes.boneName}),'exact'); 9 | if (length(childBoneIndex)>1) 10 | error(['ASF: Bone name "' childBoneName '" is not unique!']); 11 | end 12 | if (length(childBoneIndex)<1) 13 | error(['ASF: Unknown bone "' childBoneName '"!']); 14 | end 15 | 16 | skel.nodes(currentNode_id).children = [skel.nodes(currentNode_id).children; childBoneIndex]; 17 | skel.nodes(childBoneIndex).parentID = currentNode_id; 18 | 19 | % in which lines of the hierarchy data does the current child appear as a parent? 20 | childHierarchyIndex = strmatch(upper(childBoneName),upper({hierarchy{:,1}}),'exact'); 21 | 22 | if (length(childHierarchyIndex)>=1) % found one or more lines where current child appears as a parent. 23 | for m = 1:length(childHierarchyIndex) 24 | [result,skel] = constructSkeleton(skel,childBoneIndex,hierarchy,childHierarchyIndex(m)); 25 | end 26 | end 27 | 28 | k = k + 1; 29 | end 30 | 31 | result = true; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/forwardKinematicsQuat.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function jointTrajectories = forwardKinematicsQuat(skel,mot) 22 | jointTrajectories = recursive_forwardKinematicsQuat(skel,... 23 | mot,... 24 | 1,... 25 | mot.rootTranslation + repmat(skel.nodes(1).offset,1,mot.nframes),... 26 | quatmult(repmat(skel.rootRotationalOffsetQuat,1,mot.nframes),mot.rotationQuat{1}),... 27 | mot.jointTrajectories); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/reflectMotYZ.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function mot = reflectMotYZ(mot) 22 | %%%%%%%% reflect elderwalk about yz plane 23 | for k=1:length(mot.jointTrajectories) 24 | mot.jointTrajectories{k,1}([1],:) = -mot.jointTrajectories{k,1}([1],:); 25 | mot.jointTrajectories{k,1} = mot.jointTrajectories{k,1} - repmat(mot.rootTranslation(:,1) - mot.rootTranslation(:,1),1,mot.nframes); 26 | end 27 | mot.rootTranslation([1],:) = -mot.rootTranslation([1],:); 28 | mot.rootTranslation = mot.rootTranslation - repmat(mot.rootTranslation(:,1) - mot.rootTranslation(:,1),1,mot.nframes); 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/averageFrontVector.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function v = averageFrontVector(mot,varargin) 22 | 23 | p1_name = 'lhip'; 24 | p2_name = 'rhip'; 25 | if (nargin>2) 26 | p2_name = varargin{2}; 27 | end 28 | 29 | if (nargin>1) 30 | p1_name = varargin{1}; 31 | end 32 | 33 | p1 = trajectoryID(mot,p1_name); 34 | p2 = trajectoryID(mot,p2_name); 35 | 36 | n = mot.jointTrajectories{p1} - mot.jointTrajectories{p2}; 37 | n = n([1 3],:); 38 | n = n./repmat(sqrt(sum(n.^2)),2,1); 39 | v = mean(n,2); 40 | v = v/sqrt(sum(v.^2)); 41 | v = [-v(2);v(1)]; % compute front vector as normal of average direction from lhip to rhip -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/scaleSkelMot.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [skel,mot] = scaleSkelMot(skel,mot,S) 22 | % [skel,mot] = scaleSkelMot(skel,mot,S) 23 | % S is the downscale factor 24 | 25 | for k=1:length(skel.nodes) 26 | skel.nodes(k).length = skel.nodes(k).length/S; 27 | skel.nodes(k).offset = skel.nodes(k).offset/S; 28 | end 29 | 30 | mot.rootTranslation = mot.rootTranslation/S; 31 | mot.jointTrajectories = forwardKinematicsQuat(skel,mot); 32 | mot.boundingBox = computeBoundingBox(mot); 33 | 34 | s = sprintf('Motion scaled using "scaleSkelMot" with factor %f',S); 35 | mot.documentation = vertcat(mot.documentation,{s}); 36 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/LCS/readMocapSmartLCS.m: -------------------------------------------------------------------------------- 1 | function [ skel, mot ] = readMocapSmartLCS( fullFilename, generateSkel, noCaching, noScaling ) 2 | % [ skel, mot ] = readMocapSmartLCS( fullFilename, generateSkel, noCaching, noScaling ) 3 | % 4 | % 5 | % 6 | % readMocapSmart does not require specification of ASF-file 7 | % and automatically performs scaling (unit conversion) 8 | % 9 | % noCaching: Don't read *.MAT-file 10 | % noScaling: Don't scale ASF/AMC files by 2.54 (default: false) 11 | % generateSkel: Generate LCS-Skeleton 12 | % 13 | % Units are may be in centimeter or in inches 14 | % (ASF/AMC units of HDM05 files are in inches) 15 | % (C3D units of HDM05 files are in centimeters) 16 | % 17 | % noScaling = false -> scaling by factor 1/2.54 to 18 | % convert inches -> centimeters (only for ASF/AMC) 19 | % 20 | 21 | if nargin < 2 22 | generateSkel = false; 23 | end 24 | if nargin < 3 25 | noCaching = false; 26 | end 27 | if nargin < 4 28 | noScaling = false; 29 | end 30 | 31 | info = filename2info(fullFilename); 32 | 33 | if strcmpi(info.filetype, 'C3D') 34 | [skel, mot] = readMocapLCS(fullFilename, [], generateSkel, noCaching ); 35 | elseif strcmpi(info.filetype, 'ASF/AMC') 36 | skelFile = fullfile(info.amcpath, info.asfname); 37 | [skel, mot] = readMocap(skelFile, fullFilename, [], true, true, true, noCaching); 38 | 39 | if ~noScaling 40 | [skel, mot] = scaleSkelMot(skel, mot, 1/2.54); % our ASF 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/distRP3.m: -------------------------------------------------------------------------------- 1 | function d = distRP3(varargin) 2 | % Q = distRP3(q1,q2,tol) 3 | % Computes the distance between q1 and q2 in RP3, i.e. S3 / {-1,1}. 4 | % 5 | % Input: * q1,q2 are sequences of quaternions represented as 4xn matrices. 6 | % Non-unit quaternions might be normalized prior to 7 | % interpolation, see next point. 8 | % * If tol is specified, it denotes the allowable deviation from unit 9 | % length for the input quaternions. Deviations less than tol will 10 | % lead to re-normalization, deviations larger than tol will lead 11 | % to re-normalization and a warning. If tol is not specified, 12 | % all deviations larger than the machine precision will lead to 13 | % an error. 14 | % 15 | % Output: d is a 1xn vector of distances, where d(i) is the spherical distance 16 | % between q1(:,i) and q2(:,i) 17 | 18 | switch (nargin) 19 | case 2 20 | q1 = varargin{1}; 21 | q2 = varargin{2}; 22 | tol = 10*eps; 23 | error_on_deviations = true; 24 | case 3 25 | q1 = varargin{1}; 26 | q2 = varargin{2}; 27 | tol = varargin{3}; 28 | error_on_deviations = false; 29 | otherwise 30 | error('Wrong number of arguments.'); 31 | end 32 | 33 | if (size(q1,1)~=4 || size(q2,1)~=4 || (size(q1,2) ~= size(q2,2))) 34 | error('Input arrays: wrong dimensions.'); 35 | end 36 | 37 | d = acos(abs(dot(q1,q2))); 38 | 39 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/gramschmidt.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function B = gramschmidt(A) 22 | n = size(A,1); 23 | if (size(A,2) ~= n) 24 | return; 25 | end; 26 | B = zeros(n,n); 27 | 28 | B(:,1) = (1/norm(A(:,1)))*A(:,1); 29 | 30 | for i=2:n 31 | v = A(:,i); 32 | U = B(:,1:i-1); % subspace basis which has already been orthonormalized 33 | pc = transpose(U)*v; % orthogonal projection coefficients of v onto U 34 | p = U * pc; % orthogonal projection vector of v onto U 35 | v = v - p; 36 | if (norm(v) 0 38 | line = l(k:size(l,2)); 39 | b = true; 40 | pos = ftell(fid); 41 | return; 42 | end 43 | end 44 | end 45 | b = false; 46 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/mapLabelNamesToVicon.m: -------------------------------------------------------------------------------- 1 | function newLabelNames = mapLabelNamesToVicon( oldLabelNames, caseSensitive ) 2 | % tries to map the given label names to standard Vicon-names. 3 | % The vicon names are: 4 | % 'LFHD' 'RFHD' 'LBHD' 'RBHD' 'C7' 'T10' 'CLAV' 5 | % 'STRN' 'RBAC' 'LSHO' 'LUPA' 'LELB' 'LFRM' 'LWRA' 6 | % 'LWRB' 'LFIN' 'RSHO' 'RUPA' 'RELB' 'RFRM' 'RWRA' 7 | % 'RWRB' 'RFIN' 'LFWT' 'RFWT' 'LBWT' 'RBWT' 'LTHI' 8 | % 'LKNE' 'LSHN' 'LANK' 'LHEE' 'LTOE' 'LMT5' 'RTHI' 9 | % 'RKNE' 'RSHN' 'RANK' 'RHEE' 'RTOE' 'RMT5' 10 | 11 | mapping = { { {'Left Forehead', 'LeftFhd'}, 'LFHD'}; 12 | { {'Right Forehead', 'RightFhd'}, 'RFHD'}; 13 | { {'LARM'}, 'LFRM'}; 14 | { {'RARM'}, 'RFRM'}; 15 | { {'RLEG'}, 'RSHN'}; 16 | { {'LLEG'}, 'LSHN'}; 17 | { {'R10'}, 'RBAC'}; 18 | % etc. 19 | }; 20 | 21 | newLabelNames = oldLabelNames; 22 | 23 | for i = 1:size(oldLabelNames,2) 24 | for j = 1:size(mapping, 1) 25 | if caseSensitive 26 | idx = strmatch(oldLabelNames{i}, mapping{j}{1}); 27 | else 28 | idx = strmatch(upper(oldLabelNames{i}), upper(mapping{j}{1})); 29 | end 30 | 31 | if not(isempty(idx)) 32 | fprintf('Old label name: %s, new label name. %s.\n', mapping{j}{1}, mapping{j}{2}); 33 | newLabelNames{i} = mapping{j}{2}; 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/clearTracePoses.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function clearTracePoses 22 | global VARS_GLOBAL_ANIM 23 | if (isempty(VARS_GLOBAL_ANIM)||isempty(VARS_GLOBAL_ANIM.graphics_data)) 24 | return; 25 | end 26 | 27 | f = find(cell2mat({VARS_GLOBAL_ANIM.graphics_data.figure}) == gcf); 28 | if (isempty(f)) 29 | return; 30 | end 31 | VARS_GLOBAL_ANIM.graphics_data_index = f; 32 | 33 | num_trace_poses = size(VARS_GLOBAL_ANIM.graphics_data(f).trace_poses,2); 34 | num_lines_per_pose = size(VARS_GLOBAL_ANIM.graphics_data(f).trace_poses,1); 35 | for k=1:num_trace_poses 36 | for j=1:num_lines_per_pose 37 | delete(VARS_GLOBAL_ANIM.graphics_data(f).trace_poses{j,k}(ishandle(VARS_GLOBAL_ANIM.graphics_data(f).trace_poses{j,k}))); 38 | end 39 | end 40 | VARS_GLOBAL_ANIM.graphics_data(f).trace_poses = {}; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/getAMCLengthInSeconds.m: -------------------------------------------------------------------------------- 1 | function s = getAMCLengthInSeconds(amcfullpath) 2 | 3 | [info,OK] = filename2info(amcfullpath); 4 | fs = info.samplingRate; 5 | if (~OK) 6 | fs = 120; 7 | end 8 | 9 | % first try to read compact BIN version of the file 10 | h = fopen([amcfullpath '.BIN'],'r'); 11 | if (h > 0) % does compact BIN file exist? 12 | s = readNumFramesBIN(h)/fs; 13 | else 14 | % try reading compact TXT version of the file 15 | h = fopen([amcfullpath '.TXT'],'r'); 16 | if (h > 0) % does compact TXT file exist? 17 | n = strfind(amcname,'_')-1; 18 | if (length(n)<2) 19 | disp(['**** Warning: Couldn''t locate ASF name within AMC name "' amcname '"!']); 20 | s = 0; 21 | return; 22 | end 23 | n = n(2); 24 | 25 | asffullpath = [info.amcpath info.asfname]; 26 | 27 | mot = emptyMotion; 28 | skel = readASF(asffullpath); 29 | mot.njoints = skel.njoints; 30 | mot.jointNames = skel.jointNames; 31 | mot.boneNames = skel.boneNames; 32 | mot.nameMap = skel.nameMap; 33 | mot.animated = skel.animated; 34 | mot.unanimated = skel.unanimated; 35 | mot.filename = amcname; 36 | mot.angleUnit = skel.angleUnit; 37 | [result,mot] = readFramesTXT(skel,mot,h,[1 inf]); 38 | s = lengthInSeconds(mot) 39 | else 40 | fid = fopen(amcfullpath,'r'); 41 | s = readNumFrames(fid)/fs; 42 | fclose(fid); 43 | end 44 | end 45 | 46 | disp(['Source: ' info.skeletonSource ', skelID: ' info.skeletonID ', category: ' info.motionCategory ', desc: ' info.motionDescription ', fs: ' num2str(info.samplingRate) ', duration: ' num2str(s) ' s.']); 47 | 48 | 49 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/readMocapD.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [skel,mot] = readMocapD(file_num, range) 22 | 23 | global VARS_GLOBAL 24 | 25 | if ~(exist('DB_concat')) 26 | DB_concat = DB_index_load('HDM05_amc',{'AK_lower'},4); 27 | files_name = DB_concat.files_name; 28 | end 29 | 30 | 31 | 32 | amcfullpath = fullfile(VARS_GLOBAL.dir_root, files_name{file_num}); 33 | [info,OK] = filename2info(amcfullpath); 34 | if (OK) 35 | [skel,mot] = readMocap([info.amcpath info.asfname], amcfullpath, [1 inf]); 36 | if (nargin > 2) 37 | mot = cropMot(mot, range); 38 | end 39 | elseif strcmpi(amcfullpath(end-4:end),'.bvh') 40 | [skel,mot] = readMocap(amcfullpath); 41 | else % assume an AMC file with an ASF that has the same name 42 | [skel,mot] = readMocap([amcfullpath(1:end-4) '.asf'],amcfullpath); 43 | end 44 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/test_getframe.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | figure('units','normalized','outerposition',[0 0 1 1]); 22 | 23 | 24 | % outerposition is an undocumented feature. It allows you to 25 | % define the size of the outerposition of the figure window. 26 | % The above sets the figure to full screen or you could also 27 | % try uncommenting the statements after the surf(peaks) 28 | 29 | 30 | plot([0:99],sin(1/100*[0:99]*2*pi)); 31 | %disp ('Maximize the screen, then press any key to continue'); 32 | %pause; 33 | 34 | 35 | mov=avifile('test','compression','indeo5'); 36 | %makes test.avi w/ Indeo 5 37 | 38 | 39 | %f2=getframe(gcf); % gets the gcf 40 | mov=addframe(mov,gcf); % adds the frame into mov 41 | mov=close(mov); % closes the mov 42 | 43 | 44 | %In order to run the avi from MATLAB command window: 45 | %!test.avi& -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/angularVelocity.m: -------------------------------------------------------------------------------- 1 | function [V,V_abs] = angularVelocity(varargin) 2 | % V = angularVelocity(Q,fs,abs_vel) 3 | % 4 | % Compute angular velocities from quaternion data streams. 5 | % 6 | % Input: * Q: cell array consisting of L 4xN_k matrices. Alternatively, V can be a single 4xN matrix. 7 | % fs: sampling rate, default = 1. 8 | % abs_vel: boolean flag indicating whether absolute velocities are to be computed. default: false. 9 | % 10 | % Output: * V: cell array of L 3x(N_k - 1)-arrays containing angular velocity vectors. 11 | % * V_abs: empty if abs_vel == false, else cell array of L 1x(N_k - 1)-vectors containing absolute angular velocities. 12 | 13 | switch nargin 14 | case 1 15 | Q = varargin{1}; 16 | fs = 1; 17 | abs_vel = false; 18 | case 2 19 | Q = varargin{1}; 20 | fs = varargin{2}; 21 | abs_vel = false; 22 | case 3 23 | Q = varargin{1}; 24 | fs = varargin{2}; 25 | abs_vel = varargin{3}; 26 | otherwise 27 | error('Wrong number of arguments!'); 28 | end 29 | 30 | if (~iscell(Q)) 31 | Q = {Q}; 32 | end 33 | 34 | L = length(Q); % number of data streams 35 | 36 | V = cell(L,1); 37 | if (abs_vel) 38 | V_abs = cell(L,1); 39 | else 40 | V_abs = cell(0); 41 | end 42 | for k=1:L 43 | N = size(Q{k},2); 44 | 45 | %%%%%%%% attention: constant factor of 2 (for correct phyical interpretation) has been neglected 46 | %%%%%%%% attention again: I have added the factor of 2 for correct 47 | %%%%%%%% physical interpretation. 48 | V{k} = 2 * quatlog(TH_C_quatmult(quatinv(Q{k}(:,1:N-1)),Q{k}(:,2:N)),10^-6) * fs; 49 | if (abs_vel) 50 | V_abs{k} = sqrt(sum(V{k}.^2)); 51 | end 52 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readRootASF.m: -------------------------------------------------------------------------------- 1 | function [result,skel] = readRoot(skel,fid) 2 | 3 | [result,lin] = findNextASFSection(fid); 4 | if (~result) 5 | error(['ASF: Could not find ROOT in ' skel.filename '!']); 6 | end 7 | 8 | [token,lin] = strtok(lin); 9 | token = token(2:end); % remove leading colon 10 | if ~strcmpi(token,'ROOT') 11 | error(['ASF: Expected ROOT in ' skel.filename '!']); 12 | end 13 | 14 | skel.nodes = emptySkeletonNode; 15 | 16 | while (~feof(fid)) 17 | pos = ftell(fid); 18 | lin = eatWhitespace(fgetl(fid)); 19 | if (beginsWithColon(lin)) 20 | break; 21 | end 22 | 23 | [token,lin] = strtok(lin); 24 | switch (upper(token)) 25 | case 'AXIS' 26 | [token2,lin] = strtok(lin); 27 | skel.nodes(1).rotationOrder = token2; 28 | case 'ORDER' 29 | k = 1; 30 | while length(eatWhitespace(lin))>0 31 | [dof,lin] = strtok(lin); 32 | skel.nodes(1).DOF{k,1} = dof; 33 | k = k+1; 34 | end 35 | case 'POSITION' 36 | skel.nodes(1).offset = sscanf(lin,'%f %f %f') / skel.lengthUnit; 37 | case 'ORIENTATION' 38 | skel.rootRotationalOffsetEuler = sscanf(lin,'%f %f %f'); 39 | otherwise 40 | warning(['ASF: Unknown ROOT property: ' token '!']); 41 | end 42 | end 43 | fseek(fid,pos,'bof'); 44 | 45 | skel.nodes(1).jointName = 'root'; 46 | skel.nodes(1).boneName = 'root'; 47 | skel.nodes(1).ID = 1; 48 | 49 | switch skel.angleUnit 50 | case 'deg' 51 | skel.rootRotationalOffsetQuat = euler2quat(skel.rootRotationalOffsetEuler*pi/180); 52 | case 'rad' 53 | skel.rootRotationalOffsetQuat = euler2quat(skel.rootRotationalOffsetQuat); 54 | end 55 | 56 | skel.njoints = 1; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/params_planePointNormal_yAxis.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [points,n,min_radius] = params_planePointNormal_yAxis(mot,p3_name,q_name,d) 22 | % The plane is defined as follows: 23 | % The normal n is the y axis 24 | % p3 is the fixture point for the plane. 25 | % q is the point that is tested against this plane 26 | % d is the offset distance for the plane in the direction of n. 27 | % 28 | % function returns sequence of fixture points and unit normals along with 29 | % minimum radii that make sense to visualize position of q in relation to the plane. 30 | 31 | if (ischar(p3_name)) 32 | p3 = trajectoryID(mot,p3_name); 33 | else 34 | p3 = mot.nameMap{p3_name,3}; 35 | end 36 | if (ischar(q_name)) 37 | q = trajectoryID(mot,q_name); 38 | else 39 | q = mot.nameMap{q_name,3}; 40 | end 41 | 42 | n = repmat([0;1;0],1,mot.nframes); 43 | 44 | points = mot.jointTrajectories{p3} + n*d; 45 | 46 | min_radius = sqrt(sum((mot.jointTrajectories{p3}+n*d-mot.jointTrajectories{q}).^2)); 47 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/saveCamera.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function saveCamera(varargin) 22 | 23 | ax = gca; 24 | file = 'camera.m'; 25 | if (nargin>1) 26 | file = varargin{2}; 27 | end 28 | if (nargin>0) 29 | ax = varargin{1}; 30 | end 31 | 32 | [fid,msg]=fopen(file,'w'); 33 | if (fid < 0) 34 | disp(msg); 35 | return; 36 | end 37 | 38 | fprintf(fid,'function camera(axs)\n\n'); 39 | fprintf(fid,'set(axs,''CameraPosition'', [%s],...\n',num2str(get(ax,'CameraPosition'))); 40 | fprintf(fid,' ''CameraPositionMode'',''manual'',...\n'); 41 | fprintf(fid,' ''CameraTarget'', [%s],...\n',num2str(get(ax,'CameraTarget'))); 42 | fprintf(fid,' ''CameraTargetMode'',''manual'',...\n'); 43 | fprintf(fid,' ''CameraUpVector'', [%s],...\n',num2str(get(ax,'CameraUpVector'))); 44 | fprintf(fid,' ''CameraUpVectorMode'',''manual'',...\n'); 45 | fprintf(fid,' ''CameraViewAngle'', [%s],...\n',num2str(get(ax,'CameraViewAngle'))); 46 | fprintf(fid,' ''CameraViewAngleMode'',''manual'');'); 47 | fclose(fid); -------------------------------------------------------------------------------- /eval_package/calLocalFeatureAggregationAndClusteringWithEncodedFeatures.m: -------------------------------------------------------------------------------- 1 | function idx = calLocalFeatureAggregationAndClusteringWithEncodedFeatures(X,Xl,n_clusters,varargin) 2 | 3 | 4 | % Xl(Xl~=0) = 1; 5 | %%% find the peaks in the label space to determine the time window 6 | labels = imgaussfilt(Xl,12.5); %% for CMUMAD 7 | % labels = imgaussfilt(Xl,1.5); %% for TUMKitchen 8 | peak_width_weight = 1; %% for CMUMAD 9 | % peak_width_weight = 0.5; %% for TUMKitchen 10 | 11 | [pks_label,locs_label, pks_width] = findpeaks(labels); 12 | % pks_width = 2*pks_width; 13 | pks_width = round(pks_width); 14 | %%% use the time window to aggregate features 15 | features = zeros(length(pks_label), size(X,2)); 16 | for pp = 1:length(pks_label) 17 | lb = max(1,locs_label(pp)-round(peak_width_weight*pks_width(pp))); 18 | ub = min(size(X,1), locs_label(pp)+round(peak_width_weight*pks_width(pp))); 19 | 20 | ff = X(lb : ub, :); 21 | features(pp,:) = sum(ff,1); 22 | features(pp,:) = features(pp,:)/norm(features(pp,:)); 23 | end 24 | 25 | 26 | method = 'Kmeans'; 27 | if nargin == 3 28 | method = 'Kmeans'; 29 | nc = n_clusters-1; 30 | agg_type = 'null_action'; 31 | else 32 | agg_type = varargin{1}; 33 | end 34 | 35 | if strcmp(agg_type, 'null_action') 36 | nc = n_clusters-1; 37 | elseif strcmp(agg_type, 'normal_action') 38 | nc = n_clusters-1; 39 | end 40 | 41 | 42 | if size(features,1) <= nc 43 | iidx = 1:size(features,1); 44 | elseif strcmp(method, 'Kmeans') 45 | iidx = kmeans(features, nc); 46 | 47 | elseif strcmp(method,'ours') 48 | time_window = 50; 49 | sigma = 0.1; 50 | is_temporal_reg = 0; 51 | [iidx, ~] = incrementalClustering(features, time_window,sigma,is_temporal_reg,0,2.5); 52 | 53 | end 54 | 55 | 56 | idx = zeros(size(Xl)); 57 | for pp = 1:length(pks_label) 58 | lb = max(1,locs_label(pp)-pks_width(pp)); 59 | ub = min(size(X,1), locs_label(pp)+pks_width(pp)); 60 | idx(lb:ub)=iidx(pp); 61 | end 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /eval_package/calLocalFeatureAggregationAndClustering.m: -------------------------------------------------------------------------------- 1 | function idx = calLocalFeatureAggregationAndClustering(X,Xl,C,n_clusters,varargin) 2 | 3 | 4 | % Xl(Xl~=0) = 1; 5 | %%% find the peaks in the label space to determine the time window 6 | labels = imgaussfilt(Xl,12.5); %% for CMUMAD 7 | % labels = imgaussfilt(Xl,1.5); %% for TUMKitchen 8 | peak_width_weight = 1; %% for CMUMAD 9 | % peak_width_weight = 0.5; %% for TUMKitchen 10 | 11 | [pks_label,locs_label, pks_width] = findpeaks(labels); 12 | % pks_width = 2*pks_width; 13 | pks_width = round(pks_width); 14 | %%% use the time window to aggregate features 15 | features = zeros(length(pks_label), size(C,1)); 16 | for pp = 1:length(pks_label) 17 | lb = max(1,locs_label(pp)-round(peak_width_weight*pks_width(pp))); 18 | ub = min(size(X,1), locs_label(pp)+round(peak_width_weight*pks_width(pp))); 19 | XX = X(lb : ub, :); 20 | dist = pdist2(XX, C); 21 | ff = exp(-0.1*dist)./ repmat(sum(exp(-0.1*dist),2), 1, size(C,1)); 22 | features(pp,:) = sum(ff,1); 23 | features(pp,:) = features(pp,:)/norm(features(pp,:)); 24 | end 25 | 26 | 27 | method = 'Kmeans'; 28 | if nargin == 4 29 | method = 'Kmeans'; 30 | nc = n_clusters-1; 31 | agg_type = 'null_action'; 32 | else 33 | agg_type = varargin{1}; 34 | end 35 | 36 | if strcmp(agg_type, 'null_action') 37 | nc = n_clusters-1; 38 | elseif strcmp(agg_type, 'normal_action') 39 | nc = n_clusters-1; 40 | end 41 | 42 | 43 | if size(features,1) <= nc 44 | iidx = 1:size(features,1); 45 | elseif strcmp(method, 'Kmeans') 46 | iidx = kmeans(features, nc); 47 | 48 | elseif strcmp(method,'ours') 49 | time_window = 50; 50 | sigma = 0.1; 51 | is_temporal_reg = 0; 52 | [iidx, ~] = incrementalClustering(features, time_window,sigma,is_temporal_reg,0,2.5); 53 | 54 | end 55 | 56 | 57 | idx = zeros(size(Xl)); 58 | for pp = 1:length(pks_label) 59 | lb = max(1,locs_label(pp)-pks_width(pp)); 60 | ub = min(size(X,1), locs_label(pp)+pks_width(pp)); 61 | idx(lb:ub)=iidx(pp); 62 | end 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/showTrajectory.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function handle = showTrajectory(varargin) 22 | % showTrajectory(mot,trajname,linestyle,downsampling_fac) 23 | 24 | switch (nargin) 25 | case 2 26 | mot = varargin{1}; 27 | trajname = varargin{2}; 28 | linestyle = 'red o'; 29 | downsampling_fac = 1; 30 | case 3 31 | mot = varargin{1}; 32 | trajname = varargin{2}; 33 | linestyle = varargin{3}; 34 | downsampling_fac = 1; 35 | case 4 36 | mot = varargin{1}; 37 | trajname = varargin{2}; 38 | linestyle = varargin{3}; 39 | downsampling_fac = varargin{4}; 40 | otherwise 41 | error('Wrong number of arguments!'); 42 | end 43 | if (ischar(trajname)) 44 | ID = trajectoryID(mot,trajname); 45 | elseif (isnum(trajname)) 46 | ID = trajname; 47 | else 48 | error('Expected trajectory name or numeric trajectory ID!'); 49 | end 50 | 51 | if (~ishold) 52 | hold; 53 | end 54 | 55 | handle = plot3(mot.jointTrajectories{ID}(1,1:downsampling_fac:end),mot.jointTrajectories{ID}(2,1:downsampling_fac:end),mot.jointTrajectories{ID}(3,1:downsampling_fac:end),linestyle); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/params_planePointNormal_hipMiddle.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [points,n,min_radius] = params_planePointNormal_hipMiddle(mot,p3_name,q_name,d) 22 | % The plane is defined as follows: 23 | % The normal n is the direction vector from the point halfway between the hips to the root. 24 | % p3 is the fixture point for the plane. 25 | % q is the point that is tested against this plane 26 | % d is the offset distance for the plane in the direction of n. 27 | % 28 | % function returns sequence of fixture points and unit normals along with 29 | % minimum radii that make sense to visualize position of q in relation to the plane. 30 | 31 | if (ischar(p3_name)) 32 | p3 = trajectoryID(mot,p3_name); 33 | else 34 | p3 = mot.nameMap{p3_name,3}; 35 | end 36 | if (ischar(q_name)) 37 | q = trajectoryID(mot,q_name); 38 | else 39 | q = mot.nameMap{q_name,3}; 40 | end 41 | 42 | p1 = 0.5*(mot.jointTrajectories{trajectoryID(mot,'lhip')}+mot.jointTrajectories{trajectoryID(mot,'rhip')}); 43 | n = mot.jointTrajectories{trajectoryID(mot,'root')} - p1; 44 | n = n./repmat(sqrt(sum(n.^2)),3,1); 45 | 46 | points = mot.jointTrajectories{p3} + n*d; 47 | 48 | min_radius = sqrt(sum((mot.jointTrajectories{p3}+n*d-mot.jointTrajectories{q}).^2)); 49 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/readTUMKitchenAnnotation.m: -------------------------------------------------------------------------------- 1 | function [y_left_arm, y_right_arm, y_torso] = ... 2 | readTUMKitchenAnnotation(anno) 3 | 4 | 5 | %% read annotation from the file 6 | left_arm_states = {}; 7 | right_arm_states = {}; 8 | torso_states = {}; 9 | frame_idx = []; 10 | for ii = 2:length(anno) 11 | gt_info = strsplit(anno{ii},','); 12 | frame_idx = [frame_idx; str2num(gt_info{1})]; 13 | 14 | % 15 | % if ~isempty(left_arm_states) 16 | % if ~strcmp(gt_info{2}, left_arm_states(end)) 17 | % timestamp_left_arm_change = [timestamp_left_arm_change; str2num(gt_info{1})]; 18 | % end 19 | % end 20 | % 21 | % if ~isempty(right_arm_states) 22 | % if ~strcmp(gt_info{3}, right_arm_states(end)) 23 | % timestamp_right_arm_change = [timestamp_right_arm_change; str2num(gt_info{1})]; 24 | % end 25 | % end 26 | % 27 | % 28 | % if ~isempty(torso_states) 29 | % if ~strcmp(gt_info{4}, torso_states(end)) 30 | % timestamp_torso_change = [timestamp_torso_change; str2num(gt_info{1})]; 31 | % end 32 | % end 33 | 34 | left_arm_states{end+1} = (gt_info{2}); 35 | right_arm_states{end+1} =(gt_info{3}); 36 | torso_states{end+1} = (gt_info{4}); 37 | end 38 | 39 | %% encode string labels to numbers 40 | torso_labels = {'StandingStill','HumanWalkingProcess'}; 41 | hand_labels = {'Reaching','TakingSomething','LoweringAnObject','ReleasingGraspOfSomething',... 42 | 'OpeningADoor','ClosingADoor','OpeningADrawer','ClosingADrawer','CarryingWhileLocomoting'}; 43 | 44 | y_left_arm = zeros(length(anno)-1,1); 45 | y_right_arm = zeros(length(anno)-1,1); 46 | y_torso = zeros(length(anno)-1,1); 47 | 48 | for ii = 1:length(torso_labels) 49 | idx = find(contains(torso_states,torso_labels{ii})); 50 | y_torso(idx) = ii; 51 | end 52 | 53 | for ii = 1:length(hand_labels) 54 | idx = find(contains(left_arm_states,hand_labels{ii})); 55 | y_left_arm(idx) = ii; 56 | 57 | idx = find(contains(right_arm_states,hand_labels{ii})); 58 | y_right_arm(idx) = ii; 59 | 60 | end 61 | 62 | 63 | 64 | 65 | 66 | 67 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/emptySkeletonNode.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function node = emptySkeletonNode 22 | 23 | node = struct('children',[],... % struct array containing this node's child nodes' indices within "nodes" array of skeleton data structure 24 | 'jointName','',... % name of this joint (if it is a joint (BVH)) 25 | 'boneName','',... % name of this bone (if it is a bone (ASF)) 26 | 'ID',0,... % ID number of this joint/bone 27 | 'parentID',0,... % parent node ID 28 | 'offset',[0;0;0],... % offset vector from the parent of this node to this node 29 | 'direction',[0;0;0],... % direction vector for this bone, given in global coordinates 30 | 'length',0,... % length of this bone 31 | 'axis',[0;0;0],... % axis of rotation for this node 32 | 'DOF',cell(1,1),... % degrees of freedom and rotation order for this node, in the form {'tx','ty','tz','rx','ry','rz'} (e.g.) 33 | 'rotationOrder','',... % rotation order in string representation (e.g., 'xyz') 34 | 'limits',[]); % kx2, kx2 or kx2 matrix of limits for this node's DOFs 35 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/addAnimatedPatches.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function mot = addAnimatedPatches(mot,function_name,function_params,varargin) 22 | % mot,function_name,function_params,type,color,alpha,overwrite) 23 | 24 | type = cell(length(function_name),1); 25 | color = cell(length(function_name),1); 26 | alpha = zeros(length(function_name),1); 27 | overwrite = false; 28 | for k=1:length(function_name) 29 | type{k} = 'disc'; 30 | color{k} = 'blue'; 31 | alpha(k) = 1; 32 | end 33 | if (nargin>6) 34 | overwrite = varargin{4}; 35 | end 36 | if (nargin>5) 37 | alpha = varargin{3}; 38 | end 39 | if (nargin>4) 40 | color = varargin{2}; 41 | end 42 | if (nargin>3) 43 | type = varargin{1}; 44 | end 45 | 46 | if (overwrite | ~isfield(mot,'animated_patch_data')) 47 | mot.animated_patch_data = animatedPatchStruct(length(function_name)); 48 | k0 = 0; 49 | else 50 | k0 = length(mot.animated_patch_data); 51 | end 52 | 53 | for k = k0+1:k0+length(function_name) 54 | mot.animated_patch_data(k).function_name = function_name{k-k0}; 55 | mot.animated_patch_data(k).function_params = function_params{k-k0}; 56 | mot.animated_patch_data(k).type = type{k-k0}; 57 | mot.animated_patch_data(k).color = color{k-k0}; 58 | mot.animated_patch_data(k).alpha = alpha(k-k0); 59 | end 60 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/readMocapSmart.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [ skel, mot ] = readMocapSmart( fullFilename, noCaching, noScaling ) 22 | % [ skel, mot ] = readMocapSmart( fullFilename, noCaching, noScaling ) 23 | % 24 | % 25 | % 26 | % readMocapSmart does not require specification of ASF-file 27 | % and automatically performs scaling (unit conversion) 28 | % 29 | % noCaching: Don't read *.MAT-file 30 | % noScaling: Don't scale ASF/AMC files by 2.54 (default: false) 31 | % 32 | % 33 | % Units are may be in centimeter or in inches 34 | % (ASF/AMC units of HDM05 files are in inches) 35 | % (C3D units of HDM05 files are in centimeters) 36 | % 37 | % noScaling = false -> scaling by factor 1/2.54 to 38 | % convert inches -> centimeters (only for ASF/AMC) 39 | % 40 | 41 | 42 | if nargin < 2 43 | noCaching = false; 44 | end 45 | if nargin < 3 46 | noScaling = false; 47 | end 48 | 49 | info = filename2info(fullFilename); 50 | 51 | if strcmpi(info.filetype, 'C3D') 52 | [skel, mot] = readMocap(fullFilename, [], noCaching ); 53 | elseif strcmpi(info.filetype, 'ASF/AMC') 54 | skelFile = fullfile(info.amcpath, info.asfname); 55 | [skel, mot] = readMocap(skelFile, fullFilename, [], true, true, true, noCaching); 56 | 57 | if ~noScaling 58 | [skel, mot] = scaleSkelMot(skel, mot, 1/2.54); % our ASF 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/filterS3.m: -------------------------------------------------------------------------------- 1 | function [y,t] = filterS3(varargin) 2 | % y = filterS3(b,quat_data,padding_method) 3 | % Filters a sequence of unit quaternions using an orientation filter 4 | % 5 | % Input: b, orientation filter constructed via orientationFilter(). 6 | % quat_data, sequence of N unit quaternions represented as a 4xN array. 7 | % padding_method, string, either 'symmetric' or 'zero' 8 | % 9 | % Output: y, Input quaternions filtered by the orientation filter b, represented as a 4xN array. 10 | % t, running time for filter. 11 | % 12 | % Remark: Angular velocity is computed as omega = log((q_i)^{-1}q_{i+1}), the factor 13 | % 0.5 is omitted. 14 | % 15 | % Reference: J. Lee and S. Shin: General Construction of Time-Domain Filters for Orientation Data, 16 | % Trans. IEEE Vis. and Comp. Graph., 2002 17 | 18 | switch (nargin) 19 | case 2 20 | b = varargin{1}; 21 | quat_data = varargin{2}; 22 | padding_method = 'symmetric'; 23 | case 3 24 | b = varargin{1}; 25 | quat_data = varargin{2}; 26 | padding_method = varargin{3}; 27 | otherwise 28 | error('Wrong number of arguments!'); 29 | end 30 | 31 | N = size(quat_data,2); 32 | k = length(b)/2; 33 | if (2*k>N) 34 | error('Filter length must not be larger than number of data points!'); 35 | end 36 | 37 | tic; 38 | omega = quatlog(quatmult(quatinv(quat_data(:,1:N-1)),quat_data(:,2:N)),10*eps); 39 | 40 | if (strncmp(padding_method,'symmetric',1)) 41 | pre = fliplr(omega(:,1:k)); 42 | post = fliplr(omega(:,N-1-k+1:N-1)); % omega is of length N-1. 43 | elseif (strncmp(padding_method,'zero',1)) 44 | pre = zeros(3,k); 45 | post = zeros(3,k); 46 | else 47 | error('Unknown padding option!'); 48 | end 49 | omega = [pre omega post]; 50 | 51 | % omega is of length N-1. We pre- and post-pad it by k zeros/symmetrically, so the resulting sequence 52 | % is of length 2*k + N-1. 53 | 54 | y = zeros(4,N); 55 | 56 | for i = 1:N 57 | s = zeros(3,1); 58 | for m = 1:2*k 59 | s = s + b(m)*omega(:,i+m-1); 60 | end 61 | y(:,i) = quatmult(quat_data(:,i),quatexp(s)); 62 | end 63 | t = toc; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/readMocapGUI.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function [skel, mot] = readMocapGUI(noCaching); 22 | % [skel, mot] = readMocapGUI(noCaching) 23 | 24 | if nargin < 1 25 | noCaching = false; 26 | end 27 | 28 | global VARS_GLOBAL; 29 | 30 | oldPath = cd; 31 | 32 | try 33 | defaultPath = VARS_GLOBAL.readMocapGUILastDir; 34 | catch 35 | try 36 | defaultPath = VARS_GLOBAL.dir_root; 37 | catch 38 | defaultPath = cd; 39 | end 40 | end 41 | 42 | cd(defaultPath); 43 | 44 | [datafile,datapath] = uigetfile('*.c3d; *.amc', 'Choose data file', 40, 40); 45 | if datafile ~= 0 46 | VARS_GLOBAL.readMocapGUILastDir = datapath; 47 | 48 | idx = findstr(datafile,'.'); 49 | ext = upper(datafile(idx(end):end)); 50 | 51 | if strcmp(ext, '.C3D') 52 | [skel, mot] = readMocap([datapath,datafile], [], noCaching); 53 | elseif strcmp(ext, '.AMC') 54 | asfFiles = dir([datapath '\*.ASF']); 55 | if isempty(asfFiles) 56 | cd(datapath); 57 | [asfFile, asfPath] = uigetfile('*.asf', 'Choose ASF file', 40, 40); 58 | else 59 | asfPath = datapath; 60 | asfFile = [datafile(1:6) '.ASF']; 61 | end 62 | [skel, mot] = readMocap([datapath,asfFile], [datapath,datafile], [], true, true, true, noCaching); 63 | end 64 | end 65 | 66 | cd(oldPath); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/convert2quat.m: -------------------------------------------------------------------------------- 1 | function mot = convert2quat(skel,mot) 2 | 3 | switch lower(mot.angleUnit) 4 | case 'deg' 5 | conversion_factor = pi/180; 6 | case 'rad' 7 | conversion_factor = 1; 8 | otherwise 9 | error(['Unknown angle unit: ' mot.angleUnit]); 10 | end 11 | nTraj = size(mot.rotationEuler,1); 12 | mot.rotationQuat = cell(nTraj, 1); 13 | for k = 1:nTraj 14 | node = skel.nodes(k); 15 | nRotDOF = size(mot.rotationEuler{node.ID,1},1); % number of rotational DOFs 16 | 17 | % zero-pad Euler array at the appropriate places, according to rotation order and presence/absence of respective DOFs 18 | if nRotDOF > 0 19 | completeEulers = zeros(3,mot.nframes); 20 | d = 1; % index for DOFs present in mot.rotationEuler 21 | for r = 1:3 % go through rotationOrder. 22 | idx = strmatch(['r' lower(node.rotationOrder(r))], lower(node.DOF), 'exact'); 23 | if (~isempty(idx)) 24 | completeEulers(r,:) = mot.rotationEuler{node.ID,1}(d,:)*conversion_factor; 25 | d = d+1; 26 | end 27 | end 28 | axis_quat = repmat(euler2quat(flipud(node.axis)*conversion_factor,'zyx'),1,mot.nframes); % According to ASF specs, rotation order for "axis" should be XYZ. However, they use the opposite multiplication order as we do! 29 | if (node.ID == 1) % root node? => special case for determination of rotation order (node.rotationOrder only concerns the global rotational offset in this case) 30 | rootTransformationOrder = char(node.DOF); 31 | rootTransformationOrder = rootTransformationOrder(:,2)'; 32 | [x,IA,IB] = intersect({'rx','ry','rz'}, lower(node.DOF)); 33 | rootRotationOrder = rootTransformationOrder(sort(IB)); 34 | mot.rotationQuat{node.ID,1} = euler2quat(flipud(completeEulers),fliplr(rootRotationOrder)); % ASF specs use opposite multiplication order as we do, hence fliplr() and flipud()! 35 | else 36 | mot.rotationQuat{node.ID,1} = quatmult(axis_quat,quatmult(euler2quat(flipud(completeEulers),fliplr(node.rotationOrder)),quatinv(axis_quat))); % ASF specs use opposite multiplication order as we do, hence fliplr() and flipud()! 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/recursive_forwardKinematicsQuat.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function trajectories = recursive_forwardKinematicsQuat(skel, mot, node_id, current_position, current_rotation, trajectories) 22 | % trajectories = recursive_forwardKinematicsQuat(skel, mot, node_id, current_position, current_rotation, trajectories) 23 | % 24 | % skel: skeleton 25 | % mot: motion 26 | % node_id: index of current node in node array 27 | % current_position: for all frames: current local coordinate offsets from world origin (3xnframes sequence of vectors) 28 | % current_rotation: for all frames: current local coordinate rotations against world coordinate frame (4xnframes sequence of quaternions) 29 | % trajectories: input & output cell array containing the trajectories that have been computed so far 30 | 31 | trajectories{node_id,1} = current_position; 32 | 33 | for child_id = skel.nodes(node_id).children' 34 | child = skel.nodes(child_id); 35 | 36 | if (~isempty(mot.rotationQuat{child_id})) 37 | child_rotation = quatmult(current_rotation,mot.rotationQuat{child_id}); 38 | else 39 | child_rotation = current_rotation; 40 | end 41 | 42 | child_position = current_position + quatrot(repmat(child.offset,1,mot.nframes),child_rotation); 43 | 44 | trajectories = recursive_forwardKinematicsQuat(skel, mot, child_id, child_position, child_rotation, trajectories); 45 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/forwardKinematicsEuler.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function jointTrajectories = forwardKinematicsEuler(skel,mot) 22 | switch lower(mot.angleUnit) 23 | case 'deg' 24 | conversion_factor = pi/180; 25 | case 'rad' 26 | conversion_factor = 1; 27 | otherwise 28 | error(['Unknown angle unit: ' mot.angleUnit]); 29 | end 30 | 31 | % root node involves special case for determination of rotation order (node.rotationOrder only concerns the global rotational offset in this case) 32 | rootTransformationOrder = char(skel.nodes(1).DOF); 33 | rootTransformationOrder = rootTransformationOrder(:,2)'; 34 | [x,IA,IB] = intersect({'rx','ry','rz'}, lower(skel.nodes(1).DOF)); 35 | rootRotationOrder = rootTransformationOrder(sort(IB)); 36 | mot.rotationQuat{node.ID,1} = euler2quat(flipud(completeEulers),fliplr(node.rotationOrder)); % ASF specs use opposite multiplication order as we do, hence fliplr() and flipud()! 37 | 38 | jointTrajectories = recursive_forwardKinematicsEuler(skel,... 39 | mot,... 40 | 1,... 41 | mot.rootTranslation + repmat(skel.nodes(1).offset,1,mot.nframes),... 42 | quatmult(repmat(skel.rootRotationalOffsetQuat,1,mot.nframes),euler2quat(conversion_factor*flipud(mot.rotationEuler{1}),rootRotationOrder)),... 43 | mot.jointTrajectories); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/showTracePoses.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function showTracePoses(skel,mot,frames) 22 | 23 | global VARS_GLOBAL_ANIM 24 | 25 | if (isempty(VARS_GLOBAL_ANIM)||isempty(VARS_GLOBAL_ANIM.graphics_data)) 26 | VARS_GLOBAL_ANIM = emptyVarsGlobalAnimStruct; 27 | animate_initGraphics; 28 | end 29 | 30 | f = find(cell2mat({VARS_GLOBAL_ANIM.graphics_data.figure}) == gcf); 31 | if (isempty(f)) 32 | animate_initGraphics; 33 | f = gcf; 34 | end 35 | 36 | VARS_GLOBAL_ANIM.graphics_data_index = f; 37 | for k=1:length(frames) 38 | VARS_GLOBAL_ANIM.graphics_data(f).trace_poses=... 39 | [VARS_GLOBAL_ANIM.graphics_data(f).trace_poses; ... 40 | createSkeletonLines({skel,mot},frames(k),... 41 | VARS_GLOBAL_ANIM.trace_pose_Color,... 42 | VARS_GLOBAL_ANIM.trace_pose_LineWidth,... 43 | VARS_GLOBAL_ANIM.trace_pose_LineStyle,... 44 | VARS_GLOBAL_ANIM.trace_pose_Marker,... 45 | VARS_GLOBAL_ANIM.trace_pose_MarkerSize,... 46 | VARS_GLOBAL_ANIM.trace_pose_MarkerEdgeColor,... 47 | VARS_GLOBAL_ANIM.trace_pose_MarkerFaceColor)]; 48 | % {skel, mot}, frames, color, linewidth, linestyle, marker, markersize, markeredgecolor, markerfacecolor 49 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/BVHparser/readBVH.m: -------------------------------------------------------------------------------- 1 | function [skel,mot] = readBVH(varargin) 2 | % skel,mot] = readBVH(filename,range,compute_quats,do_FK) 3 | 4 | switch (nargin) 5 | case 1 6 | filename = varargin{1}; 7 | range = [-inf inf]; 8 | compute_quats = true; 9 | do_FK = true; 10 | case 2 11 | filename = varargin{1}; 12 | range = varargin{2}; 13 | compute_quats = true; 14 | do_FK = true; 15 | case 3 16 | filename = varargin{1}; 17 | range = varargin{2}; 18 | compute_quats = varargin{3}; 19 | do_FK = true; 20 | case 4 21 | filename = varargin{1}; 22 | range = varargin{2}; 23 | compute_quats = varargin{3}; 24 | do_FK = varargin{4}; 25 | otherwise 26 | error('Wrong number of arguments!'); 27 | end 28 | 29 | cl1 = clock; 30 | %%%%%%%%%%%%%% open BVH file 31 | fid = fopen(filename,'rt'); 32 | if fid ~= -1 33 | %%%%%%%%%%%%%% read HIERARCHY 34 | skel = emptySkeleton; 35 | skel.filename = filename; 36 | skel.fileType = 'BVH'; 37 | skel.name = 'BVH'; 38 | 39 | [result, skel] = readHierarchyBVH(skel,fid); 40 | if ~result 41 | close(hF); 42 | fclose(fid); 43 | error('Error parsing HIERARCHY section in BVH file.'); 44 | end 45 | 46 | if (nargout>1) % "read motion" requested by user 47 | %%%%%%%%%%%%%% read MOTION 48 | mot = emptyMotion; 49 | mot.filename = filename; 50 | mot.nameMap = skel.nameMap; 51 | 52 | [result, mot, skel] = readMotion(mot,skel,fid, range, compute_quats); 53 | if ~result 54 | close(hF); 55 | error('Error parsing MOTION section in BVH file.'); 56 | end 57 | 58 | % fclose(fid); % this is done by readMotion 59 | else 60 | fclose(fid); 61 | end 62 | else 63 | error('Could not open BVH file.'); 64 | end 65 | 66 | if (do_FK) 67 | tic 68 | if (compute_quats) 69 | mot.jointTrajectories = forwardKinematicsQuat(skel,mot); 70 | else 71 | mot.jointTrajectories = forwardKinematicsEuler(skel,mot); 72 | end 73 | t = toc; 74 | disp(['Computed joint trajectories from ' mot.filename ' in ' num2str(t) ' seconds.']); 75 | mot.boundingBox = computeBoundingBox(mot); 76 | end 77 | 78 | t=etime(clock,cl1); 79 | disp(['Total elapsed time : ' num2str(t) ' seconds.']); 80 | 81 | 82 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/cropMot.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function mot_out = cropMot(mot_in,range) 22 | 23 | if isempty(range) 24 | mot_out = mot_in; 25 | return; 26 | end 27 | 28 | mot_out = emptyMotion; 29 | 30 | mot_out.njoints = mot_in.njoints; 31 | mot_out.nframes = length(range); 32 | mot_out.frameTime = mot_in.frameTime; 33 | mot_out.samplingRate = mot_in.samplingRate; 34 | mot_out.jointNames = mot_in.jointNames; 35 | mot_out.boneNames = mot_in.boneNames; 36 | mot_out.nameMap = mot_in.nameMap; 37 | mot_out.animated = mot_in.animated; 38 | mot_out.unanimated = mot_in.unanimated; 39 | 40 | if not(isempty(mot_in.rootTranslation)) 41 | mot_out.rootTranslation = mot_in.rootTranslation(:,range); 42 | end 43 | for k = 1:size(mot_in.jointTrajectories,1) 44 | if ~isempty(mot_in.jointTrajectories{k,1}) 45 | mot_out.jointTrajectories{k,1} = mot_in.jointTrajectories{k,1}(:,range); 46 | end 47 | end 48 | for k = 1:size(mot_in.rotationEuler,1) 49 | if (~isempty(mot_in.rotationEuler{k})) 50 | mot_out.rotationEuler{k,1} = mot_in.rotationEuler{k,1}(:,range); 51 | end 52 | end 53 | for k = 1:size(mot_in.rotationQuat,1) 54 | if (~isempty(mot_in.rotationQuat{k,1})) 55 | mot_out.rotationQuat{k,1} = mot_in.rotationQuat{k,1}(:,range); 56 | end 57 | end 58 | 59 | mot_out.filename = mot_in.filename; 60 | mot_out.documentation = vertcat(mot_in.documentation,{['The original file has been cropped to the range ' num2str(range) '!']}); 61 | mot_out.angleUnit = mot_in.angleUnit; 62 | mot_out.boundingBox = computeBoundingBox(mot_out); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/bisectS3.m: -------------------------------------------------------------------------------- 1 | function R = bisectS3(varargin) 2 | % R = bisectS3(P,Q,tol) 3 | % 4 | % Compute the bisector quaternion between two quaternions on S3. 5 | % 6 | % Input: * P,Q are sequences of quaternions represented as 4xn matrices. 7 | % Non-unit quaternions might be normalized prior to 8 | % interpolation, see next point. 9 | % * If tol is specified, it denotes the allowable deviation from unit 10 | % length for the input quaternions. Deviations less than tol will 11 | % lead to re-normalization, deviations larger than tol will lead 12 | % to re-normalization and a warning. If tol is not specified, 13 | % all deviations larger than the machine precision will lead to 14 | % an error. 15 | % 16 | % Output: R, 4xn matrix of quaternions representing the bisectors of (P(:,i),Q(:,i)) 17 | 18 | switch (nargin) 19 | case 2 20 | P = varargin{1}; 21 | Q = varargin{2}; 22 | tol = 10*eps; 23 | error_on_deviations = true; 24 | case 3 25 | P = varargin{1}; 26 | Q = varargin{2}; 27 | tol = varargin{3}; 28 | error_on_deviations = false; 29 | otherwise 30 | error('Wrong number of arguments.'); 31 | end 32 | 33 | if (size(P,1)~=4 || size(Q,1)~=4 || (size(P,2) ~= size(Q,2))) 34 | error('Input arrays: wrong dimensions.'); 35 | end 36 | 37 | nsq = sum(P.^2); 38 | deviating = find(abs(nsq - 1)>tol); 39 | if (length(deviating)>0) 40 | deviating 41 | if (error_on_deviations) 42 | error('The input quaternions in P with the above indices are not of unit length!'); 43 | else 44 | warning('The input quaternions in P with the above indices are not of unit length!'); 45 | end 46 | P(:,deviating) = P(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 47 | end 48 | 49 | nsq = sum(Q.^2); 50 | deviating = find(abs(nsq - 1)>tol); 51 | if (length(deviating)>0) 52 | deviating 53 | if (error_on_deviations) 54 | error('The input quaternions with the above indices are not of unit length!'); 55 | else 56 | warning('The input quaternions with the above indices are not of unit length!'); 57 | end 58 | Q(:,deviating) = Q(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 59 | end 60 | 61 | R = (P+Q)./repmat(sqrt(quatnormsq(P+Q)),4,1); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/doubleS3.m: -------------------------------------------------------------------------------- 1 | function R = doubleS3(varargin) 2 | % R = doubleS3(P,Q,tol) 3 | % 4 | % Slerp-connect 2 quaternions on S3 and extend the connection by a length factor of 2. 5 | % 6 | % Input: * P,Q are sequences of quaternions represented as 4xn matrices. 7 | % Non-unit quaternions might be normalized prior to 8 | % interpolation, see next point. 9 | % * If tol is specified, it denotes the allowable deviation from unit 10 | % length for the input quaternions. Deviations less than tol will 11 | % lead to re-normalization, deviations larger than tol will lead 12 | % to re-normalization and a warning. If tol is not specified, 13 | % all deviations larger than the machine precision will lead to 14 | % an error. 15 | % 16 | % Output: R, 4xn matrix of quaternions representing the "doubles" of (P(:,i),Q(:,i)) 17 | 18 | switch (nargin) 19 | case 2 20 | P = varargin{1}; 21 | Q = varargin{2}; 22 | tol = 10*eps; 23 | error_on_deviations = true; 24 | case 3 25 | P = varargin{1}; 26 | Q = varargin{2}; 27 | tol = varargin{3}; 28 | error_on_deviations = false; 29 | otherwise 30 | error('Wrong number of arguments.'); 31 | end 32 | 33 | if (size(P,1)~=4 || size(Q,1)~=4 || (size(P,2) ~= size(Q,2))) 34 | error('Input arrays: wrong dimensions.'); 35 | end 36 | 37 | nsq = sum(P.^2); 38 | deviating = find(abs(nsq - 1)>tol); 39 | if (length(deviating)>0) 40 | deviating 41 | if (error_on_deviations) 42 | error('The input quaternions in P with the above indices are not of unit length!'); 43 | else 44 | warning('The input quaternions in P with the above indices are not of unit length!'); 45 | end 46 | P(:,deviating) = P(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 47 | end 48 | 49 | nsq = sum(Q.^2); 50 | deviating = find(abs(nsq - 1)>tol); 51 | if (length(deviating)>0) 52 | deviating 53 | if (error_on_deviations) 54 | error('The input quaternions with the above indices are not of unit length!'); 55 | else 56 | warning('The input quaternions with the above indices are not of unit length!'); 57 | end 58 | Q(:,deviating) = Q(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 59 | end 60 | 61 | R = 2*repmat(dot(P,Q),4,1).*Q - P; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/distS3.m: -------------------------------------------------------------------------------- 1 | function d = distS3(varargin) 2 | % Q = distS3(q1,q2,tol) 3 | % Computes the spherical distance between q1 and q2. 4 | % 5 | % Input: * q1,q2 are sequences of quaternions represented as 4xn matrices. 6 | % Non-unit quaternions might be normalized prior to 7 | % interpolation, see next point. 8 | % * If tol is specified, it denotes the allowable deviation from unit 9 | % length for the input quaternions. Deviations less than tol will 10 | % lead to re-normalization, deviations larger than tol will lead 11 | % to re-normalization and a warning. If tol is not specified, 12 | % all deviations larger than the machine precision will lead to 13 | % an error. 14 | % 15 | % Output: d is a 1xn vector of distances, where d(i) is the spherical distance 16 | % between q1(:,i) and q2(:,i) 17 | 18 | switch (nargin) 19 | case 2 20 | q1 = varargin{1}; 21 | q2 = varargin{2}; 22 | tol = 10*eps; 23 | error_on_deviations = true; 24 | case 3 25 | q1 = varargin{1}; 26 | q2 = varargin{2}; 27 | tol = varargin{3}; 28 | error_on_deviations = false; 29 | otherwise 30 | error('Wrong number of arguments.'); 31 | end 32 | 33 | nsq = sum(q1.^2); 34 | deviating = find(abs(nsq - 1)>tol); 35 | if (length(deviating)>0) 36 | deviating 37 | if (error_on_deviations) 38 | error('The input quaternions in q1 with the above indices are not of unit length!'); 39 | else 40 | warning('The input quaternions in q1 with the above indices are not of unit length!'); 41 | end 42 | q1(:,deviating) = q1(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 43 | end 44 | 45 | nsq = sum(q2.^2); 46 | deviating = find(abs(nsq - 1)>tol); 47 | if (length(deviating)>0) 48 | deviating 49 | if (error_on_deviations) 50 | error('The input quaternions in q2 with the above indices are not of unit length!'); 51 | else 52 | warning('The input quaternions in q2 with the above indices are not of unit length!'); 53 | end 54 | q2(:,deviating) = q2(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 55 | end 56 | 57 | if (size(q1,1)~=4 || size(q2,1)~=4 || (size(q1,2) ~= size(q2,2))) 58 | error('Input arrays: wrong dimensions.'); 59 | end 60 | 61 | d = acos(dot(q1,q2)); 62 | 63 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/resumeAnimation.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function resumeAnimation(varargin) 22 | global VARS_GLOBAL_ANIM 23 | 24 | if (nargin >1) 25 | new_time_stretch_factor = varargin{2}; 26 | else 27 | new_time_stretch_factor = -1; 28 | end 29 | 30 | if (nargin >0) 31 | range = varargin{1}; 32 | current_frame = range(1); 33 | if(length(range) == 2) 34 | last_frame = range(2); 35 | else 36 | last_frame = VARS_GLOBAL_ANIM.frames_total; 37 | end 38 | else 39 | current_frame = VARS_GLOBAL_ANIM.current_frame; 40 | last_frame = VARS_GLOBAL_ANIM.frames_total; 41 | end 42 | 43 | t = timerfind('Name','AnimationTimer'); 44 | try 45 | if(~isempty(t)) 46 | t = t(1); 47 | num_frames = last_frame - current_frame +1; 48 | set(t,'TasksToExecute',num_frames); 49 | VARS_GLOBAL_ANIM.current_frame = current_frame; 50 | 51 | if(new_time_stretch_factor ~= -1) 52 | desired_frame_time = VARS_GLOBAL_ANIM.mot(1).frameTime; 53 | period = round(1000*desired_frame_time/new_time_stretch_factor)/1000; 54 | VARS_GLOBAL_ANIM.timer_period = period; 55 | if (period == 0) 56 | warning(['Requested timer period of ' num2str(desired_frame_time/time_stretch_factor) ' s is too short for Matlab! Setting period to minimum of 1 ms :-(']); 57 | period = 0.001; 58 | end 59 | set(t,'Period',period); 60 | end 61 | 62 | start(t); 63 | end 64 | catch 65 | delete(t); 66 | return 67 | end 68 | 69 | VARS_GLOBAL_ANIM.animation_paused = false; 70 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/matrix_to_amc.m: -------------------------------------------------------------------------------- 1 | % Writes motion data from matrix D to an AMC file on disk. 2 | % The ACM format is the format used in the CMU online motion capture database 3 | % function [] = matrix_to_amc(fname, D) 4 | % fname = output disk file name for AMC file 5 | % D = input Matlab data matrix 6 | % Example: 7 | % matrix_to_amc('running1.amc', D) 8 | % 9 | % 10 | 11 | % Jernej Barbic 12 | % CMU 13 | % March 2003 14 | % Databases Course 15 | function [] = matrix_to_amc(fname, D) 16 | 17 | fid=fopen(fname, 'wt'); 18 | if fid == -1, 19 | fprintf('Error, can not open file %s.\n', fname); 20 | return; 21 | end; 22 | 23 | % print header 24 | fprintf(fid,'#!Matlab matrix to amc conversion\n'); 25 | fprintf(fid,':FULLY-SPECIFIED\n'); 26 | fprintf(fid,':DEGREES\n'); 27 | 28 | [rows, cols] = size(D); 29 | 30 | % print data 31 | for frame=1:rows 32 | fprintf(fid,'%d\n',frame); 33 | 34 | fprintf(fid,'root %f %f %f %f %f %f\n', D(frame,1:6)); 35 | fprintf(fid,'lowerback %f %f %f\n', D(frame,7:9)); 36 | fprintf(fid,'upperback %f %f %f\n', D(frame,10:12)); 37 | fprintf(fid,'thorax %f %f %f\n', D(frame,13:15)); 38 | fprintf(fid,'lowerneck %f %f %f\n', D(frame,16:18)); 39 | fprintf(fid,'upperneck %f %f %f\n', D(frame,19:21)); 40 | fprintf(fid,'head %f %f %f\n', D(frame,22:24)); 41 | fprintf(fid,'rclavicle %f %f\n', D(frame,25:26)); 42 | fprintf(fid,'rhumerus %f %f %f\n', D(frame,27:29)); 43 | fprintf(fid,'rradius %f\n', D(frame,30)); 44 | fprintf(fid,'rwrist %f\n', D(frame,31)); 45 | fprintf(fid,'rhand %f %f\n', D(frame,32:33)); 46 | fprintf(fid,'rfingers %f\n', D(frame,34)); 47 | fprintf(fid,'rthumb %f %f\n', D(frame,35:36)); 48 | fprintf(fid,'lclavicle %f %f\n', D(frame,37:38)); 49 | fprintf(fid,'lhumerus %f %f %f\n', D(frame,39:41)); 50 | fprintf(fid,'lradius %f\n', D(frame,42)); 51 | fprintf(fid,'lwrist %f\n', D(frame,43)); 52 | fprintf(fid,'lhand %f %f\n', D(frame,44:45)); 53 | fprintf(fid,'lfingers %f\n', D(frame,46)); 54 | fprintf(fid,'lthumb %f %f\n', D(frame,47:48)); 55 | fprintf(fid,'rfemur %f %f %f\n', D(frame,49:51)); 56 | fprintf(fid,'rtibia %f\n', D(frame,52)); 57 | fprintf(fid,'rfoot %f %f\n', D(frame,53:54)); 58 | fprintf(fid,'rtoes %f\n', D(frame,55)); 59 | fprintf(fid,'lfemur %f %f %f\n', D(frame,56:58)); 60 | fprintf(fid,'ltibia %f\n', D(frame,59)); 61 | fprintf(fid,'lfoot %f %f\n', D(frame,60:61)); 62 | fprintf(fid,'ltoes %f\n', D(frame,62)); 63 | 64 | end 65 | 66 | fclose(fid); 67 | 68 | 69 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readBone.m: -------------------------------------------------------------------------------- 1 | function [result,bone] = readBone(skel,fid) 2 | 3 | [result, lin] = findKeyword(fid,'begin'); 4 | if ~result 5 | error('ASF: Expected BEGIN while reading bones!'); 6 | end 7 | 8 | bone = emptySkeletonNode; 9 | while (~feof(fid)) 10 | pos = ftell(fid); 11 | lin = eatWhitespace(fgetl(fid)); 12 | if (length(lin)<1) 13 | continue; 14 | end 15 | if (strcmpi(lin(1:3),'end')) 16 | break; % passed end of bone! 17 | end 18 | 19 | bone.ID = skel.njoints+1; % ID is an optional field in ASF files... this choice is a good default value for a unique ID. 20 | [token,lin] = strtok(lin); 21 | lin = eatWhitespace(lin); 22 | switch (upper(token)) 23 | case 'ID' 24 | [token2,lin] = strtok(lin); 25 | bone.ID = str2num(token2) + 1; % "+ 1" because we want root node (which is not treated as a separate node in ASF) to occupy ID 1 26 | case 'NAME' 27 | [token2,lin] = strtok(lin); 28 | bone.boneName = token2; 29 | case 'DIRECTION' 30 | bone.direction = sscanf(lin,'%f %f %f'); 31 | case 'LENGTH' 32 | bone.length = sscanf(lin,'%f') / skel.lengthUnit; 33 | case 'AXIS' 34 | [bone.axis,count,errmsg,nextindex] = sscanf(lin,'%f %f %f'); 35 | lin = lin(nextindex:end); 36 | [token2,lin] = strtok(lin); 37 | bone.rotationOrder = token2; 38 | case 'DOF' 39 | k = 1; 40 | while length(eatWhitespace(lin))>0 41 | [dof,lin] = strtok(lin); 42 | bone.DOF{k,1} = dof; 43 | k = k+1; 44 | end 45 | case 'LIMITS' 46 | nDOF = size(bone.DOF,1); 47 | bone.limits = zeros(nDOF,2); 48 | bone.limits(1,:) = transpose(sscanf(lin,'(%f %f)')); 49 | for n = 2:nDOF 50 | lin = eatWhitespace(fgetl(fid)); 51 | bone.limits(n,:) = transpose(sscanf(lin,'(%f %f)')); 52 | end 53 | case 'BODYMASS' 54 | case 'COFMASS' 55 | otherwise 56 | warning(['ASF: Unknown bone property: ' token '!']); 57 | end 58 | end 59 | if (norm(bone.direction) > 0) 60 | bone.offset = bone.direction/norm(bone.direction) * bone.length; 61 | end 62 | 63 | fseek(fid,pos,'bof'); 64 | 65 | 66 | [result, lin] = findKeyword(fid,'end'); 67 | if ~result 68 | error('ASF: Expected END while reading bones!'); 69 | end 70 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/filterR4.m: -------------------------------------------------------------------------------- 1 | function [Y,t] = filterR4(varargin) 2 | % Y = filterR4(w,X,step,padding_method) 3 | % Filters curves embedded in the unit quaternion sphere with a sliding window. 4 | % Simply views quats as 4D data without additional structure and renormalizes 5 | % to S^3 after filtering 6 | % 7 | % Input: w, weight vector 8 | % X, 4xN matrix of input unit quaternions 9 | % optional: step, step size for window (window length is length(w)), default is step=1. 10 | % ->!! Length of output sequence is ceil(N/step). !! <- 11 | % optional: padding method, one of {'symmetric', 'zero'}. default is 'symmetric' 12 | % 13 | % Output: Y, Filtered version of X 14 | % t, running time for filter. 15 | % 16 | 17 | 18 | switch (nargin) 19 | case 2 20 | w = varargin{1}; 21 | X = varargin{2}; 22 | step = 1; 23 | padding_method = 'symmetric'; 24 | case 3 25 | w = varargin{1}; 26 | X = varargin{2}; 27 | step = varargin{3}; 28 | padding_method = 'symmetric'; 29 | case 4 30 | w = varargin{1}; 31 | X = varargin{2}; 32 | step = varargin{3}; 33 | padding_method = varargin{4}; 34 | otherwise 35 | error('Wrong number of arguments!'); 36 | end 37 | 38 | L = size(w,2); 39 | N = size(X,2); 40 | 41 | if (L>N) 42 | error('Filter length must not be larger than number of data points!'); 43 | end 44 | 45 | %%%% prepare data set X by means of pre- and postpadding 46 | switch mod(L,2) 47 | case 0 % even filter length 48 | prepad_length = L/2; 49 | postpad_length = L/2 - 1; 50 | case 1 % odd filter length 51 | prepad_length = (L - 1)/2; 52 | postpad_length = (L - 1)/2; 53 | end 54 | 55 | tic; 56 | if (strncmp(padding_method,'symmetric',1)) 57 | pre = fliplr(X(:,1:prepad_length)); 58 | post = fliplr(X(:,N-postpad_length+1:N)); 59 | elseif (strncmp(padding_method,'zero',1)) 60 | pre = [ones(1,prepad_length);zeros(3,prepad_length)]; 61 | post = [ones(1,postpad_length);zeros(3,postpad_length)];; 62 | else 63 | error('Unknown padding option!'); 64 | end 65 | X = [pre X post]; 66 | 67 | Y = zeros(4,ceil(N/step)); 68 | for (i=1:ceil(N/step)) 69 | pos = step*(i-1)+1; 70 | Y(:,i) = bruteForceAverageR4(X(:,pos:pos+L-1),w); 71 | end 72 | t = toc; 73 | 74 | %%%%%%%%%%% 75 | 76 | function Y = bruteForceAverageR4(X,w) 77 | 78 | Y = sum(X.*repmat(w,4,1),2); 79 | Y = Y./sqrt(sum(Y.^2,1)); -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/sphericalAverageA1.m: -------------------------------------------------------------------------------- 1 | function [q,iterations] = sphericalAverageA1(varargin) 2 | % q = sphericalAverageA1(P,w,max_error,max_iterations) 3 | % Computes the spherical weighted average of n unit quaternions using 4 | % algorithm A1 from Buss/Fillmore (2001) 5 | % 6 | % Input: P, 4xn array of unit quaternions. 7 | % w, weight array of length n, sum(w)=1. 8 | % max_error, error bound for loop termination, default = 1000*eps. 9 | % max_iterations, maximum number of iterations 10 | % 11 | % Output: q, spherical average of the quaternions in q. 12 | % iterations, number of iterations. 13 | % 14 | % Reference: S. Buss, J. Fillmore: Spherical Averages and Applications to 15 | % Spherical Splines and Interpolation, ACM Trans. Graphics 20 (2001): 16 | % 95--126 17 | 18 | switch(nargin) 19 | case 1 20 | P = varargin{1}; 21 | w = (1/size(P,2))*ones(1,size(P,2)); 22 | max_error = 1000*eps; 23 | max_iterations = inf; 24 | case 2 25 | P = varargin{1}; 26 | w = varargin{2}; 27 | max_error = 1000*eps; 28 | max_iterations = inf; 29 | case 3 30 | P = varargin{1}; 31 | w = varargin{2}; 32 | max_error = varargin{3}; 33 | max_iterations = inf; 34 | case 4 35 | P = varargin{1}; 36 | w = varargin{2}; 37 | max_error = varargin{3}; 38 | max_iterations = varargin{4}; 39 | otherwise 40 | error('Wrong number of arguments.'); 41 | end 42 | 43 | if (size(P,1)~=4) 44 | error('P must be a 4xn array!'); 45 | end 46 | n = size(P,2); 47 | if (size(w,1)~=1) 48 | error('Weights must be a row vector!'); 49 | end 50 | if (size(w,2)~=n) 51 | error('#quaternions = #weights required!'); 52 | end 53 | if (abs(sum(w)-1)>1000*eps) 54 | error('Sum of weights must be 1!'); 55 | end 56 | 57 | 58 | q = sum(repmat(w,4,1).*P,2); 59 | q = q/sqrt(quatnormsq(q)); 60 | 61 | q = quatnormalizeSign(q); 62 | 63 | norm_u = inf; 64 | iterations = 0; 65 | while (norm_u>max_error && iterations < max_iterations) 66 | %Pstar = quatlog(quatmult(repmat(quatinv(q),1,n),P),max_error); 67 | qinv = quatinv(q); 68 | Pstar = quatlog(quatmult(qinv(:, ones(1,n)),P),max_error); 69 | u = sum(w(ones(1,3),:).*Pstar,2); 70 | % disp(norm(u)); 71 | q = quatmult(q,quatexp(u)); 72 | iterations = iterations+1; 73 | norm_u = norm(u); 74 | end 75 | 76 | if (iterations==max_iterations) 77 | warning('Maximum number of iterations reached.'); 78 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/animate/createGroundPlane.m: -------------------------------------------------------------------------------- 1 | % This code belongs to the HDM05 mocap database which can be obtained 2 | % from the website http://www.mpi-inf.mpg.de/resources/HDM05 . 3 | % 4 | % If you use and publish results based on this code and data, please 5 | % cite the following technical report: 6 | % 7 | % @techreport{MuellerRCEKW07_HDM05-Docu, 8 | % author = {Meinard M{\"u}ller and Tido R{\"o}der and Michael Clausen and Bernd Eberhardt and Bj{\"o}rn Kr{\"u}ger and Andreas Weber}, 9 | % title = {Documentation: Mocap Database {HDM05}}, 10 | % institution = {Universit{\"a}t Bonn}, 11 | % number = {CG-2007-2}, 12 | % year = {2007} 13 | % } 14 | % 15 | % 16 | % THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 17 | % KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 19 | % PARTICULAR PURPOSE. 20 | 21 | function h = createGroundPlane(bb,bb_extension,ground_tile_size) 22 | 23 | x_min = bb(1); x_max = bb(2); z_min = bb(5); z_max = bb(6); 24 | x_width = x_max - x_min; x_rest = mod(x_width,ground_tile_size); x_min = x_min-x_rest/2; x_max = x_max+x_rest/2; 25 | z_width = z_max - z_min; z_rest = mod(z_width,ground_tile_size); z_min = z_min-z_rest/2; z_max = z_max+z_rest/2; 26 | [floor_x,floor_z] = meshgrid(x_min:ground_tile_size:x_max,z_min:ground_tile_size:z_max); 27 | %h = surf(floor_x,repmat(bb(3)-bb_extension(3),size(floor_x)),floor_z); 28 | nx = size(floor_x,1); 29 | nz = size(floor_z,2); 30 | X = zeros(nx*nz,1); 31 | Y = zeros(nx*nz,1); 32 | Z = zeros(nx*nz,1); 33 | for k=1:nz 34 | X((k-1)*nx+1:k*nx) = floor_x(:,k); 35 | Z((k-1)*nx+1:k*nx) = floor_z(:,k); 36 | end 37 | ntiles_x = nx - 1; 38 | ntiles_z = nz - 1; 39 | 40 | faces = zeros(ntiles_x*ntiles_z,4); 41 | C = zeros(ntiles_x*ntiles_z,1); 42 | c = zeros(1,ntiles_x); c(2:2:length(c)) = 1; 43 | for z = 1:ntiles_z 44 | faces((z-1)*ntiles_x+1:z*ntiles_x,:) = (z-1)*nx + [1:ntiles_x; 2:nx; nx+2:nx+1+ntiles_x; nx+1:nx+ntiles_x]'; 45 | C((z-1)*ntiles_x+1:z*ntiles_x) = c; 46 | c = 1-c; 47 | end 48 | 49 | % c1 = [0.5 0.5 0.5]; 50 | % c2 = [0 0 0]; 51 | %c1 = [0.75 0.75 0.75]; 52 | %c2 = [0.5 0.5 0.5]; 53 | c1 = [9.2/10 9.2/10 9.2/10]; 54 | c2 = [8/10 8/10 8/10]; 55 | Y = repmat(bb(3)-bb_extension(3),size(X)); 56 | h = patch('Vertices',[X Y Z],... 57 | 'Faces',faces,... 58 | 'FaceVertexCData',C*c1+(1-C)*c2,... 59 | 'FaceColor','flat',... 60 | 'EdgeColor','none',... 61 | 'FaceLighting','none',... 62 | 'UserData', 'GroundPlane'); 63 | % set(h,'facecolor','black'); 64 | %alpha(h,0.5); 65 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/slerp.m: -------------------------------------------------------------------------------- 1 | function Q = slerp(varargin) 2 | % Q = slerp(q1,q2,u,tol) 3 | % Computes the spherical linear interpolation between q1 and q2 for the 4 | % parameter u \in [0,1] 5 | % 6 | % Input: * q1,q2 are quaternions represented as column vectors. 7 | % Non-unit quaternions will be normalized prior to 8 | % interpolation! 9 | % * u is a vector from [0,1]^n specifying interpolation parameter 10 | % values at n positions 11 | % * If tol is specified, it denotes the allowable deviation from unit 12 | % length for the input quaternions. Deviations less than tol will 13 | % lead to re-normalization, deviations larger than tol will lead 14 | % to re-normalization and a warning. If tol is not specified, 15 | % all deviations larger than the machine precision will lead to 16 | % an error. 17 | % 18 | % Output: Q is a 4xn array of spherically interpolated unit quaternions 19 | 20 | switch (nargin) 21 | case 3 22 | q1 = varargin{1}; 23 | q2 = varargin{2}; 24 | u = varargin{3}; 25 | tol = 10*eps; 26 | error_on_deviations = true; 27 | case 4 28 | q1 = varargin{1}; 29 | q2 = varargin{2}; 30 | u = varargin{3}; 31 | tol = varargin{4}; 32 | error_on_deviations = false; 33 | otherwise 34 | error('Wrong number of arguments.'); 35 | end 36 | 37 | if (size(q1,1) ~= 4 || size(q2,1)~= 4 || quatnormsq(q1)tol) 42 | if (error_on_deviations) 43 | error('Input quaternion q1 is not of unit length!'); 44 | else 45 | warning('Input quaternion q1 is not of unit length! q1 will be re-normalized.'); 46 | end 47 | q1 = quatnormalize(q1); 48 | end 49 | 50 | if (abs(quatnormsq(q2)-1)>tol) 51 | if (error_on_deviations) 52 | error('Input quaternion q2 is not of unit length!'); 53 | else 54 | warning('Input quaternion q2 is not of unit length! q2 will be re-normalized.'); 55 | end 56 | q2 = quatnormalize(q2); 57 | end 58 | 59 | n = length(u); 60 | 61 | Q = zeros(4,n); 62 | for i=1:n 63 | Q(:,i) = quatmult(q1,quatexp(u(i)*quatlog(quatmult(quatinv(q1),q2),tol))); 64 | % costheta = transpose(q1)*q2; 65 | % sintheta = sqrt(1-costheta*costheta); 66 | % if (abs(sintheta) end_frame) % swap, if necessary 44 | h = end_frame; 45 | end_frame = start_frame; 46 | start_frame = h; 47 | end 48 | if (start_frame == -inf) 49 | start_frame = 1; 50 | end 51 | if (end_frame == inf) 52 | end_frame = frame_num; 53 | end 54 | if (end_frame > frame_num) 55 | error('end_frame greater than number of frames in file!'); 56 | end 57 | 58 | fclose(fid); 59 | mot.nframes = end_frame - start_frame + 1; 60 | data = textread(mot.filename,'',mot.nframes,'headerlines',lc + start_frame - 1)'; 61 | if max(abs(data(size(data,1),:))) == 0 62 | data = data(1:size(data,1)-1,:); 63 | end 64 | t = toc; 65 | 66 | disp(['Read ' num2str(mot.nframes) ' frames of motion data from ' mot.filename ' in ' num2str(t) ' seconds.']); 67 | 68 | mot.rootTranslation = extractRootTranslation(skel,data); 69 | %%%%%%%% extract and convert data 70 | tic 71 | [mot.rotationEuler, mot.rotationQuat] = extractRotation(skel, 1, data, 1, cell(mot.njoints,1), cell(mot.njoints,1), compute_quats); 72 | t = toc; 73 | if (compute_quats) 74 | disp(['Converted motion data from ' mot.filename ' in ' num2str(t) ' seconds.']); 75 | end 76 | 77 | mot.njoints = skel.njoints; 78 | mot.jointNames = skel.jointNames; 79 | mot.boneNames = skel.boneNames; 80 | mot.animated = skel.animated; 81 | mot.unanimated = skel.unanimated; 82 | 83 | result = true; 84 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/ASFAMCparser/readASF.m: -------------------------------------------------------------------------------- 1 | function skel = readASF(filename) 2 | % skel = readASF(filename) 3 | 4 | cl1 = clock; 5 | %%%%%%%%%%%%%% open ASF file 6 | fid = fopen(filename,'rt'); 7 | if fid ~= -1 8 | skel = emptySkeleton; 9 | 10 | idxBackSlash = findstr(filename, '\'); 11 | if not(isempty(idxBackSlash)) 12 | skel.filename = filename(idxBackSlash(end)+1:end); 13 | else 14 | skel.filename = filename; 15 | end 16 | 17 | if strncmp(skel.filename, 'TOM', 3) == 1 18 | % for the database of tomohiko assign another asf-filetype as 19 | % for the HDM05-ASF-filem because the tomokiko-files contain 20 | % different joints. The filetype is used in the constructNameMap 21 | % file where for the tomohiko asf-files a different name map has to 22 | % be constructed. 23 | skel.fileType = 'TOM.ASF'; 24 | else 25 | skel.fileType = 'ASF'; 26 | end 27 | 28 | [result1, skel] = readVersion(skel,fid); 29 | [result2, skel] = readName(skel,fid); 30 | [result3, skel] = readUnits(skel,fid); 31 | [result4, skel] = readDocumentation(skel,fid); 32 | [result5, skel] = readRootASF(skel,fid); 33 | [result6, skel] = readBonedata(skel,fid); 34 | [result7, hierarchy] = readHierarchyASF(fid); 35 | [result8, skel] = readSkin(skel,fid); 36 | if ~(result1 & result2 & result4 & result5 & result6 & result7) 37 | fclose(fid); 38 | error(['ASF: Error parsing file ' filename '!']); 39 | end 40 | 41 | fclose(fid); 42 | else 43 | error(['Could not open ASF file "' filename '"!']); 44 | end 45 | 46 | %%%%%%%%% build skeleton data structure 47 | [result,skel] = constructSkeleton(skel, 1, hierarchy, 1); 48 | if ~result 49 | error(['ASF: Error constructing skeleton topology from hierarchy data in ' filename '!']); 50 | end 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 52 | 53 | % traverse kinematic chain to generate a minimal edge-disjoint path covering used in the rendering process 54 | skel = constructPaths(skel, 1, 1); 55 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 56 | 57 | % traverse kinematic chain filling in skel's "name" and "animated/unanimated" arrays 58 | skel = constructAuxiliaryArrays(skel, 1); 59 | skel.animated = sort(skel.animated); 60 | skel.unanimated = sort(skel.unanimated); 61 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 62 | 63 | skel.nameMap = constructNameMap(skel); 64 | 65 | t=etime(clock,cl1); 66 | disp(['Read ASF file ' filename ' in ' num2str(t) ' seconds.']); 67 | 68 | 69 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/parser/C3Dparser/convert.m: -------------------------------------------------------------------------------- 1 | function [skel, mot] = convert(Markers, ParameterGroup, VideoFrameRate, c3dFilename) 2 | 3 | numMarkers = size(Markers, 2); 4 | numFrames = size(Markers, 1); 5 | skel = emptySkeleton; 6 | mot = emptyMotion; 7 | 8 | mot.njoints = numMarkers; 9 | skel.njoints = mot.njoints; 10 | mot.nframes = numFrames; 11 | mot.frameTime = 1 / VideoFrameRate; 12 | mot.samplingRate = VideoFrameRate; 13 | idx = findstr(c3dFilename, '\'); 14 | if isempty(idx) 15 | mot.filename = c3dFilename; 16 | else 17 | mot.filename = c3dFilename(idx(end)+1:end); 18 | end 19 | skel.filename = mot.filename; 20 | 21 | %% get joint names from ParameterGroup 22 | pointIdx = strmatch('POINT',[ParameterGroup(:).name]); 23 | labelsIdx = strmatch('LABELS', [ParameterGroup( pointIdx ).Parameter(:).name]); 24 | labels = ParameterGroup(pointIdx).Parameter(labelsIdx).data; 25 | 26 | %% get scaling factor from ParameterGroup 27 | scaleIdx = strmatch('SCALE', [ParameterGroup( pointIdx ).Parameter(:).name]); 28 | scalingFactor = ParameterGroup(pointIdx).Parameter(scaleIdx).data; 29 | 30 | %% get coordinate mappings from ParameterGroup 31 | xScreenIdx = strmatch('X_SCREEN', [ParameterGroup( pointIdx ).Parameter(:).name]); 32 | if (~isempty(xScreenIdx)) 33 | xScreen = ParameterGroup(pointIdx).Parameter(xScreenIdx).data; 34 | else 35 | xScreen = '+X'; 36 | end 37 | 38 | yScreenIdx = strmatch('Y_SCREEN', [ParameterGroup( pointIdx ).Parameter(:).name]); 39 | if (~isempty(yScreenIdx)) 40 | yScreen = ParameterGroup(pointIdx).Parameter(yScreenIdx).data; 41 | else 42 | yScreen = '+Z'; 43 | end 44 | 45 | coordinateMapping = mapCoordinates(xScreen, yScreen); 46 | 47 | %% remove joint name group labels (everything before and including ':') 48 | for i = 1:size(labels,2) 49 | pos = strfind(labels{i}, ':'); 50 | if not(isempty(pos)) 51 | labels{i} = labels{i}(pos+1:length(labels{i})); 52 | end 53 | end 54 | 55 | % map labels to standard vicon-names 56 | labels = mapLabelNamesToVicon(labels, 0); 57 | 58 | % copy trajectories for point-cloud animation 59 | for i = 1:size(Markers,2) 60 | mot.nameMap{i,1} = char(labels(i)); 61 | mot.nameMap{i,2} = 0; 62 | mot.nameMap{i,3} = i; 63 | end 64 | 65 | for i = 1:size(Markers,2) 66 | mot.jointTrajectories{i,1}(1,:) = Markers(:, i, coordinateMapping(3)) * (-scalingFactor); 67 | mot.jointTrajectories{i,1}(2,:) = Markers(:, i, coordinateMapping(2)) * (-scalingFactor); 68 | mot.jointTrajectories{i,1}(3,:) = Markers(:, i, coordinateMapping(1)) * (-scalingFactor); 69 | end 70 | 71 | skel.paths = buildSkelPathsForPointCloud(skel); 72 | skel.nameMap = mot.nameMap; 73 | 74 | mot.boundingBox = computeBoundingBox(mot); 75 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/quatlog_rot.m: -------------------------------------------------------------------------------- 1 | function P = quatlog_rot(varargin) 2 | % P = quatlog_rot(Q, tol) 3 | % Implementation according to Grassia (1998) 4 | % 5 | % input: Q is a 4xn array of quaternions represented as column vectors. 6 | % If tol is specified, it denotes the allowable deviation from unit 7 | % length for the input quaternions. Deviations less than tol will 8 | % lead to re-normalization, deviations larger than tol will lead 9 | % to re-normalization and a warning. If tol is not specified, 10 | % all deviations larger than the machine precision will lead to 11 | % an error. 12 | % 13 | % output: P(:,i) is a 3-vector, the quaternionic logarithm of the 14 | % quaternion Q(:,i) 15 | 16 | switch (nargin) 17 | case 1 18 | Q = varargin{1}; 19 | tol = 10*eps; 20 | error_on_deviations = true; 21 | case 2 22 | Q = varargin{1}; 23 | tol = varargin{2}; 24 | error_on_deviations = false; 25 | otherwise 26 | error('Wrong number of arguments.'); 27 | end 28 | 29 | if (size(Q,1)~=4) 30 | error('Input array: number of rows must be 4!'); 31 | end 32 | n = size(Q,2); 33 | 34 | nsq = sum(Q.^2); 35 | deviating = find(abs(nsq - 1)>tol); 36 | if (length(deviating)>0) 37 | deviating 38 | if (error_on_deviations) 39 | error('The input quaternions with the above indices are not of unit length!'); 40 | else 41 | warning('The input quaternions with the above indices are not of unit length!'); 42 | end 43 | Q(:,deviating) = Q(:,deviating)./repmat(sqrt(nsq(deviating)),4,1); % normalization of deviating quats 44 | end 45 | 46 | cos_theta_over_two = Q(1,:); % quaternion real part = cos(theta/2) 47 | 48 | theta = 2*acos(cos_theta_over_two); 49 | 50 | zero = find(theta=eps^(1/4)); % identify nonzero thetas 52 | twopi = find(abs(theta-2*pi)0) 58 | P(:,zero) = Q(2:4,zero) ./ repmat((0.5 + (1/48)*theta(zero).^2),3,1); % use first two terms of sinc taylor expansion 59 | end 60 | if length(nonzero>0) 61 | P(:,nonzero) = Q(2:4,nonzero) ./ repmat(sin(0.5*theta(nonzero)),3,1).*repmat(theta(nonzero),3,1); 62 | end 63 | if length(twopi>0) 64 | twopi 65 | warning('The input quaternions with the above indices are at the south pole => log undefined!'); 66 | P(:,twopi) = NaN; 67 | end -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/filterSphericalAverageA1.m: -------------------------------------------------------------------------------- 1 | function [Y,max_it,t] = filterSphericalAverageA1(varargin) 2 | % Y = filterSphericalAverageA1(w,X,step,padding_method) 3 | % Uses the function sphericalAverageA1 to filter curves embedded in 4 | % the unit quaternion sphere with a sliding window. 5 | % 6 | % Input: w, weight vector 7 | % X, 4xN matrix of input unit quaternions 8 | % optional: step, step size for window (window length is length(w)), default is step=1. 9 | % ->!! Length of output sequence is ceil(N/step). !! <- 10 | % optional: padding method, one of {'symmetric', 'zero'}. default is 'symmetric' 11 | % 12 | % Output: Y, Filtered version of X 13 | % max_it, maximum number of iterations for computations of minimum weighted distances 14 | % t, running time for filter. 15 | % 16 | % Reference: S. Buss, J. Fillmore: Spherical Averages and Applications to 17 | % Spherical Splines and Interpolation, ACM Trans. Graphics 20 (2001): 18 | % 95--126 19 | 20 | 21 | switch (nargin) 22 | case 2 23 | w = varargin{1}; 24 | X = varargin{2}; 25 | step = 1; 26 | padding_method = 'symmetric'; 27 | case 3 28 | w = varargin{1}; 29 | X = varargin{2}; 30 | step = varargin{3}; 31 | padding_method = 'symmetric'; 32 | case 4 33 | w = varargin{1}; 34 | X = varargin{2}; 35 | step = varargin{3}; 36 | padding_method = varargin{4}; 37 | otherwise 38 | error('Wrong number of arguments!'); 39 | end 40 | 41 | L = size(w,2); 42 | N = size(X,2); 43 | 44 | if (L>N) 45 | error('Filter length must not be larger than number of data points!'); 46 | end 47 | 48 | %%%% prepare data set X by means of pre- and postpadding 49 | switch mod(L,2) 50 | case 0 % even filter length 51 | prepad_length = L/2; 52 | postpad_length = L/2 - 1; 53 | case 1 % odd filter length 54 | prepad_length = (L - 1)/2; 55 | postpad_length = (L - 1)/2; 56 | end 57 | 58 | tic; 59 | if (strncmp(padding_method,'symmetric',1)) 60 | pre = fliplr(X(:,1:prepad_length)); 61 | post = fliplr(X(:,N-postpad_length+1:N)); 62 | elseif (strncmp(padding_method,'zero',1)) 63 | pre = [ones(1,prepad_length);zeros(3,prepad_length)]; 64 | post = [ones(1,postpad_length);zeros(3,postpad_length)]; 65 | else 66 | error('Unknown padding option!'); 67 | end 68 | X = [pre X post]; 69 | 70 | Y = zeros(4,ceil(N/step)); 71 | it = 0; max_it = 0; 72 | for (i=1:ceil(N/step)) 73 | pos = step*(i-1)+1; 74 | [Y(:,i),it] = sphericalAverageA1(X(:,pos:pos+L-1),w, 10^-5); 75 | if (it > max_it) 76 | max_it = it; 77 | end 78 | end 79 | t = toc; -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/distS3_log.m: -------------------------------------------------------------------------------- 1 | function d = distS3_log(varargin) 2 | % Q = distS3_log(q1,q2,tol) 3 | % Computes the spherical distance between q1 and q2 using the quaternionic logarithm. 4 | % 5 | % Input: * q1,q2 are sequences of quaternions represented as 4xn matrices. 6 | % Non-unit quaternions might be normalized prior to 7 | % interpolation, see next point. 8 | % * If tol is specified, it denotes the allowable deviation from unit 9 | % length for the input quaternions. Deviations less than tol will 10 | % lead to re-normalization, deviations larger than tol will lead 11 | % to re-normalization and a warning. If tol is not specified, 12 | % all deviations larger than the machine precision will lead to 13 | % an error. 14 | % 15 | % Output: d is a 1xn vector of distances, where d(i) is the spherical distance 16 | % between q1(:,i) and q2(:,i) 17 | 18 | switch (nargin) 19 | case 2 20 | q1 = varargin{1}; 21 | q2 = varargin{2}; 22 | tol = 10*eps; 23 | error_on_deviations = true; 24 | case 3 25 | q1 = varargin{1}; 26 | q2 = varargin{2}; 27 | tol = varargin{3}; 28 | error_on_deviations = false; 29 | otherwise 30 | error('Wrong number of arguments.'); 31 | end 32 | 33 | if (size(q1,1)~=4 || size(q2,1)~=4 || (size(q1,2) ~= size(q2,2))) 34 | error('Input arrays: wrong dimensions.'); 35 | end 36 | 37 | n = size(q1,2); 38 | 39 | p = quatmult(quatinv(q1),q2); 40 | 41 | %%%%%%%%%%% now compute the log of p, omitting the error message for south pole quats %%%%%%%%%%%%%%%%%%%% 42 | cos_theta_over_two = p(1,:); % quaternion real part = cos(theta/2) 43 | 44 | theta = 2*acos(cos_theta_over_two); 45 | 46 | zero = find(theta=eps^(1/4)); % identify nonzero thetas 48 | twopi = find(abs(theta-2*pi)0) 54 | d(:,zero) = p(2:4,zero) ./ repmat((0.5 + (1/48)*theta(zero).^2),3,1); % use first two terms of sinc taylor expansion 55 | end 56 | if length(nonzero>0) 57 | d(:,nonzero) = p(2:4,nonzero) ./ repmat(sin(0.5*theta(nonzero)),3,1).*repmat(theta(nonzero),3,1); 58 | end 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 60 | 61 | d = sqrt(sum(d.*d)); 62 | d = d/2; % compensate for angle-doubling effect 63 | 64 | if length(twopi>0) 65 | d(:,twopi) = pi; 66 | end 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /ActionSegmentation_Pose/HDM05-Parser/quaternions/slerpNQuats.m: -------------------------------------------------------------------------------- 1 | function Q = slerpNQuats(varargin) 2 | % Q = slerp(Q1,Q2,u,tol) 3 | % Computes the spherical linear interpolation between pairs of Q1 and Q2 for the 4 | % parameters u \in [0,1] 5 | % 6 | % Input: * Q1,Q2 are 4xN quaternion matrices represented as column vectors. 7 | % Non-unit quaternions will be normalized prior to 8 | % interpolation! 9 | % * u is a vector from [0,1]^N specifying interpolation parameter 10 | % values for each quaternion pair (Q1(:,n), Q2(:,n)) 11 | % * If tol is specified, it denotes the allowable deviation from unit 12 | % length for the input quaternions. Deviations less than tol will 13 | % lead to re-normalization, deviations larger than tol will lead 14 | % to re-normalization and a warning. If tol is not specified, 15 | % all deviations larger than the machine precision will lead to 16 | % an error. 17 | % 18 | % Output: Q is a 4xn array of spherically interpolated unit quaternions 19 | 20 | switch (nargin) 21 | case 3 22 | Q1 = varargin{1}; 23 | Q2 = varargin{2}; 24 | u = varargin{3}; 25 | tol = 10*eps; 26 | error_on_deviations = true; 27 | case 4 28 | Q1 = varargin{1}; 29 | Q2 = varargin{2}; 30 | u = varargin{3}; 31 | tol = varargin{4}; 32 | error_on_deviations = false; 33 | otherwise 34 | error('Wrong number of arguments.'); 35 | end 36 | 37 | if (size(Q1,1) ~= 4 || size(Q2,1)~= 4 || any(quatnormsq(Q1)tol)) 42 | if (error_on_deviations) 43 | error('Some input quaternions Q1 are not of unit length!'); 44 | else 45 | warning('Some input quaternions Q1 are not of unit length! q1 will be re-normalized.'); 46 | end 47 | Q1 = quatnormalize(Q1); 48 | end 49 | 50 | if (any(abs(quatnormsq(Q2)-1)>tol)) 51 | if (error_on_deviations) 52 | error('Some input quaternions Q2 are not of unit length!'); 53 | else 54 | warning('Some input quaternion Q2 are not of unit length! Q2 will be re-normalized.'); 55 | end 56 | Q2 = quatnormalize(Q2); 57 | end 58 | 59 | N = size(Q1, 2); 60 | 61 | %Q = zeros(4,N); 62 | %for i=1:N 63 | Q = quatmult(Q1,quatexp(u([1;1;1],:).*quatlog(quatmult(quatinv(Q1),Q2),tol))); 64 | % costheta = transpose(q1)*q2; 65 | % sintheta = sqrt(1-costheta*costheta); 66 | % if (abs(sintheta)