[Bf-blender-cvs] [d74da65] soc-2014-nurbs: Interior label propagation
Jonathan deWerd
noreply at git.blender.org
Fri Jun 27 08:14:49 CEST 2014
Commit: d74da659ed2b6165ce9cfe172a28bce15be79eb2
Author: Jonathan deWerd
Date: Thu Jun 26 13:33:54 2014 -0400
https://developer.blender.org/rBd74da659ed2b6165ce9cfe172a28bce15be79eb2
Interior label propagation
===================================================================
M PolyTest/GridMesh.cpp
M PolyTest/GridMesh.h
M PolyTest/GridMesh_demo.cpp
===================================================================
diff --git a/PolyTest/GridMesh.cpp b/PolyTest/GridMesh.cpp
index 1c95ca5..fb820fd 100644
--- a/PolyTest/GridMesh.cpp
+++ b/PolyTest/GridMesh.cpp
@@ -55,10 +55,10 @@ GridMesh::GridMesh(double lowerleft_x, double lowerleft_y,
int iv2 = iv1+1;
int iv3 = iv1+2;
int iv4 = iv1+3;
- v1->next = iv2; v2->prev = iv1; v1->first = iv1;
- v2->next = iv3; v3->prev = iv2; v2->first = iv1;
- v3->next = iv4; v4->prev = iv3; v3->first = iv1;
- v4->next = iv1; v1->prev = iv4; v4->first = iv1;
+ v1->next = iv2; v2->prev = iv1; v1->first = iv1; v1->corner = 1;
+ v2->next = iv3; v3->prev = iv2; v2->first = iv1; v2->corner = 2;
+ v3->next = iv4; v4->prev = iv3; v3->first = iv1; v3->corner = 3;
+ v4->next = iv1; v1->prev = iv4; v4->first = iv1; v4->corner = 4;
}
}
}
@@ -250,9 +250,14 @@ void GridMesh::poly_draw(int poly, float shrinkby) {
// Draw the polygon verts
glPointSize(3);
glBegin(GL_POINTS);
- glColor3b(color.r, color.g, color.b);
+ glColor3ub(color.r, color.g, color.b);
v1 = poly;
do {
+ if (v[v1].is_interior) {
+ glColor3ub(255,255,0);
+ } else {
+ glColor3ub(0,0,255);
+ }
glVertex2f(v[v1].x, v[v1].y);
v1 = v[v1].next;
} while (v1 != poly);
@@ -371,14 +376,12 @@ int GridMesh::insert_vert(int poly1left,
double x1, double y1
) {
// Insert an intersection vertex into polygon 1
- printf("Insert vert into poly1: %i %i\n",poly1left,poly1right);
int newv1 = vert_new(poly1left,poly1right);
v[newv1].x = x1;
v[newv1].y = y1;
v[newv1].is_intersection = true;
// Insert an intersection vertex into polygon 2
- printf("Insert vert into poly2: %i %i\n",poly2left,poly2right);
int newv2 = vert_new(poly2left,poly2right);
v[newv2].x = x1;
v[newv2].y = y1;
@@ -438,6 +441,34 @@ int GridMesh::insert_vert_poly_gridmesh(int mpoly) {
return verts_added;
}
+void GridMesh::label_interior_cell(int x, int y, int poly, bool ll, bool *lr, bool*ul) {
+ int cell = poly_for_cell(x,y);
+ bool interior = ll;
+ bool first_is_interior = interior;
+ int vert = cell;
+ do {
+ v[vert].is_interior = interior;
+ if (v[vert].corner==2&&lr) *lr = interior;
+ if (v[vert].corner==4&&ul) *ul = interior;
+ if (v[vert].is_intersection) interior = !interior;
+ vert = v[vert].next;
+ } while (vert!=cell);
+ if (!interior==first_is_interior&&debug) {
+ printf("inconsistent interior call!\n");
+ }
+}
+
+void GridMesh::label_interior(int poly) {
+ bool ll_next_row = point_in_polygon(0, 0, poly);
+ for (int j=0; j<ny; j++) {
+ bool ll;
+ label_interior_cell(0, j, poly, ll_next_row, &ll, &ll_next_row);
+ for (int i=1; i<nx; i++) {
+ label_interior_cell(i, j, poly, ll, &ll, nullptr);
+ }
+ }
+}
+
std::vector<IntersectingEdge> GridMesh::edge_poly_intersections(int e1, int p) {
std::vector<IntersectingEdge> ret;
bool first_iter = true;
diff --git a/PolyTest/GridMesh.h b/PolyTest/GridMesh.h
index 221a8fa..c808c97 100644
--- a/PolyTest/GridMesh.h
+++ b/PolyTest/GridMesh.h
@@ -25,11 +25,12 @@ struct GreinerV2f {
bool is_intersection; // True if this vertex was added at an intersection
bool is_interior;
bool is_trivial; // True if this polygon has four vertices corresponding precisely to its cell bounds
+ char corner; // 1=ll, 2=lr, 3=ur, 4=ul, 0 = none
int neighbor; // Corresp. vertex at same {x,y} in different polygon
GreinerV2f() : next(0), prev(0),
next_poly(0), neighbor(0), first(0),
- is_intersection(false) {};
+ is_intersection(false), corner(0) {};
};
struct IntersectingEdge {
@@ -75,6 +76,8 @@ struct GridMesh {
// Intersection
bool point_in_polygon(double x, double y, int poly);
int insert_vert_poly_gridmesh(int poly); // Returns # of vertices inserted.
+ void label_interior(int poly);
+ void label_interior_cell(int x, int y, int poly, bool ll, bool *lr, bool*ul);
std::vector<IntersectingEdge> edge_poly_intersections(int e1, int p);
int insert_vert(int poly1left,
int poly1right,
diff --git a/PolyTest/GridMesh_demo.cpp b/PolyTest/GridMesh_demo.cpp
index f5aa464..f364704 100644
--- a/PolyTest/GridMesh_demo.cpp
+++ b/PolyTest/GridMesh_demo.cpp
@@ -222,6 +222,10 @@ void GLUT_keyboard(unsigned char ch, int x, int y ) {
gm->insert_vert_poly_gridmesh(clip);
glutPostRedisplay();
}
+ if (ch=='t') {
+ gm->label_interior(clip);
+ glutPostRedisplay();
+ }
if (ch=='1') toggle_cyclic(clip);
if (ch==GLUT_KEY_DELETE) delete_last_selected_vert();
}
More information about the Bf-blender-cvs
mailing list