[Bf-blender-cvs] [acef8bd] soc-2014-nurbs: Overlapping edge order fixed (exits old polygon before enters new polygon)

Jonathan deWerd noreply at git.blender.org
Fri Jun 27 08:14:50 CEST 2014


Commit: acef8bd268b6c19aec39735f046fe7ad7801badf
Author: Jonathan deWerd
Date:   Thu Jun 26 15:49:53 2014 -0400
https://developer.blender.org/rBacef8bd268b6c19aec39735f046fe7ad7801badf

Overlapping edge order fixed (exits old polygon before enters new polygon)

===================================================================

M	PolyTest/GridMesh.cpp
M	PolyTest/GridMesh_demo.cpp

===================================================================

diff --git a/PolyTest/GridMesh.cpp b/PolyTest/GridMesh.cpp
index fb820fd..8ffb68c 100644
--- a/PolyTest/GridMesh.cpp
+++ b/PolyTest/GridMesh.cpp
@@ -258,7 +258,11 @@ void GridMesh::poly_draw(int poly, float shrinkby) {
 		} else {
 			glColor3ub(0,0,255);
 		}
-		glVertex2f(v[v1].x, v[v1].y);
+		float x=v[v1].x, y=v[v1].y;
+		float cx, cy; poly_center(v[v1].first, &cx, &cy);
+		x = (1.0-shrinkby)*x + shrinkby*cx;
+		y = (1.0-shrinkby)*y + shrinkby*cy;
+		glVertex2f(x,y);
 		v1 = v[v1].next;
 	} while (v1 != poly);
 	glEnd();
@@ -296,7 +300,9 @@ void find_integer_cell_line_intersections(double x0, double y0, double x1, doubl
 											   std::vector<std::pair<int,int>> *bottom_edges,
 											   std::vector<std::pair<int,int>> *left_edges,
 											   std::vector<std::pair<int,int>> *integer_cells) {
+	bool flipped_left_right = false;
 	if (x0>x1) { // Ensure order is left to right
+		flipped_left_right = true;
 		std::swap(x0,x1);
 		std::swap(y0,y1);
 	}
@@ -367,6 +373,11 @@ void find_integer_cell_line_intersections(double x0, double y0, double x1, doubl
 			rhy += m;
 		}
 	}
+	if (flipped_left_right) {
+		if (integer_cells) std::reverse(integer_cells->begin(), integer_cells->end());
+		if (bottom_edges) std::reverse(bottom_edges->begin(), bottom_edges->end());
+		if (left_edges) std::reverse(left_edges->begin(), left_edges->end());
+	}
 }
 
 int GridMesh::insert_vert(int poly1left,
@@ -408,7 +419,7 @@ int GridMesh::insert_vert_poly_gridmesh(int mpoly) {
 		int v2 = v[v1].next;
 		float v2x=v[v2].x, v2y=v[v2].y;
 		integer_cells.clear();
-		find_integer_cell_line_intersections(v1x,v1y,v2x,v2y,nullptr,nullptr,&integer_cells);
+		find_cell_line_intersections(v1x,v1y,v2x,v2y,nullptr,nullptr,&integer_cells);
 		std::vector<IntersectingEdge> isect;
 		for (std::pair<int,int> j : integer_cells) {
 			int cell_poly = poly_for_cell(j.first, j.second);
diff --git a/PolyTest/GridMesh_demo.cpp b/PolyTest/GridMesh_demo.cpp
index f364704..f8abdd2 100644
--- a/PolyTest/GridMesh_demo.cpp
+++ b/PolyTest/GridMesh_demo.cpp
@@ -71,6 +71,7 @@ void GLUT_init(){
 
 /***************************** DRAW *****************************/
 void GLUT_display(){
+	float contraction = .2; // Move polygon edges and verts closer to their center
 	GreinerV2f *v = gm->v;
 	glClear(GL_COLOR_BUFFER_BIT);
 	// Draw Clip polygon lines
@@ -80,6 +81,12 @@ void GLUT_display(){
 	float last_x=v[clip].x, last_y=v[clip].y;
 	for (int vert=v[clip].next; vert; vert=v[vert].next) {
 		float x=v[vert].x, y=v[vert].y;
+		if (v[vert].is_intersection) {
+			float cx, cy;
+			gm->poly_center(v[v[vert].neighbor].first, &cx, &cy);
+			x = (1.0-contraction)*x + contraction*cx;
+			y = (1.0-contraction)*y + contraction*cy;
+		}
 		glVertex2f(last_x,last_y);
 		glVertex2f(x,y);
 		last_x=x; last_y=y;
@@ -93,7 +100,14 @@ void GLUT_display(){
 	glColor3f(1,0,0);
 	bool first_iter = true;
 	for (int vert=clip; vert; vert=v[vert].next) {
-		glVertex2f(v[vert].x,v[vert].y);
+		float x=v[vert].x, y=v[vert].y;
+		if (v[vert].is_intersection) {
+			float cx, cy;
+			gm->poly_center(v[v[vert].neighbor].first, &cx, &cy);
+			x = (1.0-contraction)*x + contraction*cx;
+			y = (1.0-contraction)*y + contraction*cy;
+		}
+		glVertex2f(x,y);
 		if (!first_iter && vert==clip) break;
 		first_iter = false;
 	}
@@ -102,7 +116,7 @@ void GLUT_display(){
 	// Draw Subject polygon lines & verts
 	for (int i=0; i<gm->nx; i++) {
 		for (int j=0; j<gm->ny; j++) {
-			gm->poly_draw(gm->poly_for_cell(i,j), .04);
+			gm->poly_draw(gm->poly_for_cell(i,j), contraction);
 		}
 	}




More information about the Bf-blender-cvs mailing list