Imodel Module

This module contains functions for operating on an IMOD model or on the object, contour, or point components of a specific model.

Header to include: imodel.h
(includes ilist.h and mcrfiles.h)

General Model Manipulation and Information


Imod *imodNew(void)
int imodDefault(Imod *model)
void imodDelete(Imod *imod)
void imodGetIndex(Imod *imod, int *object, int *contour, int *point)
void imodSetIndex(Imod *imod, int object, int contour, int point)
int imodGetCurMeshSurf(Imod *imod)
void imodSetCurMeshSurf(Imod *imod, int surf)
void imodel_maxpt(Imod *imod, Ipoint *pnt)
void imodel_minpt(Imod *imod, Ipoint *pnt)
void imodGetBoundingBox(Imod *imod, Ipoint *min, Ipoint *max)
int imodTransform(Imod *imod, Imat *mat)
int imodel_transform_slice(Imod *model, float *mat, int slice)
int imodel_model_clean(Imod *mod, int keepEmptyObjs)
char *imodUnits(Imod *mod)
int imodGetMaxTime(Imod *imod)
int imodChecksum(Imod *imod)
void imodCleanSurf(Imod *imod)
void imodFlipYZ(Imod *imod)
void imodRot90X(Imod *imod, int toNative)
void imodInvertZ(Imod *imod)
int imodSetRefImage(Imod *imod, MrcHeader *hdata)
void imodTransForSubsetLoad(Imod *imod, MrcHeader *hdata, IloadInfo *li)
int imodTransFromRefImage(Imod *imod, IrefImage *iref, Ipoint binScale)
void imodTransFromMats(Imod *imod, Imat *mat, Imat *matNorm, Imat *matClip)
void imodTransModel3D(Imod *model, Imat *mat, Imat *normMat, Ipoint newCen, float zscale, int doflip)
int imodGetMaxObject(Imod *imod)
float imodGetZScale(Imod *imod)
float imodGetPixelSize(Imod *imod)
const char *imodGetFilename(Imod *imod)
int imodGetFlipped(Imod *imod)

Object-related Model Functions


int imodNewObject(Imod *mod)
int imodDeleteObject(Imod *mod, int index)
int imodMoveObject(Imod *imod, int obOld, int obNew)
int imodNextObject(Imod *imod)
int imodPrevObject(Imod *mod)
Iobj *imodObjectGet(Imod *imod)
Iobj *imodObjectGetFirst(Imod *imod)
Iobj *imodObjectGetNext(Imod *imod)

Contour-related Model Functions


int imodNewContour(Imod *mod)
void imodDelCurrentContour(Imod *imod)
int imodDeleteContour(Imod *mod, int index)
int imodDeleteListOfConts(Imod *mod, int *contours, int numConts)
int imodPrevContour(Imod *mod)
int imodNextContour(Imod *imod)
Icont *imodContourGet(Imod *imod)
Icont *imodContourGetFirst(Imod *imod)
Icont *imodContourGetNext(Imod *imod)

Point-related Model Functions


int imodNewPoint(Imod *imod, Ipoint *point)
int imodInsertPoint(Imod *imod, Ipoint *point, int index)
int imodDeletePoint(Imod *imod)
int imodPrevPoint(Imod *mod)
int imodNextPoint(Imod *mod)
Ipoint *imodPointGet(Imod *imod)
Ipoint *imodPointGetFirst(Imod *imod)
Ipoint *imodPointGetNext(Imod *imod)

General Model Manipulation and Information

Imod *imodNew(void)

Allocates a new model structure and returns a pointer to it, or NULL if there is an error.  Initializes the model with imodDefault

int imodDefault(Imod *model)

Initializes model structure pointed to by model to default values and allocates an initial view (which will leak if this is called twice). Returns 0 (there are no errors)

void imodDelete(Imod *imod)

Deletes a model; frees all memory used in objects, views, and object views and frees the model itself.

void imodGetIndex(Imod *imod, int *object, int *contour, int *point)

Returns the current object, contour, and point indexes of the model in object, contour, and point

void imodSetIndex(Imod *imod, int object, int contour, int point)

Sets the current object, contour, and point indexes of the model with the values in object, contour, and point.  Indexes are checked for legality and if one is out of bounds it is set to -1.  If an index is -1, any index at a lower level is set to -1 also (e.g., point if contour is -1).

int imodGetCurMeshSurf(Imod *imod)

Returns the current mesh surface number for model imod if the current object is legal and has meshes but no contours, and if the stored surface number is in range for this object; otherwise returns -1.

void imodSetCurMeshSurf(Imod *imod, int surf)

Set the current mesh surface number for model imod to surf if the current object is legal and has meshes but no contours, and if surf is in range for this object; otherwise leaves it unchanged.

void imodel_maxpt(Imod *imod, Ipoint *pnt)

Returns the maximum coordinates of contour points in model imod in pnt, or -1,-1,-1 if there are no points

void imodel_minpt(Imod *imod, Ipoint *pnt)

Returns the minimum coordinates of contour points in the model imod in pnt, or -1,-1,-1 if there are no points

void imodGetBoundingBox(Imod *imod, Ipoint *min, Ipoint *max)

Returns the minimum and maximum coordinates of the model imod in min and max, based either on the coordinates of points in contours, or on mesh vertices for objects with no contours.  Returns -1,-1,-1 if there are no points or meshes.

int imodTransform(Imod *imod, Imat *mat)

Transforms all contour points in model imod with the 3D transform in mat.  Returns -1 if error.

int imodel_transform_slice(Imod *model, float *mat, int slice)

Transforms all contour points in model with Z values that round to slice.  The 2D transformation in mat is applied to X and Y coordinates. Returns 0.

int imodel_model_clean(Imod *mod, int keepEmptyObjs)

Cleans model mod by removing empty contours, removing empty objects if keepEmptyObjs is 0, constraining points within the model xmax, ymax, and zmax values, and making all points have the same Z value as the first point for non-wild closed contours.  Returns 0.

char *imodUnits(Imod *mod)

Returns a string (e.g., "nm") for the pixel size units of model mod.

int imodGetMaxTime(Imod *imod)

Returns the maximum time (type) value of any contour in model imod.

int imodChecksum(Imod *imod)

Computes a checksum from the coordinates and most other features of model mod and returns the value.

void imodCleanSurf(Imod *imod)

Fixes the surface size information for all objects in model imod by determining the maximum surface number for the contours in each object.

void imodFlipYZ(Imod *imod)

Flip the model imod by exchanging Y and Z in contours and meshes.

void imodRot90X(Imod *imod, int toNative)

Rotates the model in imod by 90 degrees around the X axis and shifts along the appropriate axis to retain positive values.  The rotation is by -90 degrees if toNative is 0, corresponding to the Y-Z flip in 3dmod, and by +90 degrees if toNative is non-zero, corresponding to flipping back to native orientation. The incoming ymax and zmax values will be swapped and must be correct for the current model coordinates.

void imodInvertZ(Imod *imod)

Inverts the model in imod in the Z direction and shifts it in Z to retain positive values.  The incoming model zmax value must be correct for the current model coordinates.

int imodSetRefImage(Imod *imod, MrcHeader *hdata)

Sets the IrefImage structure refImage in imod with the image coordinate information in the MRC header hdata.  Returns 1 for memory error allocating the structure.

void imodTransForSubsetLoad(Imod *imod, MrcHeader *hdata, IloadInfo *li)

Shifts the model imod back to full volume coordinates if it was saved after being loaded on a subset of the image whose header is in hdata, and also shifts it to the coordinates of a subset currently being loaded, using the xmin, ymin, and zmin elements in li, if li is not NULL.

int imodTransFromRefImage(Imod *imod, IrefImage *iref, Ipoint binScale)

Transforms the model in imod according to the old and current shift, scale, and rotation in the IrefImage structure iref, with the additional scaling required for binning in each dimension specified in binScale.  The image reference information in the existing model IrefImage structure, if any, is not considered.  Typically, if that exists, its ctrans, cscale, and crot members would be copied to the otrans, oscale and orot members of iref, and the current values in iref would be filled in from the origin, delta, and tilt angle values in an image file header.  Returns 1 for memory errors.

void imodTransFromMats(Imod *imod, Imat *mat, Imat *matNorm, Imat *matClip)

Transforms the model in imod given three matrices: mat for transforming points, matNorm for transforming the mesh normals, and matClip for transforming clip plane normals.

void imodTransModel3D(Imod *model, Imat *mat, Imat *normMat, Ipoint newCen, float zscale, int doflip)

Transforms model with the 3D matrix in mat, which includes translations.
normMat is a 3D matrix for normal transformations, or NULL if none are needed.  
newCen are the center coordinates of the volume being transformed to; the center coordinates for the transformation are taken from the xmax, ymax, and zmax members of the model structure.  
zscale is the Z scale factor, or 1 to not apply any Z scaling. doflip should be nonzero if the model is in Y-Z flipped coordinates

int imodGetMaxObject(Imod *imod)

Get the number of objects in model imod (not the maximum object index).

float imodGetZScale(Imod *imod)

Get the Z scale in model imod

float imodGetPixelSize(Imod *imod)

Get the pixel size in model imod

const char *imodGetFilename(Imod *imod)

Get a pointer to the filename of model imod

int imodGetFlipped(Imod *imod)

Returns non-zero if model imod is flipped

Object-related Model Functions

int imodNewObject(Imod *mod)

Adds new object to end of object array in model mod. Color is automatically assigned from the collection of 35 stock colors. Returns 1 if error.

int imodDeleteObject(Imod *mod, int index)

Removes the object at the given index from the model mod. All contour data is deleted and object views are deleted.  The object array is packed down and reallocated or freed if there are no more objects. Returns -1 if there is an error.

int imodMoveObject(Imod *imod, int obOld, int obNew)

Moves an object from index obOld to index obNew in the model imod. Returns 1 if memory error.

int imodNextObject(Imod *imod)

Advances from the current object to the next object in the model imod, adjusting the index of the current contour and point to stay within bounds or setting them to -1 if appropriate.  Returns new object index or -1 if there is no model or objects.

int imodPrevObject(Imod *mod)

Moves from the current object to the previous object in the model mod, adjusting the index of the current contour and point to stay within bounds or setting them to -1 if appropriate.  Returns new object index or -1 if there is no model or objects.

Iobj *imodObjectGet(Imod *imod)

Returns a pointer to the current object in model imod, or NULL if no legal object is selected.

Iobj *imodObjectGetFirst(Imod *imod)

Sets first object in model imod as current object and returns pointer to it, or NULL if error.

Iobj *imodObjectGetNext(Imod *imod)

Advances the current object index by one in model imod and returns pointer to new current object, or NULL if error or if the existing current object is the last one in the model.

Contour-related Model Functions

int imodNewContour(Imod *mod)

Adds a new contour to the current object of the model mod.  It will inherit surface and open/closed properties from the current contour and become the new current contour.  Returns -1 if error.

void imodDelCurrentContour(Imod *imod)

Deletes the current contour of the model imod.

int imodDeleteContour(Imod *mod, int index)

Deletes the contour at index in the current object of the model mod, freeing all point, size, and label data, maintaining general storage lists, and reducing the size of the contour array.  Sets the current contour and point index to -1 and returns the size of the current object or -1 if error.

int imodDeleteListOfConts(Imod *mod, int *contours, int numConts)

Deletes the list of numConts contours in contours in the current object of the model mod, freeing all point, size, and label data, maintaining general storage lists, and reducing the size of the contour array.  Contours are numbered from 0. Sets the current contour and point index to -1 and returns the size of the current object or -1 if error.

int imodPrevContour(Imod *mod)

Moves the current contour index back by one in model mod.  If there is no current contour it selects the last one in the object.  Returns the current contour index or -1 for error.

int imodNextContour(Imod *imod)

Advances the current contour index forward by one in model mod.  If there is no current contour it selects the first one in the object.  Returns the current contour index or -1 for error.

Icont *imodContourGet(Imod *imod)

Returns a pointer to the current contour in model imod, or NULL if there is no current contour or the contour index is not legal.

Icont *imodContourGetFirst(Imod *imod)

Sets the current contour index to 0 in the current object in model imod and returns pointer to first contour, or NULL if there is no contour.

Icont *imodContourGetNext(Imod *imod)

Advances to the next contour in the current object of model imod and returns pointer to the contour, or NULL if there is none (error or end of object).

Point-related Model Functions

int imodNewPoint(Imod *imod, Ipoint *point)

Adds point to the end of the current contour in model imod. Returns new number of points in contour, or 0 for an error.

int imodInsertPoint(Imod *imod, Ipoint *point, int index)

Inserts point at position index into the current contour in model imod.  Returns new number of points in contour, or 0 for an error.

int imodDeletePoint(Imod *imod)

Deletes the current point in model imod, or the current contour if it is empty.  Returns size of current contour or -1 for error.

int imodPrevPoint(Imod *mod)

Moves the current point index back by one in model mod.  Returns the new current point index or -1 if no object or contour is selected.

int imodNextPoint(Imod *mod)

Advances the current point index forward by one in model mod.  Returns the new current point index or -1 if no object or contour is selected.

Ipoint *imodPointGet(Imod *imod)

Returns a pointer to the current point in model imod, or NULL if there is no current contour or current point.

Ipoint *imodPointGetFirst(Imod *imod)

Sets the current point index to 0 in the current contour in model imod and returns pointer to first point, or NULL if there is no current contour or point.

Ipoint *imodPointGetNext(Imod *imod)

Advances to the next point in the current contour of model imod and returns pointer to the point , or NULL if there is none (error or end of contour).