draw3d.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. %% Author: Rodrigo de Barros Vimieiro
  2. % Date: April, 2018
  3. % rodrigo.vimieiro@gmail.com
  4. % =========================================================================
  5. %{
  6. %
  7. % DESCRIPTION:
  8. % Draw x-ray source, axis, projection plane and object plane.
  9. %
  10. % ---------------------------------------------------------------------
  11. % Copyright (C) <2018> <Rodrigo de Barros Vimieiro>
  12. %
  13. % This program is free software: you can redistribute it and/or modify
  14. % it under the terms of the GNU General Public License as published by
  15. % the Free Software Foundation, either version 3 of the License, or
  16. % (at your option) any later version.
  17. %
  18. % This program is distributed in the hope that it will be useful,
  19. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. % GNU General Public License for more details.
  22. %
  23. % You should have received a copy of the GNU General Public License
  24. % along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. %
  26. %}
  27. % =========================================================================
  28. %% Draw 3D animation
  29. function draw3d(xCoord,yCoord,zCoord,puCoord,pvCoord,param,projnum,theta)
  30. sb = subplot(2,2,[1 3]); % Create a subplot and merge 1 and 3
  31. cla(sb) % Clear current subplot window
  32. % Detector Coordinate sytem in (mm)
  33. [uCoord,vCoord] = meshgrid(param.us,param.vs);
  34. axis([param.us(1,end),param.us(1,1)+10,param.vs(1,1)-10,param.vs(1,end)+10,-5,1.1*param.DSD]);
  35. xlabel(['x(mm)'],'FontSize', 20);% / ', num2str(param.nx),'(Voxel Unity)'])
  36. ylabel(['y(mm)'],'FontSize', 20);% / ', num2str(param.ny),'(Voxel Unity)'])
  37. zlabel(['z(mm)'],'FontSize', 20);%;% / ', num2str(param.nz),'(Voxel Unity)'])
  38. title(num2str(projnum))
  39. view([94.6,27.4])
  40. grid on
  41. hold on
  42. % Detector plane vertices coordinates
  43. vetU = [uCoord(1,1),uCoord(end,1),uCoord(end,end),uCoord(1,end)];
  44. vetV = [vCoord(1,1),vCoord(end,1),vCoord(end,end),vCoord(1,end)];
  45. % Projection plane vertices coordinates
  46. vetPu = [puCoord(1,1),puCoord(end,1),puCoord(end,end),puCoord(1,end)];
  47. vetPv = [pvCoord(1,1),pvCoord(end,1),pvCoord(end,end),pvCoord(1,end)];
  48. % Object volume vertices coordinates
  49. vetObj = [ xCoord(1,1) yCoord(1,1) zCoord(1,1)
  50. xCoord(end,1) yCoord(end,1) zCoord(1,1)
  51. xCoord(end,end) yCoord(end,end) zCoord(1,1)
  52. xCoord(1,end) yCoord(1,end) zCoord(1,1)
  53. xCoord(1,1) yCoord(1,1) zCoord(end,1)
  54. xCoord(end,1) yCoord(end,1) zCoord(end,1)
  55. xCoord(end,end) yCoord(end,end) zCoord(end,1)
  56. xCoord(1,end) yCoord(1,end) zCoord(end,1)];
  57. % Link of vertices for each face
  58. vetor_faces = [1 2 3 4
  59. 5 6 7 8
  60. 1 2 6 5
  61. 3 4 8 7
  62. 1 4 8 5
  63. 2 6 7 3];
  64. %% Draw Everything
  65. % Draw the world's coordinate system to use as reference
  66. % - Colors: x in red, y in green, z in blue.
  67. %drawAxes([0,0,0,0,0,0], [0.15*param.su, 0.15*param.su, 0.1*param.sz], 2, ['r','g','b']);
  68. % Draw the sensor coordinate system to use as reference
  69. % - Colors: x in red, y in green, z in blue.
  70. %drawAxes([param.us(1),param.vs(1),0,0,0,0], [-0.15*param.su, 0.15*param.su, 0], 2, ['r','g','b']);
  71. % Rotate x-ray source
  72. xSource = 0;
  73. ySource = double(param.DSR.*sin(-theta));
  74. zSource = double(param.DSR.*cos(theta)+param.DDR);
  75. % Draw x-ray source
  76. plot3(xSource,ySource,zSource,'r.','markersize',45)
  77. % Draw text
  78. text(xSource,ySource-.15*abs(ySource),1.04*zSource,'X-Ray Source','FontSize', 16)
  79. % Draw Detector plane
  80. patch(vetU,vetV,[0,0,0,0],'FaceColor','none','EdgeColor','black','linewidth',2,'LineStyle','--')
  81. % Draw Projection plane
  82. patch(vetPu,vetPv,[0,0,0,0],'yellow','linewidth',1)
  83. % Draw Object volume
  84. patch('Vertices',vetObj,'Faces',vetor_faces,'FaceColor', 'blue','FaceAlpha',0.6)
  85. % Draw lines from the X-ray source to the projection plane passing
  86. % through the upper slice of the object
  87. plot3([xSource,xCoord(1,1),puCoord(1,1)],[ySource,yCoord(1,1),pvCoord(1,1)],[zSource,zCoord(end,1),0],'--')
  88. plot3([xSource,xCoord(end,1),puCoord(end,1)],[ySource,yCoord(end,1),pvCoord(end,1)],[zSource,zCoord(end,1),0],'--')
  89. plot3([xSource,xCoord(1,end),puCoord(1,end)],[ySource,yCoord(1,end),pvCoord(1,end)],[zSource,zCoord(end,1),0],'--')
  90. plot3([xSource,xCoord(end,end),puCoord(end,end)],[ySource,yCoord(end,end),pvCoord(end,end)],[zSource,zCoord(end,1),0],'--')
  91. drawnow
  92. end