[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54183] trunk/blender/source/blender: Triangulate modifier no longer uses bmesh operator api call, instead add a BM_mesh_triangulate() function.

Campbell Barton ideasman42 at gmail.com
Tue Jan 29 11:31:09 CET 2013


Revision: 54183
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54183
Author:   campbellbarton
Date:     2013-01-29 10:31:05 +0000 (Tue, 29 Jan 2013)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/CMakeLists.txt
    trunk/blender/source/blender/bmesh/bmesh.h
    trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
    trunk/blender/source/blender/bmesh/intern/bmesh_polygon.h
    trunk/blender/source/blender/bmesh/operators/bmo_triangulate.c
    trunk/blender/source/blender/modifiers/intern/MOD_triangulate.c

Added Paths:
-----------
    trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.c
    trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.h

Modified: trunk/blender/source/blender/bmesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/bmesh/CMakeLists.txt	2013-01-29 08:34:26 UTC (rev 54182)
+++ trunk/blender/source/blender/bmesh/CMakeLists.txt	2013-01-29 10:31:05 UTC (rev 54183)
@@ -114,6 +114,8 @@
 	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

Modified: trunk/blender/source/blender/bmesh/bmesh.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh.h	2013-01-29 08:34:26 UTC (rev 54182)
+++ trunk/blender/source/blender/bmesh/bmesh.h	2013-01-29 10:31:05 UTC (rev 54183)
@@ -268,8 +268,9 @@
 
 #include "intern/bmesh_inline.h"
 
+#include "tools/bmesh_bevel.h"
 #include "tools/bmesh_decimate.h"
-#include "tools/bmesh_bevel.h"
+#include "tools/bmesh_triangulate.h"
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c	2013-01-29 08:34:26 UTC (rev 54182)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c	2013-01-29 10:31:05 UTC (rev 54183)
@@ -845,8 +845,9 @@
  *
  * \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 @@
 			}
 
 			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;

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_polygon.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_polygon.h	2013-01-29 08:34:26 UTC (rev 54182)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_polygon.h	2013-01-29 10:31:05 UTC (rev 54183)
@@ -44,9 +44,8 @@
 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);
 

Modified: trunk/blender/source/blender/bmesh/operators/bmo_triangulate.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_triangulate.c	2013-01-29 08:34:26 UTC (rev 54182)
+++ trunk/blender/source/blender/bmesh/operators/bmo_triangulate.c	2013-01-29 10:31:05 UTC (rev 54183)
@@ -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)

Added: trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.c
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.c	                        (rev 0)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.c	2013-01-29 10:31:05 UTC (rev 54183)
@@ -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);
+}


Property changes on: trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.c
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.h
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.h	                        (rev 0)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.h	2013-01-29 10:31:05 UTC (rev 54183)
@@ -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__ */


Property changes on: trunk/blender/source/blender/bmesh/tools/bmesh_triangulate.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/blender/source/blender/modifiers/intern/MOD_triangulate.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_triangulate.c	2013-01-29 08:34:26 UTC (rev 54182)
+++ trunk/blender/source/blender/modifiers/intern/MOD_triangulate.c	2013-01-29 10:31:05 UTC (rev 54183)
@@ -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,14 +42,8 @@
 
 	bm = DM_to_bmesh(dm);
 
-	BM_mesh_elem_toolflags_ensure(bm);
-	BMO_push(bm, NULL);
+	BM_mesh_triangulate(bm, (flag & MOD_TRIANGULATE_BEAUTY), false);
 
-	BMO_op_callf(bm, BMO_FLAG_DEFAULTS,
-	             "triangulate faces=%af use_beauty=%b",
-	             (flag & MOD_TRIANGULATE_BEAUTY));
-	BMO_pop(bm);
-
 	result = CDDM_from_bmesh(bm, FALSE);
 	BM_mesh_free(bm);
 




More information about the Bf-blender-cvs mailing list