code cleanup and move alternate shell calculation method into its own function: BM_ve...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 14 Dec 2012 16:10:46 +0000 (16:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 14 Dec 2012 16:10:46 +0000 (16:10 +0000)
source/blender/blenkernel/intern/particle_system.c
source/blender/bmesh/intern/bmesh_queries.c
source/blender/bmesh/intern/bmesh_queries.h
source/blender/editors/screen/screen_ops.c
source/blender/editors/transform/transform_conversions.c

index 7c95265b27b80c9d898505a94f57fb82f4f24f51..037864c7e38fee1c3ff8d26a1c06dc2c8006691c 100644 (file)
@@ -2616,12 +2616,12 @@ MINLINE float pow7(float x) {
        return pow2(pow3(x)) * x;
 }
 
-static void sphclassical_density_accum_cb(void *userdata, int index, float squared_dist)
+static void sphclassical_density_accum_cb(void *userdata, int index, float UNUSED(squared_dist))
 {
        SPHRangeData *pfr = (SPHRangeData *)userdata;
        ParticleData *npa = pfr->npsys->particles + index;
        float q;
-       float qfac = 21.0f / (256.f * M_PI);
+       float qfac = 21.0f / (256.f * (float)M_PI);
        float rij, rij_h;
        float vec[3];
 
@@ -2647,7 +2647,7 @@ static void sphclassical_density_accum_cb(void *userdata, int index, float squar
        pfr->data[1] += q / npa->sphdensity;
 }
 
-static void sphclassical_neighbour_accum_cb(void *userdata, int index, float squared_dist)
+static void sphclassical_neighbour_accum_cb(void *userdata, int index, float UNUSED(squared_dist))
 {
        SPHRangeData *pfr = (SPHRangeData *)userdata;
        ParticleData *npa = pfr->npsys->particles + index;
@@ -2699,7 +2699,7 @@ static void sphclassical_force_cb(void *sphdata_v, ParticleKey *state, float *fo
 
        int i;
 
-       float qfac2 = 42.0f / (256.0f * M_PI);
+       float qfac2 = 42.0f / (256.0f * (float)M_PI);
        float rij_h;
 
        /* 4.0 here is to be consistent with previous formulation/interface */
index 633c715f257a058382d577f48d1889fcc8833f9c..5f5c60dde3f0170e9e1c7bfb5b41c9611f8700ce 100644 (file)
@@ -1113,6 +1113,40 @@ float BM_vert_calc_shell_factor(BMVert *v)
                return 1.0f;
        }
 }
+/* alternate version of #BM_vert_calc_shell_factor which only
+ * uses 'hflag' faces, but falls back to all if none found. */
+float BM_vert_calc_shell_factor_ex(BMVert *v, const char hflag)
+{
+       BMIter iter;
+       BMLoop *l;
+       float accum_shell = 0.0f;
+       float accum_angle = 0.0f;
+       int tot_sel = 0, tot = 0;
+
+       BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
+               if (BM_elem_flag_test(l->f, hflag)) {  /* <-- main difference to BM_vert_calc_shell_factor! */
+                       const float face_angle = BM_loop_calc_face_angle(l);
+                       accum_shell += shell_angle_to_dist(angle_normalized_v3v3(v->no, l->f->no)) * face_angle;
+                       accum_angle += face_angle;
+                       tot_sel++;
+               }
+               tot++;
+       }
+
+       if (accum_angle != 0.0f) {
+               return accum_shell / accum_angle;
+       }
+       else {
+               /* other main difference from BM_vert_calc_shell_factor! */
+               if (tot != 0 && tot_sel == 0) {
+                       /* none selected, so use all */
+                       return BM_vert_calc_shell_factor(v);
+               }
+               else {
+                       return 1.0f;
+               }
+       }
+}
 
 /**
  * \note quite an obscure function.
index 7a18f69371e4110e9c7a6768f7c47312c74d1be1..9af792417bf65786015e27710dde1b407f3c57b4 100644 (file)
@@ -69,6 +69,7 @@ void    BM_edge_calc_face_tangent(BMEdge *e, BMLoop *e_loop, float r_tangent[3])
 
 float   BM_vert_calc_edge_angle(BMVert *v);
 float   BM_vert_calc_shell_factor(BMVert *v);
+float   BM_vert_calc_shell_factor_ex(BMVert *v, const char hflag);
 float   BM_vert_calc_mean_tagged_edge_length(BMVert *v);
 
 BMLoop *BM_face_find_shortest_loop(BMFace *f);
index d819176e542a310d0d5cbf049f4cd3ded2e8034f..6e65d7fa59a243af23e3aa7553be70aa03de8d38 100644 (file)
@@ -140,9 +140,11 @@ static int screen_active_editable(bContext *C)
 /* when mouse is over area-edge */
 int ED_operator_screen_mainwinactive(bContext *C)
 {
+       bScreen *screen;
        if (CTX_wm_window(C) == NULL) return 0;
-       if (CTX_wm_screen(C) == NULL) return 0;
-       if (CTX_wm_screen(C)->subwinactive != CTX_wm_screen(C)->mainwin) return 0;
+       screen = CTX_wm_screen(C);
+       if (screen == NULL) return 0;
+       if (screen->subwinactive != screen->mainwin) return 0;
        return 1;
 }
 
@@ -3412,6 +3414,7 @@ static void SCREEN_OT_back_to_previous(struct wmOperatorType *ot)
 
 static int userpref_show_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 {
+       wmWindow *win = CTX_wm_window(C);
        rcti rect;
        int sizex, sizey;
        
@@ -3420,8 +3423,8 @@ static int userpref_show_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *ev
        
        /* some magic to calculate postition */
        /* pixelsize: mouse coords are in U.pixelsize units :/ */
-       rect.xmin = (event->x / U.pixelsize) + CTX_wm_window(C)->posx - sizex / 2;
-       rect.ymin = (event->y / U.pixelsize) + CTX_wm_window(C)->posy - sizey / 2;
+       rect.xmin = (event->x / U.pixelsize) + win->posx - sizex / 2;
+       rect.ymin = (event->y / U.pixelsize) + win->posy - sizey / 2;
        rect.xmax = rect.xmin + sizex;
        rect.ymax = rect.ymin + sizey;
        
index ea852fdb098a89d53c2b7336ba97664be6882eb2..c7499d3717ff0b912281c83c040608688697a2b5 100644 (file)
@@ -1880,40 +1880,6 @@ static void get_edge_center(float cent_r[3], BMVert *eve)
        }
 }
 
-/* local version of #BM_vert_calc_shell_factor which only
- * uses selected faces */
-static float bm_vert_calc_shell_factor_selected(BMVert *v)
-{
-       BMIter iter;
-       BMLoop *l;
-       float accum_shell = 0.0f;
-       float accum_angle = 0.0f;
-       int tot_sel = 0, tot = 0;
-
-       BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
-               if (BM_elem_flag_test(l->f, BM_ELEM_SELECT)) {  /* <-- only difference to BM_vert_calc_shell_factor! */
-                       const float face_angle = BM_loop_calc_face_angle(l);
-                       accum_shell += shell_angle_to_dist(angle_normalized_v3v3(v->no, l->f->no)) * face_angle;
-                       accum_angle += face_angle;
-                       tot_sel++;
-               }
-               tot++;
-       }
-
-       if (accum_angle != 0.0f) {
-               return accum_shell / accum_angle;
-       }
-       else {
-               if (tot != 0 && tot_sel == 0) {
-                       /* none selected, so use all */
-                       return BM_vert_calc_shell_factor(v);
-               }
-               else {
-                       return 1.0f;
-               }
-       }
-}
-
 /* way to overwrite what data is edited with transform */
 static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx,
                              BMEditMesh *em, BMVert *eve, float *bweight)
@@ -1962,7 +1928,7 @@ static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx
        }
        else if (t->mode == TFM_SHRINKFATTEN) {
                td->ext = tx;
-               tx->isize[0] = bm_vert_calc_shell_factor_selected(eve);
+               tx->isize[0] = BM_vert_calc_shell_factor_ex(eve, BM_ELEM_SELECT);
        }
 }