~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to source/blender/bmesh/operators/bmo_normals.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "MEM_guardedalloc.h"
30
30
 
31
31
#include "BLI_math.h"
 
32
#include "BLI_linklist_stack.h"
32
33
 
33
34
#include "bmesh.h"
34
35
 
40
41
#define FACE_FLIP       (1 << 1)
41
42
#define FACE_TEMP       (1 << 2)
42
43
 
43
 
static bool bmo_recalc_normal_edge_filter_cb(BMEdge *e, void *UNUSED(user_data))
 
44
static bool bmo_recalc_normal_edge_filter_cb(BMElem *ele, void *UNUSED(user_data))
44
45
{
45
 
        return BM_edge_is_manifold(e);
 
46
        return BM_edge_is_manifold((BMEdge *)ele);
46
47
}
47
48
 
48
49
/**
49
 
 * Given an array of faces, recalcualte their normals.
 
50
 * Given an array of faces, recalculate their normals.
50
51
 * this functions assumes all faces in the array are connected by edges.
51
52
 *
52
53
 * \param bm
65
66
        float f_len_best;
66
67
        BMFace *f;
67
68
 
68
 
        BMFace **fstack = MEM_mallocN(sizeof(*fstack) * faces_len, __func__);
69
 
        STACK_DECLARE(fstack);
 
69
        BLI_LINKSTACK_DECLARE(fstack, BMFace *);
70
70
 
71
71
        zero_v3(cent);
72
72
 
77
77
                madd_v3_v3fl(cent, f_cent, cent_fac);
78
78
 
79
79
                BLI_assert(BMO_elem_flag_test(bm, faces[i], FACE_TEMP) == 0);
 
80
                BLI_assert(BM_face_is_normal_valid(faces[i]));
80
81
        }
81
82
 
82
83
        f_len_best = -FLT_MAX;
102
103
         * have the same winding.  this is done recursively, using a manual
103
104
         * stack (if we use simple function recursion, we'd end up overloading
104
105
         * the stack on large meshes). */
105
 
        STACK_INIT(fstack);
 
106
        BLI_LINKSTACK_INIT(fstack);
106
107
 
107
 
        STACK_PUSH(fstack, faces[f_start_index]);
 
108
        BLI_LINKSTACK_PUSH(fstack, faces[f_start_index]);
108
109
        BMO_elem_flag_enable(bm, faces[f_start_index], FACE_TEMP);
109
110
 
110
 
        while ((f = STACK_POP(fstack))) {
 
111
        while ((f = BLI_LINKSTACK_POP(fstack))) {
111
112
                const bool flip_state = BMO_elem_flag_test_bool(bm, f, FACE_FLIP);
112
113
                BMLoop *l_iter, *l_first;
113
114
 
115
116
                do {
116
117
                        BMLoop *l_other = l_iter->radial_next;
117
118
 
118
 
                        if ((l_other != l_iter) && bmo_recalc_normal_edge_filter_cb(l_iter->e, NULL)) {
 
119
                        if ((l_other != l_iter) && bmo_recalc_normal_edge_filter_cb((BMElem *)l_iter->e, NULL)) {
119
120
                                if (!BMO_elem_flag_test(bm, l_other->f, FACE_TEMP)) {
120
121
                                        BMO_elem_flag_enable(bm, l_other->f, FACE_TEMP);
121
122
                                        BMO_elem_flag_set(bm, l_other->f, FACE_FLIP, (l_other->v == l_iter->v) != flip_state);
122
 
                                        STACK_PUSH(fstack, l_other->f);
 
123
                                        BLI_LINKSTACK_PUSH(fstack, l_other->f);
123
124
                                }
124
125
                        }
125
126
                } while ((l_iter = l_iter->next) != l_first);
126
127
        }
127
128
 
128
 
        MEM_freeN(fstack);
 
129
        BLI_LINKSTACK_FREE(fstack);
129
130
 
130
131
        /* apply flipping to oflag'd faces */
131
132
        for (i = 0; i < faces_len; i++) {
146
147
 
147
148
void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
148
149
{
149
 
        int *groups_array = MEM_mallocN(sizeof(groups_array) * bm->totface, __func__);
 
150
        int *groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totface, __func__);
150
151
        int faces_len;
151
152
        BMFace **faces_arr = BM_iter_as_arrayN(bm, BM_FACES_OF_MESH, NULL, &faces_len, NULL, 0);
152
 
        BMFace **faces_grp = MEM_mallocN(sizeof(faces_grp) * bm->totface, __func__);
 
153
        BMFace **faces_grp = MEM_mallocN(sizeof(*faces_grp) * bm->totface, __func__);
153
154
 
154
155
        int (*group_index)[2];
155
156
        const int group_tot = BM_mesh_calc_face_groups(bm, groups_array, &group_index,
156
 
                                                       NULL, bmo_recalc_normal_edge_filter_cb);
 
157
                                                       bmo_recalc_normal_edge_filter_cb, NULL,
 
158
                                                       0, BM_EDGE);
157
159
        int i;
158
160
 
159
161