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

Matlab crashes when using ezc3dWrite() #125

Closed
MelaroJ opened this issue Jun 2, 2020 · 11 comments
Closed

Matlab crashes when using ezc3dWrite() #125

MelaroJ opened this issue Jun 2, 2020 · 11 comments

Comments

@MelaroJ
Copy link

MelaroJ commented Jun 2, 2020

Hello there,

I'm trying to append virtual markers to the c3d file through Matlab and when I execute the ezc3dWrite() function while inputting the new c3d structure Matlab crashes.

C3D_Import_Add_Virtual_Markers.txt
matlab_crash_dump.txt

@pariterre
Copy link
Member

Hello!

What you wrote seems right, so I'll have a look why you get a core dump! I'll reach ASAP!

@pariterre
Copy link
Member

Based on the code you provided, I was unable to reproduce a core krash. However, I spotted a mistake that may explain your bug. The line 78 should read: currentVirtualMarker = virtualMarkerLabels{k}; (with curly brackets) because otherwise it stores the cells containing the names, instead of the names themselves. In any case, that does not produce a segmentation fault here (but it does raise an error).

Can you confirm that the following simplified code from yours (using the c3d files Vicon.c3d from https://github.com/pyomeca/ezc3d-testFiles) actually works? If if does not, that is probably an OS dependent issue, so I would need to know which OS you are using and which commit you compiled from.

% Housecleaning
close all 
clear
clc

c3d = ezc3dRead('Vicon.c3d');
frameToPlot = 1;


% Virtual Marker Label list %
virtualMarkerLabels = {'midAC'}';

% Append virtual marker labels to c3d label list %
for k = 1:length(virtualMarkerLabels)
    c3d.parameters.POINT.LABELS.DATA{end+1} = virtualMarkerLabels(k);
end

% Marker Labels and positions to be used for virtual marker position
% calculation
markerLabels = {'Daphnee:SCAP_CP' 'Daphnee:SCAP_RS'}';
idx_markerLabels = zeros(1,length(markerLabels))';
markerCoordinates = zeros(3,length(markerLabels));
for i = 1:length(markerLabels)
    idx_markerLabels(i) = find(strcmp(c3d.parameters.POINT.LABELS.DATA,markerLabels(i)));
    markerCoordinates(:,i) = c3d.data.points(:,idx_markerLabels(i),frameToPlot);
end
virtualMarkerCoordinates = zeros(3,length(virtualMarkerLabels));

% midAC coordinates from acromion processes
virtualMarkerCoordinates(:,1) = mean(markerCoordinates(:,1:2),2);

% Append virtual marker coordinates to c3d structure and save as new c3d
% Append virtual marker coordinates to the c3d coordinates data
frame1 = horzcat(c3d.data.points(:,:,1),virtualMarkerCoordinates);
frame2 = horzcat(c3d.data.points(:,:,2),zeros(size(virtualMarkerCoordinates)));
c3d.data.points = cat(3,frame1,frame2);

% Correct dimensions of... everything...
% data residuals
c3d.data.meta_points.residuals = horzcat(c3d.data.meta_points.residuals(:,:,1),zeros(1,size(virtualMarkerCoordinates,2)));
c3d.data.meta_points.residuals = cat(3,c3d.data.meta_points.residuals,c3d.data.meta_points.residuals);

% camera masks
c3d.data.meta_points.camera_masks = horzcat(c3d.data.meta_points.camera_masks(:,:,1),zeros(7,size(virtualMarkerCoordinates,2)));
c3d.data.meta_points.camera_masks = cat(3,c3d.data.meta_points.camera_masks,c3d.data.meta_points.camera_masks);

% Write new c3d file
ezc3dWrite('test.c3d',c3d);

c3d_2 = ezc3dRead('test.c3d');

Thanks!

@MelaroJ
Copy link
Author

MelaroJ commented Jun 2, 2020 via email

@MelaroJ
Copy link
Author

MelaroJ commented Jun 2, 2020 via email

@pariterre
Copy link
Member

That seems to be OS related then, I'll test on a windows computer as soon as I have access to one (I have colleagues that I can ask), I'll come back to you afterwards!

The compilation question is more related on how did you install ezc3d?

@MelaroJ
Copy link
Author

MelaroJ commented Jun 2, 2020

I followed the youtube video you posted in response to another issue, i.e., downloaded CMake and VisualStudio

@pariterre
Copy link
Member

Okay! I'll have a look very soon :)

@pariterre
Copy link
Member

pariterre commented Jun 3, 2020

Ok my bad... I actually made the same mistake as you! I wanted to test if it was the actual problem, so I changed the curly brackets for round brackets, but when I copied the code to send it here, I forgot to put back the curly brackets...

% Housecleaning
close all 
clear
clc

c3d = ezc3dRead('Vicon.c3d');
frameToPlot = 1;


% Virtual Marker Label list %
virtualMarkerLabels = {'midAC'}';

% Append virtual marker labels to c3d label list %
for k = 1:length(virtualMarkerLabels)
    c3d.parameters.POINT.LABELS.DATA{end+1} = virtualMarkerLabels{k};
end

% Marker Labels and positions to be used for virtual marker position
% calculation
markerLabels = {'Daphnee:SCAP_CP' 'Daphnee:SCAP_RS'}';
idx_markerLabels = zeros(1,length(markerLabels))';
markerCoordinates = zeros(3,length(markerLabels));
for i = 1:length(markerLabels)
    idx_markerLabels(i) = find(strcmp(c3d.parameters.POINT.LABELS.DATA,markerLabels(i)));
    markerCoordinates(:,i) = c3d.data.points(:,idx_markerLabels(i),frameToPlot);
end
virtualMarkerCoordinates = zeros(3,length(virtualMarkerLabels));

% midAC coordinates from acromion processes
virtualMarkerCoordinates(:,1) = mean(markerCoordinates(:,1:2),2);

% Append virtual marker coordinates to c3d structure and save as new c3d
% Append virtual marker coordinates to the c3d coordinates data
frame1 = horzcat(c3d.data.points(:,:,1),virtualMarkerCoordinates);
frame2 = horzcat(c3d.data.points(:,:,2),zeros(size(virtualMarkerCoordinates)));
c3d.data.points = cat(3,frame1,frame2);

% Correct dimensions of... everything...
% data residuals
c3d.data.meta_points.residuals = horzcat(c3d.data.meta_points.residuals(:,:,1),zeros(1,size(virtualMarkerCoordinates,2)));
c3d.data.meta_points.residuals = cat(3,c3d.data.meta_points.residuals,c3d.data.meta_points.residuals);

% camera masks
c3d.data.meta_points.camera_masks = horzcat(c3d.data.meta_points.camera_masks(:,:,1),zeros(7,size(virtualMarkerCoordinates,2)));
c3d.data.meta_points.camera_masks = cat(3,c3d.data.meta_points.camera_masks,c3d.data.meta_points.camera_masks);

% Write new c3d file
ezc3dWrite('test.c3d',c3d);

c3d_2 = ezc3dRead('test.c3d');

This should actually works!

@MelaroJ
Copy link
Author

MelaroJ commented Jun 3, 2020

Worked like a charm!

Thanks a ton!

JM

@pariterre
Copy link
Member

pariterre commented Jun 3, 2020

Just as a reminder for me, I will leave this issue open so I can produce a proper error message when non strings are casted as string.
Thanks for finding the bug!

@pariterre
Copy link
Member

Thanks again for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants