~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * ***** END GPL LICENSE BLOCK *****
21
21
 */
22
22
 
23
 
/** \file blender/bmesh/operators/bmo_subdivide.c
 
23
/** \file blender/bmesh/operators/bmo_triangulate.c
24
24
 *  \ingroup bmesh
25
25
 */
26
26
 
37
37
 
38
38
#include "intern/bmesh_operators_private.h" /* own include */
39
39
 
40
 
#define EDGE_NEW        1
41
 
#define FACE_NEW        1
42
 
 
43
40
#define ELE_NEW         1
44
41
#define FACE_MARK       2
45
42
#define EDGE_MARK       4
46
43
 
47
44
void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
48
45
{
49
 
        BMOIter siter;
50
 
        BMFace *face, **newfaces = NULL;
51
 
        BLI_array_declare(newfaces);
52
 
        float (*projectverts)[3] = NULL;
53
 
        BLI_array_declare(projectverts);
54
 
        int i;
55
 
        const int use_beauty = BMO_slot_bool_get(op, "use_beauty");
56
 
 
57
 
        for (face = BMO_iter_new(&siter, bm, op, "faces", BM_FACE); face; face = BMO_iter_step(&siter)) {
58
 
 
59
 
                BLI_array_empty(projectverts);
60
 
                BLI_array_empty(newfaces);
61
 
 
62
 
                BLI_array_growitems(projectverts, face->len * 3);
63
 
                BLI_array_growitems(newfaces, face->len);
64
 
 
65
 
                BM_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty);
66
 
 
67
 
                BMO_slot_map_ptr_insert(bm, op, "facemap", face, face);
68
 
                for (i = 0; newfaces[i]; i++) {
69
 
                        BMO_slot_map_ptr_insert(bm, op, "facemap",
70
 
                                                newfaces[i], face);
71
 
 
72
 
                }
73
 
        }
74
 
        
75
 
        BMO_slot_buffer_from_enabled_flag(bm, op, "edgeout", BM_EDGE, EDGE_NEW);
76
 
        BMO_slot_buffer_from_enabled_flag(bm, op, "faceout", BM_FACE, FACE_NEW);
77
 
        
78
 
        BLI_array_free(projectverts);
79
 
        BLI_array_free(newfaces);
 
46
        const bool use_beauty = BMO_slot_bool_get(op->slots_in, "use_beauty");
 
47
        BMOpSlot *slot_facemap_out = BMO_slot_get(op->slots_out, "face_map.out");
 
48
 
 
49
        BM_mesh_elem_hflag_disable_all(bm, BM_FACE | BM_EDGE, BM_ELEM_TAG, false);
 
50
        BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false);
 
51
 
 
52
        BM_mesh_triangulate(bm, use_beauty, true, op, slot_facemap_out);
 
53
 
 
54
        BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG);
 
55
        BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
80
56
}
81
57
 
82
58
void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op)
87
63
        BMEdge *e;
88
64
        int stop = 0;
89
65
        
90
 
        BMO_slot_buffer_flag_enable(bm, op, "constrain_edges", BM_EDGE, EDGE_MARK);
 
66
        BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, EDGE_MARK);
91
67
        
92
 
        BMO_ITER (f, &siter, bm, op, "faces", BM_FACE) {
 
68
        BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) {
93
69
                if (f->len == 3) {
94
70
                        BMO_elem_flag_enable(bm, f, FACE_MARK);
95
71
                }
101
77
                BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
102
78
                        BMVert *v1, *v2, *v3, *v4;
103
79
                        
104
 
                        if (!BM_edge_is_manifold(e) || BMO_elem_flag_test(bm, e, EDGE_MARK)) {
 
80
                        if (!BM_edge_is_manifold(e) || !BMO_elem_flag_test(bm, e, EDGE_MARK)) {
105
81
                                continue;
106
82
                        }
107
83
 
110
86
                        {
111
87
                                continue;
112
88
                        }
113
 
                        
 
89
 
114
90
                        v1 = e->l->prev->v;
115
91
                        v2 = e->l->v;
116
92
                        v3 = e->l->radial_next->prev->v;
117
93
                        v4 = e->l->next->v;
118
 
                        
 
94
 
119
95
                        if (is_quad_convex_v3(v1->co, v2->co, v3->co, v4->co)) {
120
96
                                float len1, len2, len3, len4, len5, len6, opp1, opp2, fac1, fac2;
121
97
                                /* testing rule:
139
115
                                fac2 = opp1 / (len2 + len3 + len6) + opp2 / (len4 + len1 + len6);
140
116
                                
141
117
                                if (fac1 > fac2) {
142
 
                                        e = BM_edge_rotate(bm, e, FALSE, BM_EDGEROT_CHECK_EXISTS);
 
118
                                        e = BM_edge_rotate(bm, e, false, BM_EDGEROT_CHECK_EXISTS);
143
119
                                        if (e) {
144
 
                                                BMO_elem_flag_enable(bm, e, ELE_NEW);
 
120
                                                BMO_elem_flag_enable(bm, e, ELE_NEW | EDGE_MARK);
145
121
 
146
 
                                                BMO_elem_flag_enable(bm, e->l->f, FACE_MARK|ELE_NEW);
147
 
                                                BMO_elem_flag_enable(bm, e->l->radial_next->f, FACE_MARK|ELE_NEW);
 
122
                                                BMO_elem_flag_enable(bm, e->l->f, FACE_MARK | ELE_NEW);
 
123
                                                BMO_elem_flag_enable(bm, e->l->radial_next->f, FACE_MARK | ELE_NEW);
148
124
                                                stop = 0;
149
125
                                        }
150
126
                                }
152
128
                }
153
129
        }
154
130
        
155
 
        BMO_slot_buffer_from_enabled_flag(bm, op, "geomout", BM_EDGE|BM_FACE, ELE_NEW);
 
131
        BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_EDGE | BM_FACE, ELE_NEW);
156
132
}
157
133
 
158
134
void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op)
159
135
{
 
136
        const bool use_beauty = BMO_slot_bool_get(op->slots_in, "use_beauty");
160
137
        BMOIter siter;
161
138
        BMEdge *e;
162
 
        BMOperator bmop;
163
139
        ScanFillContext sf_ctx;
164
 
        /* ScanFillEdge *eed; */ /* UNUSED */
165
 
        ScanFillVert *eve, *v1, *v2;
166
 
        ScanFillFace *efa;
 
140
        /* ScanFillEdge *sf_edge; */ /* UNUSED */
 
141
        ScanFillVert *sf_vert, *sf_vert_1, *sf_vert_2;
 
142
        ScanFillFace *sf_tri;
167
143
        SmallHash hash;
168
144
 
169
145
        BLI_smallhash_init(&hash);
170
146
        
171
 
        BLI_begin_edgefill(&sf_ctx);
 
147
        BLI_scanfill_begin(&sf_ctx);
172
148
        
173
 
        BMO_ITER (e, &siter, bm, op, "edges", BM_EDGE) {
 
149
        BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) {
174
150
                BMO_elem_flag_enable(bm, e, EDGE_MARK);
175
151
                
176
152
                if (!BLI_smallhash_haskey(&hash, (uintptr_t)e->v1)) {
177
 
                        eve = BLI_addfillvert(&sf_ctx, e->v1->co);
178
 
                        eve->tmp.p = e->v1;
179
 
                        BLI_smallhash_insert(&hash, (uintptr_t)e->v1, eve);
 
153
                        sf_vert = BLI_scanfill_vert_add(&sf_ctx, e->v1->co);
 
154
                        sf_vert->tmp.p = e->v1;
 
155
                        BLI_smallhash_insert(&hash, (uintptr_t)e->v1, sf_vert);
180
156
                }
181
157
                
182
158
                if (!BLI_smallhash_haskey(&hash, (uintptr_t)e->v2)) {
183
 
                        eve = BLI_addfillvert(&sf_ctx, e->v2->co);
184
 
                        eve->tmp.p = e->v2;
185
 
                        BLI_smallhash_insert(&hash, (uintptr_t)e->v2, eve);
 
159
                        sf_vert = BLI_scanfill_vert_add(&sf_ctx, e->v2->co);
 
160
                        sf_vert->tmp.p = e->v2;
 
161
                        BLI_smallhash_insert(&hash, (uintptr_t)e->v2, sf_vert);
186
162
                }
187
163
                
188
 
                v1 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v1);
189
 
                v2 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v2);
190
 
                /* eed = */ BLI_addfilledge(&sf_ctx, v1, v2);
191
 
                /* eed->tmp.p = e; */ /* UNUSED */
 
164
                sf_vert_1 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v1);
 
165
                sf_vert_2 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v2);
 
166
                /* sf_edge = */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_1, sf_vert_2);
 
167
                /* sf_edge->tmp.p = e; */ /* UNUSED */
192
168
        }
193
169
        
194
 
        BLI_edgefill(&sf_ctx, FALSE);
 
170
        BLI_scanfill_calc(&sf_ctx, BLI_SCANFILL_CALC_HOLES);
195
171
        
196
 
        for (efa = sf_ctx.fillfacebase.first; efa; efa = efa->next) {
 
172
        for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) {
197
173
                BMFace *f = BM_face_create_quad_tri(bm,
198
 
                                                    efa->v1->tmp.p, efa->v2->tmp.p, efa->v3->tmp.p, NULL,
199
 
                                                    NULL, TRUE);
 
174
                                                    sf_tri->v1->tmp.p, sf_tri->v2->tmp.p, sf_tri->v3->tmp.p, NULL,
 
175
                                                    NULL, true);
200
176
                BMLoop *l;
201
177
                BMIter liter;
202
178
                
208
184
                }
209
185
        }
210
186
        
211
 
        BLI_end_edgefill(&sf_ctx);
 
187
        BLI_scanfill_end(&sf_ctx);
212
188
        BLI_smallhash_release(&hash);
213
189
        
214
 
        /* clean up fill */
215
 
        BMO_op_initf(bm, &bmop, "beautify_fill faces=%ff constrain_edges=%fe", ELE_NEW, EDGE_MARK);
216
 
        BMO_op_exec(bm, &bmop);
217
 
        BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_FACE|BM_EDGE, ELE_NEW);
218
 
        BMO_op_finish(bm, &bmop);
 
190
        if (use_beauty) {
 
191
                BMOperator bmop;
 
192
 
 
193
                BMO_op_initf(bm, &bmop, op->flag, "beautify_fill faces=%ff edges=%Fe", ELE_NEW, EDGE_MARK);
 
194
                BMO_op_exec(bm, &bmop);
 
195
                BMO_slot_buffer_flag_enable(bm, bmop.slots_out, "geom.out", BM_FACE | BM_EDGE, ELE_NEW);
 
196
                BMO_op_finish(bm, &bmop);
 
197
        }
219
198
        
220
 
        BMO_slot_buffer_from_enabled_flag(bm, op, "geomout", BM_EDGE|BM_FACE, ELE_NEW);
 
199
        BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_EDGE | BM_FACE, ELE_NEW);
221
200
}