Skip to content

Commit

Permalink
Allow mz3 to save per-vertex scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Dec 21, 2024
1 parent 9c3774c commit 9ec8fff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/meshify.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static vec3s vec3d2vec4s(vec3d v) {
return (vec3s){.x = (float)v.x, .y = (float)v.y, .z = (float)v.z};
} // convert float64 to float32

static int save_mz3(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt, bool isGz) {
int save_mz3(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt, bool isGz, float *perVertexScalar) {
//https://github.com/neurolabusc/surf-ice/tree/master/mz3
#ifdef _MSC_VER
#pragma pack(2)
Expand All @@ -574,9 +574,12 @@ static int save_mz3(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt,
uint32_t NFACE, NVERT, NSKIP;
};
#endif
bool hasPerVertexScalar = (perVertexScalar != NULL);
struct mz3hdr h;
h.SIGNATURE = 0x5A4D;
h.ATTR = 3;//isFACE +1 isVERT +2
if (hasPerVertexScalar)
h.ATTR += 8;//isSCALAR +8
h.NFACE = ntri;
h.NVERT = npt;
h.NSKIP = 0;
Expand Down Expand Up @@ -632,6 +635,9 @@ static int save_mz3(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt,
#endif
{
fwrite(pts32, npt * sizeof(vec3s), 1, fp);
if (hasPerVertexScalar) {
fwrite(perVertexScalar, npt * sizeof(float), 1, fp);
}
fclose(fp);
}
free(pts32);
Expand Down Expand Up @@ -988,7 +994,7 @@ int save_mesh(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt, bool
if (strlen(fnm) > strlen(basenm))
strcpy(ext, fnm + strlen(basenm));
if (strstr(ext, ".mz3"))
return save_mz3(fnm, tris, pts, ntri, npt, isGz);
return save_mz3(fnm, tris, pts, ntri, npt, isGz, NULL);
#ifdef HAVE_FORMATS
else if (strstr(ext, ".gii"))
return save_gii(fnm, tris, pts, ntri, npt, isGz);
Expand All @@ -1015,7 +1021,7 @@ int save_mesh(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt, bool
#endif //HAVE_ZLIB
strcpy(basenm, fnm);
strcat(basenm, ".mz3");
return save_mz3(basenm, tris, pts, ntri, npt, isGz);
return save_mz3(basenm, tris, pts, ntri, npt, isGz, NULL);
}

static double sform(vec3d p, float srow[4]) {
Expand Down
1 change: 1 addition & 0 deletions src/meshify.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "meshtypes.h"

void strip_ext(char *fname);
int save_mz3(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt, bool isGz, float *perVertexScalar);
int save_mesh(const char *fnm, vec3i *tris, vec3d *pts, int ntri, int npt, bool isGz);
int meshify(float * img, short dim[3], int originalMC, float isolevel, vec3i **t, vec3d **p, int *nt, int *np, bool preSmooth, bool onlyLargest, bool fillBubbles, bool verbose);
void apply_sform(vec3i *t, vec3d *p, int nt, int np, float srow_x[4], float srow_y[4], float srow_z[4]);
Expand Down

0 comments on commit 9ec8fff

Please sign in to comment.