/***********************************************************************/ /* Open Visualization Data Explorer */ /* (C) Copyright IBM Corp. 1989,1999 */ /* ALL RIGHTS RESERVED */ /* This code licensed under the */ /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ /***********************************************************************/ /* */ #include #include #include static Error AddData(Field, Array); static Field HardCase(Array, Array); static Field MakeIR(Array, int *, int, int); static Field MakeII(Array); static Field MakeRR(Array, Array, Array); static Array DefaultOrigin(Array); static Array DefaultDeltas(Array); static Array DefaultCounts(Array); static Array MyExtractFloat(Array); static Array MyExtractIntVector(Array); static Array MyExtractFloatVector(Array); extern Array _dxfReallyCopyArray(Array); Field _dxfConstruct(Array o, Array d, Array c, Array data) { Field f=NULL; Type type; int rank, shape[32], *c_ptr, i; Category category; if (o) { if (DXGetObjectClass((Object)o) != CLASS_ARRAY) { DXSetError(ERROR_INVALID_DATA, "#10220","origin"); goto error; } DXGetArrayInfo((Array)o, NULL, &type, &category, NULL, NULL); if ((type != TYPE_FLOAT)&&(type != TYPE_INT)) { DXSetError(ERROR_BAD_PARAMETER, "origin must be of type float or integer"); goto error; } if (category != CATEGORY_REAL) { DXSetError(ERROR_BAD_PARAMETER, "origin must be category real"); goto error; } /* DXReference((Object)o); */ } if (d) { if (DXGetObjectClass((Object)d) != CLASS_ARRAY) { DXSetError(ERROR_INVALID_DATA, "#10220", "deltas"); goto error; } DXGetArrayInfo((Array)d, NULL, &type, &category, NULL, NULL); if ((type != TYPE_FLOAT)&&(type != TYPE_INT)) { DXSetError(ERROR_BAD_PARAMETER, "deltas must be of type float or integer"); goto error; } if (category != CATEGORY_REAL) { DXSetError(ERROR_BAD_PARAMETER, "deltas must be category real"); goto error; } /* DXReference((Object)d); */ } if (c) { if (DXGetObjectClass((Object)c) != CLASS_ARRAY) { DXSetError(ERROR_INVALID_DATA, "#10541", "counts"); goto error; } DXGetArrayInfo((Array)c, NULL, &type, &category, &rank, shape); c_ptr = (int *)DXGetArrayData((Array)c); if (rank==0) { if (c_ptr[0] <= 0) { DXSetError(ERROR_BAD_PARAMETER,"#10021","counts"); goto error; } } else if (rank==1) { for (i=0;i 1) counts[j++] = counts[i]; dim = j; if (dim > 0) { cA = DXMakeGridConnectionsV(dim, counts); if (! cA) goto error; if (! DXSetComponentValue(f, "connections", (Object)cA)) goto error; cA = NULL; if (dim == 1) { if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("lines"))) goto error; } else if (dim == 2) { if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("quads"))) goto error; } else if (dim == 3) { if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("cubes"))) goto error; } else { char str[64]; sprintf(str, "cubes%dD", dim); if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString(str))) goto error; } } return f; error: DXDelete((Object)pA); DXDelete((Object)cA); DXDelete((Object)f); return NULL; } static Field MakeII(Array o) { Array cA = NULL; Field f = NULL; int n; Type t; Category c; int r, s[32]; Array pA = NULL; int dim; DXGetArrayInfo(o, &n, &t, &c, &r, s); if (c != CATEGORY_REAL || (r != 1 && r != 0)) { DXSetError(ERROR_INVALID_DATA,"#10215", "origin"); goto error; } /* positions have to be vectors, even if 1D */ pA = MyExtractFloatVector(o); if (! pA) goto error; f = DXNewField(); if (! f) goto error; if (! DXSetComponentValue(f, "positions", (Object)pA)) goto error; pA = NULL; if (n > 1) { /* cA = (Array)DXNewPathArray(n); */ cA = DXMakeGridConnectionsV(1,&n); if (! cA) goto error; if (! DXSetComponentValue(f, "connections", (Object)cA)) goto error; cA = NULL; if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("lines"))) goto error; } return f; error: DXDelete((Object)pA); DXDelete((Object)cA); DXDelete((Object)f); return ERROR; } static Array DefaultOrigin(Array driver) { float p[32]; Array a = NULL; int dim, i, r; if (driver) { DXGetArrayInfo(driver, NULL, NULL, NULL, &r, &dim); if (r == 0) dim = 1; } else dim = 3; a = DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 1, dim); if (! a) goto error; for (i = 0; i < dim; i++) p[i] = 0.0; if (! DXAddArrayData(a, 0, 1, (Pointer)p)) goto error; return a; error: DXDelete((Object)a); return NULL; } static Array DefaultDeltas(Array driver) { float p[256]; Array a = NULL; int i, j, k, dim, r; if (driver) { DXGetArrayInfo(driver, NULL, NULL, NULL, &r, &dim); if (r == 0) dim = 1; } else dim = 3; k = 0; for (i = 0; i < dim; i++) p[k++] = 1.0; a = DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 1, dim); if (! a) goto error; if (! DXAddArrayData(a, 0, 1, (Pointer)p)) goto error; return a; error: DXDelete((Object)a); return NULL; } static Array DefaultCounts(Array driver) { int c[16]; Array a = NULL; int i, j, k, dim, r; if (driver) { DXGetArrayInfo(driver, NULL, NULL, NULL, &r, &dim); if (r == 0) dim = 1; } else dim = 3; k = 0; for (i = 0; i < dim; i++) c[k++] = 2; a = DXNewArray(TYPE_INT, CATEGORY_REAL, 1, dim); if (! a) goto error; if (! DXAddArrayData(a, 0, 1, (Pointer)c)) goto error; return a; error: DXDelete((Object)a); return NULL; } static Field MakeRR(Array or, Array de, Array co) { Array pA = NULL, cA = NULL; Field f = NULL; Array o = NULL, d = NULL, c = NULL; int dim, nO, nD, nC, r, s[32], i, j; float *origin = NULL; float *deltas = NULL; int *counts = NULL; if (or) o = MyExtractFloatVector(or); if (de) d = MyExtractFloatVector(de); if (co) c = MyExtractIntVector(co); DXGetArrayInfo(o, &nO, NULL, NULL, &r, s); if (nO != 1 || r != 1) { DXSetError(ERROR_INVALID_DATA, "#11827","deltas", "origin containing more than one point"); goto error; } dim = s[0]; origin = (float *)DXAllocate(dim*sizeof(float)); if (! origin) goto error; if (! DXExtractParameter((Object)o, TYPE_FLOAT, dim, 1, (Pointer)origin)) { DXSetError(ERROR_INVALID_DATA, "#10221","origin"); goto error; } DXGetArrayInfo(d, &nD, NULL, NULL, &r, s); if (r != 1 || s[0] != dim) { DXSetError(ERROR_INVALID_DATA, "#11828", "deltas", "origin"); goto error; } if (nD != 1 && nD != dim) { DXSetError(ERROR_INVALID_DATA, "#11828", "deltas","origin"); goto error; } deltas = (float *)DXAllocate(dim*dim*sizeof(float)); if (! deltas) goto error; if (! DXExtractParameter((Object)d, TYPE_FLOAT, dim, nD, (Pointer)deltas)) { DXSetError(ERROR_INVALID_DATA, "#11828", "deltas", "origin"); goto error; } if (nD == 1) { for (i = 1; i < dim; i++) for (j = 0; j < dim; j++) if (i == j) { deltas[i*dim+j] = deltas[j]; deltas[j] = 0.0; } else deltas[i*dim+j] = 0.0; } DXGetArrayInfo(c, &nC, NULL, NULL, &r, s); if (nC != 1 || !((r == 1 && (s[0] == 1 || s[0] == dim)) || r == 0)) { DXSetError(ERROR_INVALID_DATA,"#11826", "counts", "origin and deltas"); goto error; } counts = (int *)DXAllocate(dim*sizeof(int)); if (! counts) goto error; if (r == 0) { s[0] = 0; r = 1; } else r = s[0]; if (! DXExtractParameter((Object)c, TYPE_INT, s[0], 1, (Pointer)counts)) { DXSetError(ERROR_INVALID_DATA, "#11826","counts","origin and deltas"); goto error; } for (i = r; i < dim; i++) counts[i] = counts[0]; pA = DXMakeGridPositionsV(dim, counts, origin, deltas); if (! pA) goto error; for (i = j = 0; i < dim; i++) if (counts[i] > 1) counts[j++] = counts[i]; dim = j; f = DXNewField(); if (! f) goto error; if (! DXSetComponentValue(f, "positions", (Object)pA)) goto error; pA = NULL; if (dim > 0) { cA = DXMakeGridConnectionsV(dim, counts); if (! cA) goto error; if (! DXSetComponentValue(f, "connections", (Object)cA)) goto error; cA = NULL; if (dim == 1) { if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("lines"))) goto error; } else if (dim == 2) { if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("quads"))) goto error; } else if (dim == 3) { if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString("cubes"))) goto error; } else { char str[64]; sprintf(str, "cubes%dD", dim); if (! DXSetComponentAttribute(f, "connections", "element type", (Object)DXNewString(str))) goto error; } } DXFree((Pointer)counts); DXFree((Pointer)deltas); DXFree((Pointer)origin); if (o != or) DXDelete((Object)o); if (c != co) DXDelete((Object)c); if (d != de) DXDelete((Object)d); return f; error: DXFree((Pointer)counts); DXFree((Pointer)deltas); DXFree((Pointer)origin); if (o != or) DXDelete((Object)o); if (c != co) DXDelete((Object)c); if (d != de) DXDelete((Object)d); DXDelete((Object)pA); DXDelete((Object)cA); DXDelete((Object)f); return NULL; } static Array MyExtractFloatVector(Array in) { Array out = NULL; Type t; Category c; int r, s[32]; int nItems, i; float *dst; DXGetArrayInfo(in, &nItems, &t, &c, &r, s); if (r==0) { r = 1; s[0] = 1; } /* check the input array. Maybe we can use it as is */ if (DXGetArrayClass(in)==CLASS_REGULARARRAY) { out = in; return out; } out = DXNewArrayV(TYPE_FLOAT, c, r, s); if (! out) goto error; if (! DXAddArrayData(out, 0, nItems, NULL)) goto error; dst = (float *)DXGetArrayData(out); if (! dst) goto error; nItems *= DXGetItemSize(in)/DXTypeSize(t); switch(t) { case TYPE_DOUBLE: { double *src; src = (double *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_FLOAT: { float *src; src = (float *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_INT: { int *src; src = (int *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_SHORT: { short *src; src = (short *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_BYTE: { byte *src; src = (byte *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_UBYTE: { ubyte *src; src = (ubyte *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_USHORT: { ushort *src; src = (ushort *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_UINT: { uint *src; src = (uint *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } } return out; error: DXDelete((Object)out); return NULL; } static Array MyExtractFloat(Array in) { Array out = NULL; Type t; Category c; int r, s[32]; int nItems, i; float *dst; DXGetArrayInfo(in, &nItems, &t, &c, &r, s); if (r==0) s[0]=1; out = DXNewArrayV(TYPE_FLOAT, c, r, s); if (! out) goto error; if (! DXAddArrayData(out, 0, nItems, NULL)) goto error; dst = (float *)DXGetArrayData(out); if (! dst) goto error; nItems *= DXGetItemSize(in)/DXTypeSize(t); switch(t) { case TYPE_DOUBLE: { double *src; src = (double *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_FLOAT: { float *src; src = (float *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_INT: { int *src; src = (int *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_SHORT: { short *src; src = (short *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } case TYPE_UBYTE: { byte *src; src = (byte *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (float) *src++; break; } } return out; error: DXDelete((Object)out); return NULL; } static Array MyExtractIntVector(Array in) { Array out = NULL; Type t; Category c; int r, s[32]; int nItems, i; int *dst; DXGetArrayInfo(in, &nItems, &t, &c, &r, s); if (r==0) s[0]=1; out = DXNewArrayV(TYPE_INT, c, r, s); if (! out) goto error; if (! DXAddArrayData(out, 0, nItems, NULL)) goto error; dst = (int *)DXGetArrayData(out); if (! dst) goto error; nItems *= DXGetItemSize(in)/DXTypeSize(t); switch(t) { case TYPE_INT: { int *src; src = (int *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (int) *src++; break; } case TYPE_SHORT: { short *src; src = (short *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (int) *src++; break; } case TYPE_UBYTE: { byte *src; src = (byte *)DXGetArrayData(in); if (! src) goto error; for (i = 0; i < nItems; i++) *dst++ = (int) *src++; break; } default: DXSetError(ERROR_BAD_PARAMETER,"#11829","counts"); goto error; } return out; error: DXDelete((Object)out); return NULL; }