#include "mesh_type.h" #include #include #include #include #include using namespace std; CMesh trimesh; MyPolyMesh polymesh; bool OpenTriMesh(std::string PathMesh) { int position; position=PathMesh.find(".ply"); if (position!=-1) { int err=vcg::tri::io::ImporterPLY::Open(trimesh,PathMesh.c_str()); return (err==vcg::ply::E_NOERROR); } position=PathMesh.find(".obj"); if (position!=-1) { int mask; bool readed=vcg::tri::io::ImporterOBJ::LoadMask(PathMesh.c_str(),mask); if (!readed)return false; int err=vcg::tri::io::ImporterOBJ::Open(trimesh,PathMesh.c_str(),mask); return (err==vcg::tri::io::ImporterOBJ::E_NOERROR); } position=PathMesh.find(".off"); assert(position!=-1); int mask; bool readed=vcg::tri::io::ImporterOFF::LoadMask(PathMesh.c_str(),mask); if (!readed)return false; int err=vcg::tri::io::ImporterOFF::Open(trimesh,PathMesh.c_str(),mask); return (err==0); } int main(int argc, const char * argv[]) { const char* configfile; if (argc != 2) { cout << "Not enough parameters: ./MIQ configfile" << endl; exit(EXIT_FAILURE); } configfile = argv[1]; printf("configuration file %s",configfile); fflush(stdout); // Read Config File FILE *f= fopen(configfile,"r"); if (f==NULL) { printf("Cannot open config file\n"); return -1; } char buff[200]; // Mesh name fscanf(f,"mesh=%s\n",&buff[0]); std::string filename = std::string(buff); printf("FILENAME %s",filename.c_str()); fflush(stdout); bool opened=OpenTriMesh(filename); if (!opened) { printf("error loading mesh file \n"); exit(0); } vcg::tri::UpdateBounding::Box(trimesh); vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(trimesh); vcg::tri::UpdateNormal::PerFaceNormalized(trimesh); vcg::tri::UpdateTopology::FaceFace(trimesh); vcg::tri::UpdateTopology::VertexFace(trimesh); vcg::tri::UpdateFlags::FaceBorderFromFF(trimesh); vcg::tri::UpdateFlags::VertexBorderFromFace(trimesh); // Field name fscanf(f,"field=%s\n",&buff[0]); std::string fieldname = std::string(buff); int position=fieldname.find(".ffield"); if (position==-1) { printf("error loading mesh file \n"); exit(0); } bool field_loaded=vcg::tri::io::ImporterFIELD::LoadFFIELD(trimesh,fieldname.c_str()); if (!field_loaded)return false; int scalegradient; fscanf(f,"scalegradient=%d\n",&scalegradient); // Gradient Size float GradientSize; fscanf(f,"gradient=%f\n",&GradientSize); if (scalegradient!=0) GradientSize*=1.0/trimesh.bbox.Diag(); // Stiffness float Stiffness=4; // DirectRounding int DirectRound; fscanf(f,"directround=%d\n",&DirectRound); // Number of iterations int iter=10; // Number of local iterations int localIter=5; // Output name fscanf(f,"out=%s\n",&buff[0]); std::string out = std::string(buff); position=out.find(".obj"); if (position==-1) { printf("error output mesh file \n"); exit(0); } bool isvalid=MIQ_parametrization::IsValid(trimesh); if (!isvalid) { printf("mesh not valid for parametrization \n"); exit(0); } MIQ_parametrization::InitSeamsSing(trimesh,true,true,true); MIQ_parametrization::Parametrize(trimesh,MIQ_parametrization::ITERATIVE,Stiffness,GradientSize,(bool)DirectRound,iter,localIter,true); Quadrangulator Quad; Quad.TestIsProper(trimesh); Quad.Quadrangulate(trimesh,polymesh); vcg::tri::io::ExporterOBJ::Save(polymesh,out.c_str(),0); fclose(f); }