IMOD Library libmesh

The IMOD library libmesh contains functions for meshing contours and objects. It is used by imodmesh and by 3dmod.

Header to include: mkmesh.h


int analyzePrepSkinObj(Iobj *obj, int resol, Ipoint *scale, int (*inCB)(int))
int imodMeshesDeleteRes(Imesh **meshp, int *size, int resol)
int imeshPrepContours(Iobj *obj, int minz, int maxz, int incz, float tol, int useMeanZ)
Iobj *imeshDupMarkedConts(Iobj *obj, unsigned int flag)
int imeshSkinObject(Iobj *obj, Ipoint *scale, double overlap, int cap, int *cap_skip_zlist, int cap_skip_nz, int incz, unsigned int flags, int skipPasses, double tubeDiameter, int (*inCB)(int))
Imesh *imeshContoursCost(Iobj *obj, Icont *bc, Icont *tc, Ipoint *scale, int inside, int bco, int tco)
int chunkMeshAddIndex(Imesh *mesh, int index, int *maxlist)
Imesh *imeshReMeshNormal(Imesh *meshes, int *size, Ipoint *scale, int resol)
void imeshNormal(Ipoint *n, Ipoint *p1, Ipoint *p2, Ipoint *p3, Ipoint *sp)


MeshParams structure

int analyzePrepSkinObj(Iobj *obj, int resol, Ipoint *scale, int (*inCB)(int))

Provides a single call for analysis, preparation, and skinning of object obj.  Uses the meshing parameters in the meshParam member of obj, a MeshParams structure. Duplicates the contours unless IMESH_MK_IS_COPY is set in flags. Analyzes for flatness if flatCrit is nonzero and if the contours are not flat enough, finds a separate rotation to flatness for each surface. Calls imeshPrepContours and imeshSkinObj .  Returns 1 for error.

int imodMeshesDeleteRes(Imesh **meshp, int *size, int resol)

Deletes meshes pointed to by meshp and their store elements if their resolution flag matches resol.  size is the size of the mesh; both meshp and size are updated for the new mesh.  Returns -1 for error.

int imeshPrepContours(Iobj *obj, int minz, int maxz, int incz, float tol, int useMeanZ)

Flattens, resections, reduces resolution, and cleans up small numbers in the contours of obj.  Contours are flattened by setting their Z values to the Z of the first point, or to the mean Z value if useMeanZ is nonzero.  Contours with Z not between minz and maxz and not multiples of incz are eliminated (minz and maxz should both be set to DEFAULT_VALUE to retain the full Z range).  Point reduction is applied with tolerance tol if it is nonzero.  Returns 1 for error.

Iobj *imeshDupMarkedConts(Iobj *obj, unsigned int flag)

Makes an object with duplicates of the contours in obj; either contours whose flag has a non-zero AND with flags, or all non-empty contours if flag is zero.  Copies store data but not meshes. Returns NULL for error.

int imeshSkinObject(Iobj *obj, Ipoint *scale, double overlap, int cap, int *cap_skip_zlist, int cap_skip_nz, int incz, unsigned int flags, int skipPasses, double tubeDiameter, int (*inCB)(int))

The main meshing routine for closed or open contours; calls appropriate routines for open contours or tube contours.  Arguments are:
  *obj          The object to be skinned.
  *scale        Scaling used for normal calculation.
  overlap       Overlap percentage.
  cap           Cap ends of surface.
  *cap_skip_zlist  List of Z values to not cap
  cap_skip_nz      Number of Z values to not cap
  incz          Increment in z values
  int flags     Flags
  skipPasses    Number of passes for skipped sections
  tubeDiameter  Diameter for tube meshing, or 0 to use 3D line width, -1 to use point sizes, or -2 to use symbol sizes
  inCB          A callback function, or NULL for none

Imesh *imeshContoursCost(Iobj *obj, Icont *bc, Icont *tc, Ipoint *scale, int inside, int bco, int tco)

Creates and returns a mesh between two contours using a minimum area cost analysis.  The bottom and top (low Z and high Z) contours are bc and tc, and obj is the object containing them, and their contour indices are bco and tco.  These indices are used to look up general storage properties of the contours in the object.  scale contains the X, Y, and Z scale, typically 1, 1, and the model Z scale.  A non-zero value of inside indicates that the contours are inside others, at an even nesting level.  Contours from open contour objects should have the flag ICONT_OPEN set before calling.  Returns NULL for error.

int chunkMeshAddIndex(Imesh *mesh, int index, int *maxlist)

Adds index to the index list of mesh, allocating new memory in large chunks to avoid expensive frequent reallocations.  maxlist specifies the current size of the allocated list and is returned with a new size when it becomes larger.  Returns NULL for error

Imesh *imeshReMeshNormal(Imesh *meshes, int *size, Ipoint *scale, int resol)

Remakes meshes into one mesh per surface and time to store data more efficiently, and calculates normals for all vertices.  The array of meshes is in meshes, and size specifies the number of meshes.  Only meshes matching the resolution given by resol will be processed; others will be copied to the output.  The normals are scaled by the values in scale. THIS FUNCTION DELETES THE INPUT MESH BEFORE RETURNING Returns NULL for error.

void imeshNormal(Ipoint *n, Ipoint *p1, Ipoint *p2, Ipoint *p3, Ipoint *sp)

Computes a normalized normal in n from the three points pi, p2, and p3.  Scales the points by the scaling in sp first if sp is not NULL.

MeshParams structure

Parameters for meshing an object
typedef struct Meshing_Param
{
  b3dUInt32 flags;         /* IMESH_MK_* flags */
  b3dInt32 cap;            /* Capping parameter */
  b3dInt32 passes;         /* Number of passes for skipped sections */
  b3dInt32 capSkipNz;      /* Number of Z values not to cap to */
  b3dInt32 inczLowRes;     /* Z increment for low res mesh */
  b3dInt32 inczHighRes;    /* Z increment for high res mesh */
  b3dInt32 minz, maxz;     /* Starting and ending Z to mesh */
  b3dInt32 spareInt;
  b3dFloat overlap;        /* Fractional overlap required if nonzero */
  b3dFloat tubeDiameter;   /* Diameter when meshing tubes */
  b3dFloat xmin, xmax;     /* X and Y limits for triangle output */
  b3dFloat ymin, ymax;
  b3dFloat tolLowRes;      /* Point reduction tolerance for low and high res */
  b3dFloat tolHighRes;
  b3dFloat flatCrit;       /* Criterion Z difference for rotating contours */
  b3dFloat spareFloat;
  b3dInt32 *capSkipZlist;  /* List of Z values not to cap to */
} MeshParams;