www.pudn.com > AdRBF.rar > FileManager.h
#ifndef FILEMANAGER #define FILEMANAGER #include "ImplicitFunction.h" #include "EvaluationTreeD.h" #include "Mesh.h" #include "PointSet.h" #include#include class FileManager{ public: static PointSet* readPwnCFile(char* name){ ifstream in(name); printf("File read is started.\n"); int N; in >> N; printf("%d points.\n", N); PointSet* ps = new PointSet; ps->setPointSize(N); int i; for(i=0; i > x; in >> y; in >> z; ps->setPoint(i, x, y, z); 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 points are read.", i); } for(i=0; i > v; ps->setValue(i, v); } for(i=0; i > x; in >> y; in >> z; ps->setNormal(i, -x, -y, -z); 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 normals 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"); in.close(); return ps; } static PointSet* readPwnFile(char* name){ ifstream in(name); printf("File read is started.\n"); int N; in >> N; printf("%d points.\n", N); PointSet* ps = new PointSet; ps->setPointSize(N); int i; for(i=0; i > x; in >> y; in >> z; ps->setPoint(i, x, y, z); 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 points are read.", i); } for(i=0; i setValue(i, 1); } for(i=0; i > x; in >> y; in >> z; ps->setNormal(i, -x, -y, -z); 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 normals 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"); in.close(); return ps; } static void writePwnFile(PointSet* ps, char* name){ FILE* out = fopen(name, "w"); printf("File write is started.\n"); int N = ps->_pointN; fprintf(out, "%d\n", N); printf("%d points.\n", N); float (*point)[3] = ps->_point; int i; for(i=0; i _normal; for(i=0; i _pointN; fprintf(out, "%d\n", N); printf("%d points.\n", N); float (*point)[3] = ps->_point; int i; for(i=0; i _value; for(i=0; i _normal; for(i=0; i centerX, &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); int i; for(i=0; i > x >> y >> z; 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; i 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; i face[i][0] << " " << mesh->face[i][2] << " " << mesh->face[i][1] << 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; i 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; i face[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; i curvatureTensor(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; i 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; i face[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; i curvatureHK(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; i newton(mesh->vertex[i], mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2], 0.01f); 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; i face[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; i newton(mesh->vertex[i], mesh->vertex[i][0], mesh->vertex[i][1], mesh->vertex[i][2], 0.01f); 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"); } static void writeRbfFile(EvaluationTreeD* tree, char* name){ //FILE* out = fopen(name, "w"); ofstream out(name); printf("File write is started.\n"); //fprintf(out, "%f %f %f\n", tree->min[0], tree->min[1], tree->min[2]); //fprintf(out, "%f %f %f\n", tree->max[0], tree->max[1], tree->max[2]); out << tree->min[0] << " " << tree->min[1] << " " << tree->min[2] << endl; out << tree->max[0] << " " << tree->max[1] << " " << tree->max[2] << endl; int N; BasisFunction** bfs; tree->getBFS(bfs, N); //fprintf(out, "%d\n", N); //fprintf(out, "%f\n", tree->out); out << N << endl; out << tree->out << endl; printf("%d basis functions.\n", N); for(int i=0; i centerX << " " << 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 << endl; /* fprintf(out, "%6f %6f %6f %6f %6f %6f %6f %6f %6f %6f %6f %6f %6f %6f %d\n", bfi->centerX, 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);*/ 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 functions are written.", i); } out.close(); //fclose(out); 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"); delete[] bfs; } static void writeRbfFile2(EvaluationTreeD* tree, char* name){ ofstream out(name); printf("File write is started.\n"); int N; BasisFunction** bfs; tree->getBFS(bfs, N); out << N << endl; printf("%d basis functions.\n", N); for(int i=0; i centerX << " " << bfi->centerY << " " << bfi->centerZ << " " << bfi->cX << " " << bfi->cY << " " << bfi->cZ << " " << bfi->support << 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 functions 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"); delete[] bfs; } }; #endif