Page MenuHome

selrando10dev.txt

selrando10dev.txt

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 07:29:54 -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);
@@ -98,4 +99,3 @@ int bezt_compare (const void *e1, const
extern void undo_push_curve(char *name);
#endif /* BDR_EDITCURVE_H */
-
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 07:29:54 -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,142 @@ void select_less_nurb()
countall();
allqueue(REDRAWVIEW3D, 0);
BIF_undo_push("Select Less");
+}
+
+/* the basic idea of the algorithm: */
+/* [1][2][6]...[14][5][19]...[2] = array, n items. mission: pick m items randomly */
+/* We start to iterate from item before the first item (this is just to simplify the idea) */
+/* 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. */
+/* 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. */
+/* */
+/* Unfortunately the implementation is not as straighforward because we have to start from */
+/* the first item and the data structures do not form a straight, easily iterable list. */
+/* */
+/* The current implementation works fine only in case there's a single bezier curve. */
+void select_random_nurb()
+{
+ Nurb *nu;
+ BezTriple *bezt;
+ BPoint *bp;
+ static short randfac= 50;
+ int a, i= 0, steps, oldsteps= 0;
+ int amount_of_nurbs, amount_of_nurbs_left, amount_of_nurbs_to_select= 0;
+ short breakloop1= 0, breakloop2= 0, firststep= 1;
+
+ 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;
+
+ if(amount_of_nurbs_to_select == 0) return;
+
+ nu= editNurb.first;
+ BLI_srand( BLI_rand() ); /* random seed */
+
+ printf("sel rando \n");
+
+ while(1) { /* doesn't work totally alright yet. to be debugged */
+ if((nu->type & 7)==CU_BEZIER) {
+ a= nu->pntsu;
+ bezt= nu->bezt;
+ while(1) {
+ printf("oldsteps: %d \n", oldsteps);
+
+ if(oldsteps == 0) {
+ steps= floor(BLI_frand()*(amount_of_nurbs_left-amount_of_nurbs_to_select)+0.5);
+
+ /* first step is an exception */
+ if(firststep == 0) steps++;
+
+ oldsteps= steps;
+ }
+ else steps= oldsteps;
+
+ printf("amount of nurbs: %d, amount of nurbs left: %d, amount of nurbs to select: %d, steps: %d, oldsteps: %d, a: %d \n", amount_of_nurbs, amount_of_nurbs_left, amount_of_nurbs_to_select, steps, oldsteps, a);
+
+ for(i=0; i<steps; i++) {
+ a--;
+ /* we may need to jump to next nurb. note that next nurb can be either bezt or bp. Note that it is possible that there's no next nu. currently buggy */
+ if(a == 0) {
+ if(nu->next) nu= nu->next;
+ oldsteps-=(i+1); // ok?
+ breakloop2= 1;
+ break;
+ }
+ else
+ bezt++;
+ }
+
+ if(breakloop2 == 1) {
+ breakloop2= 0;
+ break;
+ }
+ else oldsteps= 0;
+
+ if (bezt->hide == 0) {
+ bezt->f1 |= 1;
+ bezt->f2 |= 1;
+ bezt->f3 |= 1;
+
+ printf("selected a nurb \n");
+ }
+
+ amount_of_nurbs_to_select--;
+ amount_of_nurbs_left-=steps;
+
+ /* first step is an exception because we start from first element */
+ if(firststep == 1) {
+ amount_of_nurbs_left--;
+ firststep= 0;
+ }
+
+ if(amount_of_nurbs_to_select == 0) {
+ breakloop1= 1;
+ break;
+ }
+ }
+ }
+ else { /* TBD */
+ a= nu->pntsu*nu->pntsv;
+ bp= nu->bp;
+ while(a > 0) { /* check this */
+ steps= BLI_frand()*(amount_of_nurbs-amount_of_nurbs_to_select);
+ if(steps == 0) steps= 1;
+
+ for(i=0; i<steps; i++) {
+ bezt++;
+ a--;
+ } /* note that we may have to go over here!!! */
+
+ if(bp->hide == 0) bp->f1 |= 1;
+
+ amount_of_nurbs_to_select--;
+
+ if(amount_of_nurbs_to_select == 0) breakloop1= 1;
+ }
+ }
+
+ if(breakloop1 == 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 07:29:55 -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 07:29:55 -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},

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e0/04/e3bbfb58c928a90e9365b2ae5ef4

Event Timeline