#include #include #include "ply.h" #include "Common.h" #include "ScratchPad.h" #include "Surface.h" #include "PerceivedLuminance.h" #include "plydecl.h" float decimation_constant_s = 10.0; float decimation_constant_e = 1.0; DiffuseDecimatedSurface* ScratchPad::constructDiffuseDecimatedSurface(const float threshold) { int fdpRpkToPly[2]; int fdpPlyToRpk[2]; int pid; DiffuseDecimatedSurface* dds = NULL; // Add accumulation parameter addAccum(); // Prepare the fork pipe(fdpRpkToPly); pipe(fdpPlyToRpk); pid = fork(); switch (pid) { case -1: fprintf(stderr,"Fork failed\n"); break; case 0: // Child // Standard input <== reading side of Father->Child pipe. close(fdpRpkToPly[1]); close(0); dup(fdpRpkToPly[0]); // Standard output <== writing side of Child->Father pipe. close(fdpPlyToRpk[0]); close(1); dup(fdpPlyToRpk[1]); // Pipe into it close(fdpRpkToPly[0]); close(fdpPlyToRpk[1]); // chdir("../SE"); execlp("desimplify",NULL); exit(0); break; default: { // FILE *fich; PlyFile *ply; // Parent close(fdpRpkToPly[0]); close(fdpPlyToRpk[1]); // Other files are closed by following lines... writePlyFile(fdpRpkToPly[1],threshold); dds = new DiffuseDecimatedSurface(patch,fdpPlyToRpk[0],ply); while (wait(NULL)!=pid) ; //ply_close(ply); close(fdpPlyToRpk[0]); } return dds; } return NULL; } void ScratchPad::writePlyFile(int fd,const float threshold) { FILE *fich; PlyFile *ply; DecimationVertex dv; DecimationFace df; int i,j,k,kp; float delta,s,it; //VEC2D vv,vw,pos; RGB rgb; if (threshold<=0.0) it = 1000000.0; else it = 1.0f/threshold; // Open stream fich = fdopen(fd,"w"); // Open ply file from stream ply = ply_write(fich,decimation_num_elems,decimation_elem_names,decimation_file_type); // Write header // Describe vertex element ply_describe_element(ply, decimation_elem_names[0], curnumcoef, 8, decimation_vert_props); // Describe face element ply_describe_element(ply, decimation_elem_names[1], issquare ? curnumsub*curnumsub*2 : curnumsub*curnumsub, 1, decimation_face_props); // Finish header ply_header_complete(ply); // Prepare to write vertex ply_put_element_setup(ply,decimation_elem_names[0]); // Delta delta = 1.0f / curnumsubfp; s = decimation_constant_s*curnumsubfp; // * decimation_constant_e / hmin; if (issquare) { dv.v = 0.0; k = 0; for (j=0;j