Commit: e38e8f1f712475719dc72f7a9a19ef3abc2f0f5e Author: Hans Goudey Date: Thu Aug 1 14:19:25 2019 -0400 Branches: soc-2019-bevel-profiles https://developer.blender.org/rBe38e8f1f712475719dc72f7a9a19ef3abc2f0f5e
Profile Widget: Dynamic Hi-Res table size The table for the sampled, curved path is a multiple of the number of control points up until a maximum size. This should speed up drawing and evaluation functions when there is a smaller number of control points. =================================================================== M source/blender/blenkernel/intern/profile_widget.c M source/blender/editors/interface/interface_draw.c M source/blender/editors/interface/interface_handlers.c M source/blender/makesdna/DNA_profilewidget_types.h =================================================================== diff --git a/source/blender/blenkernel/intern/profile_widget.c b/source/blender/blenkernel/intern/profile_widget.c index ce117dd3d18..dbac816dea6 100644 --- a/source/blender/blenkernel/intern/profile_widget.c +++ b/source/blender/blenkernel/intern/profile_widget.c @@ -227,7 +227,8 @@ ProfilePoint *profilewidget_insert(ProfileWidget *prwdgt, float x, float y) printf("PROFILEPATH INSERT\n"); #endif - if (prwdgt->totpoint == PROF_TABLE_SIZE - 1) { + /* Don't add more control points than the maximum size of the higher resolution table */ + if (prwdgt->totpoint == PROF_TABLE_MAX - 1) { return NULL; } @@ -732,7 +733,7 @@ static void profilewidget_make_table(ProfileWidget *prwdgt) int i, n_samples; /* Get locations of samples from the sampling function */ - n_samples = PROF_TABLE_SIZE; + n_samples = PROF_N_TABLE(prwdgt->totpoint); locations = MEM_callocN((size_t)n_samples * 2 * sizeof(float), "temp loc storage"); profilewidget_create_samples(prwdgt, locations, n_samples - 1, false); @@ -897,7 +898,7 @@ float profilewidget_total_length(const ProfileWidget *prwdgt) float loc1[2], loc2[2]; float total_length = 0; - for (int i = 0; i < PROF_TABLE_SIZE; i++) { + for (int i = 0; i < PROF_N_TABLE(prwdgt->totpoint); i++) { loc1[0] = prwdgt->table[i].x; loc1[1] = prwdgt->table[i].y; loc2[0] = prwdgt->table[i].x; @@ -970,7 +971,7 @@ void profilewidget_evaluate_portion(const ProfileWidget *prwdgt, float length_travelled = 0.0f; while (length_travelled < requested_length) { /* Check if we reached the last point before the final one */ - if (i == PROF_TABLE_SIZE - 2) { + if (i == PROF_N_TABLE(prwdgt->totpoint) - 2) { break; } float new_length = profilewidget_distance_to_next_point(prwdgt, i); diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 3868131231c..4262e54eaed 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -2209,12 +2209,12 @@ void ui_draw_but_PROFILE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, co /* Also add the last points on the right and bottom edges to close off the fill polygon */ bool add_left_tri = prwdgt->view_rect.xmin < 0.0f; bool add_bottom_tri = prwdgt->view_rect.ymin < 0.0f; - uint tot_points = (uint)PROF_TABLE_SIZE + 1 + add_left_tri + add_bottom_tri; + uint tot_points = (uint)PROF_N_TABLE(prwdgt->totpoint) + 1 + add_left_tri + add_bottom_tri; uint tot_triangles = tot_points - 2; /* Create array of the positions of the table's points */ float (*table_coords)[2] = MEM_mallocN(sizeof(*table_coords) * tot_points, "table x coords"); - for (i = 0; i < PROF_TABLE_SIZE; i++) { /* Only add the points from the table here */ + for (i = 0; i < (uint)PROF_N_TABLE(prwdgt->totpoint); i++) { /* Only add the points from the table here */ table_coords[i][0] = pts[i].x; table_coords[i][1] = pts[i].y; } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e4d9bbe241e..9b953ad002e 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6917,7 +6917,7 @@ static int ui_do_but_PROFILE(bContext *C, dist_min_sq = SQUARE(U.dpi_fac * 8.0f); /* loop through the curve segment table and find what's near the mouse. */ - for (i = 1; i <= PROF_TABLE_SIZE; i++) { + for (i = 1; i <= PROF_N_TABLE(prwdgt->totpoint); i++) { copy_v2_v2(f_xy_prev, f_xy); BLI_rctf_transform_pt_v(&but->rect, &prwdgt->view_rect, f_xy, &pts[i].x); diff --git a/source/blender/makesdna/DNA_profilewidget_types.h b/source/blender/makesdna/DNA_profilewidget_types.h index f9250397936..ad4a9d2807c 100644 --- a/source/blender/makesdna/DNA_profilewidget_types.h +++ b/source/blender/makesdna/DNA_profilewidget_types.h @@ -26,11 +26,10 @@ #include "DNA_vec_types.h" -#define PROF_TABLE_SIZE 256 -/* HANS-TODO: Switch to variable table size based on resolution and number of points, mostly for a - * speedup in the drawing and evaluation code if it's needed */ -//#define PROF_N_TABLE(n_pts) min_ff(512, (((n_pts) - 1) * PROF_RESOL)) /* n_pts is prwdgt->totpoint */ -//#define PROF_RESOL 16 +/** Number of points in high resolution table is dynamic up to the maximum */ +#define PROF_TABLE_MAX 512 +#define PROF_RESOL 16 /* Number of table points per control point */ +#define PROF_N_TABLE(n_pts) min_ii(PROF_TABLE_MAX, (((n_pts) - 1) * PROF_RESOL)) /* n_pts is prwdgt->totpoint */ typedef struct ProfilePoint { /** Location of the point */ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs