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
path: root/source
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-02-28 18:08:26 +0300
committerHans Goudey <h.goudey@me.com>2022-02-28 18:08:26 +0300
commit579f42ae525df065ff4436e186b7850dec86642f (patch)
tree5850393a711d9c21e977ee289d4a8c256012c8ca /source
parentf5159e078ef7a3089c3cdd9367eefe32465a2364 (diff)
Cleanup: Move mesh_validate.c to C++
This patch was tested on the build bots on all platforms.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_mesh.h2
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.cc (renamed from source/blender/blenkernel/intern/mesh_validate.c)78
3 files changed, 43 insertions, 39 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 949266c779d..2373bb289cd 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -942,7 +942,7 @@ void BKE_mesh_calc_relative_deform(const struct MPoly *mpoly,
const float (*vert_cos_org)[3],
float (*vert_cos_new)[3]);
-/* *** mesh_validate.c *** */
+/* *** mesh_validate.cc *** */
/**
* Validates and corrects a Mesh.
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index ad8b5813492..2b77b2c5dae 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -200,7 +200,7 @@ set(SRC
intern/mesh_sample.cc
intern/mesh_tangent.c
intern/mesh_tessellate.c
- intern/mesh_validate.c
+ intern/mesh_validate.cc
intern/mesh_wrapper.c
intern/modifier.c
intern/movieclip.c
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.cc
index 53e19e6d16d..cc7404e2a11 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.cc
@@ -5,10 +5,10 @@
* \ingroup bke
*/
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include "CLG_log.h"
@@ -41,25 +41,25 @@ static CLG_LogRef LOG = {"bke.mesh"};
/** \name Internal functions
* \{ */
-typedef union {
+union EdgeUUID {
uint32_t verts[2];
int64_t edval;
-} EdgeUUID;
+};
-typedef struct SortFace {
+struct SortFace {
EdgeUUID es[4];
uint index;
-} SortFace;
+};
/* Used to detect polys (faces) using exactly the same vertices. */
/* Used to detect loops used by no (disjoint) or more than one (intersect) polys. */
-typedef struct SortPoly {
+struct SortPoly {
int *verts;
int numverts;
int loopstart;
uint index;
bool invalid; /* Poly index. */
-} SortPoly;
+};
static void edge_store_assign(uint32_t verts[2], const uint32_t v1, const uint32_t v2)
{
@@ -106,7 +106,8 @@ static int int64_cmp(const void *v1, const void *v2)
static int search_face_cmp(const void *v1, const void *v2)
{
- const SortFace *sfa = v1, *sfb = v2;
+ const SortFace *sfa = static_cast<const SortFace *>(v1);
+ const SortFace *sfb = static_cast<const SortFace *>(v2);
if (sfa->es[0].edval > sfb->es[0].edval) {
return 1;
@@ -147,8 +148,8 @@ static int int_cmp(const void *v1, const void *v2)
static int search_poly_cmp(const void *v1, const void *v2)
{
- const SortPoly *sp1 = v1;
- const SortPoly *sp2 = v2;
+ const SortPoly *sp1 = static_cast<const SortPoly *>(v1);
+ const SortPoly *sp2 = static_cast<const SortPoly *>(v2);
/* Reject all invalid polys at end of list! */
if (sp1->invalid || sp2->invalid) {
@@ -168,8 +169,8 @@ static int search_poly_cmp(const void *v1, const void *v2)
static int search_polyloop_cmp(const void *v1, const void *v2)
{
- const SortPoly *sp1 = v1;
- const SortPoly *sp2 = v2;
+ const SortPoly *sp1 = static_cast<const SortPoly *>(v1);
+ const SortPoly *sp2 = static_cast<const SortPoly *>(v2);
/* Reject all invalid polys at end of list! */
if (sp1->invalid || sp2->invalid) {
@@ -275,7 +276,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
EdgeHash *edge_hash = BLI_edgehash_new_ex(__func__, totedge);
- BLI_assert(!(do_fixes && mesh == NULL));
+ BLI_assert(!(do_fixes && mesh == nullptr));
fix_flag.as_flag = 0;
free_flag.as_flag = 0;
@@ -288,7 +289,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
recalc_flag.edges = do_fixes;
}
- const float(*vert_normals)[3] = NULL;
+ const float(*vert_normals)[3] = nullptr;
BKE_mesh_assert_normals_dirty_or_calculated(mesh);
if (!BKE_mesh_vertex_normals_are_dirty(mesh)) {
vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
@@ -394,7 +395,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
MFace *mf;
MFace *mf_prev;
- SortFace *sort_faces = MEM_callocN(sizeof(SortFace) * totface, "search faces");
+ SortFace *sort_faces = (SortFace *)MEM_callocN(sizeof(SortFace) * totface, "search faces");
SortFace *sf;
SortFace *sf_prev;
uint totsortface = 0;
@@ -547,7 +548,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
{
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(mesh->totvert, __func__);
- SortPoly *sort_polys = MEM_callocN(sizeof(SortPoly) * totpoly, "mesh validate's sort_polys");
+ SortPoly *sort_polys = (SortPoly *)MEM_callocN(sizeof(SortPoly) * totpoly,
+ "mesh validate's sort_polys");
SortPoly *prev_sp, *sp = sort_polys;
int prev_end;
@@ -586,7 +588,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
/* Poly itself is valid, for now. */
int v1, v2; /* v1 is prev loop vert idx, v2 is current loop one. */
sp->invalid = false;
- sp->verts = v = MEM_mallocN(sizeof(int) * mp->totloop, "Vert idx of SortPoly");
+ sp->verts = v = (int *)MEM_mallocN(sizeof(int) * mp->totloop, "Vert idx of SortPoly");
sp->numverts = mp->totloop;
sp->loopstart = mp->loopstart;
@@ -725,7 +727,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
/* Third check pass, testing loops used by none or more than one poly. */
qsort(sort_polys, totpoly, sizeof(SortPoly), search_polyloop_cmp);
sp = sort_polys;
- prev_sp = NULL;
+ prev_sp = nullptr;
prev_end = 0;
for (i = 0; i < totpoly; i++, sp++) {
/* Free this now, we don't need it anymore, and avoid us another loop! */
@@ -733,7 +735,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
MEM_freeN(sp->verts);
}
- /* Note above prev_sp: in following code, we make sure it is always valid poly (or NULL). */
+ /* Note above prev_sp: in following code, we make sure it is always valid poly (or nullptr).
+ */
if (sp->invalid) {
if (do_fixes) {
REMOVE_POLY_TAG((&mpolys[sp->index]));
@@ -792,7 +795,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
MEM_freeN(sort_polys);
}
- BLI_edgehash_free(edge_hash, NULL);
+ BLI_edgehash_free(edge_hash, nullptr);
/* fix deform verts */
if (dverts) {
@@ -907,7 +910,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
if (free_flag.mselect) {
MEM_freeN(mesh->mselect);
- mesh->mselect = NULL;
+ mesh->mselect = nullptr;
mesh->totselect = 0;
}
}
@@ -1192,7 +1195,7 @@ void BKE_mesh_strip_loose_polysloops(Mesh *me)
MLoop *l;
int a, b;
/* New loops idx! */
- int *new_idx = MEM_mallocN(sizeof(int) * me->totloop, __func__);
+ int *new_idx = (int *)MEM_mallocN(sizeof(int) * me->totloop, __func__);
for (a = b = 0, p = me->mpoly; a < me->totpoly; a++, p++) {
bool invalid = false;
@@ -1262,7 +1265,7 @@ void BKE_mesh_strip_loose_edges(Mesh *me)
MEdge *e;
MLoop *l;
int a, b;
- uint *new_idx = MEM_mallocN(sizeof(int) * me->totedge, __func__);
+ uint *new_idx = (uint *)MEM_mallocN(sizeof(int) * me->totedge, __func__);
for (a = b = 0, e = me->medge; a < me->totedge; a++, e++) {
if (e->v1 != e->v2) {
@@ -1322,7 +1325,8 @@ static void to_edgesort(struct EdgeSort *ed, uint v1, uint v2, char is_loose, sh
static int vergedgesort(const void *v1, const void *v2)
{
- const struct EdgeSort *x1 = v1, *x2 = v2;
+ const struct EdgeSort *x1 = static_cast<const struct EdgeSort *>(v1);
+ const struct EdgeSort *x2 = static_cast<const struct EdgeSort *>(v2);
if (x1->v1 > x2->v1) {
return 1;
@@ -1380,12 +1384,12 @@ static void mesh_calc_edges_mdata(MVert *UNUSED(allvert),
if (totedge == 0) {
/* flag that mesh has edges */
- (*r_medge) = MEM_callocN(0, __func__);
+ (*r_medge) = (MEdge *)MEM_callocN(0, __func__);
(*r_totedge) = 0;
return;
}
- ed = edsort = MEM_mallocN(totedge * sizeof(struct EdgeSort), "EdgeSort");
+ ed = edsort = (EdgeSort *)MEM_mallocN(totedge * sizeof(struct EdgeSort), "EdgeSort");
for (a = totface, mface = allface; a > 0; a--, mface++) {
to_edgesort(ed++, mface->v1, mface->v2, !mface->v3, mface->edcode & ME_V1V2);
@@ -1411,7 +1415,7 @@ static void mesh_calc_edges_mdata(MVert *UNUSED(allvert),
}
totedge_final++;
- medge = MEM_callocN(sizeof(MEdge) * totedge_final, __func__);
+ medge = (MEdge *)MEM_callocN(sizeof(MEdge) * totedge_final, __func__);
for (a = totedge, med = medge, ed = edsort; a > 1; a--, ed++) {
/* edge is unique when it differs from next edge, or is last */
@@ -1469,7 +1473,7 @@ static void mesh_calc_edges_mdata(MVert *UNUSED(allvert),
}
}
- BLI_edgehash_free(hash, NULL);
+ BLI_edgehash_free(hash, nullptr);
*r_medge = medge;
*r_totedge = totedge_final;
@@ -1499,7 +1503,7 @@ void BKE_mesh_calc_edges_legacy(Mesh *me, const bool use_old)
return;
}
- medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge);
+ medge = (MEdge *)CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge);
me->medge = medge;
me->totedge = totedge;
@@ -1548,11 +1552,11 @@ void BKE_mesh_calc_edges_tessface(Mesh *mesh)
/* write new edges into a temporary CustomData */
CustomData edgeData;
CustomData_reset(&edgeData);
- CustomData_add_layer(&edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges);
- CustomData_add_layer(&edgeData, CD_ORIGINDEX, CD_CALLOC, NULL, numEdges);
+ CustomData_add_layer(&edgeData, CD_MEDGE, CD_CALLOC, nullptr, numEdges);
+ CustomData_add_layer(&edgeData, CD_ORIGINDEX, CD_CALLOC, nullptr, numEdges);
- MEdge *med = CustomData_get_layer(&edgeData, CD_MEDGE);
- int *index = CustomData_get_layer(&edgeData, CD_ORIGINDEX);
+ MEdge *med = (MEdge *)CustomData_get_layer(&edgeData, CD_MEDGE);
+ int *index = (int *)CustomData_get_layer(&edgeData, CD_ORIGINDEX);
EdgeSetIterator *ehi = BLI_edgesetIterator_new(eh);
for (int i = 0; BLI_edgesetIterator_isDone(ehi) == false;
@@ -1569,7 +1573,7 @@ void BKE_mesh_calc_edges_tessface(Mesh *mesh)
mesh->edata = edgeData;
mesh->totedge = numEdges;
- mesh->medge = CustomData_get_layer(&mesh->edata, CD_MEDGE);
+ mesh->medge = (MEdge *)CustomData_get_layer(&mesh->edata, CD_MEDGE);
BLI_edgeset_free(eh);
}