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.

This commit is contained in:
Campbell Barton
2013-01-29 10:31:05 +00:00
parent 97a5cd92bc
commit 37489d71c7
8 changed files with 121 additions and 46 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)) {
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);
BLI_array_empty(projectverts);
BLI_array_empty(newfaces);
BM_mesh_triangulate(bm, use_beauty, true);
BLI_array_grow_items(projectverts, face->len * 3);
BLI_array_grow_items(newfaces, face->len);
BM_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty);
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)

View File

@@ -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);
}

View File

@@ -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__ */

View File

@@ -33,8 +33,6 @@
#include "BKE_modifier.h"
#include "BKE_tessmesh.h"
/* triangulation modifier, directly calls the bmesh operator */
static DerivedMesh *triangulate_dm(DerivedMesh *dm, const int flag)
{
DerivedMesh *result;
@@ -44,13 +42,7 @@ static DerivedMesh *triangulate_dm(DerivedMesh *dm, const int flag)
bm = DM_to_bmesh(dm);
BM_mesh_elem_toolflags_ensure(bm);
BMO_push(bm, NULL);
BMO_op_callf(bm, BMO_FLAG_DEFAULTS,
"triangulate faces=%af use_beauty=%b",
(flag & MOD_TRIANGULATE_BEAUTY));
BMO_pop(bm);
BM_mesh_triangulate(bm, (flag & MOD_TRIANGULATE_BEAUTY), false);
result = CDDM_from_bmesh(bm, FALSE);
BM_mesh_free(bm);