00001
00011 #include <vector>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <del_interface.hpp>
00015
00016 using std::cout;
00017 using std::cerr;
00018 using std::endl;
00019 using std::vector;
00020 using std::ifstream;
00021 using std::string;
00022
00023 using namespace tpp;
00024
00025 int main(int argc, char *argv[]) {
00026
00027 if(argc != 2){
00028 cerr << "\nUsage: test input.dat\n";
00029 cerr << "input.dat should consist of 2d ascii values\n\n";
00030 exit(1);
00031 }
00032
00033 ifstream inputFile(argv[1]);
00034 if(!inputFile){
00035 cerr << "Error: Could not open input file\n";
00036 exit(1);
00037 }
00038
00039 Delaunay::Point tempP;
00040 vector< Delaunay::Point > v;
00041
00042 string ofname = "del.off";
00043 cout <<"======================================\n";
00044 cout <<" Input Points from file \n";
00045 cout <<"======================================\n";
00046 do {
00047 inputFile >> tempP[0];
00048 inputFile >> tempP[1];
00049 if(!inputFile.good()) continue;
00050 v.push_back(tempP);
00051 cout << tempP << endl;
00052 } while (!inputFile.eof());
00053 cout <<"======================================\n";
00054
00055 Delaunay delobject(v);
00056 delobject.Triangulate();
00057 cout << "Wrote del.off in geomview format\n";
00058 delobject.writeoff(ofname);
00059
00060
00061 cout << "Number of vertices in file = "
00062 << delobject.nvertices() << endl;
00063 cout << "Number of edges in delaunay = "
00064 << delobject.nedges() << endl;
00065 cout << "Number of triangles in delaunay = "
00066 << delobject.ntriangles() << endl;
00067 cout << "Hull size = "
00068 << delobject.hull_size() << endl;
00069
00070 cout <<"======================================\n";
00071 cout <<" Vertices from vertex iterator \n";
00072 cout <<"======================================\n";
00073 for(Delaunay::vIterator vit = delobject.vbegin();
00074 vit != delobject.vend();
00075 ++ vit){
00076 cout << "ID : " << delobject.vertexId(vit)
00077 << "\t" << *vit << endl;
00078 }
00079
00080 cout <<"======================================\n";
00081 cout <<" Faces from face iterator \n";
00082 cout <<"======================================\n";
00083 for(Delaunay::fIterator fit = delobject.fbegin();
00084 fit != delobject.fend();
00085 ++fit){
00086 cout << delobject.Org(fit) << ", "
00087 << delobject.Dest(fit) << ", "
00088 << delobject.Apex(fit) << " \t: Area = "
00089 << delobject.area(fit) << endl;
00090
00091 cout << "Adjacent vertices are: ";
00092 for(int i =0; i < 3; ++i)
00093 cout << delobject.Sym(fit,i) << "\t";
00094 cout << endl;
00095 }
00096
00097 cout <<"======================================\n";
00098 cout <<" Testing point location \n";
00099 cout <<"======================================\n";
00100 for(int i =0; i < delobject.nvertices(); ++i){
00101 Delaunay::fIterator fit = delobject.locate(i);
00102 cout << "Vertex " << i << " located in Triangle : "
00103 << delobject.Org(fit) << ", "
00104 << delobject.Dest(fit) << ", "
00105 << delobject.Apex(fit) << " \t: Area = "
00106 << delobject.area(fit) << endl;
00107
00108 }
00109
00110 cout <<"======================================\n";
00111 cout <<" Testing vertex incidence \n";
00112 cout <<"======================================\n";
00113 for (int j = 0 ; j < delobject.nvertices(); ++j){
00114 vector<int> vav;
00115 delobject.trianglesAroundVertex(j,vav);
00116 cout << "Triangles around vertex [" << j << "]:\n";
00117 for(unsigned int i =0; i < vav.size(); ++i){
00118 if( i % 3 == 0 ) cout << endl;
00119 cout << vav[i] << "\t";
00120 }
00121 cout << "\n---------------------------------\n";
00122 }
00123
00124 inputFile.close();
00125
00126 return 0;
00127
00128 }