Package ptolemy.data

Examples of ptolemy.data.ArrayToken


     *  actor.
     *  @exception IllegalActionException If the range parameter is malformed.
     */
    protected void _randomize() throws IllegalActionException {
        // Get the range.
        ArrayToken rangeValue = (ArrayToken) range.getToken();
        int dimensions = rangeValue.length();
        double[] randomLocation = new double[dimensions];

        CompositeActor container = (CompositeActor) getContainer();
        StringBuffer changeMoML = new StringBuffer("<group>\n");
        Iterator actors = container.deepEntityList().iterator();

        while (actors.hasNext()) {
            Entity node = (Entity) actors.next();

            // Skip actors that are not properly marked.
            Attribute mark = node.getAttribute("randomize");

            if (!(mark instanceof Variable)) {
                continue;
            }

            Token markValue = ((Variable) mark).getToken();

            if (!(markValue instanceof BooleanToken)) {
                continue;
            }

            if (!((BooleanToken) markValue).booleanValue()) {
                continue;
            }

            for (int i = 0; i < dimensions; i++) {
                ArrayToken lowHigh = (ArrayToken) rangeValue.getElement(i);

                if (lowHigh.length() < 2) {
                    throw new IllegalActionException(this, "Invalid range: "
                            + range.getExpression());
                }

                double low = ((DoubleToken) lowHigh.getElement(0))
                        .doubleValue();
                double high = ((DoubleToken) lowHigh.getElement(1))
                        .doubleValue();

                if (high < low) {
                    throw new IllegalActionException(this, "Invalid range: "
                            + range.getExpression());
View Full Code Here


        _wordLength = ((IntToken) (wordLength.getToken())).intValue();

        // Set the token consumption rate.
        input_tokenConsumptionRate.setToken(new IntToken(_wordLength));

        ArrayToken tableToken = (ArrayToken) table.getToken();
        int size = (int) Math.pow(2, _wordLength);

        if (tableToken.length() < size) {
            throw new IllegalActionException(this, "Table parameter must "
                    + "have at least " + size + " entries, but only has "
                    + tableToken.length());
        }

        _table = tableToken.arrayValue();
    }
View Full Code Here

     @exception IllegalActionException If parameter values are invalid,
     *   or if there is no director.
     */
    public void fire() throws IllegalActionException {
        if (newCoefficients.hasToken(0)) {
            ArrayToken coefficientsToken = (ArrayToken) (newCoefficients.get(0));
            reflectionCoefficients.setToken(coefficientsToken);
        }

        for (int i = 0; i < _blockSizeValue; i++) {
            super.fire();
View Full Code Here

                    _setInputTokenMap(portChannelName + "_isPresent", port,
                            BooleanToken.TRUE);
                    _setInputTokenMap(portName, port, tokens[0]);
                    _setInputTokenMap(portChannelName, port, tokens[0]);

                    ArrayToken arrayToken = new ArrayToken(tokens);
                    _setInputTokenMap(portName + "Array", port, arrayToken);
                    _setInputTokenMap(portChannelName + "Array", port,
                            arrayToken);
                } else {
                    _setInputTokenMap(portName + "_isPresent", port,
View Full Code Here

        super.fire();

        while (input.hasToken(0)) {
            RecordToken recordToken = (RecordToken) input.get(0);

            ArrayToken locationArray = (ArrayToken) recordToken.get("location");

            if (locationArray.length() < 2) {
                throw new IllegalActionException(this,
                        "Input is malformed: location field does not "
                                + "have two entries.");
            }

            double locationX = ((DoubleToken) locationArray.getElement(0))
                    .doubleValue();
            double locationY = ((DoubleToken) locationArray.getElement(1))
                    .doubleValue();

            double time = ((DoubleToken) recordToken.get("time")).doubleValue();

            // First check whether the location matches one already in the
            // buffer.  At the same time, identify the entry with the
            // oldest time and the newest time.
            boolean foundMatch = false;
            int oldestTimeIndex = 0;
            double oldestTime = Double.POSITIVE_INFINITY;
            double newestTime = Double.NEGATIVE_INFINITY;

            for (int i = 0; i < 3; i++) {
                if ((_locationsX[i] == locationX)
                        && (_locationsY[i] == locationY)) {
                    _times[i] = time;
                    foundMatch = true;
                }

                if (_times[i] < oldestTime) {
                    oldestTime = _times[i];
                    oldestTimeIndex = i;
                }

                if (_times[i] > newestTime) {
                    newestTime = _times[i];
                }
            }

            if (!foundMatch) {
                if (_debugging) {
                    _debug("Did not find match");
                }
                _locationsX[oldestTimeIndex] = locationX;
                _locationsY[oldestTimeIndex] = locationY;
                _times[oldestTimeIndex] = time;

                // Have to recalculate the oldest time now
                // since it has changed.
                oldestTime = Double.POSITIVE_INFINITY;

                for (int i = 0; i < 3; i++) {
                    if (_times[i] < oldestTime) {
                        oldestTime = _times[i];
                    }
                }
            }

            // Next check whether we have three observations within
            // the specified time window.  Since the time entries are
            // all initialized to negative infinity, the time span
            // will be infinity if we have not seen three observations
            // from three distinct locations.
            double timeSpan = newestTime - oldestTime;
            double timeWindowValue = ((DoubleToken) timeWindow.getToken())
                    .doubleValue();

            if (timeSpan > timeWindowValue) {
                // We do not have enough data.
                if (_debugging) {
                    _debug("We do not have enough data: " + timeSpan + " > " + timeWindowValue);
                }
                return;
            }

            // Get signal speed, from the signalPropagationSpeed parameter.
            double speed = ((DoubleToken) (signalPropagationSpeed.getToken()))
                    .doubleValue();

            // FIXME: Pass in the arrays for scalability.
            // FIXME: Replace naked 3 everywhere.
            double[] result = _locate(_locationsX[0], _locationsY[0],
                    _times[0], _locationsX[1], _locationsY[1], _times[1],
                    _locationsX[2], _locationsY[2], _times[2], speed);

            if (Double.isInfinite(result[2]) || Double.isNaN(result[2])) {
                // Result is not valid (inconsistent data).
                if (_debugging) {
                    _debug("Result is not valid: " + result[2]);
                }
                return;
            }

            Token[] resultArray = new Token[2];
            resultArray[0] = new DoubleToken(result[0]);
            resultArray[1] = new DoubleToken(result[1]);

            output.broadcast(new ArrayToken(resultArray));
        }
    }
View Full Code Here

     */
    public MovableViewScreen3D(CompositeEntity container, String name)
            throws IllegalActionException, NameDuplicationException {
        super(container, name);
        viewerPosition = new PortParameter(this, "viewerPosition",
                new ArrayToken("{0.0, 0.0, 2.4}"));
        viewerRotationAxis = new PortParameter(this, "viewerRotationAxis",
                new ArrayToken("{0.0, 0.0, -1.0}"));
        viewerRotationAngle = new PortParameter(this, "viwerRoationAngle",
                new DoubleToken("0.0"));

        viewerPosition.setTypeEquals(new ArrayType(BaseType.DOUBLE));
        viewerRotationAxis.setTypeEquals(new ArrayType(BaseType.DOUBLE));
View Full Code Here

        super.fire();
        viewerPosition.update();
        viewerRotationAxis.update();
        viewerRotationAngle.update();

        ArrayToken positionToken = (ArrayToken) viewerPosition.getToken();
        ArrayToken axisToken = (ArrayToken) viewerRotationAxis.getToken();
        DoubleToken angleToken = (DoubleToken) viewerRotationAngle.getToken();

        if ((positionToken.length() != 3) || (axisToken.length() != 3)) {
            throw new IllegalActionException(
                    "viewerPosition and viewerRotaionAxis arrays must have length 3.");
        }

        BooleanToken equals = positionToken.isEqualTo(_position);
        equals = equals.and(axisToken.isEqualTo(_axis));
        equals = equals.and(angleToken.isEqualTo(_angle));

        if (!equals.booleanValue()) {
            double xPosition;
            double yPosition;
            double zPosition;
            double axisX;
            double axisY;
            double axisZ;
            double angle;
            xPosition = ((DoubleToken) positionToken.getElement(0))
                    .doubleValue();
            yPosition = ((DoubleToken) positionToken.getElement(1))
                    .doubleValue();
            zPosition = ((DoubleToken) positionToken.getElement(2))
                    .doubleValue();
            axisX = ((DoubleToken) axisToken.getElement(0)).doubleValue();
            axisY = ((DoubleToken) axisToken.getElement(1)).doubleValue();
            axisZ = ((DoubleToken) axisToken.getElement(2)).doubleValue();
            angle = (angleToken).doubleValue();

            Quat4d quaternion = new Quat4d();
            quaternion.set(new AxisAngle4d(axisX, axisY, axisZ, angle));
View Full Code Here

            if ((time.doubleValue() > _timeValue)
                    || ((time.doubleValue() == _timeValue) && (d.intValue() < _parentDepth))) {
                //the root node may have been changed
                //or there is a shorter path.
                ArrayToken locationArray = (ArrayToken) inputToken
                        .get("location");
                int length = locationArray.length();
                _parentLocation = new double[length];

                for (int i = 0; i < length; i++) {
                    _parentLocation[i] = ((DoubleToken) locationArray
                            .getElement(i)).doubleValue();
                }

                _timeValue = time.doubleValue();
                _parentDepth = d.intValue();
View Full Code Here

    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////
    private void _getWorkRange() throws IllegalActionException {
        ArrayToken rangeValue = (ArrayToken) workRange.getToken();
        int dimensions = rangeValue.length();

        if (dimensions < 2) {
            throw new IllegalActionException(this, "Invalid range dimension: "
                    + workRange.getExpression());
        }

        _workRange = new double[dimensions][dimensions];

        for (int i = 0; i < dimensions; i++) {
            ArrayToken lowHigh = (ArrayToken) rangeValue.getElement(i);

            if (lowHigh.length() < 2) {
                throw new IllegalActionException(this, "Invalid range: "
                        + workRange.getExpression());
            }

            double low = ((DoubleToken) lowHigh.getElement(0)).doubleValue();
            double high = ((DoubleToken) lowHigh.getElement(1)).doubleValue();

            if (high < low) {
                throw new IllegalActionException(this, "Invalid range: "
                        + workRange.getExpression());
            }
View Full Code Here

        int vergilHeight = 800;

        try {
            WindowPropertiesAttribute windowProperties = (WindowPropertiesAttribute) _model
                    .getAttribute("_windowProperties");
            ArrayToken boundsToken = (ArrayToken) ((RecordToken) windowProperties
                    .getToken()).get("bounds");

            appletWidth = ((IntToken) boundsToken.getElement(2)).intValue();
            appletHeight = ((IntToken) boundsToken.getElement(3)).intValue();
        } catch (Exception ex) {
            System.out.println("Warning: Failed to get applet width "
                    + "and height, using defaults: " + ex.getMessage());
        }
View Full Code Here

TOP

Related Classes of ptolemy.data.ArrayToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.