[Bf-blender-cvs] [c5644bc] soc-2014-nurbs: Timing code (TODO: REMOVE, it's platform-specific), reorganization of coords (now stored apart from verts) for compatibility with tess code.

Jonathan deWerd noreply at git.blender.org
Sat Jul 12 09:24:36 CEST 2014


Commit: c5644bc7666f38f30a6442a91ceaa5b3276dede5
Author: Jonathan deWerd
Date:   Wed Jul 9 22:44:02 2014 -0400
https://developer.blender.org/rBc5644bc7666f38f30a6442a91ceaa5b3276dede5

Timing code (TODO: REMOVE, it's platform-specific), reorganization of coords (now stored apart from verts) for compatibility with tess code.

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

M	source/blender/blenkernel/intern/displist.c
M	source/blender/editors/curve/CMakeLists.txt
M	source/blender/editors/curve/GridMesh.cpp
M	source/blender/editors/curve/GridMesh.h
M	source/blender/editors/curve/GridMesh_GLUT_debug_tool.cpp
A	source/blender/editors/curve/surf_tess.cpp
A	source/blender/editors/curve/surf_tess.h
M	source/blender/editors/io/io_rhino_import.cpp

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

diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index cf894e7..1997a9d 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -63,6 +63,10 @@
 
 #include "BLI_sys_types.h" // for intptr_t support
 
+#include <CoreServices/CoreServices.h>
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+
 static void boundbox_displist_object(Object *ob);
 
 void BKE_displist_elem_free(DispList *dl)
@@ -1197,6 +1201,7 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
 	DispList *dl;
 	float *data;
 	int len;
+	uint64_t timer_start = mach_absolute_time();
 
 	if (!for_render && cu->editnurb) {
 		BKE_nurbList_duplicate(&nubase, BKE_curve_editNurbs_get(cu));
@@ -1246,7 +1251,7 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
 
 				dl = MEM_callocN(sizeof(DispList), "makeDispListsurf");
 				dl->verts = MEM_mallocN(len * sizeof(float[3]), "dlverts");
-				BLI_addtail(dispbase, dl);
+				BLI_addtail(dispbase, dl); // <----- WHERE MESH GETS OUTPUTTED TO CALLER
 
 				dl->col = nu->mat_nr;
 				dl->charidx = nu->charidx;
@@ -1276,6 +1281,10 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
 		                          for_render, use_render_resolution);
 	}
 
+	uint64_t timer_stop = mach_absolute_time();
+	int t = timer_stop-timer_start;
+	nu = nubase.first;
+	printf("%i %i %i %i\n",len,nu->pntsu*nu->resolu,nu->pntsv*nu->resolv,t);
 	BKE_nurbList_free(&nubase);
 }
 
diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt
index 0b449c4..30781ca 100644
--- a/source/blender/editors/curve/CMakeLists.txt
+++ b/source/blender/editors/curve/CMakeLists.txt
@@ -39,8 +39,10 @@ set(SRC
 	editcurve_add.c
 	editfont.c
 	lorem.c
+	surf_tess.cpp
 
 	curve_intern.h
+	surf_tess.h
 )
 
 if(WITH_INTERNATIONAL)
diff --git a/source/blender/editors/curve/GridMesh.cpp b/source/blender/editors/curve/GridMesh.cpp
index 8056c5e..1cbf727 100644
--- a/source/blender/editors/curve/GridMesh.cpp
+++ b/source/blender/editors/curve/GridMesh.cpp
@@ -63,50 +63,58 @@ void GridMesh::set_ll_ur(double lowerleft_x, double lowerleft_y,
 	inv_dy = 1.0/dy;
 }
 
+GridMeshVert::GridMeshVert() :	next(0), prev(0),
+								next_poly(0), neighbor(0), first(0),
+								is_intersection(false), is_interior(true), is_entry(false),
+								is_used(false), corner(0), tmp(0), is_pristine(0),
+								owns_coords(0), coord_idx(0)
+{}
+
 GridMesh::GridMesh(double lowerleft_x, double lowerleft_y,
 				   double upperright_x, double upperright_y,
 				   int num_x_cells, int num_y_cells) {
 	nx = num_x_cells; ny = num_y_cells;
 	set_ll_ur(lowerleft_x, lowerleft_y, upperright_x, upperright_y);
-	v_capacity = nx*ny*4 + 256;
-	v_count = nx*ny*4+1;
-	v = (GreinerV2f*)malloc(sizeof(GreinerV2f)*v_capacity);
-	new (v) GreinerV2f();
-	v->x = v->y = -1234;
+	coords.resize((nx+1)*(ny+1)*2);
+	for (int j=0; j<ny+1; j++) {
+		for (int i=0; i<nx+1; i++) {
+			GridMeshCoord& c = coords[gridpt_for_cell(i,j)];
+			c.x = llx + i*dx;
+			c.y = lly + j*dy;
+			c.z = 0;
+		}
+	}
+	v.resize(nx*ny*4*2);
+	ie_grid.resize(nx*ny+1,false);
+	ie_isect_right.resize(nx*ny+1,false);
+	ie_isect_up.resize(nx*ny+1,false);
+	vert_set_coord(0, -1234, -1234, -1234);
 	for (int j=0; j<ny; j++) {
-		double b = lly + j*dy;
-		double t = (j==ny-1)? ury : lly + (j+1)*dy;
 		for (int i=0; i<nx; i++) {
-			double l = llx + i*dx;
-			double r = (i==nx-1)? urx : llx + (i+1)*dx;
-			GreinerV2f *v1 = &v[poly_for_cell(i, j)];
-			GreinerV2f *v2 = v1+1;
-			GreinerV2f *v3 = v1+2;
-			GreinerV2f *v4 = v1+3;
-			new (v1) GreinerV2f(); v1->x=l; v1->y=b;
-			new (v2) GreinerV2f(); v2->x=r; v2->y=b;
-			new (v3) GreinerV2f(); v3->x=r; v3->y=t;
-			new (v4) GreinerV2f(); v4->x=l; v4->y=t;
-			int iv1 = vert_id(v1);
-			int iv2 = iv1+1;
-			int iv3 = iv1+2;                                 // 13   + 1
-			int iv4 = iv1+3;                                 // 02
+			int iv1=poly_for_cell(i, j), iv1c=gridpt_for_cell(i, j);
+			int iv2=iv1+1, iv2c=iv1c+1;
+			int iv3=iv1+2, iv3c=iv1c+nx+2;
+			int iv4=iv1+3, iv4c=iv1c+nx+1;
+			GridMeshVert *v1 = &v[iv1];
+			GridMeshVert *v2 = v1+1;
+			GridMeshVert *v3 = v1+2;
+			GridMeshVert *v4 = v1+3;
+			v1->coord_idx = iv1c;
+			v2->coord_idx = iv2c;
+			v3->coord_idx = iv3c;
+			v4->coord_idx = iv4c;
 			v1->next = iv2; v2->prev = iv1; v1->first = iv1; v1->corner = 1;
 			v2->next = iv3; v3->prev = iv2; v2->first = iv1; v2->corner = 3;
 			v3->next = iv4; v4->prev = iv3; v3->first = iv1; v3->corner = 4;
 			v4->next = iv1; v1->prev = iv4; v4->first = iv1; v4->corner = 2;
+			v1->is_pristine = 1;
 		}
 	}
 }
 
 int GridMesh::vert_new() {
-	if (v_count>=v_capacity) {
-		long newcap = v_capacity*2;
-		v = (GreinerV2f*)realloc(v, newcap*sizeof(GreinerV2f));
-		v_capacity = newcap;
-	}
-	new (v+v_count) GreinerV2f();
-	return int(v_count++);
+	v.push_back(GridMeshVert());
+	return int(v.size()-1);
 }
 
 int GridMesh::vert_new(int prev, int next) {
@@ -124,6 +132,43 @@ int GridMesh::vert_new(int prev, int next) {
 	return ret;
 }
 
+int GridMesh::vert_dup(int vert) {
+	int ret = vert_new();
+	new (&v[ret]) GridMeshVert(v[vert]);
+	return ret;
+}
+
+void GridMesh::vert_set_coord(int vert, double x, double y, double z) {
+	if (v[vert].owns_coords) {
+		GridMeshCoord& xyz = coords[v[vert].coord_idx];
+		xyz.x=x; xyz.y=y; xyz.z=z;
+		return;
+	}
+	coords.push_back(GridMeshCoord(x,y,z));
+	v[vert].coord_idx = int(coords.size()-1);
+	v[vert].owns_coords = 1;
+}
+
+void GridMesh::vert_get_coord(int vert, double* xyz) {
+	GridMeshCoord *gmc = &coords[v[vert].coord_idx];
+	xyz[0] = gmc->x;
+	xyz[1] = gmc->y;
+	xyz[2] = gmc->z;
+}
+
+
+int GridMesh::poly_new(const std::vector<float>& packed_coords) {
+	size_t num_verts = packed_coords.size()/2;
+	int last=0, first=0;
+	for (int i=0; i<num_verts; i++) {
+		int vert = vert_new(last,0);
+		if (!first) first=vert;
+		v[vert].first = first;
+		vert_set_coord(vert, packed_coords[2*i+0], packed_coords[2*i+1], 0);
+		last = vert;
+	}
+	return first;
+}
 
 int GridMesh::poly_first_vert(int vert) {
 	int v2 = vert;
@@ -162,6 +207,12 @@ void GridMesh::poly_set_cyclic(int poly, bool cyc) {
 	}
 }
 
+int GridMesh::gridpt_for_cell(int x, int y) {
+	if (x<0||x>=nx+1) return 0;
+	if (y<0||y>=ny+1) return 0;
+	return 1+(y*(nx+1)+x);
+}
+
 int GridMesh::poly_for_cell(int x, int y) {
 	if (x<0||x>=nx) return 0;
 	if (y<0||y>=ny) return 0;
@@ -191,7 +242,8 @@ int GridMesh::poly_num_edges(int poly) {
 int GridMesh::poly_vert_at(int anyvert, float x, float y) {
 	bool first_iter = true;
 	for(int vert = poly_first_vert(anyvert); vert; vert=v[vert].next) {
-		if (fabs(x-v[vert].x)+fabs(y-v[vert].y)<tolerance) return vert;
+		double vc[3];
+		if (fabs(x-vc[0])+fabs(y-vc[1])<tolerance) return vert;
 		if (first_iter) {
 			first_iter = false;
 		} else {
@@ -250,12 +302,12 @@ void GridMesh::poly_grid_BB(int poly, int *bb) { //int bb[4] = {minx,maxx,miny,m
 	float minx=std::numeric_limits<float>::max(), maxx=std::numeric_limits<float>::min();
 	float miny=std::numeric_limits<float>::max(), maxy=std::numeric_limits<float>::min();
 	do {
-		GreinerV2f& g = v[vert];
-		minx = fmin(g.x,minx);
-		maxx = fmax(g.x,maxx);
-		miny = fmin(g.y,miny);
-		maxy = fmax(g.y,maxy);
-		vert = g.next;
+		double xyz[3]; vert_get_coord(vert, xyz);
+		minx = fmin(xyz[0],minx);
+		maxx = fmax(xyz[0],maxx);
+		miny = fmin(xyz[1],miny);
+		maxy = fmax(xyz[1],maxy);
+		vert = v[vert].next;
 	} while (vert && vert!=first);
 	bb[0] = xs_FloorToInt((minx-llx)*inv_dx);
 	bb[1] = xs_FloorToInt((maxx-llx)*inv_dx);
@@ -283,8 +335,9 @@ void GridMesh::poly_center(int poly, float *cx, float *cy) {
 	double sum_x=0, sum_y=0;
 	int n=0;
 	do {
-		sum_x += v[vert].x;
-		sum_y += v[vert].y;
+		double xyz[3]; vert_get_coord(vert, xyz);
+		sum_x += xyz[0];
+		sum_y += xyz[1];
 		n += 1;
 		vert = v[vert].next;
 	} while (vert && vert!=poly && vert!=v[poly].first);
@@ -320,8 +373,10 @@ void GridMesh::poly_draw(int poly, float shrinkby, int maxedges) {
 		do {
 			int v2 = v[v1].next;
 			NURBS_TESS_PRINTF("%i-%i, ",v1,v2);
-			glVertex2f((1-shrinkby)*v[v1].x+shrinkby*cx, (1-shrinkby)*v[v1].y+shrinkby*cy);
-			glVertex2f((1-shrinkby)*v[v2].x+shrinkby*cx, (1-shrinkby)*v[v2].y+shrinkby*cy);
+			double v1xyz[3]; vert_get_coord(v1, v1xyz);
+			double v2xyz[3]; vert_get_coord(v2, v2xyz);
+			glVertex2f((1-shrinkby)*v1xyz[0]+shrinkby*cx, (1-shrinkby)*v1xyz[1]+shrinkby*cy);
+			glVertex2f((1-shrinkby)*v2xyz[0]+shrinkby*cx, (1-shrinkby)*v2xyz[1]+shrinkby*cy);
 			++num_drawn_edges;
 			if (maxedges && num_drawn_edges>=maxedges)
 				break;
@@ -340,7 +395,8 @@ void GridMesh::poly_draw(int poly, float shrinkby, int maxedges) {
 			} else {
 				glColor3ub(0,0,255);
 			}
-			float x=v[v1].x, y=v[v1].y;
+			double v1xyz[3]; vert_get_coord(v1, v1xyz);
+			float x=v1xyz[0], y=v1xyz[1];
 			float cx, cy; poly_center(v[v1].first, &cx, &cy);
 			x = (1.0-shrinkby)*x + shrinkby*cx;
 			y = (1.0-shrinkby)*y + shrinkby*cy;
@@ -465,14 +521,12 @@ int GridMesh::insert_vert(int poly1left,
 						  ) {
 	// Insert an intersection vertex into polygon 1
 	int newv1 = vert_new(poly1left,poly1right);
-	v[newv1].x = x1;
-	v[newv1].y = y1;
+	vert_set_coord(newv1, x1, y1, 0);
 	v[newv1].is_intersection = true;
 	
 	// Insert an intersection vertex into polygon 2
 	int newv2 = vert_new(poly2left,poly2right);
-	v[newv2].x = x1;
-	v[newv2].y = y1;
+	vert_set_coord(newv2, x1, y1, 0);
 	v[newv2].is_intersection = true;
 	
 	// Tell the intersection vertices that they're stacked on top of one another
@@ -487,12 +541,12 @@ void GridMesh::bool_AND(int poly2) {
 	poly_grid_BB(poly2, bb);
 	int num_v, num_e; insert_vert_poly_gridmesh(poly2, &num_v, &num_e);
 	bool add_poly_after_end = false;
+	double p2xyz[3]; vert_get_coord(poly2, p2xyz);
 	if (num_v==0 && num_e==0) {
-		int p = poly_for_cell(v[poly2].x, v[poly2].y);
+		int p = poly_for_cell((float)p2xyz[0], (float)p2xyz[1]);
 		if (p) {
-			double p2x=v[poly2].x, p2y=v[poly2].y;
 			for (int subpoly=p; subpoly; subpoly=v[subpoly].next_poly) {
-				if (point_in_polygon(p2x, p2y, subpoly)) {
+				if (point_in_polygon(p2xyz[0], 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list