diff --git a/ShoulderCase/@ShoulderCase/plot.m b/ShoulderCase/@ShoulderCase/plot.m index 9af258c..9be1664 100644 --- a/ShoulderCase/@ShoulderCase/plot.m +++ b/ShoulderCase/@ShoulderCase/plot.m @@ -1,241 +1,246 @@ function outputArg = plot(obj) %%PLOT Plot a SCase figure; % Create figure hold on; % Superpose objects on the same figure %% Scapula % If exists, plot the segemented surface (manual) +boneColor = [0.89, 0.855, 0.788]; if strcmp(obj.shoulder.scapula.segmentation, 'M') points = obj.shoulder.scapula.surface.points; faces = obj.shoulder.scapula.surface.faces; x = points(:,1); y = points(:,2); z = points(:,3); - trisurf(faces,x,y,z,'Facecolor','yellow','FaceAlpha',0.5,'EdgeColor','none','FaceLighting','gouraud'); + trisurf(faces,x,y,z,'Facecolor',boneColor,'FaceAlpha',1.0,'EdgeColor','none','FaceLighting','gouraud'); %scatter3(x,y,z,1,'black'); % Point points end % If exists, plot the segemented surface (auto) -%{ + if strcmp(obj.shoulder.scapulaAuto.segmentation, 'A') points = obj.shoulder.scapulaAuto.surface.points; faces = obj.shoulder.scapulaAuto.surface.faces; x = points(:,1); y = points(:,2); z = points(:,3); - trisurf(faces,x,y,z,'Facecolor','red','FaceAlpha',0.25,'EdgeColor','none','FaceLighting','gouraud'); +% trisurf(faces,x,y,z,'Facecolor','red','FaceAlpha',0.25,'EdgeColor','none','FaceLighting','gouraud'); + trisurf(faces,x,y,z,'Facecolor','yellow','FaceAlpha',1.0,'EdgeColor','none','FaceLighting','gouraud'); end -%} + % Plot scapula groove (manual) points = obj.shoulder.scapula.groove; x = points(:,1); y = points(:,2); z = points(:,3); scatter3(x,y,z,100,'blue'); % If exists, plot segments between manual and auto %{ if ~isempty(obj.shoulder.scapulaAuto.groove) pointsAuto = obj.shoulder.scapulaAuto.groove; for iPts=1:length(pointsAuto) x = [points(iPts,1), pointsAuto(iPts,1)]; y = [points(iPts,2), pointsAuto(iPts,2)]; z = [points(iPts,3), pointsAuto(iPts,3)]; plot3(x,y,z,'Color','blue','LineWidth', 5); end end %} % Plot scapula markers points = [... obj.shoulder.scapula.angulusInferior; obj.shoulder.scapula.trigonumSpinae; obj.shoulder.scapula.processusCoracoideus; obj.shoulder.scapula.acromioClavicular; obj.shoulder.scapula.angulusAcromialis; obj.shoulder.scapula.spinoGlenoidNotch... ]; x = points(:,1); y = points(:,2); z = points(:,3); scatter3(x,y,z,100,'blue','LineWidth',2); % If exists, plot segments between manual and auto %{ if ~isempty(obj.shoulder.scapulaAuto.angulusInferior) pointsAuto = [... obj.shoulder.scapulaAuto.angulusInferior; obj.shoulder.scapulaAuto.trigonumSpinae; obj.shoulder.scapulaAuto.processusCoracoideus; obj.shoulder.scapulaAuto.acromioClavicular; obj.shoulder.scapulaAuto.angulusAcromialis; obj.shoulder.scapulaAuto.spinoGlenoidNotch... ]; for iPts=1:length(pointsAuto) x = [points(iPts,1), pointsAuto(iPts,1)]; y = [points(iPts,2), pointsAuto(iPts,2)]; z = [points(iPts,3), pointsAuto(iPts,3)]; plot3(x,y,z,'Color','blue','LineWidth', 5); end end %} - +%{ % Plot scapular plane axisLength = 50; pt0 = obj.shoulder.scapula.coordSys.origin; pt1 = pt0 + (obj.shoulder.scapula.coordSys.ML + obj.shoulder.scapula.coordSys.IS) * axisLength ; pt2 = pt1 - obj.shoulder.scapula.coordSys.IS * pdist([pt1 ; obj.shoulder.scapula.angulusInferior]); pt3 = pt2 - obj.shoulder.scapula.coordSys.ML * pdist([pt1 ; obj.shoulder.scapula.trigonumSpinae] ); pt4 = pt3 + obj.shoulder.scapula.coordSys.IS * pdist([pt1 ; obj.shoulder.scapula.angulusInferior]); X = [pt1(1) pt2(1) pt3(1) pt4(1)]; Y = [pt1(2) pt2(2) pt3(2) pt4(2)]; Z = [pt1(3) pt2(3) pt3(3) pt4(3)]; patch(X,Y,Z,'black','FaceAlpha',0.3); % Transparent plane +%} % Plot scapular axis pt1 = obj.shoulder.scapula.coordSys.origin; axisLength = 10 + pdist([pt1 ; obj.shoulder.scapula.trigonumSpinae]); pt2 = pt1 - obj.shoulder.scapula.coordSys.ML * axisLength; x = [pt1(1), pt2(1)]; y = [pt1(2), pt2(2)]; z = [pt1(3), pt2(3)]; plot3(x,y,z,'Color','blue','LineWidth', 5); % Plot scapular coordinate system axisLength = 50; % Length of the cood. sys. axes pt0 = obj.shoulder.scapula.coordSys.origin; pt1 = pt0 + obj.shoulder.scapula.coordSys.PA*axisLength; % X pt2 = pt0 + obj.shoulder.scapula.coordSys.IS*axisLength; % Y %pt3 = pt0 + obj.shoulder.scapula.coordSys.ML*axisLength; % Z x = [pt0(1), pt1(1)]; y = [pt0(2), pt1(2)]; z = [pt0(3), pt1(3)]; plot3(x,y,z,'Color','red','LineWidth', 5); x = [pt0(1), pt2(1)]; y = [pt0(2), pt2(2)]; z = [pt0(3), pt2(3)]; plot3(x,y,z,'Color','green','LineWidth', 5); % Not plotting ML axis to avoid its superposition with scapular axis on glenoid center % x = [pt0(1), pt3(1)]; % y = [pt0(2), pt3(2)]; % z = [pt0(3), pt3(3)]; % plot3(x,y,z,'Color','blue','LineWidth', 5); % plot scapular axis on glenoid center axisLength = 50; pt1 = obj.shoulder.scapula.glenoid.center; pt2 = pt1 + obj.shoulder.scapula.coordSys.ML*axisLength; x = [pt1(1), pt2(1)]; y = [pt1(2), pt2(2)]; z = [pt1(3), pt2(3)]; plot3(x,y,z,'Color','blue','LineWidth', 5); - +%} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Glenoid % Plot the glenoid surface % We might move them in the direction of th glenoid center % instead of the ML axis - +%{ points = obj.shoulder.scapula.glenoid.surface.points +... obj.shoulder.scapula.coordSys.ML * 0.2; faces = obj.shoulder.scapula.glenoid.surface.faces; x = points(:,1); y = points(:,2); z = points(:,3); %scatter3(x,y,z,1,'blach'); trisurf(faces,x,y,z,'Facecolor','none','FaceAlpha',1,'EdgeColor','magenta','FaceLighting','none'); - +%} % plot glenoid centerline pt1 = obj.shoulder.scapula.glenoid.center; pt2 = pt1 + obj.shoulder.scapula.glenoid.centerLine; x = [pt1(1), pt2(1)]; y = [pt1(2), pt2(2)]; z = [pt1(3), pt2(3)]; plot3(x,y,z,'Color','magenta','LineWidth', 5); % We might add spherical cap % plot glenoid sphere %{ n = 20; % number of lines [X,Y,Z] = sphere(n); X = X*obj.shoulder.scapula.glenoid.radius; Y = Y*obj.shoulder.scapula.glenoid.radius; Z = Z*obj.shoulder.scapula.glenoid.radius; Xc = pt2(1); Yc = pt2(2); Zc = pt2(3); mesh(X+Xc,Y+Yc,Z+Zc,'LineStyle','none','FaceColor','magenta','FaceAlpha',0.3,'FaceLighting','gouraud'); %} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Humerus % plot humeral head sphere %{ n = 20; % number of lines [X,Y,Z] = sphere(n); X = X*obj.shoulder.humerus.radius; Y = Y*obj.shoulder.humerus.radius; Z = Z*obj.shoulder.humerus.radius; Xc = obj.shoulder.humerus.center(1); Yc = obj.shoulder.humerus.center(2); Zc = obj.shoulder.humerus.center(3); mesh(X+Xc,Y+Yc,Z+Zc,'LineStyle','none','FaceColor','magenta','FaceAlpha',0.3,'FaceLighting','gouraud'); % hidden off; % Transparent sphere % check 'FaceLighting','gouraud', %} - +%{ % plot humeral head centerline pt1 = obj.shoulder.scapula.glenoid.center; pt2 = obj.shoulder.humerus.center; x = [pt1(1), pt2(1)]; y = [pt1(2), pt2(2)]; z = [pt1(3), pt2(3)]; plot3(x,y,z,'Color','magenta','LineWidth', 5); - +%} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Graph properties axis off; % remove axis lightPosition = obj.shoulder.scapula.glenoid.center + ... (... obj.shoulder.scapula.coordSys.ML + ... - obj.shoulder.scapula.coordSys.IS + ... + obj.shoulder.scapula.coordSys.IS - ... obj.shoulder.scapula.coordSys.PA ... - ) * 100; + ) * 50; light('Position',lightPosition,'Style','local'); %{ grid on; xlabel('X (CT)'); ylabel('Y (CT)'); zlabel('Z (CT)'); axis square; %} axis vis3d; % fixed limits and scaling -viewPoint = obj.shoulder.scapula.coordSys.ML + ... - obj.shoulder.scapula.coordSys.IS + ... - obj.shoulder.scapula.coordSys.PA; -viewPoint = obj.shoulder.scapula.coordSys.PA; +% axis on/off +%viewPoint = obj.shoulder.scapula.coordSys.ML + ... +% obj.shoulder.scapula.coordSys.IS + ... +% obj.shoulder.scapula.coordSys.PA; +viewPoint = obj.shoulder.scapula.coordSys.IS; view(viewPoint); % view from lateral side % Align IS axis with window vertical axis -camup(obj.shoulder.scapula.coordSys.IS); +camup(obj.shoulder.scapula.coordSys.ML); figureHandle = gca; figureHandle.DataAspectRatio = [1 1 1]; % Same relative length of data units along each axis +figureHandle.CameraViewAngle=10; figureHandle.Box = 'On'; set(gcf,'color','w'); % Set background color to white outputArg = 1; end \ No newline at end of file diff --git a/openLogFile.m b/openLogFile.m index 662408e..bd4f4a5 100644 --- a/openLogFile.m +++ b/openLogFile.m @@ -1,20 +1,22 @@ function logFileID = openLogFile(filename) %SETLOGFILE Creates a log file using filename in a log directory, within %current working directory. % The directory log is created if not present. % Check if log dir exists in working directory logDir = 'log'; if ~exist('log', 'dir') % If not create dir log mkdir('log') end -logFile = [logDir '/' filename]; +%logFile = [logDir '/' filename]; % Toavoid problem when run plotSCase from +%another dir than enclosing plotScase +logFile = [filename]; logFileID = fopen(logFile, 'w'); fprintf(logFileID, filename); % Write name of file fprintf(logFileID, '\nDate: '); % Write date fprintf(logFileID, datestr(datetime)); % Write time output = 1; message = 'OK'; end