Istore Module

The module contains functions for manipulating the general storage lists that can be added to models, objects, contours, and meshes. These lists are Ilist structures that contain Istore elements.

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

General Operation and Information Functions


int imodWriteStore(Ilist *list, int id, FILE *fout)
Ilist *imodReadStore(FILE *fin, int *error)
void istoreSort(Ilist *list)
int istoreInsert(Ilist **list, Istore *store)
int istoreLookup(Ilist *list, int index, int *after)
void istoreDump(Ilist *list)
double istoreChecksum(Ilist *list)
int istoreCountItems(Ilist *list, int type, int stop)
int istoreCountObjectItems(Iobj *obj, int type, int doCont, int doMesh, int stop)
int istoreCountContSurfItems(Ilist *list, int index, int surfFlag)
int istorePointIsGap(Ilist *list, int index)
int istoreConnectNumber(Ilist *list, int index)
int istoreAddMinMax(Ilist **list, int type, float min, float max)
int istoreFindAddMinMax1(Iobj *obj)
int istoreFindAddMinMax(Iobj *obj, int type)
int istoreGetMinMax(Ilist *list, int size, int type, float *min, float *max)
int istoreRetainPoint(Ilist *list, int index)

Higher-level Functions for Manipulating Changes


int istoreInsertChange(Ilist **listp, Istore *store)
int istoreEndChange(Ilist *list, int type, int index)
int istoreClearChange(Ilist *list, int type, int index)
void istoreClearRange(Ilist *list, int type, int start, int end)
int istoreAddOneIndexItem(Ilist **listp, Istore *store)
int istoreClearOneIndexItem(Ilist *list, int type, int index, int surfFlag)
int istoreGenerateItems(Ilist **listp, DrawProps *props, int stateFlags, int index, int genFlags)
int istoreGenPointItems(Ilist *clist, DrawProps *contProps, int contState, int ptInd, Ilist **mlistp, int meshInd, int genFlags)

Functions Related to Editing Contours


int istoreBreakChanges(Ilist *list, int index, int psize)
int istoreFindBreak(Ilist *list, int index)
void istoreShiftIndex(Ilist *list, int ptIndex, int startScan, int amount)
int istoreDeletePoint(Ilist *list, int index, int psize)
void istoreDeleteContSurf(Ilist *list, int index, int surfFlag)
int istoreBreakContour(Icont *cont, Icont *ncont, int p1, int p2)
int istoreInvert(Ilist **listp, int psize)
void istoreCleanEnds(Ilist *list)
int istoreExtractChanges(Ilist *olist, Ilist **nlistp, int indStart, int indEnd, int newStart, int psize)
int istoreCopyNonIndex(Ilist *olist, Ilist **nlistp)
int istoreCopyContSurfItems(Ilist *olist, Ilist **nlistp, int indFrom, int indTo, int surfFlag)

Drawing-Related Functions


void istoreDefaultDrawProps(Iobj *obj, DrawProps *props)
int istoreContSurfDrawProps(Ilist *list, DrawProps *defProps, DrawProps *contProps, int co, int surf, int *contState, int *surfState)
int istoreFirstChangeIndex(Ilist *list)
int istoreNextChange(Ilist *list, DrawProps *defProps, DrawProps *ptProps, int *stateFlags, int *changeFlags)
int istorePointDrawProps(Iobj *obj, DrawProps *contProps, DrawProps *ptProps, int co, int pt)
int istoreListPointProps(Ilist *list, DrawProps *contProps, DrawProps *ptProps, int pt)
int istoreSkipToIndex(Ilist *list, int index)
int istoreTransStateMatches(Ilist *list, int state)

Structures and Definitions for I/O Functions


StoreUnion union
Istore structure
DrawProps structure
Istore definitions

General Operation and Information Functions

int imodWriteStore(Ilist *list, int id, FILE *fout)

Writes general storage list to the model file with pointer fout, including the value in id, which can indicate a model, objext, contour, or mesh list.  Returns non-zero for error.

Ilist *imodReadStore(FILE *fin, int *error)

Reads a general storage chunk from the model file with pointer fin. Allocates a new Ilist and returns its address, or NULL if an error occurs.  Set error non-zero for error also.

void istoreSort(Ilist *list)

Sorts the given list of Istore elements based on their index values placing any elements with no index value at the end.

int istoreInsert(Ilist **list, Istore *store)

Inserts the element store into the list of sorted Istore elements pointed to by list.  The element is inserted after any existing elements with the same index, unless GEN_STORE_REVERT is set in flags, in which case it is inserted before existing elements.  If GEN_STORE_NOINDEX is set in flags, it is inserted at the end of the list.  Works if list points to a NULL. Returns 1 for error.

int istoreLookup(Ilist *list, int index, int *after)

Looks for elements with index in the given list of sorted Istore elements, returns after with the list index of the first element with an index after the given value or the list size if there is none, and returns the list index of the first matching element, or -1 if there is no match or if list is empty or NULL.

void istoreDump(Ilist *list)

Prints the values of general storage elements in list.  index and value items will be printed as int, byte, short, or float based upon the flags in flags.

double istoreChecksum(Ilist *list)

Computes a checksum from the elements in the list, adding all types, flags, indexes and values.

int istoreCountItems(Ilist *list, int type, int stop)

Returns the number of items whose type is type in the list, or just stops and returns 1 upon finding the first such change if stop is nonzero.

int istoreCountObjectItems(Iobj *obj, int type, int doCont, int doMesh, int stop)

Returns the number of items whose type is type in the storage lists of object obj.  It always searches obj->store, then searches the store lists of all contours if doCont is nonzero, then the store lists of all meshes if doMesh is nonzero.  If stop is nonzero, it just stops and returns 1 upon finding the first such change.

int istoreCountContSurfItems(Ilist *list, int index, int surfFlag)

Counts the number of items in list with index value of index, for either contours, if surfFlag is 0, or surfaces, if surfFlag is nonzero.

int istorePointIsGap(Ilist *list, int index)

Returns 1 if an item in list with point index equal to index is a gap, or 0 if not.

int istoreConnectNumber(Ilist *list, int index)

Returns connection number for an item in list with point index equal to index, or -1 if there is none.

int istoreAddMinMax(Ilist **list, int type, float min, float max)

Adds an item containing the given min and max, of the given type (e.g., GEN_STORE_MINMAX1) to the storage list pointed to by list, or updates the values in such an item if it already exists. Returns 1 for error.

int istoreFindAddMinMax1(Iobj *obj)

Computes the min and max values for all GEN_STORE_VALUE1 items in object obj and its contours, and adds or updates a GEN_STORE_MINMAX1 item with these values for the object.  Returns -1 if there are no values in the object, or 1 if there is an error inserting the min/max in the object store.

int istoreFindAddMinMax(Iobj *obj, int type)

Computes the min and max values for all value items of the given type (e.g., GEN_STORE_VALUE1) in object obj and its contours, and adds or updates a corresponding GEN_STORE_MINMAX item with these * values for the object.  Returns -1 if there are no values of the given type in the object, 1 if there is an error inserting the min/max in the object store, or 2 if the type is inappropriate.

int istoreGetMinMax(Ilist *list, int size, int type, float *min, float *max)

Looks for a min/max value in the given list of a given type (e.g., GEN_STORE_MINMAX1).  The size of the entity containing this storage list should be provided in size, although this entry is currently unused (e.g., contsize for an object store).  If a min/max entry is found, values are returned in min and max and the return value is 1; otherwise the function returns 0.

int istoreRetainPoint(Ilist *list, int index)

Returns 1 if a point should be retained in a shave or reduce operation because either it has an item, it is after a gap, or it precedes an end.

Higher-level Functions for Manipulating Changes

int istoreInsertChange(Ilist **listp, Istore *store)

Inserts a change described in store into the list pointed to by listp. A matching change or end at the same index is removed.  Redundant entries of the change are avoided or eliminated.  Returns 1 for error.

int istoreEndChange(Ilist *list, int type, int index)

Inserts an end for a change into list, where type specifies the type and index indicates the point index.  A later end will be deleted if there is not an intervening start of the same type, and a start at the given index will also be deleted.  Returns 1 for error.

int istoreClearChange(Ilist *list, int type, int index)

Clears a whole change sequence in list with the type given by type and containing the point at index.  All changes of the given type are removed from the starting change to an end, if any.  Returns 1 for an empty list. This must be called only if the given point is contained in a change.

void istoreClearRange(Ilist *list, int type, int start, int end)

Clears a change sequence of the given type from the list for all points from start to end, removing starts before the range and an end after the range if necessary.  This may be called even if there is no change.

int istoreAddOneIndexItem(Ilist **listp, Istore *store)

Inserts the item in store into the list pointed to by listp, where the item specifies a property that applies to only one point or contour. A matching item at the same index is replaced.  Returns 1 for error.

int istoreClearOneIndexItem(Ilist *list, int type, int index, int surfFlag)

Removes the item in list with the type given by type and containing the point at index, where the item specifies a property that applies to only one point or contour.  surfFlag should be 0 for a point or contour, or non-zero for a surface.  Returns 1 for an empty list, -1 if no matching item is found.

int istoreGenerateItems(Ilist **listp, DrawProps *props, int stateFlags, int index, int genFlags)

Adds Istore items to the list pointed to by listp for properties in props specified by genFlags that are not in the default state, as indicated by stateFlags. Each item's index will be index.  Only handles 3D items: color, fill color, transparency, 3D width, and general value.  Returns 1 for error.

int istoreGenPointItems(Ilist *clist, DrawProps *contProps, int contState, int ptInd, Ilist **mlistp, int meshInd, int genFlags)

Adds Istore items to the mesh storage list pointed to by mlistp for a single point with index ptInd.  Its properties are determined from the contour storage list in clist, the contour properties in contProps, and the state flags for the contour in contState.  Items are added for non-default properties specified by genFlags. Each item's index will be meshInd.  Only handles 3D items: color, fill color, transparency, 3D width. and general value.  Returns 1 for error.

Functions Related to Editing Contours

int istoreBreakChanges(Ilist *list, int index, int psize)

Breaks all changes in list at the point index given by index; namely terminates all changes at index - 1 and restarts them at index.  psize specifies the number of points in the contour.  If index equals psize then terminations will be inserted without any restarts.  Returns 1 for error.

int istoreFindBreak(Ilist *list, int index)

Returns the index in list of the first new change starting at a point index greater than or equal to index.  Ends at that index are assumed to occur before changes.

void istoreShiftIndex(Ilist *list, int ptIndex, int startScan, int amount)

Shifts indexes in list by amount, for all storage items with indexes >= ptIndex.  Set startScan to a list index at which to start scanning the list, or to -1 to have the routine search for the starting index. Items with the GEN_STORE_SURFACE flag set will not be shifted, so this routine will work for contour or point indexes.

int istoreDeletePoint(Ilist *list, int index, int psize)

Manages any elements in list associated with the point given by index when that point is deleted.  They will be moved to the next point or removed, and all following indexes will be reduced by 1.  psize must indicate the size of the contour before the point is deleted.  Returns 1 for error.

void istoreDeleteContSurf(Ilist *list, int index, int surfFlag)

Removes any elements in list associated with the contour or surface whose index is index, depending on whether surfFlag is 0 or not.  For contours, it reduces all following contour indexes by 1.

int istoreBreakContour(Icont *cont, Icont *ncont, int p1, int p2)

Breaks general storage list in contour cont into two pieces and assigns changes occurring from point index p1 through p2 to the new contour ncont.  Returns 1 for error.

int istoreInvert(Ilist **listp, int psize)

Inverts the changes in the list of Istore elements pointed to by listp so that the same changes will occur with an inverted contour.  psize specifies the size of the corresponding contour.  Returns 1 for error.

void istoreCleanEnds(Ilist *list)

Removes extraneous ends from list at indexes that have a matching start.

int istoreExtractChanges(Ilist *olist, Ilist **nlistp, int indStart, int indEnd, int newStart, int psize)

Extracts all of the changes in olist between indexes indStart and indEnd, inclusive, into the list pointed to by nlistp.  The indexes of the changes are shifted so that indStart is shifted to newStart. psize specifies the size of the corresponding contour.  nlistp may point to a NULL.  Returns 1 for error.

int istoreCopyNonIndex(Ilist *olist, Ilist **nlistp)

Copies all non-index items in olist to the list pointed to by nlistp. Returns 1 for error.

int istoreCopyContSurfItems(Ilist *olist, Ilist **nlistp, int indFrom, int indTo, int surfFlag)

Copies items having index indFrom from general store list olist to the new list pointed to by nlist, changing the index to indTo in the new list.  Contour items are copied if surfFlag is 0, and surface items are copied if surfFlag is nonzero.  Returns 1 for error.

Drawing-Related Functions

void istoreDefaultDrawProps(Iobj *obj, DrawProps *props)

Fills a draw property structure props with default values for the object obj.

int istoreContSurfDrawProps(Ilist *list, DrawProps *defProps, DrawProps *contProps, int co, int surf, int *contState, int *surfState)

Gets a draw property structure contProps for a contour or surface based on the default object properties in defProps and entries in list.  For a contour, co specifies the contour number and surf specifies its surface number; for a surface, co should be negative.  Returns a set of flags for which items are changed from the default; separate flags for nondefault items are returned in contState and surfState for contour and surface, respectively.

int istoreFirstChangeIndex(Ilist *list)

Returns the point index of the first item with a change in the list, or -1 if there are no changes.  Leaves the current index of list at this item.

int istoreNextChange(Ilist *list, DrawProps *defProps, DrawProps *ptProps, int *stateFlags, int *changeFlags)

Gets the next change in point drawing properties described by list.   The default drawing properties for the contour are supplied in defProps, and the point's drawing properties are returned in ptProps.  The current state of each type of change is returned in stateFlags, which should be zeroed by the caller at the start of a contour and maintained between calls. Flags for which properties changed at this point are returned in changeFlags, while the return value is the point index of the next change in the list, or -1 if there are no more changes.

int istorePointDrawProps(Iobj *obj, DrawProps *contProps, DrawProps *ptProps, int co, int pt)

Determines the drawing properties for point pt in contour co of object obj.  Returns the default contour drawing properties in contProps, the point drawing properties in ptProps, and the return value is the flags for the state of various properties (changed versus default for contour).

int istoreListPointProps(Ilist *list, DrawProps *contProps, DrawProps *ptProps, int pt)

Determines the drawing properties for point pt from the changes in list, a list of changes for a contour.  The default contour drawing properties are supplied in contProps, the point drawing properties are returned in ptProps, and the return value is the flags for the state of various properties (changed versus default).

int istoreSkipToIndex(Ilist *list, int index)

Skips to location in list where the item index is index or greater. Returns the index of the next item in the list, or -1 if there is none.

int istoreTransStateMatches(Ilist *list, int state)

Returns 1 if the storage list in list has a transparency change that matches state, which should be 0 for trans of 0 and 1 for trans > 0, or returns 0 if there is no list or no such trans change.  A reversion to the default state is not counted.

Structures and Definitions for I/O Functions

StoreUnion union

Union of types for the general storage structure Istore
typedef union store_type {
  b3dInt32 i;
  b3dFloat f;
  b3dUInt16 us[2];
  b3dInt16 s[2];
  b3dUByte b[4];
} StoreUnion;

Istore structure

The storage structure
typedef struct Mod_Store 
{
  b3dInt16 type;            /* Type of information */
  b3dUInt16 flags;          /* Flags for data types, modifiers */
  StoreUnion index;         /* Item index in simplest usage */
  StoreUnion value;         /* Item value in simplest usage */
} Istore;

DrawProps structure

The drawing property structure
typedef struct draw_properties
{
  float red, green, blue;            /* Keep as floats so they are GL-ready */
  float fillRed, fillGreen, fillBlue;
  int trans;
  int connect;
  int gap;
  int linewidth;
  int linewidth2;
  int symtype;
  int symflags;
  int symsize;
  float value1;
  int valskip;    /* Flag that gap is set because of skipping lo/hi values */
  int noCap;
} DrawProps;

Istore definitions

Bits 0-1 of flags have one of these values to indicate type of index, and bits 2-3 have one of these values to indicate type of value
#define GEN_STORE_INT   0
#define GEN_STORE_FLOAT 1
#define GEN_STORE_SHORT 2
#define GEN_STORE_BYTE  3

/* Additional defined flags for general storage */
#define GEN_STORE_NOINDEX  (1l << 4)  /* Index is not a sortable value */
#define GEN_STORE_REVERT   (1l << 5)  /* Revert to default values */
#define GEN_STORE_SURFACE  (1l << 6)  /* Index is a surface # */
#define GEN_STORE_ONEPOINT (1l << 7)  /* Type applies to one point */
#define ISO_STORE_CAP      (1l << 5)
#define ISO_STORE_DELETE   (1l << 6)
#define ISO_STORE_HAS_OUTER (1l << 7)

/* Defined values for type */
#define GEN_STORE_COLOR   1    /* Color change */
#define GEN_STORE_FCOLOR  2    /* Fill color change */
#define GEN_STORE_TRANS   3    /* Transparency change */
#define GEN_STORE_GAP     4    /* Do not connect to next point */
#define GEN_STORE_CONNECT 5    /* A connection number for meshing */
#define GEN_STORE_3DWIDTH 6    /* 3D line width change */
#define GEN_STORE_2DWIDTH 7    /* 2D line width change */
#define GEN_STORE_SYMTYPE 8    /* Symbol type (including open/closed) */
#define GEN_STORE_SYMSIZE 9    /* Symbol size */
#define GEN_STORE_VALUE1  10   /* Arbitrary value */
#define GEN_STORE_MINMAX1 11   /* Min and max of value1 */
#define GEN_STORE_VALUE2  12   /* Arbitrary value 2 */
#define GEN_STORE_MINMAX2 13   /* Min and max of value2 */
#define GEN_STORE_VALUE3  14   /* Arbitrary value 3 */
#define GEN_STORE_MINMAX3 15   /* Min and max of value3 */
#define GEN_STORE_VALUE4  16   /* Arbitrary value 4 */
#define GEN_STORE_MINMAX4 17   /* Min and max of value4 */
#define GEN_STORE_VALUE5  18   /* Arbitrary value 5 */
#define GEN_STORE_MINMAX5 19   /* Min and max of value5 */
#define GEN_STORE_VALUE6  20   /* Arbitrary value 6 */
#define GEN_STORE_MINMAX6 21   /* Min and max of value6 */
#define ISO_STORE_PARAMS  22   /* Model isosurface: flags, bin, smooth, sigma, etc. */
#define ISO_STORE_THRESH  23   /* Model isosurface: thresholds by time index */
#define GEN_STORE_NO_CAP  24   /* Do not cap contour */

/* Defined flags for indicating changes */
#define CHANGED_COLOR     (1l << 0)    /* Color change */
#define CHANGED_FCOLOR    (1l << 1)    /* Fill color change */
#define CHANGED_TRANS     (1l << 2)    /* Transparency change */
#define CHANGED_GAP       (1l << 3)    /* Do not connect to next point */
#define CHANGED_CONNECT   (1l << 4)    /* A connection number for meshing */
#define CHANGED_3DWIDTH   (1l << 5)    /* 3D line width change */
#define CHANGED_2DWIDTH   (1l << 6)    /* 2D line width change */
#define CHANGED_SYMTYPE   (1l << 7)    /* Symbol type */
#define CHANGED_SYMSIZE   (1l << 8)    /* Symbol size */
#define CHANGED_VALUE1    (1l << 9)    /* Arbitrary value */

/* Indexes for isosurface items in the value entry */
#define ISO_STORE_BIN_IND     0
#define ISO_STORE_SMOOTH_IND  1
#define ISO_STORE_OUTER_IND   2
#define ISO_STORE_SIGMA_IND   0
#define ISO_STORE_MINSIZE_IND 1

/* A very handy macro */                          
#define istoreItem(list, index) ((Istore *)ilistItem(list, index))