-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateEvent.m
168 lines (143 loc) · 6.16 KB
/
createEvent.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
% Create an event in a C3D file and save the C3D file
%
% Tim Dorn
% June 2009
%
% --------------------------------------------------------------------
% Usage: createEvent(c3dFile, foot, label, frame)
% --------------------------------------------------------------------
%
% Inputs: c3dFile: the name of the c3d file
%
% foot: 'R' for right foot event, 'L' for left foot event
% 'G' for general foot event
%
% label: 'FS' for footstrike, 'FO' for footoff
% 'GEN' for general event
%
% frame: video frame number to add the event at
%
%
% Outputs: OVERWRITES the input c3d file with new events
% (irreversible with this code so make sure to
% backup the original c3d file first!)
%
% --------------------------------------------------------------------
%
% Copyright (c) 2008 Tim Dorn
% Use of the GaitExtract Toolbox is permitted provided that the following
% conditions are met:
% 1. The software is not distributed or redistributed. Software distribution is allowed
% only through https://simtk.org/home/c3dtoolbox.
% 2. Use of the GaitExtract Toolbox software must be acknowledged in all publications,
% presentations, or documents describing work in which the GaitExtract Toolbox was used.
% 3. Credits to developers may not be removed from source files
% 4. Modifications of source code must retain the above copyright notice, this list of
% conditions and the following disclaimer.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
% OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
% SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
% TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR BUSINESS INTERRUPTION) OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
% WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
% --------------------------------------------------------------------
function createEvent(c3dFile, foot, label, frame)
usage = 'createEvent(c3dFile, foot, label, frame)';
if nargin ~= 4
error(usage)
end
switch upper(foot)
case 'R'
contexts = 'Right';
case 'L'
contexts = 'Left';
case 'G'
contexts = 'General';
otherwise
error(usage)
end
switch upper(label)
case 'FS'
icon_ids = 1;
labels = 'Foot Strike';
descriptions = labels;
generic_flags = 0;
case 'FO'
icon_ids = 2;
labels = 'Foot Off';
descriptions = labels;
generic_flags = 0;
case 'GEN'
icon_ids = 0;
labels = 'General Event';
descriptions = labels;
generic_flags = 1;
otherwise
error(usage)
end
% ADD EVENT
% ----------
itf = c3dserver();
openc3d(itf, 0, c3dFile);
% check if events group exists. if not, then create the group
% and all parameters that come under it.
eventGroupName = 'EVENT'; % do not change
eventIndex = itf.GetGroupIndex(eventGroupName);
if eventIndex < 0
itf.AddGroup(0, eventGroupName, 'Event Labels', char(0));
itf.AddParameter('USED', 'Used', eventGroupName, char(0), 2, 0, int16([1,0]), {});
itf.AddParameter('CONTEXTS', 'Contexts', eventGroupName, char(0), -1, 2, int16([16,0]), {});
itf.AddParameter('ICON_IDS', 'Icon IDs', eventGroupName, char(0), 2, 1, int16([1,0]), {});
itf.AddParameter('LABELS', 'Labels', eventGroupName, char(0), -1, 2, int16([32,0]), {});
itf.AddParameter('DESCRIPTIONS', 'Descriptions', eventGroupName, char(0), -1, 2, int16([80,0]), {});
itf.AddParameter('SUBJECTS', 'Subjects', eventGroupName, char(0), -1, 2, int16([32,0]), {});
itf.AddParameter('TIMES', 'Times', eventGroupName, char(0), 4, 2, int16([2,0]), {});
itf.AddParameter('GENERIC_FLAGS', 'Generic Flags', eventGroupName, char(0), 1, 1, int16([1,0]), {});
index3 = itf.GetParameterIndex(eventGroupName, 'ICON_IDS');
itf.RemoveParameterData(index3, 0);
index8 = itf.GetParameterIndex(eventGroupName, 'GENERIC_FLAGS');
itf.RemoveParameterData(index8, 0);
end
index1 = itf.GetParameterIndex(eventGroupName, 'USED');
oldnumEvents = itf.GetParameterValue(index1, 0);
itf.SetParameterValue(index1, 0, oldnumEvents+1);
index2 = itf.GetParameterIndex(eventGroupName, 'CONTEXTS');
itf.AddParameterData(index2, 1);
itf.SetParameterValue(index2, oldnumEvents, contexts);
itf.GetParameterValue(index2, oldnumEvents);
index3 = itf.GetParameterIndex(eventGroupName, 'ICON_IDS');
itf.AddParameterData(index3, 1);
itf.SetParameterValue(index3, oldnumEvents, icon_ids);
index4 = itf.GetParameterIndex(eventGroupName, 'LABELS');
itf.AddParameterData(index4, 1);
itf.SetParameterValue(index4, oldnumEvents, labels);
index5 = itf.GetParameterIndex(eventGroupName, 'DESCRIPTIONS');
itf.AddParameterData(index5, 1);
itf.SetParameterValue(index5, oldnumEvents, descriptions);
index6 = itf.GetParameterIndex(eventGroupName, 'SUBJECTS');
if oldnumEvents == 0
subjects = 'SUBJECT';
else
subjects = itf.GetParameterValue(index6, oldnumEvents-1);
end
itf.AddParameterData(index6, 1);
itf.SetParameterValue(index6, oldnumEvents, subjects);
index7 = itf.GetParameterIndex(eventGroupName, 'TIMES');
times = (frame-1)/itf.GetVideoFrameRate;
itf.AddParameterData(index7, 1);
itf.SetParameterValue(index7, 2*oldnumEvents+1, times);
index8 = itf.GetParameterIndex(eventGroupName, 'GENERIC_FLAGS');
itf.AddParameterData(index8, 1);
itf.SetParameterValue(index8, oldnumEvents, generic_flags);
% SAVE C3D FILE
% --------------
nRet = itf.SaveFile('', -1);
if nRet ~= 1
fprintf('WARNING: C3D file could not be saved!\n');
end
closec3d(itf);