diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-29 14:31:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-29 14:31:05 +0400 |
commit | 37489d71c7f0007ffc3aa252a4cc63d1aa903399 (patch) | |
tree | 8d535c6ff229d8a30855a88a8cb3e2051e0485e8 /source/blender/bmesh | |
parent | 97a5cd92bc807a03c4983ec70b1b961491062b13 (diff) |
Triangulate modifier no longer uses bmesh operator api call, instead add a BM_mesh_triangulate() function. Gives ~2x speedup in my tests on an optimized build.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/bmesh/bmesh.h | 3 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 12 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.h | 5 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_triangulate.c | 34 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_triangulate.c | 66 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_triangulate.h | 35 |
7 files changed, 120 insertions, 37 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index 42a1a5e0f3e..aa1fb2dda46 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -114,6 +114,8 @@ set(SRC tools/bmesh_decimate.h tools/bmesh_edgesplit.c tools/bmesh_edgesplit.h + tools/bmesh_triangulate.c + tools/bmesh_triangulate.h bmesh.h bmesh_class.h diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index f593f78bab7..3b33513b575 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -268,8 +268,9 @@ extern "C" { #include "intern/bmesh_inline.h" -#include "tools/bmesh_decimate.h" #include "tools/bmesh_bevel.h" +#include "tools/bmesh_decimate.h" +#include "tools/bmesh_triangulate.h" #ifdef __cplusplus } diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 5c3d164c768..b8b7abdbc76 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -845,8 +845,9 @@ static BMLoop *find_ear(BMFace *f, float (*verts)[3], const bool use_beauty, flo * * \note newedgeflag sets a flag layer flag, obviously not the header flag. */ -void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], const short newedge_oflag, - const short newface_oflag, BMFace **newfaces, const bool use_beauty) +void BM_face_triangulate(BMesh *bm, BMFace *f, + float (*projectverts)[3], BMFace **newfaces, + const bool use_beauty, const bool use_tag) { int i, nvert, nf_i = 0; bool done; @@ -900,8 +901,11 @@ void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], const s } copy_v3_v3(f->no, l_iter->f->no); - BMO_elem_flag_enable(bm, newl->e, newedge_oflag); - BMO_elem_flag_enable(bm, f, newface_oflag); + + if (use_tag) { + BM_elem_flag_enable(newl->e, BM_ELEM_TAG); + BM_elem_flag_enable(f, BM_ELEM_TAG); + } if (newfaces) newfaces[nf_i++] = f; diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h index a0c6ac5eeaa..7c2b1782584 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.h +++ b/source/blender/bmesh/intern/bmesh_polygon.h @@ -44,9 +44,8 @@ void BM_vert_normal_update_all(BMVert *v); void BM_face_normal_flip(BMesh *bm, BMFace *f); bool BM_face_point_inside_test(BMFace *f, const float co[3]); -void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], - const short newedge_oflag, const short newface_oflag, BMFace **newfaces, - const bool use_beauty); +void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], BMFace **newfaces, + const bool use_beauty, const bool use_tag); void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len); diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c index 744f706681d..c4d15034c0f 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.c +++ b/source/blender/bmesh/operators/bmo_triangulate.c @@ -37,45 +37,21 @@ #include "intern/bmesh_operators_private.h" /* own include */ -#define EDGE_NEW 1 -#define FACE_NEW 1 - #define ELE_NEW 1 #define FACE_MARK 2 #define EDGE_MARK 4 void bmo_triangulate_exec(BMesh *bm, BMOperator *op) { - BMOIter siter; - BMFace *face, **newfaces = NULL; - BLI_array_declare(newfaces); - float (*projectverts)[3] = NULL; - BLI_array_declare(projectverts); - int i; const bool use_beauty = BMO_slot_bool_get(op->slots_in, "use_beauty"); - BMOpSlot *slot_facemap_out = BMO_slot_get(op->slots_out, "face_map.out"); - - for (face = BMO_iter_new(&siter, op->slots_in, "faces", BM_FACE); face; face = BMO_iter_step(&siter)) { - - BLI_array_empty(projectverts); - BLI_array_empty(newfaces); - BLI_array_grow_items(projectverts, face->len * 3); - BLI_array_grow_items(newfaces, face->len); + BM_mesh_elem_hflag_disable_all(bm, BM_FACE | BM_EDGE, BM_ELEM_TAG, false); + BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false); - BM_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty); + BM_mesh_triangulate(bm, use_beauty, true); - BMO_slot_map_elem_insert(op, slot_facemap_out, face, face); - for (i = 0; newfaces[i]; i++) { - BMO_slot_map_elem_insert(op, slot_facemap_out, newfaces[i], face); - } - } - - BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "edges.out", BM_EDGE, EDGE_NEW); - BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, FACE_NEW); - - BLI_array_free(projectverts); - BLI_array_free(newfaces); + BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG); + BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG); } void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op) diff --git a/source/blender/bmesh/tools/bmesh_triangulate.c b/source/blender/bmesh/tools/bmesh_triangulate.c new file mode 100644 index 00000000000..7e6e41a12e6 --- /dev/null +++ b/source/blender/bmesh/tools/bmesh_triangulate.c @@ -0,0 +1,66 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Joseph Eagar + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/bmesh/tools/bmesh_triangulate.c + * \ingroup bmesh + * + * Triangulate. + * + */ + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" +#include "BLI_array.h" + +#include "bmesh.h" + +#include "bmesh_triangulate.h" /* own include */ + +void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only) +{ + BMIter iter; + BMFace *face; + float (*projectverts)[3] = NULL; + BLI_array_declare(projectverts); + + if (tag_only == false) { + BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) { + BLI_array_empty(projectverts); + BLI_array_reserve(projectverts, face->len * 3); + + BM_face_triangulate(bm, face, projectverts, NULL, use_beauty, false); + } + } + else { + BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) { + if (BM_elem_flag_test(face, BM_ELEM_TAG)) { + BLI_array_empty(projectverts); + BLI_array_grow_items(projectverts, face->len * 3); + + BM_face_triangulate(bm, face, projectverts, NULL, use_beauty, true); + } + } + } + + BLI_array_free(projectverts); +} diff --git a/source/blender/bmesh/tools/bmesh_triangulate.h b/source/blender/bmesh/tools/bmesh_triangulate.h new file mode 100644 index 00000000000..9632ab5957f --- /dev/null +++ b/source/blender/bmesh/tools/bmesh_triangulate.h @@ -0,0 +1,35 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Joseph Eagar + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/bmesh/tools/bmesh_triangulate.c + * \ingroup bmesh + * + * Triangulate. + * + */ + +#ifndef __BMESH_TRIAMGULATE_H__ +#define __BMESH_TRIAMGULATE_H__ + +void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only); + +#endif /* __BMESH_TRIAMGULATE_H__ */ |