Example #1
0
  public void fire() throws IllegalActionException {
    if (_debugging) {
      _debug("Called fire()");
    }

    ArrayToken lineStartToken = ((ArrayToken) lineStart.getToken());
    ArrayToken lineEndToken = ((ArrayToken) lineEnd.getToken());
    ArrayToken rgbColorValue = ((ArrayToken) rgbColor.getToken());
    DoubleToken widthValue = (DoubleToken) width.getToken();

    GL gl = ((GRODirector) getDirector()).getGL();

    gl.glLineWidth((float) widthValue.doubleValue());
    gl.glBegin(GL.GL_LINES);

    gl.glColor3d(
        ((DoubleToken) rgbColorValue.getElement(0)).doubleValue(),
        ((DoubleToken) rgbColorValue.getElement(1)).doubleValue(),
        ((DoubleToken) rgbColorValue.getElement(2)).doubleValue());

    // origin of the line
    gl.glVertex3d(
        ((DoubleToken) lineStartToken.getElement(0)).doubleValue(),
        ((DoubleToken) lineStartToken.getElement(1)).doubleValue(),
        ((DoubleToken) lineStartToken.getElement(2)).doubleValue());

    // ending point of the line
    gl.glVertex3d(
        ((DoubleToken) lineEndToken.getElement(0)).doubleValue(),
        ((DoubleToken) lineEndToken.getElement(1)).doubleValue(),
        ((DoubleToken) lineEndToken.getElement(2)).doubleValue());

    gl.glEnd();
  }
Example #2
0
  /**
   * If there is a new token on the <i>input</i> port, then put it on the FIFO.
   *
   * <p>If the queue is not empty, then send the oldest token on the queue to the <i>output</i>
   * port. Send the resulting FIFO size to the <i>size</i> output port.
   *
   * @exception IllegalActionException If getting tokens from input and read ports or sending token
   *     to output throws it.
   */
  public void fire() throws IllegalActionException {
    super.fire();

    // sends copy of the oldest token to the output
    int comp = getDirector().getModelTime().compareTo(nextFlit);
    if (_queue.size() != 0 && (comp == 0 | comp == 1)) {
      output.send(0, (Token) _queue.get(0));
      if (_debugging) _debug("data sent at: " + getDirector().getModelTime());
    }

    // reads input port
    // stores token on the FIFO if there is room
    // sends ack or nack regarding the storage of the token
    if (input.hasToken(0)) {
      Token k = input.get(0);
      if (_queue.size() < _queue.getCapacity()) {
        _queue.put(k);
        ack.send(0, new BooleanToken(true));
      } else {
        ack.send(0, new BooleanToken(false));
      }
    }

    if (_queue.size() != 0) {
      // requests new firing after period
      nextFlit = getDirector().getModelTime();
      DoubleToken per = (DoubleToken) period.getToken();
      nextFlit = nextFlit.add(per.doubleValue());

      getDirector().fireAt(this, nextFlit);
    }

    // sends the FIFO size to the size port
    size.send(0, new IntToken(_queue.size()));
  }
Example #3
0
  public void initialize() throws IllegalActionException {
    ptolemy.data.Token[] tokens = initialOutputs_CGToken.arrayValue();
    int i = initialOutputs_CGToken.length();

    for (int i_1_ = 0; i_1_ < i; i_1_++) {
      ptolemy.data.Token token = tokens[i_1_];
      DoubleToken doubletoken;

      if (token instanceof DoubleToken) {
        doubletoken = (DoubleToken) token;
      } else {
        if (!(token instanceof IntToken)) {
          throw new IllegalActionException("Token Exception");
        }

        doubletoken = new DoubleToken(((IntToken) token).doubleValue());
      }

      System.out.println("token = " + doubletoken.toString());
    }
  }
Example #4
0
  // NOTE: No clone() method, so don't clone this.
  public void fire() throws IllegalActionException {
    super.fire();
    double increment = 0.0;

    if ((input.getWidth() > 0) && input.hasToken(0)) {
      DoubleToken in = (DoubleToken) input.get(0);
      increment = in.doubleValue();
    }

    output.broadcast(new DoubleToken(value + increment));
    value += 1.0;

    Director director = getDirector();
    Time time = director.getModelTime();
    count++;

    if (count >= 5) {
      director.fireAt(this, time.add(1.0));
      count = 0;
    } else {
      director.fireAt(this, time);
    }
  }
Example #5
0
  // Converts a matlab engine mxArray (ma) variable to a Ptolemy II Token.
  // @param ma Pointer to the matlab engine variable's mxArray
  // structure as a java long.
  // @return Ptolemy II Token of type that corresponds to ma's type.
  // @exception IllegalActionException If ma cannot be obtained from
  // the matlab engine, or if the mxArray type is not one of
  // 'double', 'struct', 'char' or 'cell', or if not all elements of
  // an ArrayToken to be created are of the same type.
  // @see Engine
  private Token _convertMxArrayToToken(long ma, ConversionParameters par)
      throws IllegalActionException {
    String maClassStr = ptmatlabGetClassName(ma);
    int[] dims = ptmatlabGetDimensions(ma);
    int nRows = dims[0];
    int nCols = dims[1];
    boolean scalarStructs = (nCols == 1) && (nRows == 1);
    boolean scalarMatrices = (nCols == 1) && (nRows == 1) && par.getScalarMatrices;
    Token retval = null;

    if (maClassStr.equals("double")) {
      if (ptmatlabIsComplex(ma)) {
        Complex[][] a = ptmatlabGetComplexMatrix(ma, nRows, nCols);

        if (a == null) {
          throw new IllegalActionException("can't get complex matrix from matlab engine.");
        }

        if (scalarMatrices) {
          retval = new ComplexToken(a[0][0]);
        } else {
          retval = new ComplexMatrixToken(a);
        }
      } else {
        double[][] a = ptmatlabGetDoubleMatrix(ma, nRows, nCols);

        if (a == null) {
          throw new IllegalActionException("can't get double matrix from matlab engine.");
        }

        if (scalarMatrices) {
          double tmp = a[0][0];

          if (_doubleisInteger(tmp)) {
            retval = new IntToken((int) tmp);
          } else {
            retval = new DoubleToken(tmp);
          }
        } else {
          boolean allIntegers = par.getIntMatrices;

          for (int i = 0; allIntegers && (i < a.length); i++) {
            for (int j = 0; allIntegers && (j < a[0].length); j++) {
              allIntegers &= _doubleisInteger(a[i][j]);
            }
          }

          if (allIntegers) {
            int[][] tmp = new int[a.length][a[0].length];

            for (int i = 0; i < a.length; i++) {
              for (int j = 0; j < a[0].length; j++) {
                tmp[i][j] = (int) a[i][j];
              }
            }

            retval = new IntMatrixToken(tmp);
          } else {
            retval = new DoubleMatrixToken(a);
          }
        }
      }
    } else if (maClassStr.equals("logical")) {
      int[][] a = ptmatlabGetLogicalMatrix(ma, nRows, nCols);

      if (a == null) {
        throw new IllegalActionException("can't get logical matrix from matlab engine.");
      }

      if (scalarMatrices) {
        retval = new IntToken(a[0][0]);
      } else {
        retval = new IntMatrixToken(a);
      }
    } else if (maClassStr.equals("struct")) {
      int nfields = ptmatlabGetNumberOfFields(ma);
      Token[] ta = new Token[nCols];
      Token[] tr = new Token[nRows];
      String[] fieldNames = new String[nfields];

      for (int k = 0; k < nfields; k++) {
        fieldNames[k] = ptmatlabGetFieldNameByNumber(ma, k);
      }

      Token[] fieldValues = new Token[nfields];

      for (int n = 0; n < nRows; n++) {
        for (int m = 0; m < nCols; m++) {
          for (int k = 0; k < nfields; k++) {
            long fma = ptmatlabGetFieldByNumber(ma, k, n, m);

            if (fma != 0) {
              fieldValues[k] = _convertMxArrayToToken(fma, par);
            } else {
              throw new IllegalActionException(
                  "can't get field "
                      + fieldNames[k]
                      + "from matlab "
                      + "struct "
                      + nRows
                      + "x"
                      + nCols);
            }
          }

          ta[m] = new RecordToken(fieldNames, fieldValues);
        }

        tr[n] = new ArrayToken(ta);
      }

      if (scalarStructs) {
        retval = ((ArrayToken) tr[0]).getElement(0);
      } else {
        retval = new ArrayToken(tr);
      }
    } else if (maClassStr.equals("cell")) {
      Token[] ta = new Token[nCols];
      Token[] tr = new Token[nRows];

      for (int n = 0; n < nRows; n++) {
        boolean anyIntegers = false;
        boolean anyDoubles = false;

        for (int m = 0; m < nCols; m++) {
          long cma = ptmatlabGetCell(ma, n, m);

          if (cma != 0) {
            ta[m] = _convertMxArrayToToken(cma, par);

            // Track whether we get mixed types back
            if (ta[m] instanceof IntToken) {
              anyIntegers = true;
            } else if (ta[m] instanceof DoubleToken) {
              anyDoubles = true;
            }
          } // else - throw exception?
        }

        if (anyIntegers && anyDoubles) {
          for (int m = 0; m < ta.length; m++) {
            if (ta[m] instanceof IntToken) {
              ta[m] = DoubleToken.convert(ta[m]);
            }
          }
        }

        tr[n] = new ArrayToken(ta);

        // If not all tokens are of the same, this will throw
        // an exception.
      }

      if (nRows == 1) {
        retval = tr[0];
      } else {
        retval = new ArrayToken(tr);
      }
    } else if (maClassStr.equals("char")) {
      if (nRows == 1) {
        retval = new StringToken(ptmatlabGetString(ma, 0));
      } else {
        Token[] ta = new Token[nRows];

        for (int n = 0; n < nRows; n++) {
          ta[n] = new StringToken(ptmatlabGetString(ma, n));
        }

        retval = new ArrayToken(ta);
      }
    } else {
      throw new IllegalActionException(
          "no support for mxArray class " + maClassStr + " " + dims[0] + " x " + dims[1]);
    }

    return retval;
  }