Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan deWerd <jjoonathan@gmail.com>2014-07-13 02:58:47 +0400
committerJonathan deWerd <jjoonathan@gmail.com>2014-07-13 02:58:47 +0400
commitdbf2f19b355605586f87ac05909b89c7fb772675 (patch)
treee4926858499068bd487e6227cbf0cb7edd25c233
parente8e3bab45b7e079818f5c97f995c5888bad2b14a (diff)
NURBS pushforward (U,V)->(x,y,z) works properly
-rw-r--r--source/blender/blenkernel/BKE_curve.h3
-rw-r--r--source/blender/blenkernel/intern/curve.cpp104
-rw-r--r--source/blender/blenkernel/intern/displist.c3
-rw-r--r--source/blender/blenkernel/intern/surf_gridmesh.cpp60
-rw-r--r--source/blender/blenkernel/intern/surf_gridmesh.h7
-rw-r--r--source/blender/blenlib/intern/polyfill2d.c2
-rw-r--r--tests/interactive/nurbs_trimtess.cpp94
7 files changed, 175 insertions, 98 deletions
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index d51505931ef..e40ed009493 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -45,6 +45,7 @@ struct Scene;
struct Path;
struct TextBox;
struct rctf;
+struct DispList;
typedef struct CurveCache {
ListBase disp;
@@ -180,6 +181,6 @@ void BKE_nurb_handles_test(struct Nurb *nu, const bool use_handles);
/* Does not traverse nu's linked list. Fills dl with a mesh corresponding to
* the single surface nu, performing trim if necessary.
*/
-void BKE_nurb_make_displist(struct Nurb *nurb, struct DispList *dl, int nu, int nv);
+void BKE_nurb_make_displist(struct Nurb *nurb, struct DispList *dl);
#endif /* __BKE_CURVE_H__ */
diff --git a/source/blender/blenkernel/intern/curve.cpp b/source/blender/blenkernel/intern/curve.cpp
index a85d9c4f982..065fc1defad 100644
--- a/source/blender/blenkernel/intern/curve.cpp
+++ b/source/blender/blenkernel/intern/curve.cpp
@@ -4252,12 +4252,14 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *t
r_rect->ymin = r_rect->ymax - tb->h;
}
-void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl, int totu, int totv) {
+float subj0[] = {0.512000,0.938000, 0.374000,0.950000, 0.248000,0.908000, 0.170000,0.866000, 0.092000,0.740000, 0.092000,0.602000, 0.092000,0.440000, 0.116000,0.260000, 0.254000,0.110000, 0.476000,0.074000, 0.746000,0.092000, 0.836000,0.206000, 0.848000,0.422000, 0.812000,0.644000, 0.716000,0.686000, 0.614000,0.734000, 0.488000,0.728000, 0.386000,0.710000, 0.260000,0.626000, 0.272000,0.476000, 0.350000,0.338000, 0.482000,0.278000, 0.632000,0.308000, 0.644000,0.404000, 0.638000,0.494000, 0.590000,0.572000, 0.494000,0.584000, 0.422000,0.518000, 0.458000,0.392000, 0.548000,0.398000, 0.506000,0.506000, 0.572000,0.506000, 0.596000,0.386000, 0.566000,0.338000, 0.470000,0.338000, 0.368000,0.434000, 0.374000,0.608000, 0.578000,0.656000, 0.680000,0.644000, 0.740000,0.554000, 0.782000,0.308000, 0.758000,0.224000, 0.548000,0.164000, 0.338000,0.224000, 0.212000,0.374000, 0.170000,0.626000, 0.236000,0.764000, 0.368000,0.824000, 0.524000,0.836000, 1.184000,0.848000}; int subj0_nv=50;
+void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl) {
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
dl->rt = nu->flag & ~CU_2D;
// Figure out the domain
+ int totu=(nu->pntsu-nu->orderu+1)*nu->resolu, totv=(nu->pntsv-nu->orderv+1)*nu->resolv;
float ustart = nu->knotsu[nu->orderu - 1];
float uend;
if (nu->flagu & CU_NURB_CYCLIC)
@@ -4274,19 +4276,24 @@ void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl, int totu, int
// Trim the uniform grid in 2D UV space
GridMesh *gm = new GridMesh();
int coords_len = (totu+1)*(totv+1)*2;
- float *coords = (float*)MEM_mallocN(coords_len * sizeof(float[3]), "dlcoords");
- gm->coords_import((GridMeshCoord*)coords, coords_len);
+ GridMeshCoord *coords = (GridMeshCoord*)MEM_mallocN(coords_len * sizeof(GridMeshCoord), "NURBS_tess_1");
+ gm->mallocN = MEM_mallocN;
+ gm->reallocN = MEM_reallocN_id;
+ gm->coords_import(coords, coords_len);
gm->set_ll_ur(ustart,vstart,uend,vend);
gm->init_grid(totu,totv);
+ int s0poly = gm->poly_new(subj0, subj0_nv*2);
+ gm->bool_SUB(s0poly);
// Extract the results
- dl->verts = coords = (float*)gm->coords_export(NULL);
- int idxs_len = 2 * 6*sizeof(int)*totu*totv;
- int *idxs = (int*)MEM_mallocN(idxs_len, "index array nurbs");
+ coords = gm->coords_export(&coords_len);
+ int idxs_len = 4 * 3*sizeof(int)*totu*totv;
+ int *idxs = (int*)MEM_mallocN(sizeof(int)*idxs_len, "NURBS_tess_2.0");
int ii=0; // Index index
#define TESS_MAX_POLY_VERTS 32
- float *coords_tmp[TESS_MAX_POLY_VERTS];
- int *idx_tmp[TESS_MAX_POLY_VERTS];
+ float (*coords_tmp)[2] = (float(*)[2])MEM_mallocN(sizeof(*coords_tmp)*TESS_MAX_POLY_VERTS,"NURBS_tess_3");
+ int reindex_tmp[TESS_MAX_POLY_VERTS];
+ unsigned (*idx_tmp)[3] = (unsigned(*)[3])MEM_mallocN(sizeof(*idx_tmp)*TESS_MAX_POLY_VERTS,"NURBS_tess_4");
for (int j=0; j<totv; j++) {
for (int i=0; i<totu; i++) {
int cell = gm->poly_for_cell(i, j);
@@ -4295,6 +4302,11 @@ void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl, int totu, int
if (!v[poly].next) continue;
if (v[poly].is_pristine) {
int ll_gp = gm->gridpt_for_cell(i, j);
+ if (ii+6>=idxs_len) {
+ //printf("1Growing idxs %i to %i\n",idxs_len,idxs_len*2);
+ idxs_len *= 2;
+ idxs = (int*)MEM_reallocN_id(idxs, sizeof(int)*idxs_len, "NURBS_tess_2.1");
+ }
idxs[ii++] = ll_gp;
idxs[ii++] = ll_gp+1;
idxs[ii++] = ll_gp+(totu+1)+1;
@@ -4302,29 +4314,79 @@ void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl, int totu, int
idxs[ii++] = ll_gp+(totu+1);
idxs[ii++] = ll_gp;
} else {
- int coords_tot=0;
- for (int vert=poly; vert!=poly; vert=v[poly].next) {
- coords_tmp[coords_tot] = &coords[v[poly].coord_idx];
- idx_tmp[coords_tot] = &idxs[ii];
- ii += 3;
- coords_tot++;
- }
- ii-=6; // n vert polygon has n-2 tris in triangulation
- BLI_polyfill_calc((float(*)[2])coords_tmp,
- coords_tot,
+ int num_verts=0; int vert=poly;
+ do {
+ int idx = v[vert].coord_idx;
+ GridMeshCoord& crd = coords[idx];
+ coords_tmp[num_verts][0] = crd.x;
+ coords_tmp[num_verts][1] = crd.y;
+ reindex_tmp[num_verts] = idx;
+ num_verts++;
+ vert=v[vert].next;
+ if (num_verts>=TESS_MAX_POLY_VERTS) {
+ printf("WARNING: maximum tessellation polygon verts (%i) exceeded. %i<-%i->%i\n",TESS_MAX_POLY_VERTS,v[vert].prev,vert,v[vert].next);
+ break;
+ }
+ } while (vert!=poly);
+ BLI_polyfill_calc(coords_tmp,
+ num_verts,
0, // tell polyfill to do concave check
- (unsigned int(*)[3])idx_tmp);
+ idx_tmp);
+ if (ii+(num_verts-2)*3>=idxs_len) {
+ int new_idxlen = idxs_len*2 + (num_verts-2)*3;
+ //printf("2Growing idxs %i to %i\n",idxs_len,new_idxlen);
+ idxs = (int*)MEM_reallocN_id(idxs, sizeof(int)*new_idxlen, "NURBS_tess_2.2");
+ idxs_len = new_idxlen;
+ }
+ for (int z=0; z<num_verts-2; z++) {
+ idxs[ii++] = reindex_tmp[idx_tmp[z][0]];
+ idxs[ii++] = reindex_tmp[idx_tmp[z][1]];
+ idxs[ii++] = reindex_tmp[idx_tmp[z][2]];
+ }
}
}
}
}
- dl->verts = coords;
+ dl->verts = (float*)coords;
dl->index = idxs;
+ dl->nors = NULL;
dl->type = DL_INDEX3;
dl->parts = ii/3;
+ dl->nr = ii;
// Pushforward through the NURBS map
- //gm->pushforward(nu);
+ int NknotU=KNOTSU(nu), NknotV=KNOTSV(nu);
+ float *basisu = (float*)MEM_mallocN(sizeof(float)*(NknotU+NknotV),"NURBS_tess_5");
+ float *basisv = basisu+NknotU;
+ int startu,endu, startv,endv;
+ int orderu=nu->orderu, orderv=nu->orderv, pntsu=nu->pntsu, pntsv=nu->pntsv;
+ float *knotsu=nu->knotsu, *knotsv=nu->knotsv;
+ int coord=1;
+ float cached_v=0.0/0.0;
+ for (; coord<coords_len; coord++) {
+ float *xyz = (float*)&coords[coord];
+ // Right now xyz = {u,v,0.0}. Apply the NURBS map to transform it to {x,y,z}
+ if (xyz[1]!=cached_v) {
+ basisNurb(xyz[1], orderv, pntsv, knotsv, basisv, &startv, &endv);
+ cached_v = xyz[1];
+ }
+ basisNurb(xyz[0], orderu, pntsu, knotsu, basisu, &startu, &endu);
+ float accum[3] = {0,0,0};
+ for (int vi=startv; vi<=endv; vi++) {
+ for (int ui=startu; ui<=endu; ui++) {
+ float uweight=basisu[ui], vweight=basisv[vi];
+ float wcp[3]; mul_v3_v3fl(wcp, nu->bp[ui+pntsu*vi].vec, uweight*vweight);
+ add_v3_v3(accum, wcp);
+ }
+ }
+ copy_v3_v3(xyz,accum);
+ }
+ // Cleanup
+ //MEM_freeN(coords);
+ //MEM_freeN(idxs);
+ MEM_freeN(coords_tmp);
+ MEM_freeN(idx_tmp);
+ MEM_freeN(basisu);
delete gm;
}
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 137709d1363..55b8ae57c61 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1249,8 +1249,7 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
else {
dl = MEM_callocN(sizeof(DispList), "makeDispListsurf");
BLI_addtail(dispbase, dl);
- int totu = nu->pntsu * resolu, totv = nu->pntsv * resolv;
- BKE_nurb_make_displist(nu, dl, totu, totv);
+ BKE_nurb_make_displist(nu, dl);
}
}
}
diff --git a/source/blender/blenkernel/intern/surf_gridmesh.cpp b/source/blender/blenkernel/intern/surf_gridmesh.cpp
index b280e552784..cfd7caefa19 100644
--- a/source/blender/blenkernel/intern/surf_gridmesh.cpp
+++ b/source/blender/blenkernel/intern/surf_gridmesh.cpp
@@ -61,6 +61,8 @@ GridMeshVert::GridMeshVert() : next(0), prev(0),
GridMesh::GridMesh() {
coords = NULL;
coords_len = coords_reserved_len = 0;
+ mallocN = NULL;
+ reallocN = NULL;
}
GridMesh::~GridMesh() {
@@ -69,12 +71,19 @@ GridMesh::~GridMesh() {
void GridMesh::coords_reserve(int new_reserved_len) {
if (coords_reserved_len>=new_reserved_len) return;
+ new_reserved_len *= 2;
if (!coords) {
- coords = (GridMeshCoord*)malloc(sizeof(*coords)*new_reserved_len);
- coords_reserved_len = new_reserved_len;
+ if (mallocN)
+ coords = (GridMeshCoord*)mallocN(sizeof(*coords)*new_reserved_len,"NURBS_gridmesh");
+ else
+ coords = (GridMeshCoord*)malloc(sizeof(*coords)*new_reserved_len);
} else if (coords_reserved_len<new_reserved_len){
- coords = (GridMeshCoord*)realloc(coords, sizeof(*coords)*new_reserved_len);
+ if (reallocN)
+ coords = (GridMeshCoord*)reallocN(coords, sizeof(*coords)*new_reserved_len, "NURBS_gridmesh");
+ else
+ coords = (GridMeshCoord*)realloc(coords, sizeof(*coords)*new_reserved_len);
}
+ coords_reserved_len = new_reserved_len;
}
void GridMesh::coords_import(GridMeshCoord *c, int len) {
@@ -94,26 +103,28 @@ void GridMesh::set_ll_ur(double lowerleft_x, double lowerleft_y,
double upperright_x, double upperright_y) {
llx = lowerleft_x; lly = lowerleft_y;
urx = upperright_x; ury = upperright_y;
+}
+
+void GridMesh::init_grid(int num_x_cells, int num_y_cells) {
+ nx = num_x_cells; ny = num_y_cells;
double Dx = urx-llx;
double Dy = ury-lly;
dx = Dx/nx;
dy = Dy/ny;
inv_dx = 1.0/dx;
inv_dy = 1.0/dy;
-}
-void GridMesh::init_grid(int num_x_cells, int num_y_cells) {
- nx = num_x_cells; ny = num_y_cells;
int num_coords = (nx+1)*(ny+1)*2+1;
coords_reserve(num_coords);
- for (int j=0; j<ny+1; j++) {
- for (int i=0; i<nx+1; i++) {
+ for (int j=0; j<=ny; j++) {
+ for (int i=0; i<=nx; i++) {
GridMeshCoord& c = coords[gridpt_for_cell(i,j)];
c.x = llx + i*dx;
c.y = lly + j*dy;
c.z = 0;
}
}
+ coords_len = (1+nx)*(1+ny)+1;
v.resize(nx*ny*4*2);
ie_grid.resize(nx*ny+1,false);
ie_isect_right.resize(nx*ny+1,false);
@@ -175,9 +186,9 @@ void GridMesh::vert_set_coord(int vert, double x, double y, double z) {
return;
}
int idx = coords_len;
- coords_reserve(coords_len++);
- GridMeshCoord& xyz = coords[idx];
- xyz.x=x; xyz.y=y; xyz.z=z;
+ coords_reserve(++coords_len);
+ GridMeshCoord *xyz = &coords[idx];
+ xyz->x=x; xyz->y=y; xyz->z=z;
v[vert].coord_idx = idx;
v[vert].owns_coords = 1;
}
@@ -190,8 +201,9 @@ void GridMesh::vert_get_coord(int vert, double* xyz) {
}
-int GridMesh::poly_new(const std::vector<float>& packed_coords) {
- size_t num_verts = packed_coords.size()/2;
+int GridMesh::poly_new(const float* packed_coords, int len) {
+ size_t num_verts = len/2;
+ if (!num_verts) return 0;
int last=0, first=0;
for (int i=0; i<num_verts; i++) {
int vert = vert_new(last,0);
@@ -200,6 +212,8 @@ int GridMesh::poly_new(const std::vector<float>& packed_coords) {
vert_set_coord(vert, packed_coords[2*i+0], packed_coords[2*i+1], 0);
last = vert;
}
+ v[first].prev = last;
+ v[last].next = first;
return first;
}
@@ -222,6 +236,12 @@ int GridMesh::poly_next(int anyvert) {
return v[poly_first_vert(anyvert)].next_poly;
}
+int GridMesh::poly_last(int poly) {
+ while (v[poly].next_poly) poly = v[poly].next_poly;
+ return poly;
+}
+
+
bool GridMesh::poly_is_cyclic(int poly) {
if (!v[poly].next) return false;
return bool(v[poly_first_vert(poly)].prev);
@@ -1124,18 +1144,18 @@ int line_line_intersection(double ax, double ay, // Line 1, vert 1 A
return true;
}
-// 1 0
-// v
-// 2 3
+// pi/2<=theta<pi 1 0 0<=theta<pi/2
+// v
+// pi<=theta<3pi/2 2 3 3pi/2<=theta<2pi
inline int quadrant(float x, float y, float vx, float vy) {
if (y>vy) { // Upper half-plane is easy
- return int(x<=vx);
- } else {
+ return x<=vx ? 1 : 0;
+ } else { // y<=vy
if (y<vy) { // So is lower half-plane
return 2+int(x>=vx);
- } else { //y==0
+ } else { // y==0
if (x>vx) return 0;
- else if (x<vx) return 0;
+ else if (x<vx) return 2;
return 99; // x==vx, y==vy
}
}
diff --git a/source/blender/blenkernel/intern/surf_gridmesh.h b/source/blender/blenkernel/intern/surf_gridmesh.h
index 42b29b377c5..2f5636bc2af 100644
--- a/source/blender/blenkernel/intern/surf_gridmesh.h
+++ b/source/blender/blenkernel/intern/surf_gridmesh.h
@@ -91,6 +91,10 @@ struct GridMesh {
std::vector<bool> ie_isect_right;
std::vector<bool> ie_isect_up;
+ // Permit usage of blender's memory management system
+ void* (*mallocN)(size_t sz, const char *name);
+ void* (*reallocN)(void *old, size_t sz, const char *name);
+
double llx, lly, urx, ury; // Coordinates of lower left and upper right grid corners
double dx, dy; // Width of a cell in the x, y directions
double inv_dx, inv_dy; // 1/(width of a cell), 1/(height of a cell)
@@ -115,7 +119,7 @@ struct GridMesh {
int gridpt_for_cell(int x, int y);
// Poly manipulation
- int poly_new(const std::vector<float>& packed_coords);
+ int poly_new(const float* packed_coords, int len);
int poly_for_cell(int x, int y);
int poly_for_cell(float x, float y);
int poly_first_vert(int anyvert);
@@ -123,6 +127,7 @@ struct GridMesh {
int poly_next(int anyvert);
int poly_vert_at(int anyvert, float x, float y);
int poly_num_edges(int poly);
+ int poly_last(int poly);
bool poly_is_cyclic(int poly);
void poly_set_cyclic(int poly, bool cyclic);
void poly_set_interior(int poly, bool interior);
diff --git a/source/blender/blenlib/intern/polyfill2d.c b/source/blender/blenlib/intern/polyfill2d.c
index 8c93b0766ee..c7189021603 100644
--- a/source/blender/blenlib/intern/polyfill2d.c
+++ b/source/blender/blenlib/intern/polyfill2d.c
@@ -906,7 +906,7 @@ void BLI_polyfill_calc(
const int coords_sign,
unsigned int (*r_tris)[3])
{
- PolyFill pf; printf(".");
+ PolyFill pf;
PolyIndex *indices = BLI_array_alloca(indices, coords_tot);
#ifdef DEBUG_TIME
diff --git a/tests/interactive/nurbs_trimtess.cpp b/tests/interactive/nurbs_trimtess.cpp
index ae24116585e..50b0ee7894e 100644
--- a/tests/interactive/nurbs_trimtess.cpp
+++ b/tests/interactive/nurbs_trimtess.cpp
@@ -68,11 +68,22 @@ bool subj_cyclic = true;
std::vector<float> clip_verts = {0.201000,0.201000, 4.436000,-0.268000, 4.460000,3.356000, 0.284000,4.292000};
std::vector<std::vector<float>> subj_polys = {};
std::vector<float> inout_pts = {};
-float gm_llx=0,gm_lly=0,gm_urx=4,gm_ury=4; // GridMesh params
-int gm_nx=20, gm_ny=30;
+float gm_llx=0,gm_lly=0,gm_urx=1,gm_ury=1; // GridMesh params
+int gm_nx=4, gm_ny=4;
#endif
#if defined(GRIDMESH_GEOM_TEST_5)
+bool clip_cyclic = true; // Required for initialization
+bool subj_cyclic = true;
+std::vector<float> clip_verts = {0.201000,0.201000, 4.436000,-0.268000, 4.460000,3.356000, 0.284000,4.292000};
+std::vector<float> subj0 = {0.512000,0.938000, 0.374000,0.950000, 0.248000,0.908000, 0.170000,0.866000, 0.092000,0.740000, 0.092000,0.602000, 0.092000,0.440000, 0.116000,0.260000, 0.254000,0.110000, 0.476000,0.074000, 0.746000,0.092000, 0.836000,0.206000, 0.848000,0.422000, 0.812000,0.644000, 0.716000,0.686000, 0.614000,0.734000, 0.488000,0.728000, 0.386000,0.710000, 0.260000,0.626000, 0.272000,0.476000, 0.350000,0.338000, 0.482000,0.278000, 0.632000,0.308000, 0.644000,0.404000, 0.638000,0.494000, 0.590000,0.572000, 0.494000,0.584000, 0.422000,0.518000, 0.458000,0.392000, 0.548000,0.398000, 0.506000,0.506000, 0.572000,0.506000, 0.596000,0.386000, 0.566000,0.338000, 0.470000,0.338000, 0.368000,0.434000, 0.374000,0.608000, 0.578000,0.656000, 0.680000,0.644000, 0.740000,0.554000, 0.782000,0.308000, 0.758000,0.224000, 0.548000,0.164000, 0.338000,0.224000, 0.212000,0.374000, 0.170000,0.626000, 0.236000,0.764000, 0.368000,0.824000, 0.524000,0.836000, 1.184000,0.848000};
+std::vector<std::vector<float>> subj_polys = {subj0};
+std::vector<float> inout_pts = {};
+float gm_llx=0,gm_lly=0,gm_urx=1,gm_ury=1; // GridMesh params
+int gm_nx=4, gm_ny=4;
+#endif
+
+#if defined(GRIDMESH_TIME_TEST)
// Use this for timing runs
bool clip_cyclic = true; // Required for initialization
bool subj_cyclic = true;
@@ -108,52 +119,20 @@ void glut_coords_2_scene(float gx, float gy, float* sx, float* sy) {
void init_default_scene() {
// Create the gridmesh
- gm = new GridMesh(gm_llx,gm_lly,gm_urx,gm_ury,gm_nx,gm_ny);
+ gm = new GridMesh();
+ gm->set_ll_ur(gm_llx,gm_lly,gm_urx,gm_ury);
+ gm->init_grid(gm_nx,gm_ny);
// Import the clip polygon into the linked-list datastructure
- int last = 0;
- size_t clip_n = clip_verts.size()/2;
- for (int i=0; i<clip_n; i++) {
- int v = gm->vert_new(last,0);
- if (!clip) clip = v;
- gm->v[v].first = clip;
- gm->vert_set_coord(v, clip_verts[2*i+0], clip_verts[2*i+1], 0);
- last = v;
- }
- if (clip_cyclic) {
- gm->v[clip].prev = last;
- gm->v[last].next = clip;
- }
+ clip = gm->poly_new(&clip_verts[0], int(clip_verts.size()));
// Import the subject polygons into the linked list datastructure
- GridMeshVert *v = &gm->v[0];
- last = 0;
+ int last = 0;
for (std::vector<float> poly_verts : subj_polys) {
- // Different subject polygons are stored in
- // subj, subj->nextPoly, subj->nextPoly->nextPoly etc
- int newpoly_first_vert = gm->vert_new();
- v[newpoly_first_vert].first = newpoly_first_vert;
- if (!subj) {
- subj = newpoly_first_vert;
- } else {
- v[last].next_poly = newpoly_first_vert;
- }
- last = newpoly_first_vert;
- // Fill in the vertices of the polygon we just finished hooking up
- // to the polygon list
- int last_inner = 0;
- for (size_t i=0,l=poly_verts.size()/2; i<l; i++) {
- int vert;
- if (i==0) {
- vert = newpoly_first_vert;
- } else {
- vert = gm->vert_new();
- }
- gm->vert_set_coord(vert, poly_verts[2*i+0], poly_verts[2*i+1], 0);
- v[vert].prev = last_inner;
- v[vert].first = last;
- if (last_inner) v[last_inner].next = vert;
- last_inner = vert;
- }
- gm->poly_set_cyclic(newpoly_first_vert, subj_cyclic);
+ int np = gm->poly_new(&subj0[0], int(subj0.size()));
+ if (last)
+ gm->v[last].next_poly = np;
+ else
+ subj = np;
+ last = np;
}
}
@@ -548,6 +527,7 @@ void GLUT_passive(int x, int y) {
}
}
+#if defined(GRIDMESH_TIME_TEST)
void time_start() {
time_noclip = fopen("/tmp/noclip_nurbs.txt","w");
int subj_count=int(subj_polys.size());
@@ -562,25 +542,27 @@ void time_clip() {
uint64_t start,stop;
start = mach_absolute_time();
- gm = new GridMesh(gm_llx,gm_lly,gm_urx,gm_ury,gm_nx,gm_ny);
+ gm = new GridMesh();
+ gm->set_ll_ur(gm_llx,gm_lly,gm_urx,gm_ury);
+ gm->init_grid(gm_nx,gm_ny);
delete gm;
stop = mach_absolute_time();
fprintf(time_noclip, "%i %i %llu\n",gm_nx*gm_ny,0,stop-start);
for (subj_no=0; subj_no<subj_count; subj_no++) {
start = mach_absolute_time();
- gm = new GridMesh(gm_llx,gm_lly,gm_urx,gm_ury,gm_nx,gm_ny);
- int clip_poly = gm->poly_new(subj_polys[subj_no]);
- int cpverts = int(subj_polys[subj_no].size()/2);
+ gm = new GridMesh();
+ gm->set_ll_ur(gm_llx,gm_lly,gm_urx,gm_ury);
+ gm->init_grid(gm_nx,gm_ny);
+ std::vector<float>& clipvec=subj_polys[subj_no];
+ int clip_poly = gm->poly_new(clipvec[0],clipvec.size());
+ int cpverts = int(clipvec.size()/2);
gm->bool_SUB(clip_poly);
delete gm;
stop = mach_absolute_time();
fprintf(time_subj[subj_no], "%i %i %llu\n",gm_nx*gm_ny,cpverts,stop-start);
}
}
-
-
-/***************************** MAIN *****************************/
void time_main() {
time_start();
for (int res=32; res<=400; res+=8) {
@@ -588,6 +570,10 @@ void time_main() {
time_clip();
}
}
+#endif
+
+
+/***************************** MAIN *****************************/
void interactive_main(int argc, char**argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
@@ -617,6 +603,10 @@ void interactive_main(int argc, char**argv) {
glutMainLoop();
}
int main(int argc, char **argv){
+#if defined(GRIDMESH_TIME_TEST)
+ time_main()
+#else
interactive_main(argc,argv);
+#endif
return 0;
} \ No newline at end of file