Skip to content

Instantly share code, notes, and snippets.

@cesare-corrado
Created June 4, 2015 10:23
Show Gist options
  • Save cesare-corrado/55a142355655cee81581 to your computer and use it in GitHub Desktop.
Save cesare-corrado/55a142355655cee81581 to your computer and use it in GitHub Desktop.
I used CGAL4.6 on a ubuntu 12.04 (64 bit) machine and g++ 4.6.3 compiler.
The code i used is the same CGAL-4.6/examples/Mesh_3/ mesh_3D_image.cpp, but with pipe.inr (see after) as input file and :
facet_angle = 30
facet_size = 0.8
facet_distance = 2
cell_rad_edge_ratio = 2.0
cell_size = 0.8
For creating the .img file i used the following matlab script:
spacings=[0.2 0.2 0.3];
X=uint8(zeros(305, 380, 470));
[nx,ny,nz]=size(X);
center=0.5*spacings.*size(X);
bbox=spacings.*size(X);
radius1=0.85*min(0.5*bbox(1:2));
radius0=0.65*min(0.5*bbox(1:2));
clear('bbox');
length=0.85*(spacings(3)*nz);
dh=0.5*(1.0-0.85)*(spacings(3)*nz);
dh2=0.05*0.85*(spacings(3)*nz);
z0=dh;
z1=dh+length;
iz0=floor(z0/spacings(3)+0.5);
iz1=round(z1/spacings(3)+0.5);
iz0pdh2=round((z0+dh2)/spacings(3)+0.5);
iz1mdh2=floor((z1-dh2)/spacings(3)+0.5);
ic0=floor((center(3)-0.5*dh2)/spacings(3)+0.5);
ic1=round((center(3)+0.5*dh2)/spacings(3)+0.5);
clear('dh');
for ix=1:nx
x=(ix-0.5)*spacings(1);
dx=x-center(1);
for iy=1:ny
y=(iy-0.5)*spacings(2);
dy=y-center(2);
r=sqrt(dx*dx+dy*dy);
if((r>=radius0) && (r<=radius1))
%1 default if is inside the pipe
X(ix,iy,(iz0:iz1))=uint8(1);
X(ix,iy,(iz0:iz0pdh2))=uint8(2);
X(ix,iy,(iz1mdh2:iz1))=uint8(2);
for iz=ic0:1:ic1
z=(iz-0.5)*spacings(3);
dz=2*abs(z-center(3));
%if on one extrema 2
if( (dz<=dh2) )
X(ix,iy,iz)=uint8(1);
end
%if is within the center then labeling
clear('z','dz');
end
end
clear('r','y','dy');
end
clear('x','dx')
end
clear('z0','z1','iz0pdh2','iz1mdh2','ic0','ic1');
X=uint8(X);
clear('ix','iy','iz');
disp('write coarse pipe example for potential');
dirPipe=[dirExample,'/pipeCoarse4Potential'];
system(['mkdir -p ',dirPipe]);
fid=fopen([dirPipe,'/pipe.inr'],'wb');
if(fid==-1)
error('You do not have permission to save mesh files.');
end
btype='unsigned fixed';
dtype='uint8';
bitlen=8;
header=sprintf(['#INRIMAGE-4#{\nXDIM=%d\nYDIM=%d\nZDIM=%d\nVDIM=1\nTYPE=%s\n' ...
'PIXSIZE=%d bits\nCPU=decm\nVX=%6.4f\nVY=%6.4f\nVZ=%6.4f\n'],size(X),btype,bitlen,spacings);
header=[header char(10*ones(1,256-4-length(header))) '##}' char(10)];
fwrite(fid,header,'char');
fwrite(fid,X,dtype);
fclose(fid);
@cesare-corrado
Copy link
Author

I used CGAL4.6 on a ubuntu 12.04 (64 bit) machine and g++ 4.6.3 compiler.
The code i used is the same CGAL-4.6/examples/Mesh_3/ mesh_3D_image.cpp, but with pipe.inr (see after) as input file and :
facet_angle = 30
facet_size = 0.8
facet_distance = 2
cell_rad_edge_ratio = 2.0
cell_size = 0.8
attached the matlab script I used for creating the .inr file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment