Synopsis
create/get/set a float array subobject to an object
int FLDadd_float_array (
OMobj_id field,
const char *name,
int size);
int FLDset_array_float (
OMobj_id field,
int size,
int mode,
float *array,
const char *name);
int FLDget_array_float (
OMobj_id field,
float **array,
int *size,
int mode,
const char *name);
Description
These routines add a new float array subobject to an existing field data schema object, and then set/get its values. They could also be used when you want to construct and reference an entirely new data object and add float array subobjects to it, but you want to do this within the code of a function, rather than using V.
Note: If you are accessing an existing, defined subobject, use the specific routine for that subobject (for example, FLDget_coord_extent). Use FLDadd/set/ get_float_array only when you have created your own, unique, named subobject, or when no FLD routine exists for a pre-defined subobject.
FLDadd_float_array adds a float array subobject to the object specified by OMobj_id field. The object is named in the Object Manager by the string name. size indicates the total number of array values. For example, a [100][2] array would have size 200. The new subobject is flagged as "not set."
FLDset_array_float sets the float array object named name within field equal to the array formed by the first size values found in the float array pointed to by array.
FLDget_array_float returns the value of the float subobject name within field in via the double pointer array.
Parameters
OMobj_id field
The OMobj_id of an object. This can be any object, not just a "Field".
const char *name
In FLDadd_float_array, a character string that names the new float subobject.
In FLDset_array_float and FLDget_array_float, a character string that specifies the name of the float array subobject of field to get/set.
int size
int *size
In FLDadd_float_array, size is the total number of array values to create. A [100][3] array would have size=300.
In FLDset_array_float, size is how many sequential values to take from array and assign to the subobject.
In FLDget_array_float, size is a pointer to an integer in which the size of the subobject array will be returned.
int mode
An integer constant that establishes the access mode for the array subobject. Constants for the possible values are defined in avs/om.h as follows.
For FLDset_array_float:
Mode
|
Value
|
Meaning
|
OM_SET_ARRAY_COPY |
0 |
Copy the array into the Object Manager |
OM_SET_ARRAY_FREE |
1 |
If possible, do not copy the array. Instead, set the object's array pointer to node_data. AVS/Express copies the array anyway if the function is running in an external process or if data type conversion is required. AVS/Express manages the array and will determine when the array can be freed. You must allocate space for the array with a call to ARRalloc. |
OM_SET_ARRAY_STATIC |
2 |
If possible, do not copy the array. Instead, set the object's array pointer to node_data. AVS/Express copies the array anyway if the function is running in an external process or if data type conversion is required. AVS/Express does not manage the array. You must ensure that the array is valid for the life of the object or until the object replaces the array. |
For FLDget_array_float:
Mode
|
Value
|
Meaning
|
OM_GET_ARRAY_RD |
0 |
The program intends to read the array, but not write to it. |
OM_GET_ARRAY_WR |
1 |
The program intends to write to the array, completely replacing it, but not read it. |
OM_GET_ARRAY_RW |
2 |
The program intends to both read and write to the array. |
OM_GET_ARRAY_RD_
|
3 |
The program requires a copy of the array for its own, private use (reading or writing). |
float *array
float **array
In FLDset_array_float, array is an array of floats of which size values will be assigned to the name subobject.
In FLDget_array_float, array should be the address of a pointer to floats. Upon return, *array will be filled in with a pointer to the float values. You must call ARRfree on that array when you are done using it.
Example
This abstracted section of code is taken from modules/pln_dist.c. It adds a double array of three values to a Plane_Mesh datatype that will hold the plane's normals. It keeps it in the Object Manager, querying its existence each time the function executes. If necessary, it resets the values of the normals array at the end of each execution.
...
int FUNCplane_dist (in, plane, out, dist);
OMobj_id in, plane, out;
{
...
int stat;
int size;
float norm_xfm[3], *norm_x;
float plane_dist;
...
MATxform_vecs(1, norm, xfm, norm_xfm);
plane_dist = VEC_DOT(bounds, norm_xfm);
...
stat = FLDget_array_float(out, "plane_norm", &norm_x, &size, OM_GET_ARRAY_RD);
if (stat < 1) {
if (FLDadd_float_array (out, "plane_norm", 3)!=1 {
ERR_RETURN("cannot create normal array");
}
}
...
VEC_CROSS(cross, norm_xfm, norm_x);
...<test for new data, set recomp if new >...
if (recomp) {
...
for (i=0; i<nnodes; i++)
node_dist[i] = VEC_DOT((coord+3*i), norm_xfm);
if (FLDset_array_float(out, "plane_norm", 3, norm_xfm, OM_SET_ARRAY_COPY)
!= 1)
{
ERR_RETURN("cannot set normal array");
}
}
}
Related routines