Index: source/blender/include/BDR_editcurve.h =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/include/BDR_editcurve.h,v retrieving revision 1.14 diff -u -p -u -r1.14 BDR_editcurve.h --- source/blender/include/BDR_editcurve.h 6 Nov 2006 18:20:56 -0000 1.14 +++ source/blender/include/BDR_editcurve.h 27 Apr 2007 09:45:32 -0000 @@ -83,6 +83,7 @@ void select_more_nurb(void); void select_less_nurb(void); void select_next_nurb(void); void select_prev_nurb(void); +void select_random_nurb(void); void adduplicate_nurb(void); void delNurb(void); void nurb_set_smooth(short event); Index: source/blender/src/editcurve.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/src/editcurve.c,v retrieving revision 1.59 diff -u -p -u -r1.59 editcurve.c --- source/blender/src/editcurve.c 22 Apr 2007 22:08:18 -0000 1.59 +++ source/blender/src/editcurve.c 27 Apr 2007 09:45:32 -0000 @@ -50,6 +50,7 @@ #include "BLI_blenlib.h" #include "BLI_arithb.h" #include "BLI_dynstr.h" +#include "BLI_rand.h" #include "DNA_curve_types.h" #include "DNA_ipo_types.h" @@ -3331,6 +3332,119 @@ void select_less_nurb() countall(); allqueue(REDRAWVIEW3D, 0); BIF_undo_push("Select Less"); +} + +/* random number based on rejection sampling */ +static float rejsamprand() { + float i=0, j=0, k=0; + + while(k < 1000) { + i= BLI_frand(); + j= BLI_frand(); + + if(i < j) + return i; + } + return i; +} + +/* the basic idea of the algorithm: */ +/* [1][2][6]...[14][5][19]...[2] = array, n items. target: pick m items randomly */ +/* We start to iterate from item before the first item */ +/* Possible amount of steps we can take is (amountOfItems-amountMoved)-amountToBePicked. */ +/* We can pick the amount of steps to take randomly as long as it is between 1 and this */ +/* calculation. Note that we have to make small numbers more probable to make the result */ +/* more random. */ +/* After we have moved the wanted amount of steps forward, we pick the item but do not */ +/* remove it. Now we can figure out the amount of steps we can take again till we have */ +/* found our items. */ +void select_random_nurb() +{ + Nurb *nu; + BezTriple *bezt; + BPoint *bp; + static short randfac= 50; + int a, i, j= 0, steps; + int amount_of_nurbs, amount_of_nurbs_left, amount_of_nurbs_left_to_select, amount_of_nurbs_to_select= 0, prevsteps= 0; + int itemstobeselected[count_curveverts(&editNurb)]; /* not optimal */ + short breakloop= 0; + + if(!G.obedit) return; + + if(!button(&randfac,0, 100,"Percentage:")) return; + + if(randfac == 0) return; + + amount_of_nurbs= count_curveverts(&editNurb); /* returns value with handles */ + for(nu= editNurb.first; nu; nu= nu->next) { + if((nu->type & 7)==CU_BEZIER) { + amount_of_nurbs -= nu->pntsu*2; /* subtract handles */ + } + } + + amount_of_nurbs_left= amount_of_nurbs; + amount_of_nurbs_to_select= amount_of_nurbs*randfac/100; + amount_of_nurbs_left_to_select= amount_of_nurbs_to_select; + nu= editNurb.first; + BLI_srand( BLI_rand() ); /* random seed */ + + /* figure out which items to select */ + for(i=0; inext) { + if((nu->type & 7)==CU_BEZIER) { + bezt= nu->bezt; + a= nu->pntsu; + while(a--) { + if(i == itemstobeselected[j]) { + if(bezt->hide==0) { + bezt->f1 |= 1; + bezt->f2 |= 1; + bezt->f3 |= 1; + } + j++; + } + bezt++; + i++; + + if(j == amount_of_nurbs_to_select) { + breakloop= 1; + break; + } + } + } + else { + bp= nu->bp; + a= nu->pntsu*nu->pntsv; + while(a--) { + if(i == itemstobeselected[j]) { + if(bp->hide==0) bp->f1 |= 1; + j++; + } + bp++; + i++; + + if(j == amount_of_nurbs_to_select) { + breakloop= 1; + break; + } + } + } + + if(breakloop == 1) break; + } + + countall(); + allqueue(REDRAWVIEW3D, 0); + BIF_undo_push("Select Random:Nurbs"); } void adduplicate_nurb() Index: source/blender/src/header_view3d.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/src/header_view3d.c,v retrieving revision 1.230 diff -u -p -u -r1.230 header_view3d.c --- source/blender/src/header_view3d.c 22 Apr 2007 22:08:18 -0000 1.230 +++ source/blender/src/header_view3d.c 27 Apr 2007 09:45:33 -0000 @@ -1102,6 +1102,9 @@ void do_view3d_select_curvemenu(void *ar case 12: /* select previous */ select_prev_nurb(); break; + case 13: /* select random */ + select_random_nurb(); + break; } allqueue(REDRAWVIEW3D, 0); } @@ -1121,6 +1124,7 @@ static uiBlock *view3d_select_curvemenu( uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Random...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, ""); if (OBACT->type == OB_SURF) { uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); Index: source/blender/src/toolbox.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/src/toolbox.c,v retrieving revision 1.163 diff -u -p -u -r1.163 toolbox.c --- source/blender/src/toolbox.c 22 Apr 2007 22:08:19 -0000 1.163 +++ source/blender/src/toolbox.c 27 Apr 2007 09:45:33 -0000 @@ -948,6 +948,7 @@ static TBitem tb_curve_select[]= { { 0, "SEPR", 0, NULL}, { 0, "(De)select All|A", 2, NULL}, { 0, "Inverse", 3, NULL}, +{ 0, "Random...", 13, NULL}, { 0, "Row|Shift R", 5, NULL}, { 0, "SEPR", 0, NULL}, { 0, "(De)select First", 7, NULL},