Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-19 14:40:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-19 14:40:32 +0400
commite527ce552e9e3864c7a2f5bb688ffa1d4cd0d5f1 (patch)
treea340f534a7d62e6f9129bbfbbd31b297b7e214b5 /source/blender
parentb7642348e44c10710c0d3f65ccfdafdd964829a2 (diff)
add option to initialize heap with a known number of elements, since this may be known in advance - it avoids re-allocing too much.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_heap.h1
-rw-r--r--source/blender/blenlib/intern/BLI_heap.c12
-rw-r--r--source/blender/bmesh/intern/bmesh_decimate.c2
-rw-r--r--source/blender/modifiers/intern/MOD_decimate.c32
4 files changed, 43 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_heap.h b/source/blender/blenlib/BLI_heap.h
index b378f2bb365..9d7e6107f19 100644
--- a/source/blender/blenlib/BLI_heap.h
+++ b/source/blender/blenlib/BLI_heap.h
@@ -42,6 +42,7 @@ typedef void (*HeapFreeFP)(void *ptr);
/* 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);
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index ee7d93ea1a9..5e0762a5d68 100644
--- a/source/blender/blenlib/intern/BLI_heap.c
+++ b/source/blender/blenlib/intern/BLI_heap.c
@@ -67,16 +67,22 @@ struct Heap {
/***/
-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;
diff --git a/source/blender/bmesh/intern/bmesh_decimate.c b/source/blender/bmesh/intern/bmesh_decimate.c
index d8aa8adef55..122f24955c6 100644
--- a/source/blender/bmesh/intern/bmesh_decimate.c
+++ b/source/blender/bmesh/intern/bmesh_decimate.c
@@ -531,7 +531,7 @@ void BM_mesh_decimate(BMesh *bm, const float factor)
/* 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;
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c
index cb6681bfa68..171d601ea6d 100644
--- a/source/blender/modifiers/intern/MOD_decimate.c
+++ b/source/blender/modifiers/intern/MOD_decimate.c
@@ -47,6 +47,10 @@
#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"
@@ -70,6 +74,33 @@ static void copyData(ModifierData *md, ModifierData *target)
}
#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))
@@ -192,6 +223,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
return dm;
}
}
+#endif // USE_DECIMATE_BMESH
#else // WITH_MOD_DECIMATE
static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob),
DerivedMesh *derivedData,