10 #include "allocation.hh" 11 #include "geometry.hh" 22 string &outputFilename,\
24 string &VTKInputFilename,\
26 string &GnuplotSkeletonFilename,\
28 string &GnuplotAltSkeletonFilename,\
30 string &descriptorsFilename,\
32 string ¶metersFilename)
39 cout <<
"Can't open file " << filename << endl;
44 fin >>
openCell; fin.ignore(256,
'\n');
45 fin >>
save_dat; fin.ignore(256,
'\n');
46 fin >>
save_vtk; fin.ignore(256,
'\n');
47 fin >>
dstrut; fin.ignore(256,
'\n');
48 fin >>
dedge; fin.ignore(256,
'\n');
50 fin >>
RANDOM; fin.ignore(256,
'\n');
51 fin >>
grid; fin.ignore(256,
'\n');
52 fin >>
nx; fin.ignore(256,
'\n');
53 fin >>
ny; fin.ignore(256,
'\n');
54 fin >>
nz; fin.ignore(256,
'\n');
55 fin >>
sx; fin.ignore(256,
'\n');
56 fin >>
sy; fin.ignore(256,
'\n');
57 fin >>
sz; fin.ignore(256,
'\n');
62 fin >> outputFilename; fin.ignore(256,
'\n');
63 fin >> VTKInputFilename; fin.ignore(256,
'\n');
64 fin >> GnuplotSkeletonFilename; fin.ignore(256,
'\n');
65 fin >> GnuplotAltSkeletonFilename; fin.ignore(256,
'\n');
66 fin >> descriptorsFilename; fin.ignore(256,
'\n');
67 fin >> parametersFilename; fin.ignore(256,
'\n');
81 cout <<
"reading vtk file" << endl;
90 sscanf(line.c_str(),
"%s %d %d %d",word,&vtkx,&vtky,&vtkz);
94 cout <<
"dimensions: " << vtkx <<
", " << vtky <<
", " << vtkz << endl;
95 cout <<
"allocating" << endl;
98 for (i = 0; i <
nx; i++)
99 for (j = 0; j <
ny; j++)
100 for (k = 0; k <
nz; k++)
120 cout <<
"reading vtk file" << endl;
129 sscanf(line.c_str(),
"%s %d %d %d",word,&vtkx,&vtky,&vtkz);
133 cout <<
"dimensions: " << vtkx <<
", " << vtky <<
", " << vtkz << endl;
134 cout <<
"loading data file" << endl;
136 bmat = (
int *)calloc((
size_t)vtkx*vtky*vtkz,
sizeof(int));
139 sscanf(line.c_str(),
"%e %e %e",&a,&b,&c);
145 for (i=1;i<vtkx*vtky*vtkz/2-1;i++) {
148 sscanf(line.c_str(),
"%e %e",&a,&b);
149 bmat[2*i+1]=int(a+0.5);
150 bmat[2*i+2]=int(b+0.5);
157 sscanf(line.c_str(),
"%e",&a);
158 bmat[vtkx*vtky*vtkz-1]=int(a+0.5);
162 for (i=0;i<vtkz;i++) {
163 for (j=0;j<vtky;j++) {
164 for (k=0;k<vtkx;k++) {
165 if (amat[i][j][k]==0) {
166 amat[i][j][k]=bmat[l];
179 const char* filename ,\
187 cout <<
"saving in Paraview style..." << endl;
189 strmo = fopen(filename,
"w");
191 fprintf (stderr,
"Can't open file %s\n",filename);
195 fprintf (strmo,
"# vtk DataFile Version 3.0\n");
196 fprintf (strmo,
"vtkfile\n");
197 fprintf (strmo,
"ASCII\n");
198 fprintf (strmo,
"DATASET STRUCTURED_POINTS\n");
199 fprintf (strmo,
"DIMENSIONS %d %d %d\n",
nx,
ny,
nz);
200 fprintf (strmo,
"ORIGIN 1 1 1\n");
201 fprintf (strmo,
"SPACING %g %g %g\n",1.0/
nx,1.0/
ny,1.0/
nz);
202 fprintf (strmo,
"POINT_DATA %d\n",
nx*
ny*
nz);
203 fprintf (strmo,
"SCALARS values int\n");
204 fprintf (strmo,
"LOOKUP_TABLE default\n");
206 for (i = 0; i <
nx; i++) {
207 for (j = 0; j <
ny; j++) {
208 for (k = 0; k < nz; k++)
209 fprintf (strmo,
" %c", (amat[i][j][k] >= 1) ?
'0' :
'1');
211 fprintf (strmo,
"\n");
213 fprintf (strmo,
"\n");
215 fprintf (strmo,
"\n");
221 const char* filename ,\
229 cout <<
"saving in DX style..." << endl;
231 strmo = fopen(filename,
"w");
233 fprintf (stderr,
"Can't open file %s\n",filename);
237 fprintf (strmo,
"NCX = %d ;\n",
nx);
238 fprintf (strmo,
"NCY = %d ;\n",
ny);
239 fprintf (strmo,
"NCZ = %d ;\n",
nz);
241 fprintf (strmo,
"A = [\n");
242 for (i = 0; i <
nx; i++) {
243 for (j = 0; j <
ny; j++) {
244 for (k = 0; k <
nz; k++)
245 fprintf (strmo,
" %c", (amat[i][j][k] >= 1) ?
'0' :
'1');
247 fprintf (strmo,
"\n");
249 fprintf (strmo,
"\n");
251 fprintf (strmo,
"];\n");
268 cout <<
"saving shifted Voronoi diagram" << endl;
271 if (!fout.is_open()) {
272 cout <<
"can't open file " << filename << endl;
275 for (i=0; i<sv; i++) {
276 if (
in_domain(vert[i][0],vert[i][1],vert[i][2])) {
277 for (j=0; j<incmax; j++) {
278 if (vinc[i][j] != -1) {
279 fout << vert[i][0] <<
" " << vert[i][1] <<
" " << \
281 fout << vert[vinc[i][j]][0] <<
" " << \
282 vert[vinc[i][j]][1] <<
" " << \
283 vert[vinc[i][j]][2] << endl;
303 cout <<
"saving descriptors" << endl;
306 if (!fout.is_open()) {
307 cout <<
"can't open file " << filename << endl;
322 cout <<
"saving parameters" << endl;
325 if (!fout.is_open()) {
326 cout <<
"can't open file " << filename << endl;
329 fout << dedge << endl;
bool openCell
make open cell foam
void saveDescriptors(string filename, double por, double fs, bool report)
Saves morphology descriptors (porosity and strut content) to a file.
bool progress_report
show detailed progress report
double dedge
parameter influencing size of struts in cell edges
void readParameters(string filename, string &outputFilename, string &VTKInputFilename, string &GnuplotSkeletonFilename, string &GnuplotAltSkeletonFilename, string &descriptorsFilename, string ¶metersFilename)
bool save_voro_diag1
gnuplot Voronoi diagram
bool createEdges
create struts at cell edges
void saveToGnuplot(string filename, int sv, int incmax, double **vert, int **vinc, bool report)
Saves tessellation diagram to gnuplot file.
bool save_vtk
save file in new paraview style
bool save_voro_diag2
alternative gnuplot Voronoi diagram
int *** allocateFromVTK(string filename, int ***amat, bool report)
Allocates the matrix from dimensions read from VTK file.
void saveToDX(const char *filename, int ***amat, bool report)
Saves morphology to DX file.
Defines global variables, macros, templates and namespace.
bool save_dat
save file in old dx style
real(dp) dstrut
strut diameter
void saveParameters(string filename, double dedge, bool report)
Saves parameters (dedge) to a file.
bool in_domain(double x, double y, double z)
True if the point is in the domain, False otherwise.
void saveToVTK(const char *filename, int ***amat, bool report)
Saves morphology to VTK file.
bool createNodes
create struts at cell vertices
integer nz
spatial discretization
namespace with global variables
void importFromVTK(string filename, int ***amat, bool report)
Reads morphology from VTK file. Changes amat.
bool import_vtk
import morphology from vtk
int *** alloc_3Dmatrix(int nx, int ny, int nz)
allocate 3D integer matrix