⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_expr.c

📁 LastWave
💻 C
📖 第 1 页 / 共 5 页
字号:
      }      if (r == RangeType) {        *resVC = (VALUE) TNewImage();        SizeImage((IMAGE) *resVC,1,rg->size);        for(j=0;j<rg->size;j++) {          ((IMAGE) *resVC)->pixels[j] = rg->first+j*rg->step;        }        return(ImageType);      }      Errorf("Not yet implemented");    }        /* Set output */    if (r == FloatType) {Clean(*resVC);}    else TTSetOutput1(r,*resVC,&vc3);    /* Set Input/Output arrays */    s3 = NULL;    i3 = NULL;    rg3 = NULL;    if (r==SignalType) {      s3 = (SIGNAL) vc3;      r3 = SignalType;      size = s->size;      array = s->Y;       array3 = s3->Y;     }    else if (r==RangeType) {      s3 = (SIGNAL) vc3;      r3 = SignalType;      size = rg->size;      array = NULL;      array3 = s3->Y;     }    else if (r==ImageType) {      i3 = (IMAGE) vc3;      r3 = ImageType;      array = i->pixels;      size = i->nrow*i->ncol;      array3 = i3->pixels;     }    else {      array3 = array = resFlt;      size = 1;      r3 = FloatType;    }         /* Computation */    if (arrayIndex == 1) {      switch(opIndex) {        /* ! */         case 1 :           /* Range case */          if (array == NULL) {for (j=0;j<size;j++) array3[j] = (RangeVal(rg,j)==0); break;}          /* Regular Signal case */          else { for (j=0;j<size;j++) array3[j] = (array[j]==0); break;}        /* - */         case 3 :           /* Vector case */          if (array == NULL) {for (j=0;j<size;j++) array3[j] = -(RangeVal(rg,j)); break;}          /* Regular Signal case */          else {for (j=0;j<size;j++) array3[j] = -array[j]; break;}        default : Errorf("Expr9() : Weired error Array1");      }    }    else {      switch(opIndex) {        /* sinh */         case 1 : Apply1(array3,array,rg,sinh); break;        /* sin */         case 2 : Apply1(array3,array,rg,sin); break;        /* cosh */         case 3 : Apply1(array3,array,rg,cosh); break;        /* cos */         case 4 : Apply1(array3,array,rg,cos); break;        /* tanh */         case 5 : Apply1(array3,array,rg,tanh); break;        /* tan */         case 6 : Apply1(array3,array,rg,tan); break;        /* acos */         case 7 : Apply1(array3,array,rg,acos); break;        /* asin */         case 8 : Apply1(array3,array,rg,asin); break;        /* atan */         case 9 : Apply1(array3,array,rg,atan); break;        /* log2 */         case 10 : Apply1(array3,array,rg,MyLog2); break;        /* log */         case 11 : Apply1(array3,array,rg,MyLog10); break;        /* ln */         case 12 : Apply1(array3,array,rg,MyLog); break;        /* sqrt */         case 13 : Apply1(array3,array,rg,MySqrt); break;        /* abs */         case 14 : Apply1(array3,array,rg,fabs); break;        /* exp */         case 15 : Apply1(array3,array,rg,exp); break;        /* ceil */         case 16 : Apply1(array3,array,rg,ceil); break;        /* floor */         case 17 : Apply1(array3,array,rg,floor); break;        /* LWTROUND */         case 18 :           /* Range case */          if (array == NULL) {for (j=0;j<size;j++) array3[j] = (RangeVal(rg,j) >= 0 ? (int) (RangeVal(rg,j)+.5) : (int) (RangeVal(rg,j)-.5)); break;}                    /* Regular Signal case */          else {for (j=0;j<size;j++) array3[j] = (array[j] >= 0 ? (int) (array[j]+.5) : (int) (array[j]-.5)); break;}        /* frac */         case 19 :           /* Vector case */          if (array == NULL) {for (j=0;j<size;j++) array3[j] = RangeVal(rg,j) - ((int) RangeVal(rg,j));  break;}                    /* Regular Signal case */          else {for (j=0;j<size;j++) array3[j] = array[j] - ((int) array[j]); break;}        /* int */         case 20 : Apply1(array3,array,rg,(int)); break;                default : Errorf("Expr8() : Weired error Array2");      }    }           if (s3) *resVC = (VALUE) s3;    else if (i3) *resVC = (VALUE) i3;    else if (rg3) *resVC = (VALUE) rg3;        if (r3 == SignalType && NoDefaultSig(defParam)) {SetDefaultSig(defParam,((SIGNAL) *resVC),NO);}    else if (r3 == ImageType && NoDefaultSig(defParam)) {SetDefaultIm(defParam,((IMAGE) *resVC),NO);}        return(r3);  }          /***********************************************************   *    * Operators "Zero","One","Id","I","J","Grand","Urand"   *    * 'op' 'op(expr0_Num)' 'op(expr0_Num,expr0_Num)'    *   ***********************************************************/  /* Third array */  arrayIndex = 3;  for (op = opArray3, opSize = opSizeArray3 ;;op++,opSize++) {                                                             if (*op == NULL) break;     if (!strncmp(begin,*op,*opSize) && !IsValidSymbolChar(begin[*opSize])) break;   }  opIndex = op-opArray3+1;      if (*op != NULL) {        /* Check some types */    if (flagType == FloatType) {      SetErrorf("Expecting a number, not a signal or an image !");      Clean(*resVC);      return(0);    }    /* Skip operator */    begin2= begin;     begin  += *opSize;     ParamSkipSpace(begin);     *left = begin;    /* Case there is a op(expr0_Int... */    f1 = f2 = -1;    s3 = NULL;    i3 = NULL;    if (*begin == '(') {      begin1 = begin;      begin++;      *left = begin;      oldFlagSpace = defParam->flagSpace;      defParam->flagSpace = YES;      if (!TTExpr1(begin,left,resFlt,resVC,FloatType,defParam)) return(0);      if (*resFlt <= 0 || *resFlt != ((int) *resFlt)) {        *left = begin;        SetErrorf("Bad dimension '%g'",*resFlt);        Clean(*resVC);        return(0);      }      r = SignalType;      f1 = *resFlt;      begin = *left;            /* Case of op(expr0_Int,expr0_Int) */      if (**left == ',') {                /* Error if Id(n, */        if (opIndex==3) {          *left = begin2;          SetErrorf("The operator 'Id' takes only 1 argument");          Clean(*resVC);          return(0);        }        r = ImageType;        begin++;        *left = begin;        if (!TTExpr1(begin,left,resFlt,resVC,FloatType,defParam)) {          Clean(*resVC);          return(0);        }        if (*resFlt <= 0 || *resFlt != ((int) *resFlt)) {          *left = begin;          SetErrorf("Bad dimension '%g'",*resFlt);          Clean(*resVC);          return(0);        }        begin = *left;        f2 = *resFlt;        if (**left != ')') {          SetErrorf("Expecting a parenthesis ')'");           Clean(*resVC);          return(0);        }        (*left)++;        begin = (*left);        defParam->flagSpace = oldFlagSpace;      }            /* Error if J(n) */      else if (opIndex==5) {        *left = begin2;        SetErrorf("The operator 'J' is missing one argument");        Clean(*resVC);        return(0);      }            /* Closing parenthesis of  op(expr0_Int) */      else {        if (**left != ')') {          SetErrorf("Expecting a parenthesis ')'");           Clean(*resVC);          return(0);        }        (*left)++;        begin = (*left);        defParam->flagSpace = oldFlagSpace;        /* Id(n) */        if (opIndex==3) {f2 = f1; r = ImageType;}      }            /* Set the default sig/images */      if (f2 == -1) {SetDefaultSizeX0Dx(defParam,(int) f1,0,1,NO);}      else if (f1 == 1) {SetDefaultSizeX0Dx(defParam,(int) f2,0,1,NO);}      else if (f2 != -1) {SetDefaultNColNRow(defParam,(int) f2,(int) f1,NO);}    }    /* Case there is a op */        else {      /* if the operator is not J and we don't know if we should build an image or a signal error */      if ((flagType & ImageType && defParam->_theImageNRow != -1) && (flagType & SignalType && defParam->_theSignalSize!=-1) && opIndex!=5) {        SetErrorf("Cannot infer whether I should build a signal or an image (you should specify the sizes)");        *left = begin2;        Clean(*resVC);        return(0);      }      /* J ==> image, otherwise we check what is expected */      if (opIndex == 5) {        r = ImageType;        if (defParam->_theImageNRow == -1)  {          SetErrorf("Cannot infer the size for the operator '%s'",opArray3[opIndex-1]);          *left = begin2;          Clean(*resVC);          return(0);        }      }       else if (flagType & SignalType && defParam->_theSignalSize != -1) r = SignalType;      else if (flagType & ImageType && defParam->_theImageNRow != -1) r = ImageType;      else {        SetErrorf("Cannot infer the size for the operator '%s'",opArray3[opIndex-1]);        *left = begin2;        Clean(*resVC);        return(0);      }      /* Id ==> squared image, otherwise error */      if (opIndex == 3 && r == SignalType) {        SetErrorf("You should specify an argument to 'Id' operator");        *left = begin2;        Clean(*resVC);        return(0);      }      if (opIndex == 3 &&  (defParam->_theImageNRow == -1 || defParam->_theImageNRow != defParam->_theImageNCol)) {        SetErrorf("You should specify an argument to 'Id' operator (default image is not square)");        *left = begin2;        Clean(*resVC);        return(0);      }    }        /* Some conversions */    if (f1 == 1 && (flagType & SignalType)) {      f1 = f2;      f2 = -1;      r = SignalType;    }            /* Check some types */    if (!(r & flagType)) {      if (r == SignalType) SetErrorf("Expecting an image");      else SetErrorf("Expecting a signal");      Clean(*resVC);      *left = begin2;      return(0);    }        /* Setting f1 and f2 (the signal/image dimension) */    if (f1 == -1 && r==SignalType) {      if (NoDefaultSig(defParam)) {        *left = begin2;        SetErrorf("Do not know the size of the signal");        Clean(*resVC);        return(0);      }      f1 = DefaultSigSize(defParam);    }    else if (f1 == -1 && r==ImageType) {      if (NoDefaultIm(defParam) == -1) {        *left = begin2;        SetErrorf("Do not know the size of the image");        Clean(*resVC);        return(0);      }      f1 = DefaultImNRow(defParam);      f2 = DefaultImNCol(defParam);    }          /* Allocation */    if (r==SignalType) {            /* Case of I (=>Vector) */      if (opIndex == 4) {        Clean(*resVC);        rg3 = TNewRange();        *resVC = (VALUE) rg3;        rg3->first = 0;        rg3->step = 1;        rg3->size = (int) f1;        SetDefaultSizeX0Dx(defParam,rg3->size,0,1,NO);        return(RangeType);      }            if (*resVC != NULL && (*resVC)->nRef == 1 && (GetTypeValue(*resVC) == signaliType || GetTypeValue(*resVC) == signalType)) s3 = (SIGNAL) *resVC;      else {        Clean(*resVC);        s3 = TNewSignal();        *resVC = (VALUE) s3;      }      /* Case of J (=>One) */      if (opIndex == 5) opIndex = 2;      SizeSignal(s3,(int) f1,YSIG);    }    else {      if (*resVC != NULL && (*resVC)->nRef == 1 && (GetTypeValue(*resVC) == imageiType || GetTypeValue(*resVC) == imageType)) i3 = (IMAGE) *resVC;      else {        Clean(*resVC);        i3 = TNewImage();        *resVC = (VALUE) i3;      }      SizeImage(i3,(int) f2,(int) f1);    }        /* Set Input/Output arrays */    if (*resVC != NULL && r == SignalType) {       size = s3->size;      array3 = s3->Y;     }    else if (*resVC != NULL) {      size = i3->nrow*i3->ncol;      array3 = i3->pixels;     }    /* Computation */    switch(opIndex) {      /* Zero */       case 1 : for (j=0;j<size;j++) array3[j] = 0; break;      /* One */       case 2 : for (j=0;j<size;j++) array3[j] = 1; break;      /* Id */       case 3 : for(j=0;j<f1;j++) for(j1=0;j1<f2;j1++) i3->pixels[j * ((int) f2) + j1] = (j==j1); break;      /* I */       case 4 :         if (i3 == NULL) break;        else  for(j=0;j<f1;j++) for(j1=0;j1<f2;j1++) i3->pixels[j * ((int) f2) + j1] = j1;        break;      /* J */       case 5 :  for(j=0;j<f1;j++) for(j1=0;j1<f2;j1++) i3->pixels[j * ((int) f2) + j1] = j; break;      /* Grand */       case 6 : for (j=0;j<size;j++) array3[j] = Grand(1); break;      /* Urand */       case 7 : for (j=0;j<size;j++) array3[j] = Urand(); break;      default : Errorf("Expr8() : Weired error Array3");    }        if (r==SignalType) {SetDefaultSig(defParam,(SIGNAL) (*resVC),NO);}    else if (r==ImageType) {SetDefaultIm(defParam,(IMAGE) (*resVC),NO);}    return(r);  }  /***********************************************************   *    * Operator "XY"   *    * 'op(expr0_Sig,expr0_Sig)'   *   ***********************************************************/  /* Fourth array */  arrayIndex = 4;  for (op = opArray4, opSize = opSizeArray4 ;;op++,opSize++) {                                                             if (*op == NULL) break; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -