[Bf-blender-cvs] [f88a54c] mesh-transfer-data: cleanup: move island calculation back into mesh_mapping
Campbell Barton
noreply at git.blender.org
Mon Nov 17 14:10:19 CET 2014
Commit: f88a54c1f168116d09bca9bfb60f4198806535be
Author: Campbell Barton
Date: Mon Nov 17 14:09:15 2014 +0100
Branches: mesh-transfer-data
https://developer.blender.org/rBf88a54c1f168116d09bca9bfb60f4198806535be
cleanup: move island calculation back into mesh_mapping
also make uv-island computing take arrays instead of a derivedmesh.
===================================================================
M source/blender/blenkernel/BKE_mesh_mapping.h
M source/blender/blenkernel/BKE_mesh_remap.h
M source/blender/blenkernel/intern/mesh_mapping.c
M source/blender/blenkernel/intern/mesh_remap.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h
index af76e89..d6fa468 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -31,8 +31,9 @@
* \ingroup bke
*/
-struct MPoly;
+struct MVert;
struct MEdge;
+struct MPoly;
struct MLoop;
struct MLoopUV;
@@ -126,7 +127,54 @@ void BKE_mesh_origindex_map_create(
const int totorig,
const int *final_origindex, const int totfinal);
-/* smoothgroups */
+
+/* islands */
+
+/* Loop islands data helpers. */
+enum {
+ MISLAND_TYPE_VERT = 1,
+ MISLAND_TYPE_EDGE = 2,
+ MISLAND_TYPE_POLY = 3,
+ MISLAND_TYPE_LOOP = 4,
+};
+
+typedef struct MeshIslands {
+ short item_type; /* MISLAND_TYPE_... */
+ short island_type; /* MISLAND_TYPE_... */
+
+ int nbr_items;
+ int *items_to_islands_idx;
+
+ int nbr_islands;
+ struct MeshElemMap **islands; /* Array of pointers, one item per island. */
+
+ void *mem; /* Memory handler, internal use only. */
+ size_t allocated_islands;
+} MeshIslands;
+
+void BKE_loop_islands_init(MeshIslands *islands, const short item_type, const int num_items, const short island_type);
+void BKE_loop_islands_free(MeshIslands *islands);
+void BKE_loop_islands_add_island(MeshIslands *islands, const int num_items, int *item_indices,
+ const int num_island_items, int *island_item_indices);
+
+typedef bool (*loop_island_compute)(
+ struct MVert *verts, const int totvert,
+ struct MEdge *edges, const int totedge,
+ struct MPoly *polys, const int totpoly,
+ struct MLoop *loops, const int totloop,
+ struct MeshIslands *r_islands);
+
+/* Above vert/UV mapping stuff does not do what we need here, but does things we do not need here.
+ * So better keep them separated for now, I think.
+ */
+bool BKE_loop_poly_island_compute_uv(
+ struct MVert *verts, const int totvert,
+ struct MEdge *edges, const int totedge,
+ struct MPoly *polys, const int totpoly,
+ struct MLoop *loops, const int totloop,
+ MeshIslands *r_islands);
+
+
int *BKE_mesh_calc_smoothgroups(
const struct MEdge *medge, const int totedge,
const struct MPoly *mpoly, const int totpoly,
@@ -135,14 +183,14 @@ int *BKE_mesh_calc_smoothgroups(
/** Callback deciding whether the given poly/loop/edge define an island boundary or not.
*/
-typedef bool (*check_island_boundary)(
+typedef bool (*MeshRemap_CheckIslandBoundary)(
const struct MPoly *mpoly, const struct MLoop *mloop, const struct MEdge *medge,
const int nbr_egde_users);
void BKE_poly_loop_islands_compute(
const struct MEdge *medge, const int totedge, const struct MPoly *mpoly, const int totpoly,
const struct MLoop *mloop, const int totloop, const bool use_bitflags,
- check_island_boundary edge_boundary_check,
+ MeshRemap_CheckIslandBoundary edge_boundary_check,
int **r_poly_groups, int *r_totgroup);
/* No good (portable) way to have exported inlined functions... */
diff --git a/source/blender/blenkernel/BKE_mesh_remap.h b/source/blender/blenkernel/BKE_mesh_remap.h
index 2b43ff6..535684b 100644
--- a/source/blender/blenkernel/BKE_mesh_remap.h
+++ b/source/blender/blenkernel/BKE_mesh_remap.h
@@ -29,39 +29,6 @@ struct DerivedMesh;
struct MVert;
struct MeshElemMap;
-/* Loop islands data helpers. */
-enum {
- MISLAND_TYPE_VERT = 1,
- MISLAND_TYPE_EDGE = 2,
- MISLAND_TYPE_POLY = 3,
- MISLAND_TYPE_LOOP = 4,
-};
-
-typedef struct MeshIslands {
- short item_type; /* MISLAND_TYPE_... */
- short island_type; /* MISLAND_TYPE_... */
-
- int nbr_items;
- int *items_to_islands_idx;
-
- int nbr_islands;
- struct MeshElemMap **islands; /* Array of pointers, one item per island. */
-
- void *mem; /* Memory handler, internal use only. */
- size_t allocated_islands;
-} MeshIslands;
-
-void BKE_loop_islands_init(MeshIslands *islands, const short item_type, const int num_items, const short island_type);
-void BKE_loop_islands_free(MeshIslands *islands);
-void BKE_loop_islands_add_island(MeshIslands *islands, const int num_items, int *item_indices,
- const int num_island_items, int *island_item_indices);
-
-typedef bool (*loop_island_compute)(struct DerivedMesh *dm, MeshIslands *r_islands);
-/* Above vert/UV mapping stuff does not do what we need here, but does things we do not need here.
- * So better keep them separated for now, I think.
- */
-bool BKE_loop_poly_island_compute_uv(struct DerivedMesh *dm, MeshIslands *r_islands);
-
/* Generic ways to map some geometry elements from a source mesh to a dest one. */
typedef struct Mesh2MeshMappingItem {
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 73533e0..b37be42 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -36,6 +36,7 @@
#include "BKE_mesh_mapping.h"
#include "BKE_customdata.h"
+#include "BLI_memarena.h"
#include "BLI_strict_flags.h"
@@ -383,7 +384,7 @@ void BKE_mesh_origindex_map_create(MeshElemMap **r_map, int **r_mem,
void BKE_poly_loop_islands_compute(
const MEdge *medge, const int totedge, const MPoly *mpoly, const int totpoly,
const MLoop *mloop, const int totloop, const bool use_bitflags,
- check_island_boundary edge_boundary_check,
+ MeshRemap_CheckIslandBoundary edge_boundary_check,
int **r_poly_groups, int *r_totgroup)
{
int *poly_groups;
@@ -532,7 +533,7 @@ void BKE_poly_loop_islands_compute(
*r_poly_groups = poly_groups;
}
-static bool poly_island_is_boundary_smooth_cb(
+static bool poly_is_island_boundary_smooth_cb(
const MPoly *mp, const MLoop *UNUSED(ml), const MEdge *me,
const int nbr_egde_users)
{
@@ -556,8 +557,153 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
int *poly_groups = NULL;
BKE_poly_loop_islands_compute(medge, totedge, mpoly, totpoly, mloop, totloop, use_bitflags,
- poly_island_is_boundary_smooth_cb, &poly_groups, r_totgroup);
+ poly_is_island_boundary_smooth_cb, &poly_groups, r_totgroup);
return poly_groups;
}
+
+
+void BKE_loop_islands_init(MeshIslands *islands, const short item_type, const int num_items, const short island_type)
+{
+ MemArena *mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+
+ BLI_assert(ELEM(item_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
+ BLI_assert(ELEM(island_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
+
+ BKE_loop_islands_free(islands);
+
+ islands->item_type = item_type;
+ islands->nbr_items = num_items;
+ islands->items_to_islands_idx = BLI_memarena_alloc(mem, sizeof(*islands->items_to_islands_idx) * (size_t)num_items);
+
+ islands->island_type = island_type;
+ islands->allocated_islands = 64;
+ islands->islands = BLI_memarena_alloc(mem, sizeof(*islands->islands) * islands->allocated_islands);
+
+ islands->mem = mem;
+}
+
+void BKE_loop_islands_free(MeshIslands *islands)
+{
+ MemArena *mem = islands->mem;
+
+ if (mem) {
+ BLI_memarena_free(mem);
+ }
+
+ islands->item_type = 0;
+ islands->nbr_items = 0;
+ islands->items_to_islands_idx = NULL;
+
+ islands->island_type = 0;
+ islands->nbr_islands = 0;
+ islands->islands = NULL;
+
+ islands->mem = NULL;
+ islands->allocated_islands = 0;
+}
+
+void BKE_loop_islands_add_island(MeshIslands *islands, const int num_items, int *items_indices,
+ const int num_island_items, int *island_item_indices)
+{
+ MemArena *mem = islands->mem;
+
+ MeshElemMap *isld;
+ const int curr_island_idx = islands->nbr_islands++;
+ const size_t curr_num_islands = (size_t)islands->nbr_islands;
+ int i = num_items;
+
+ islands->nbr_items = num_items;
+ while (i--) {
+ islands->items_to_islands_idx[items_indices[i]] = curr_island_idx;
+ }
+
+ if (UNLIKELY(curr_num_islands > islands->allocated_islands)) {
+ MeshElemMap **islds;
+
+ islands->allocated_islands *= 2;
+ islds = BLI_memarena_alloc(mem, sizeof(*islds) * islands->allocated_islands);
+ memcpy(islds, islands->islands, sizeof(*islds) * (curr_num_islands - 1));
+ islands->islands = islds;
+ }
+
+ islands->islands[curr_island_idx] = isld = BLI_memarena_alloc(mem, sizeof(*isld));
+
+ isld->count = num_island_items;
+ isld->indices = BLI_memarena_alloc(mem, sizeof(*isld->indices) * (size_t)num_island_items);
+ memcpy(isld->indices, island_item_indices, sizeof(*isld->indices) * (size_t)num_island_items);
+}
+
+/* TODO: I'm not sure edge seam flag is enough to define UV islands? Maybe we should also consider UVmaps values
+ * themselves (i.e. different UV-edges for a same mesh-edge => boundary edge too?).
+ * Would make things much more complex though, and each UVMap would then need its own mesh mapping,
+ * not sure we want that at all!
+ */
+static bool mesh_check_island_boundary_uv(
+ const MPoly *UNUSED(mp), const MLoop *UNUSED(ml), const MEdge *me,
+ const int UNUSED(nbr_egde_users))
+{
+ /* Edge is UV boundary if tagged as seam. */
+ return (me->flag & ME_SEAM) != 0;
+}
+
+/* Note: all this could be optimized... Not sure it would be worth the more complex code, though, those loops
+ * are supposed to be really quick to do... */
+bool BKE_loop_poly_island_compute_uv(
+ MVert *UNUSED(verts), const int UNUSED(totvert),
+ MEdge *edges, const int totedge,
+ MPoly *polys, const int totpoly,
+ MLoop *loops, const int totloop,
+
+ MeshIslands *r_islands)
+{
+ int *poly_groups = NULL;
+ int num_poly_groups;
+
+ int *poly_indices = MEM_mallocN(sizeof(*poly_indices) * (size_t)totpoly, __func__);
+ int *loop_indices = MEM_mallocN(sizeof(*loop_indices) * (size_t)totloop, __func__);
+ int num_pidx, num_lidx;
+
+ int grp_idx, p_idx, pl_idx, l_idx;
+
+ BKE_loop_islands_free(r_islands);
+ BKE_loop_islands_init(r_islands, MISLAND_TYPE_LOOP, totloop, MISLAND_TYPE_POLY);
+
+ BKE_poly_loop_islands_compute(
+ edges, totedge, polys, totpoly, loops, totloop, false,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list