00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <vcg/complex/complex.h>
00024 #include <vcg/complex/algorithms/update/topology.h>
00025 #include <vcg/complex/algorithms/parametrization/tangent_field_operators.h>
00026 #include <wrap/io_trimesh/import.h>
00027 #include <wrap/io_trimesh/export.h>
00028 #include <wrap/miq/MIQ.h>
00029 #include <wrap/miq/quadrangulator.h>
00030
00031
00032 using namespace vcg;
00033
00034 class CFace;
00035 class CVertex;
00036
00037 struct MyUsedTypes : public UsedTypes< Use<CVertex>::AsVertexType, Use<CFace>::AsFaceType >{};
00038
00039 class CVertex : public Vertex< MyUsedTypes,
00040 vertex::Coord3d, vertex::Normal3d,
00041 vertex::BitFlags, vertex::VFAdj,
00042 vertex::TexCoord2d, vertex::Qualityd>{};
00043
00044 class CFace : public Face< MyUsedTypes, face::VertexRef,
00045 face::VFAdj, face::FFAdj, face::Normal3d,
00046 face::WedgeTexCoord2d, face::BitFlags, face::CurvatureDird,
00047 face::Qualityd, face::Color4b, face::Mark>{};
00048
00049 class CMesh : public tri::TriMesh< std::vector<CVertex>, std::vector<CFace> >{};
00050
00051
00052 class MyPolyFace;
00053 class MyPolyVertex;
00054 struct PolyUsedTypes: public UsedTypes<Use<MyPolyVertex> ::AsVertexType,
00055 Use<MyPolyFace> ::AsFaceType
00056 >{};
00057
00058 class MyPolyVertex:public Vertex< PolyUsedTypes,
00059 vertex::Coord3f,
00060 vertex::Normal3f,
00061 vertex::BitFlags>{} ;
00062
00063 class MyPolyFace:public Face< PolyUsedTypes,
00064 face::PolyInfo,
00065 face::PFVAdj,
00066 face::BitFlags,
00067 face::Normal3f
00068 > {};
00069
00070 class MyPolyMesh: public
00071 tri::TriMesh< std::vector<MyPolyVertex>,
00072 std::vector<MyPolyFace > >{};
00073
00074
00075 using namespace std;
00076
00077 int main(int argc, const char * argv[])
00078 {
00079 const char* configfile;
00080
00081 if (argc != 2)
00082 {
00083 cout << "Not enough parameters;\nUsage:\n\n./quadrangulator configfile" << endl;
00084 exit(EXIT_FAILURE);
00085 }
00086
00087 configfile = argv[1];
00088 printf("configuration file %s",configfile);
00089 fflush(stdout);
00090
00091
00092 FILE *fp= fopen(configfile,"r");
00093 if (fp==NULL)
00094 {
00095 printf("Cannot open config file %s\n",configfile);
00096 return -1;
00097 }
00098
00099 char meshFilename[200]; fscanf(fp,"mesh=%s\n", meshFilename);
00100 char fieldFilename[200]; fscanf(fp,"field=%s\n", fieldFilename);
00101 int scalegradient; fscanf(fp,"scalegradient=%d\n", &scalegradient);
00102 float GradientSize; fscanf(fp,"gradient=%f\n", &GradientSize);
00103 int DirectRounding; fscanf(fp,"directround=%d\n", &DirectRounding);
00104 char outFilename[200]; fscanf(fp,"out=%s\n", outFilename);
00105
00106 fclose(fp);
00107
00108
00109 float Stiffness=4;
00110 int iterationNum=10;
00111 int localIterationNum=5;
00112
00113
00114
00115
00116 CMesh trimesh;
00117 if (tri::io::Importer<CMesh>::Open(trimesh, meshFilename)!=0)
00118 {
00119 printf("error loading mesh file %s\n",meshFilename);
00120 exit(0);
00121 }
00122
00123 tri::UpdateBounding<CMesh>::Box(trimesh);
00124 tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFaceNormalized(trimesh);
00125 tri::UpdateTopology<CMesh>::FaceFace(trimesh);
00126 tri::UpdateTopology<CMesh>::VertexFace(trimesh);
00127
00128 if (std::string(fieldFilename).find(".ffield")==-1)
00129 {
00130 printf("error loading field file %s\n",fieldFilename);
00131 exit(0);
00132 }
00133 bool field_loaded=tri::io::ImporterFIELD<CMesh>::LoadFFIELD(trimesh,fieldFilename);
00134 if (!field_loaded) return false;
00135
00136 if (scalegradient!=0)
00137 GradientSize*=1.0/trimesh.bbox.Diag();
00138
00139 if (! MIQ_parametrization<CMesh>::IsValid(trimesh) )
00140 {
00141 printf("Mesh not valid for quadrangulation: \n"
00142 "It must be a 2-manifold single connected component \n");
00143 exit(0);
00144 }
00145
00146
00147
00148 MyPolyMesh polymesh;
00149 MIQ_parametrization<CMesh>::InitSeamsSing(trimesh,true,true,true);
00150 MIQ_parametrization<CMesh>::Parametrize(trimesh,MIQ_parametrization<CMesh>::ITERATIVE,Stiffness,GradientSize,(bool)DirectRounding,iterationNum,localIterationNum,true);
00151
00152 Quadrangulator<CMesh,MyPolyMesh> Quad;
00153 Quad.TestIsProper(trimesh);
00154 Quad.Quadrangulate(trimesh,polymesh);
00155
00156 tri::io::Exporter<MyPolyMesh>::Save(polymesh,outFilename);
00157
00158 }
00159