amiraWriter.m 1.0 KB

123456789101112131415161718192021222324
  1. function amiraWriter(data,filename,dx,dy,dz,M,N,P,FOV,zFOV)
  2. fid = fopen([filename],'w');
  3. fprintf(fid,'# AmiraMesh 3D BINARY 2.0\n\n');
  4. fprintf(fid,['# CreationDate: ' datestr(now,'ddd mmm') datestr(now,' dd HH:MM:SS yyyy') '\n\n']);
  5. fprintf(fid,'define Lattice %g %g %g\n\n',M,N,P);
  6. fprintf(fid,'Parameters {\n');
  7. fprintf(fid,' Content "%gx%gx%g %s, uniform coordinates",',M,N,P,'float');
  8. fprintf(fid,' BoundingBox %g %g %g %g %g %g,\n',(50-FOV)/2+dx/2,50-(50-FOV)/2-dx/2,(50-FOV)/2+dy/2,50-(50-FOV)/2-dy/2,0,zFOV-dz);
  9. % fprintf(fid,' BoundingBox %g %g %g %g %g %g,\n',0,FOV-dx,0,FOV-dy,0,zFOV-dz);
  10. fprintf(fid,' CoordType "uniform"\n');
  11. fprintf(fid,'}\n\n');
  12. fprintf(fid,'Lattice { %s Data } @1\n\n','float');
  13. fprintf(fid,'# Data section follows\n');
  14. fprintf(fid,'@1\n');
  15. fclose(fid); % close the text part of the file
  16. % write the data in big endian format
  17. fid = fopen([filename],'ab','ieee-be');
  18. fwrite(fid,data(:,:,:),'float');
  19. fclose(fid);