00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "PrFastUnorganized_OP.h"
00012 #include "PrTriangulation_OP.h"
00013 #include "PrParametrizeInt.h"
00014 #include "PrParametrizeBdy.h"
00015 #include "PrPrmShpPres.h"
00016 #include "PrPrmUniform.h"
00017 #include "PrPrmLeastSquare.h"
00018 #include "PrPrmEDDHLS.h"
00019 #include "PrPrmMeanValue.h"
00020 #include <fstream>
00021 #include <string>
00022 #include <boost/shared_ptr.hpp>
00023 #include <boost/tokenizer.hpp>
00024
00025 using namespace std;
00026 using namespace boost;
00027
00028 string suffix_of(char* filename);
00029
00030 int main(int argc, const char** argv)
00031 {
00032 if (argc < 2) {
00033 cerr << "This sample program generates a parametrization for a given triangulation, and " << endl;
00034 cerr << "writes the result to disk." << endl;
00035 cerr << "Usage: demo <-option argument>, where options/arguments are: " << endl;
00036 cerr << " -i <filename> : specify file containing the input triangulation." << endl;
00037 cerr << " If the filename suffix is 'pcloud', it is assumed to " << endl;
00038 cerr << " be a pointcloud. Otherwise it is assumed to be a " << endl;
00039 cerr << " triangulation. See 'NOTES_DATA_FORMAT' for " << endl;
00040 cerr << " specification of formats." << endl;
00041 cerr << " -intpar <integer> : specify method for parametrizing interior of triangulation" << endl;
00042 cerr << " Valid options are: 1 - shape-preserving parametrization" << endl;
00043 cerr << " 2 - uniform parametrization" << endl;
00044 cerr << " 3 - least-square based parametrization" << endl;
00045 cerr << " 4 - the EDDHLS parametrization" << endl;
00046 cerr << " 5 - mean value parametrization" << endl;
00047 cerr << " -bdypar <integer> : specify method for parametrizing boundary of triangulation " << endl;
00048 cerr << " Valid options are: 1 - chord length parametrization " << endl;
00049 cerr << " 2 - centripetal parametrization " << endl;
00050 cerr << " 3 - uniform boundary parametrization " << endl;
00051 cerr << " -bdymeth <integer> : specify shape of parameter domain " << endl;
00052 cerr << " Valid options are: 1 - circle" << endl;
00053 cerr << " 2 - rectangle, based on shape of 3D " << endl;
00054 cerr << " geometry" << endl;
00055 cerr << " 3 - rectangle, based on extent of current" << endl;
00056 cerr << " parametrization. Don't use this if " << endl;
00057 cerr << " your data is not already " << endl;
00058 cerr << " parametrized somehow. " << endl;
00059 cerr << "The result (the parametrized triangulation) will be written to the file" << endl;
00060 cerr << "\"triangulation\"." << endl;
00061 return 0;
00062 }
00063
00064 bool inf_specified = false;
00065 char inf[80];
00066 int intparam_type = 5;
00067 int bdyparam_type = 1;
00068 int bdy_method = 1;
00069
00070 int undefCmd = 0;
00071
00072 for (int i=1; i<argc; i=i+2)
00073 {
00074 if(strcmp(argv[i],"-i") == 0) {
00075 strncpy(inf,argv[i+1],80);
00076 inf_specified = true;
00077 } else if( strcmp(argv[i],"-intpar") == 0 ) {
00078 intparam_type = atoi(argv[i+1]);
00079 } else if( strcmp(argv[i],"-bdypar") == 0 ) {
00080 bdyparam_type = atoi(argv[i+1]);
00081 } else if ( strcmp(argv[i],"-bdymeth") == 0) {
00082 bdy_method = atoi(argv[i+1]);
00083 } else {
00084 undefCmd = 1;
00085 }
00086 }
00087
00088 if(undefCmd)
00089 {
00090 cerr << "Error in command line" << endl;
00091 return -1;
00092 }
00093 if (!inf_specified) {
00094 cerr << "No input file specified. Aborting." << endl;
00095 return -1;
00096 }
00097 std::ifstream infile(inf);
00098 if (!infile) {
00099 cerr << "Unable to open file '" << inf << "'. Aborting." << endl;
00100 return -1;
00101 }
00102
00103 bool is_pointcloud = suffix_of(inf) == string("pcloud");
00104
00105
00106 int no_comps = 1, genus = 1;
00107 shared_ptr<PrOrganizedPoints> pr_triang;
00108 if (is_pointcloud) {
00109 shared_ptr<PrFastUnorganized_OP> tmp(new PrFastUnorganized_OP);
00110 tmp->scanRawData(infile);
00111 tmp->initNeighbours();
00112 no_comps = tmp->findNumComponents();
00113 pr_triang = tmp;
00114
00115 } else {
00116 shared_ptr<PrTriangulation_OP> tmp(new PrTriangulation_OP);
00117 tmp->scanRawData(infile);
00118 tmp->printInfo(cout);
00119 no_comps = tmp->findNumComponents();
00120 genus = tmp->findGenus();
00121 pr_triang = tmp;
00122
00123 }
00124
00125 if(no_comps == 1 && genus == 1)
00126 {
00127 PrParametrizeBdy pb;
00128
00129 switch(bdyparam_type)
00130 {
00131 case 1: pb.setParamKind(PrCHORDLENGTHBDY); break;
00132 case 2: pb.setParamKind(PrCENTRIPETAL); break;
00133 case 3: pb.setParamKind(PrUNIFBDY); break;
00134 }
00135
00136 pb.attach(pr_triang);
00137
00138 cout << "Parametrizing boundary..." << endl;
00139 int cor[4];
00140
00141 if(bdy_method == 1)
00142 {
00143 pb.parametrize();
00144 }
00145 else
00146 {
00147 if(bdy_method == 2) {
00148 pb.findCornersFromXYZ(cor);
00149 } else if(bdy_method == 3) {
00150 pb.findCornersFromUV(cor);
00151 } else {
00152 cerr << "erroneous boundary shape type. Aborting. " << endl;
00153 return -1;
00154 }
00155
00156 for(int k=0; k<4; k++)
00157 {
00158 cout << "corner(i,u,v,x,y,z) = " << cor[k];
00159 cout << " " << pr_triang->getU(cor[k]);
00160 cout << " " << pr_triang->getV(cor[k]);
00161 cout << " " << pr_triang->get3dNode(cor[k]).x();
00162 cout << " " << pr_triang->get3dNode(cor[k]).y();
00163 cout << " " << pr_triang->get3dNode(cor[k]).z();
00164 cout << endl;
00165 }
00166 pb.parametrize(cor[0],cor[1],cor[2],cor[3]);
00167 }
00168
00169 cout << "Parametrizing interior..." << endl;
00170
00171 PrParametrizeInt *pi;
00172 switch(intparam_type)
00173 {
00174 case 1: pi = new PrPrmShpPres; break;
00175 case 2: pi = new PrPrmUniform; break;
00176 case 3: pi = new PrPrmLeastSquare; break;
00177 case 4: pi = new PrPrmEDDHLS; break;
00178 case 5: pi = new PrPrmMeanValue; break;
00179 }
00180
00181 pi->attach(pr_triang);
00182 pi->parametrize();
00183 delete pi;
00184
00185 std::ofstream uv_nodes_file("uv_nodes");
00186 pr_triang->printUVNodes(uv_nodes_file);
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 if (!is_pointcloud) {
00199 std::ofstream triangulation_file("triangulation");
00200 shared_dynamic_cast<PrTriangulation_OP, PrOrganizedPoints>(pr_triang)->print(triangulation_file);
00201 }
00202 }
00203 else return 0;
00204 }
00205
00206
00207
00208 string suffix_of(char* filename)
00209 {
00210 typedef boost::tokenizer<char_separator<char> > tokenizer;
00211 string s(filename);
00212 boost::char_separator<char> sep(".");
00213 tokenizer tok(s, sep);
00214 tokenizer::iterator last;
00215 for (tokenizer::iterator it = tok.begin(); it != tok.end(); last = it++);
00216 return *last;
00217 }