/***********************************************************************/ /* 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 "interact.h" #define MIN(a,b) ((ab) ? a: b) #define MAX_INPUTS 9 extern Array DXScalarConvert(Array ); extern Error _dxfvector_base(Object *, Object *, int); static Error vec_minmax(Object, int , int *,int , float *, float *); static Error constant_minmax(Array , Type ,int ,float *, float *); static Error IsInvalid(Object, InvalidComponentHandle *); static Error vec_reset(float *, float *, int , int , int , float *); static Error setoutput(float *, int , int , int , int , Object *); static int isthisint(float *,int ,int ); int m_Vector(Object *in, Object *out) { if (!_dxfvector_base(in, out,0)) return ERROR; return OK; } extern Error _dxfvector_base(Object *in, Object *out, int islist) { struct einfo ei; float valtemp; float *min, *max, *incr; int *decimal; float *val,min1,max1,incr1; char *label, *id, *incrmethod; int i,item=0,change=0,j,n,nitem=-1,range,isint=0; int rank=1,dim=3,size,valdim,dec1,dimcount=0; int change1,change4,change5,changen=0,req_param=1,decimalzero=1; method_type method; Object idobj; int iprint[MAXPRINT],ip[MAXPRINT],msglen=0,shape[1]; int refresh = 0; /* required parameters */ if (!in[1] && (!in[4] || !in[5])) req_param=0; ei.msgbuf=NULL; /* get id */ if (!DXExtractString(in[0], &id)){ DXSetError(ERROR_BAD_PARAMETER,"#10000","id"); return ERROR; } idobj=in[0]; val = NULL; /* initialize ip to 0 (print nothing) */ for (i=0; i 0 || change4 >0 || change5 >0 ){ change=1; /* DXWarning("getting min max, change=%d",change); */ if (in[1]){ /* function vec_minmax takes vector array and returns min,max * of each dimension */ if (!DXGetType(in[1],NULL,NULL,&rank,NULL)) goto error; if (rank!=1){ DXSetError(ERROR_INVALID_DATA,"#10221","input data"); goto error; } if (!in[4] || !in[5]){ if (!vec_minmax(in[1],dim,&size,rank,min,max)) goto error; } } if (in[4]){ if (DXExtractFloat(in[4],&min1)){ for (i=0; i 1.0)){ DXSetError(ERROR_BAD_PARAMETER,"#10110","delta",0,1); goto error1; } else if (method==ABSOLUTE && incr[i] < 0.0){ DXSetError(ERROR_BAD_PARAMETER,"#10010","delta"); goto error1; } } } else{ if (in[7] && method==ABSOLUTE){ for (i=0; i 6){ DXSetError(ERROR_BAD_PARAMETER,"#10040","decimal",0,6); goto error1; } } if (n > 0)decimalzero = 0; } else{ if (req_param==0){ for (i=0; i 1){ DXSetError(ERROR_BAD_PARAMETER,"must be 0 or 1"); goto error1; } } else refresh = 0; /* cache attributes and get min and max if unchanged */ for (n=0; n=0) item=nitem; val = (float *)DXAllocate(sizeof(float)*item *dim); if (!vec_reset(min,max,item,dim,-1,val)) goto error1; ip[4]=1; } else { if (islist) changen=ip[6]; if (ip[0]==1 || ip[1]==1) change=1; else change=0; /* read in scalar parameter * if no change then pass flag and use previously cached value * possible exec changed it previously */ if (in[2]){ if (!DXGetArrayInfo((Array)in[2],&item,NULL,NULL,NULL,&valdim)) goto error1; if (req_param==1 && (valdim != dim || changen==1)){ /* if dimension or number of items change, reset */ if (nitem >=0) item=nitem; val = (float *)DXAllocate(sizeof(float)*item *dim); if (!vec_reset(min,max,item,dim,-1,val)) goto error1; ip[4]=1; } else{ if (change==0){ val = (float *)DXAllocate(sizeof(float)*item *dim); if (!DXExtractParameter(in[2],TYPE_FLOAT,valdim,item, (Pointer)val)){ DXSetError(ERROR_INTERNAL,"can't extract current value"); goto error1; } } /* check for outofrange the min or max have changed*/ else{ val = (float *)DXAllocate(sizeof(float)*item *dim); if (valdim != dim){ for (i=0; i=0) item=nitem; DXFree((Pointer)val); val = (float *)DXAllocate(sizeof(float)*item *dim); if (!vec_reset(min,max,item,dim,-1,val)) goto error1; ip[4]=1; break; } } if (range==1) break; } } else{ for (i=0; i=0) item=nitem; val = (float *)DXAllocate(sizeof(float)*item*dim); if (!vec_reset(min,max,item,dim,-1,val)) goto error1; ip[4]=1; } else{ item=1; val = (float *)DXAllocate(sizeof(float)*item *dim); for (j=0; j 0 float */ if (!in[8]) isint = isthisint(val,dim,item); else{ for(n=0; n 0) isint = 0; } } if (isint==0){ for(n=0; n0){ shape[0]=(int)strlen(label); sprintf(ei.mp,"label="); while(*ei.mp) ei.mp++; if (!_dxfprint_message(label, &ei,TYPE_STRING,1,shape,1)) goto error1; } /* in DXMessage there is static buffer of MAX_MSGLEN so check length */ if (strlen(ei.msgbuf) > MAX_MSGLEN){ DXSetError(ERROR_INVALID_DATA,"#10920"); goto error1; } if (strcmp(ei.msgbuf,"")) DXUIMessage(id,ei.msgbuf); /* create array for output object */ if (ip[4]==1){ if (item==0) out[0]=NULL; else{ if (!setoutput(val,rank,item,dim,isint,out)) goto error; } } else out[0]=in[2]; DXFree(min); DXFree(max); DXFree(incr); DXFree(decimal); DXFree(ei.msgbuf); if (val) DXFree((Pointer)val); return OK; error: error1: /* change cache of data object so min and max will be cached */ change1 = _dxfcheck_obj_cache(in[0],id,0,idobj); DXFree(min); DXFree(max); DXFree(incr); DXFree(decimal); if (val) DXFree(val); if (ei.msgbuf) DXFree(ei.msgbuf); return ERROR; } static Error vec_minmax(Object o,int dim,int *size,int rank, float *min, float *max) { float *vec_f; int *vec_i; double *vec_d; short *vec_s; byte *vec_b; uint *vec_ui; ubyte *vec_ub; ushort *vec_us; int i,ig,j; Array a; float v; Type type; Category category; Object oo; Class class; Pointer dp; InvalidComponentHandle inv=NULL; /* determine class of object, if group recurse */ class = DXGetObjectClass(o); switch (class){ case CLASS_FIELD: case CLASS_ARRAY: if (class!=CLASS_ARRAY){ a = (Array)DXGetComponentValue((Field)o,"data"); if(!a){ DXSetError(ERROR_BAD_PARAMETER,"#10250","object","data"); return ERROR; } /* is there invalid data with this field */ if (!IsInvalid(o,&inv)) return ERROR; } else a = (Array)o; if (!DXGetArrayInfo(a,size,&type,&category,NULL,NULL)) return ERROR; if (category != CATEGORY_REAL){ DXSetError(ERROR_BAD_TYPE,"#11150","data"); return ERROR; } /* if class constant array return min, max */ if (DXQueryConstantArray(a,NULL,NULL)){ if (!constant_minmax(a,type,dim,min,max)) return ERROR; return OK; } /* if one-vector use statistics to get min and max */ if (dim==1){ if (!DXStatistics(o, "data", &min[0], &max[0], NULL, NULL)) return ERROR; return OK; } /* get pointer to data dependant on type */ switch (type){ case (TYPE_FLOAT): vec_f = (float *)DXGetArrayData(a); break; case (TYPE_INT): vec_i = (int *)DXGetArrayData(a); break; case (TYPE_DOUBLE): vec_d = (double *)DXGetArrayData(a); break; case (TYPE_SHORT): vec_s = (short *)DXGetArrayData(a); break; case (TYPE_BYTE): vec_b = (byte *)DXGetArrayData(a); break; case (TYPE_UINT): vec_ui = (uint *)DXGetArrayData(a); break; case (TYPE_UBYTE): vec_ub = (ubyte *)DXGetArrayData(a); break; case (TYPE_USHORT): vec_us = (ushort *)DXGetArrayData(a); break; default: DXSetError(ERROR_BAD_TYPE,"#10600","data type"); return ERROR; } for (i=0; i<(*size); i++){ if (inv && (DXIsElementInvalidSequential(inv,i))) continue; for (j=0; j= 0) value[offset] = (max[offset] +min[offset])/2.0; else{ for (j=0; j= 0){ for (i=0; i