]> Creatis software - CreaPhase.git/blobdiff - utilities_LW/CreateSphere3D.m
Useful functions for simulations (created by LW, free to use)
[CreaPhase.git] / utilities_LW / CreateSphere3D.m
diff --git a/utilities_LW/CreateSphere3D.m b/utilities_LW/CreateSphere3D.m
new file mode 100644 (file)
index 0000000..32c0bce
--- /dev/null
@@ -0,0 +1,41 @@
+%%%%%%%%%%%%%%%%
+%%% Function that creates a 3D matrix (size dimx, dimy, dimz) containing a sphere, centered at (cx,
+%%% cy, cz), of radius r
+%%% Loriane, oct 2014
+%c=128
+%r=40
+%%%%%%%%%%%%%%%%
+
+
+r=70
+cx=200;
+cy=cx;
+cz=50;
+dimx=400;
+dimy=dimx;
+dimz=100;
+coeff=9.917*10^-7;  % mu ou autre
+
+Sphere=zeros(dimx, dimy, dimz);
+
+for(i=1:dimx)
+    for(j=1:dimy)
+        for(k=1:dimz)
+            if((i-cx)^2+(j-cy)^2+(k-cz)^2 <= r^2)
+                Sphere(i,j,k)=1;
+            end
+        end
+    end
+end
+
+
+Sphere=Sphere*coeff;
+name='sphere_phase_Mg_19keV'
+
+fid=fopen(strcat(name, '.raw'), 'w')
+fwrite(fid, Sphere, 'float32');
+fclose(fid);
+
+cmd = ['/data/id19/bones01/bones/program/linux_debian/bin/rawtomhd filein=', strcat(name, '.raw'), ' fileout=', strcat(name, '.mhd'), ' dimx=', num2str(dimx), ' dimy=', num2str(dimy), ' dimz=', num2str(dimz), ' format=FLOAT'];
+unix(cmd)
+