Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace getline and tokenize func #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 35 additions & 55 deletions matlab/acclaimReadSkel.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@

boneCount = 0;
fid = fopen(fileName, 'r');
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
skel.length = 1.0;
skel.mass = 1.0;
skel.angle = 'deg';
skel.type = 'acclaim';
skel.documentation = '';
skel.name = fileName;
while ~feof(fid)
while ischar(lin(1))
if lin(1)==':'
switch lin(2:end)
case 'name'
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
skel.name = lin;
case 'units'
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
while(lin(1) ~= ':')
parts = tokenise(lin, ' ');
parts = strsplit(lin);
switch parts{1}
case 'mass'
skel.mass = str2num(parts{2});
Expand All @@ -47,15 +47,15 @@
case 'angle'
skel.angle = strtrim(parts{2});
end
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
end
case 'documentation'
skel.documentation = [];
lin = getline(fid);
lin = fgets(fid);
while(lin(1) ~=':')
skel.documentation = [skel.documentation char(13) lin];
lin = getline(fid);
lin = fgets(fid);
end
lin = strtrim(lin);

Expand All @@ -77,10 +77,10 @@
'posInd', [], ...
'children', [], ...
'limits', []);
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
while(lin(1) ~= ':')
parts = tokenise(lin, ' ');
parts = strsplit(lin);
switch parts{1}
case 'order'
order = [];
Expand Down Expand Up @@ -121,14 +121,14 @@
str2num(parts{3}) ...
str2num(parts{4})];
end
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
end
case 'bonedata'
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
while(lin(1)~=':')
parts = tokenise(lin, ' ');
parts = strsplit(lin, ' ');
switch parts{1}
case 'begin'
boneCount = boneCount + 1;
Expand All @@ -149,28 +149,28 @@
'posInd', [], ...
'children', [], ...
'limits', []);
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);

case 'id'
skel.tree(boneCount+1).id = str2num(parts{2});
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
skel.tree(boneCount+1).children = [];

case 'name'
skel.tree(boneCount+1).name = parts{2};
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);

case 'direction'
direction = [str2num(parts{2}) str2num(parts{3}) str2num(parts{4})];
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);

case 'length'
lgth = str2num(parts{2});
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);

case 'axis'
Expand All @@ -179,7 +179,7 @@
str2num(parts{4})];
% order is reversed compared to bvh
skel.tree(boneCount+1).axisOrder = lower(parts{end}(end:-1:1));
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);

case 'dof'
Expand Down Expand Up @@ -208,47 +208,47 @@
end
% order is reversed compared to bvh
skel.tree(boneCount+1).order = order(end:-1:1);
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);

case 'limits'
limitsCount = 1;
skel.tree(boneCount+1).limits(limitsCount, 1:2) = ...
[str2num(parts{2}(2:end)) str2num(parts{3}(1:end-1))];

lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
while(~strcmp(lin, 'end'))
parts = tokenise(lin, ' ');
parts = strsplit(lin, ' ');

limitsCount = limitsCount + 1;
skel.tree(boneCount+1).limits(limitsCount, 1:2) = ...
[str2num(parts{1}(2:end)) str2num(parts{2}(1:end-1))];
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
end

case 'end'
skel.tree(boneCount+1).offset = direction*lgth;
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
end

end

case 'hierarchy'
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
while(~strcmp(lin, 'end'))
parts = tokenise(lin, ' ');
parts = strsplit(lin, ' ');
if ~strcmp(lin, 'begin')
ind = skelReverseLookup(skel, parts{1});
for i = 2:length(parts)
skel.tree(ind).children = [skel.tree(ind).children ...
skelReverseLookup(skel, parts{i})];
end
end
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
end
if feof(fid)
Expand All @@ -261,40 +261,20 @@
skel = finaliseStructure(skel);
return
end
lin = getline(fid);
lin = fgets(fid);
lin = strtrim(lin);
end
else
if isempty(lin)
if isempty(lin) || lin(1) == '#'
lin = fgets(fid);
lin = strtrim(lin);
continue
elseif lin(1) == '#'
lin = fgets(fid);
lin = strtrim(lin);
continue
else
error('Unrecognised file format');
end
end
end

function skel = finaliseStructure(skel)

% FINALISESTRUCTURE

skel.tree = treeFindParents(skel.tree);
ordered = false;
while ordered == false
for i = 1:length(skel.tree)
ordered = true;
if(skel.tree(i).parent>i)
ordered = false;
skel.tree = swapNode(skel.tree, i, skel.tree(i).parent);
end
end
end

for i = 1:length(skel.tree)
skel.tree(i).C = rotationMatrix(deg2rad(skel.tree(i).axis(1)), ...
deg2rad(skel.tree(i).axis(2)), ...
deg2rad(skel.tree(i).axis(3)), ...
skel.tree(i).axisOrder);
skel.tree(i).Cinv = inv(skel.tree(i).C);
end