[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51420] trunk/blender/source/blender: add option to initialize heap with a known number of elements, since this may be known in advance - it avoids re-allocing too much.

Campbell Barton ideasman42 at gmail.com
Fri Oct 19 12:40:33 CEST 2012


Revision: 51420
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51420
Author:   campbellbarton
Date:     2012-10-19 10:40:32 +0000 (Fri, 19 Oct 2012)
Log Message:
-----------
add option to initialize heap with a known number of elements, since this may be known in advance - it avoids re-allocing too much.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_heap.h
    trunk/blender/source/blender/blenlib/intern/BLI_heap.c
    trunk/blender/source/blender/bmesh/intern/bmesh_decimate.c
    trunk/blender/source/blender/modifiers/intern/MOD_decimate.c

Modified: trunk/blender/source/blender/blenlib/BLI_heap.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_heap.h	2012-10-19 10:37:24 UTC (rev 51419)
+++ trunk/blender/source/blender/blenlib/BLI_heap.h	2012-10-19 10:40:32 UTC (rev 51420)
@@ -42,6 +42,7 @@
 
 /* Creates a new heap. BLI_memarena is used for allocating nodes. Removed nodes
  * are recycled, so memory usage will not shrink. */
+Heap           *BLI_heap_new_ex(unsigned int tot_reserve);
 Heap           *BLI_heap_new(void);
 void            BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp);
 

Modified: trunk/blender/source/blender/blenlib/intern/BLI_heap.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_heap.c	2012-10-19 10:37:24 UTC (rev 51419)
+++ trunk/blender/source/blender/blenlib/intern/BLI_heap.c	2012-10-19 10:40:32 UTC (rev 51420)
@@ -67,16 +67,22 @@
 
 /***/
 
-Heap *BLI_heap_new(void)
+/* use when the size of the heap is known in advance */
+Heap *BLI_heap_new_ex(unsigned int tot_reserve)
 {
 	Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__);
-	heap->bufsize = 1;
-	heap->tree = (HeapNode **)MEM_mallocN(sizeof(HeapNode *), "BLIHeapTree");
+	heap->bufsize = tot_reserve;
+	heap->tree = (HeapNode **)MEM_mallocN(tot_reserve * sizeof(HeapNode *), "BLIHeapTree");
 	heap->arena = BLI_memarena_new(1 << 16, "heap arena");
 
 	return heap;
 }
 
+Heap *BLI_heap_new(void)
+{
+	return BLI_heap_new_ex(1);
+}
+
 void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp)
 {
 	int i;

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_decimate.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_decimate.c	2012-10-19 10:37:24 UTC (rev 51419)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_decimate.c	2012-10-19 10:40:32 UTC (rev 51420)
@@ -531,7 +531,7 @@
 
 	/* alloc vars */
 	vquadrics = MEM_callocN(sizeof(Quadric) * bm->totvert, __func__);
-	eheap = BLI_heap_new();
+	eheap = BLI_heap_new_ex(bm->totedge);
 	eheap_table = MEM_callocN(sizeof(HeapNode *) * bm->totedge, __func__);
 	tot_edge_orig = bm->totedge;
 

Modified: trunk/blender/source/blender/modifiers/intern/MOD_decimate.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_decimate.c	2012-10-19 10:37:24 UTC (rev 51419)
+++ trunk/blender/source/blender/modifiers/intern/MOD_decimate.c	2012-10-19 10:40:32 UTC (rev 51420)
@@ -47,7 +47,11 @@
 #include "BKE_particle.h"
 #include "BKE_cdderivedmesh.h"
 
+#include "BKE_tessmesh.h"
 
+/* testing only! - Campbell */
+// #define USE_DECIMATE_BMESH
+
 #ifdef WITH_MOD_DECIMATE
 #include "LOD_decimation.h"
 #endif
@@ -70,12 +74,39 @@
 }
 
 #ifdef WITH_MOD_DECIMATE
+#ifdef USE_DECIMATE_BMESH
+
+#include "bmesh.h"
+
 static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
                                   DerivedMesh *derivedData,
                                   ModifierApplyFlag UNUSED(flag))
 {
 	DecimateModifierData *dmd = (DecimateModifierData *) md;
 	DerivedMesh *dm = derivedData, *result = NULL;
+	BMEditMesh *em;
+	BMesh *bm;
+
+	em = DM_to_editbmesh(dm, NULL, FALSE);
+	bm = em->bm;
+
+	BM_mesh_decimate(bm, dmd->percent);
+
+	BLI_assert(em->looptris == NULL);
+	result = CDDM_from_BMEditMesh(em, NULL, TRUE, FALSE);
+	BMEdit_Free(em);
+	MEM_freeN(em);
+
+	return result;
+}
+
+#else
+static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
+                                  DerivedMesh *derivedData,
+                                  ModifierApplyFlag UNUSED(flag))
+{
+	DecimateModifierData *dmd = (DecimateModifierData *) md;
+	DerivedMesh *dm = derivedData, *result = NULL;
 	MVert *mvert;
 	MFace *mface;
 	LOD_Decimation_Info lod;
@@ -192,6 +223,7 @@
 		return dm;
 	}
 }
+#endif // USE_DECIMATE_BMESH
 #else // WITH_MOD_DECIMATE
 static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob),
                                   DerivedMesh *derivedData,




More information about the Bf-blender-cvs mailing list