-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_c3dMarkerless_to_trc.m
87 lines (82 loc) · 2.88 KB
/
dynamic_c3dMarkerless_to_trc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function [ftkratio, TRC_FILE, MOT_FILE, Y, Y_kinematic, markerStruct, forcesStruct, pf, af]=dynamic_c3dMarkerless_to_trc(path, cut, FP_used, threshold, convert_type, removemarkers)
%% Cut
acq = btkReadAcquisition(path);
pf = btkGetPointFrequency(acq);
af = btkGetAnalogFrequency(acq);
try
ftkratio = af/pf;
fpw = btkGetForcePlatformWrenches(acq, 1);
verticalgrf = fpw(FP_used).F(:,3); %for goran 1
Y = getContact_FP_app(verticalgrf', threshold);
Y_kinematic = unique(fix(Y/ftkratio));
td_analog = Y(1);
to_analog = Y(end);
ff = btkGetFirstFrame(acq);
td_kinematic =fix( Y(1)/ftkratio);
to_kinematic =fix(Y(end)/ftkratio);
catch
end
if cut ==1
try
btkCropAcquisition(acq, ff+(td_kinematic-20), (to_kinematic-(td_kinematic-20))+20)
% btkWriteAcquisition(acq, path)
% [markers, markersInfo, markersResidual] = btkGetMarkers(acq);
% markernames = fieldnames (markers);
% idxrm = sort(find(contains(markernames, 'C_')), 'descend');
% for i = 1 : length(idxrm)
% [points, pointsInfo] = btkRemovePoint(acq, idxrm(i));
% end
% btkWriteAcquisition(acq, path)
catch
disp('file to short to crop')
end
else
end
try %% add force plate corners as markers
[forceplates, forceplatesInfo] = btkGetForcePlatforms(acq);
for cp = 1 : length({forceplates.corners})
for sp = 1 : length(forceplates(cp).corners)
residuals = ones(1,length(markers.(markernames{1, 1})))';
[points, pointsInfo] = btkAppendPoint(acq, 'marker' , ['V_FP_',num2str(cp), '_Corner', num2str(sp)], repmat([forceplates(cp).corners(:,sp)]',length(markers.(markernames{1, 1} )),1), residuals);
end
end
catch
end
if removemarkers ==1;
try %% remove vicon random makers
[markers, markersInfo, markersResidual] = btkGetMarkers(acq);
markernames = fieldnames (markers);
idxrm = sort(find(contains(markernames, 'C_')), 'descend');
for i = 1 : length(idxrm)
[points, pointsInfo] = btkRemovePoint(acq, idxrm(i));
end
% btkWriteAcquisition(acq, path)
catch
end
else
end
btkWriteAcquisition(acq, path)
clearvars fpw Y Y_kinematic
fpw = btkGetForcePlatformWrenches(acq, 1);
verticalgrf = fpw(FP_used).F(:,3);
Y = getContact_FP_app(verticalgrf', threshold);
Y_kinematic = unique(fix(Y/ftkratio));
btkCloseAcquisition(acq)
%% fill gaps (todo)
%% Foot on force plate checker (todo)
%% Convert to trc file
c3d = osimC3D(path,convert_type); %1
c3d.rotateData('x' ,-90); %('x' ,-90); for goran ('z',90)
c3d.rotateData('y' ,270); %('x' ,-90); for goran ('z',90)
c3d.convertMillimeters2Meters();
[markerStruct, forcesStruct] = c3d.getAsStructs();
try
%c3d.writeTRC([erase(path, '.c3d'), '.trc']);
TRC_FILE = [erase(path, '.c3d'), '.trc'];
catch
display('No marker-based trc file created')
%TRC_FILE= '0';
end
c3d.writeMOT([erase(path, '.c3d'), '.mot']);
MOT_FILE = [erase(path, '.c3d'), '.mot'];
end