mirror of
				https://github.com/jhasse/poly2tri.git
				synced 2025-10-31 04:27:09 +01:00 
			
		
		
		
	code cleanup; refined hole API
This commit is contained in:
		| @@ -48,7 +48,11 @@ void MainLoop(const double zoom); | |||||||
| void Draw(const double zoom); | void Draw(const double zoom); | ||||||
| void DrawMap(const double zoom); | void DrawMap(const double zoom); | ||||||
| void ConstrainedColor(bool constrain); | void ConstrainedColor(bool constrain); | ||||||
|  | double StringToDouble(const std::string& s); | ||||||
|  |  | ||||||
|  | /// Dude hole examples | ||||||
| vector<Point*> CreateHeadHole(); | vector<Point*> CreateHeadHole(); | ||||||
|  | vector<Point*> CreateChestHole(); | ||||||
|  |  | ||||||
| float rotate_y = 0, | float rotate_y = 0, | ||||||
|       rotate_z = 0; |       rotate_z = 0; | ||||||
| @@ -63,16 +67,10 @@ double cy = 0.0; | |||||||
| vector<Triangle*> triangles; | vector<Triangle*> triangles; | ||||||
| /// Triangle map | /// Triangle map | ||||||
| list<Triangle*> map; | list<Triangle*> map; | ||||||
|  | /// Polylines | ||||||
|  | vector< vector<Point*> > polylines; | ||||||
|  |  | ||||||
| double StringToDouble(const std::string& s) | /// Draw the entire triangle map? | ||||||
| { |  | ||||||
|   std::istringstream i(s); |  | ||||||
|   double x; |  | ||||||
|   if (!(i >> x)) |  | ||||||
|     return 0; |  | ||||||
|   return x; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool draw_map = false; | bool draw_map = false; | ||||||
|  |  | ||||||
| int main(int argc, char* argv[]) | int main(int argc, char* argv[]) | ||||||
| @@ -95,12 +93,12 @@ int main(int argc, char* argv[]) | |||||||
|   double y = rand() % (b - a - 1) + a + 1; |   double y = rand() % (b - a - 1) + a + 1; | ||||||
|   polyline[i] = Point(x, y); |   polyline[i] = Point(x, y); | ||||||
|    } |    } | ||||||
|  |  | ||||||
|   */ |   */ | ||||||
|  |  | ||||||
|   cx = atof(argv[2]); |   cx = atof(argv[2]); | ||||||
|   cy = atof(argv[3]); |   cy = atof(argv[3]); | ||||||
|    |    | ||||||
|  |   // Parse and tokenize data file | ||||||
|   string line; |   string line; | ||||||
|   ifstream myfile(argv[1]); |   ifstream myfile(argv[1]); | ||||||
|   vector<p2t::Point*> points; |   vector<p2t::Point*> points; | ||||||
| @@ -124,19 +122,35 @@ int main(int argc, char* argv[]) | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   cout << "Number of points = " << points.size() << endl; |   cout << "Number of points = " << points.size() << endl; | ||||||
|  |   polylines.push_back(points); | ||||||
|    |    | ||||||
|   Init(); |   Init(); | ||||||
|  |  | ||||||
|   // Perform triangulation |   ///  | ||||||
|  |   /// Perform triangulation | ||||||
|  |   ///  | ||||||
|  |    | ||||||
|   double init_time = glfwGetTime(); |   double init_time = glfwGetTime(); | ||||||
|  |   // Step 1 - Create CDT and add primary polyline | ||||||
|   CDT* cdt = new CDT(points); |   CDT* cdt = new CDT(points); | ||||||
|    |    | ||||||
|   string s = argv[1]; |   // Step 2 - Add holes if necessary | ||||||
|   if(s.rfind("dude.dat", 0) != string::npos) { |   string s(argv[1]); | ||||||
|     cout << "Dude!" << endl; |   if(s.find("dude.dat", 0) != string::npos) { | ||||||
|  |     // Add head hole | ||||||
|  |     vector<Point*> head_hole = CreateHeadHole(); | ||||||
|  |     cdt->AddHole(head_hole); | ||||||
|  |     // Add chest hole | ||||||
|  |     vector<Point*> chest_hole = CreateChestHole(); | ||||||
|  |     cdt->AddHole(chest_hole); | ||||||
|  |      | ||||||
|  |     polylines.push_back(head_hole); | ||||||
|  |     polylines.push_back(chest_hole); | ||||||
|   } |   } | ||||||
|    |    | ||||||
|  |   // Step 3 - Triangulate! | ||||||
|   cdt->Triangulate(); |   cdt->Triangulate(); | ||||||
|  |    | ||||||
|   double dt = glfwGetTime() - init_time; |   double dt = glfwGetTime() - init_time; | ||||||
|   cout << "Elapsed time (secs) = " << dt << endl; |   cout << "Elapsed time (secs) = " << dt << endl; | ||||||
|  |  | ||||||
| @@ -255,6 +269,18 @@ void Draw(const double zoom) | |||||||
|     glVertex2f(c.x, c.y); |     glVertex2f(c.x, c.y); | ||||||
|     glEnd(); |     glEnd(); | ||||||
|   } |   } | ||||||
|  |    | ||||||
|  |   // green | ||||||
|  |   glColor3f(0, 1, 0); | ||||||
|  |      | ||||||
|  |   for(int i = 0; i < polylines.size(); i++) { | ||||||
|  |     vector<Point*> poly = polylines[i]; | ||||||
|  |     glBegin(GL_LINE_LOOP); | ||||||
|  |       for(int j = 0; j < poly.size(); j++) { | ||||||
|  |         glVertex2f(poly[j]->x, poly[j]->y); | ||||||
|  |       } | ||||||
|  |     glEnd(); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| void DrawMap(const double zoom) | void DrawMap(const double zoom) | ||||||
| @@ -311,11 +337,27 @@ vector<Point*> CreateHeadHole() { | |||||||
|   head_hole.push_back(new Point(332, 423)); |   head_hole.push_back(new Point(332, 423)); | ||||||
|    |    | ||||||
|   return head_hole; |   return head_hole; | ||||||
|  | } | ||||||
|  |  | ||||||
|   /* | vector<Point*> CreateChestHole() { | ||||||
|    val chestHole = Array(Point(320.72342f,480f), Point(338.90617f,465.96863f), |  | ||||||
|                                 Point(347.99754f,480.61584f), Point(329.8148f,510.41534f), |   vector<Point*> chest_hole; | ||||||
|                                 Point(339.91632f,480.11077f), Point(334.86556f,478.09046f)) |   chest_hole.push_back(new Point(320.72342,480)); | ||||||
|   */ |   chest_hole.push_back(new Point(338.90617,465.96863)); | ||||||
|  |   chest_hole.push_back(new Point(347.99754,480.61584)); | ||||||
|  |   chest_hole.push_back(new Point(329.8148,510.41534)); | ||||||
|  |   chest_hole.push_back(new Point(339.91632,480.11077)); | ||||||
|  |   chest_hole.push_back(new Point(334.86556,478.09046)); | ||||||
|  |    | ||||||
|  |   return chest_hole; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | double StringToDouble(const std::string& s) | ||||||
|  | { | ||||||
|  |   std::istringstream i(s); | ||||||
|  |   double x; | ||||||
|  |   if (!(i >> x)) | ||||||
|  |     return 0; | ||||||
|  |   return x; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zzzzrrr
					zzzzrrr