#ifndef FILEMANAGER #define FILEMANAGER #include "ImplicitFunction.h" #include "EvaluationTreeD.h" #include "Mesh.h" #include #include #define PI 3.1415926535897932385 class FileManager{ public: static EvaluationTreeD* readRbfFile(char* name){ FILE* in = fopen(name, "r"); printf("File read is started.\n"); float max[3], min[3]; fscanf(in, "%f %f %f", &min[0], &min[1], &min[2]); fscanf(in, "%f %f %f", &max[0], &max[1], &max[2]); int N; fscanf(in, "%d", &N); float out; fscanf(in, "%f", &out); printf("%d basis functions.\n", N); BasisFunction** bfs = new BasisFunction*[N]; for(int i=0; icenterX, &bfi->centerY, &bfi->centerZ, &bfi->cXX, &bfi->cYY, &bfi->cZZ, &bfi->cXY, &bfi->cYZ, &bfi->cZX, &bfi->cX, &bfi->cY, &bfi->cZ, &bfi->c0, &bfi->support, &bfi->level); bfs[i] = bfi; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d function are read.", i); } printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFile read is done. \n\n"); EvaluationTreeD* tree = new EvaluationTreeD(bfs, N, min, max); tree->out = out; return tree; } static Mesh* readMeshFile(char* name){ ifstream in(name); cout << "File read is started." << endl; int vN, fN; in >> vN >> fN; Mesh* mesh = new Mesh; mesh->setSize(vN, fN); double a = 0.25*PI; double b = 0.25*PI; int i; for(i=0; i> x >> y >> z; //float xt = cos(a)*x - sin(a)*cos(b)*y - sin(a)*sin(b)*z; //float yt = sin(a)*x + cos(a)*cos(b)*y + cos(a)*sin(b)*z; //float zt = -sin(b)*y + cos(b)*z; //mesh->setVertex(i, xt, yt, zt); mesh->setVertex(i, x, y, z); } for(i=0; i> n >> i0 >> i1 >> i2; mesh->setFace(i, i0, i1, i2); } in.close(); return mesh; } static void writeMeshFile(Mesh* mesh, char* name){ ofstream out(name); printf("File write is started.\n"); int vN = mesh->vertexN; int fN = mesh->faceN; out << vN << endl; out << fN << endl; int i; for(i=0; ivertex[i][0] << " " << mesh->vertex[i][1] << " " << mesh->vertex[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d vertices are written.", i); } for(i=0; iface[i][0] << " " << mesh->face[i][1] << " " << mesh->face[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d triangles are written.", i); } out.close(); printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFile write is done. \n\n"); } static void writeMeshWithTensorFile(Mesh* mesh, ImplicitFunction* func, char* name){ ofstream out(name); printf("File write is started.\n"); int vN = mesh->vertexN; int fN = mesh->faceN; out << vN << endl; out << fN << endl; int i; for(i=0; ivertex[i][0] << " " << mesh->vertex[i][1] << " " << mesh->vertex[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d vertices are written.", i); } for(i=0; iface[i][0] << " " << mesh->face[i][1] << " " << mesh->face[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d triangles are written.", i); } for(i=0; icurvatureTensor(k_max, k_min, t_max, t_min, mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2]); out << k_max << " " << k_min << " "; out << t_max[0] << " " << t_max[1] << " " << t_max[2] << " "; out << t_min[0] << " " << t_min[1] << " " << t_min[2] << endl; if(i%1000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d curvature tensors are estimated and written.", i); } out.close(); printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFile write is done. \n\n"); } static void writeMeshWithHkFile(Mesh* mesh, ImplicitFunction* func, char* name){ ofstream out(name); printf("File write is started.\n"); int vN = mesh->vertexN; int fN = mesh->faceN; out << vN << endl; out << fN << endl; int i; for(i=0; ivertex[i][0] << " " << mesh->vertex[i][1] << " " << mesh->vertex[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d vertices are written.", i); } for(i=0; iface[i][0] << " " << mesh->face[i][1] << " " << mesh->face[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d triangles are written.", i); } for(i=0; icurvatureHK(H, K, mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2]); out << H << " " << K << endl; if(i%1000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d curvature tensors are estimated and written.", i); } out.close(); printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFile write is done. \n\n"); } static void writeMeshWithRd(Mesh* mesh, ImplicitFunction* func, char* name){ ofstream out(name); printf("File write is started.\n"); int vN = mesh->vertexN; int fN = mesh->faceN; out << vN << endl; out << fN << endl; int i; for(i=0; inewton(mesh->vertex[i], mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2], 0.00001f); out << mesh->vertex[i][0] << " " << mesh->vertex[i][1] << " " << mesh->vertex[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d vertices are written.", i); } for(i=0; iface[i][0] << " " << mesh->face[i][1] << " " << mesh->face[i][2] << endl; if(i%10000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d triangles are written.", i); } for(i=0; inewton(mesh->vertex[i], mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2], 0.0001f); func->curvatureDerivative(Kmax, Kmin, Rmax, Rmin, Tmax, Tmin, mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2]); Dmax = Dmin = 0; //func->curvatureDerivative(Kmax, Kmin, Rmax, Rmin, Dmax, Dmin, Tmax, Tmin, // mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2]); out << Kmax << " " << Kmin << " " << Rmax << " " << Rmin << " " << Dmax << " " << Dmin << " "; out << Tmax[0] << " " << Tmax[1] << " " << Tmax[2] << " "; out << Tmin[0] << " " << Tmin[1] << " " << Tmin[2] << endl; if(i%1000 == 0) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d curvature tensors are estimated and written.", i); } out.close(); printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFile write is done. \n\n"); } }; #endif