Search in sources :

Example 1 with NumericInputProbe

use of artisynth.core.probes.NumericInputProbe in project artisynth_core by artisynth.

the class FemMuscleHeart method addHeartProbe.

protected void addHeartProbe(MuscleBundle longBundle, MuscleBundle radialBundle) {
    Property[] props = new Property[2];
    props[0] = longBundle.getProperty("excitation");
    props[1] = radialBundle.getProperty("excitation");
    NumericInputProbe probe = new NumericInputProbe();
    probe.setInputProperties(props);
    double startTime = 3.0;
    double stopTime = 60.0;
    // seconds per heart beat
    double cycleTime = 0.8;
    probe.setStartStopTimes(startTime, stopTime);
    // beat cycle
    double[] beat0 = { 0, 0 };
    double[] beat1 = { 0.9, 0 };
    double[] beat2 = { 0, 0.3 };
    for (double t = 0; t < stopTime - startTime; t += cycleTime) {
        // NOTE: times are relative to "startTime"
        probe.addData(t, beat0);
        probe.addData(t + cycleTime * 0.15, beat1);
        probe.addData(t + cycleTime * 0.3, beat2);
        probe.addData(t + cycleTime * 0.4, beat0);
    }
    addInputProbe(probe);
}
Also used : NumericInputProbe(artisynth.core.probes.NumericInputProbe) Property(maspack.properties.Property)

Example 2 with NumericInputProbe

use of artisynth.core.probes.NumericInputProbe in project artisynth_core by artisynth.

the class InputNumericProbeEditor method setInputProbe.

// //
// // Called when a user adds an input property
// //
// public void addInputProbeProperty (int index, Property prop)
// {
// myProperties.set (index, prop);
// 
// NumericConverter conv = new NumericConverter(prop.get());
// String varname = getUniqueVariableName(INPUT_PREFIX);
// NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
// myVariables.put (varname, var);
// NumericProbeDriver driver = new NumericProbeDriver();
// driver.setExpression (varname, myVariables);
// myDrivers.set (index, driver);
// 
// AddVectorPane newVec = new AddVectorPane(this, varname);
// newVec.setDim(var.getDimension());
// addVectorGUI(newVec);
// super.updateGUI();
// }
private void setInputProbe() {
    ArrayList<String> variableNames = new ArrayList<String>();
    ArrayList<Integer> variableDims = new ArrayList<Integer>();
    for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
        variableNames.add(entry.getKey());
        variableDims.add(entry.getValue().getDimension());
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }
    int[] varDimsInt = new int[variableDims.size()];
    for (int i = 0; i < variableDims.size(); i++) {
        varDimsInt[i] = variableDims.get(i);
    // System.out.println("size of V="+variableDims.get(i));
    }
    NumericInputProbe probeToSet;
    if (oldProbe == null) {
        ModelComponent refComp = ComponentUtils.getPropertyComponent(myProperties.get(0));
        probeToSet = new NumericInputProbe(refComp);
    } else {
        probeToSet = oldProbe;
    }
    probeToSet.set(myProperties.toArray(new Property[0]), getDriverExpressions(), variableNames.toArray(new String[0]), varDimsInt);
    probeToSet.setStartTime(startTimeField.getDoubleValue());
    probeToSet.setStopTime(endTimeField.getDoubleValue());
    probeToSet.setScale(scaleField.getDoubleValue());
    probeToSet.setName(probeNameField.getStringValue());
    String attachedFilePath = attachedFileField.getStringValue();
    if (attachedFilePath != null) {
        if (attachedFilePath.equals("") || !attachedInputFileValid(attachedFilePath, null)) {
            attachedFilePath = null;
        }
    }
    if (attachedFilePath != null) {
        probeToSet.setAttachedFileName(attachedFilePath);
        try {
            probeToSet.load();
            ((Displayable) probeToSet).updateDisplays();
        } catch (IOException e) {
            System.err.println("Couldn't load probe ");
            e.printStackTrace();
            probeToSet.setAttachedFileName(null);
        }
    } else {
        probeToSet.setAttachedFileName(null);
        if (probeToSet.getNumericList().isEmpty()) {
            // add knots at beginning and end
            if (probeToSet.isSettable()) {
                probeToSet.setData(probeToSet.getStartTime());
                probeToSet.setData(probeToSet.getStopTime());
            } else {
                probeToSet.loadEmpty();
            }
        }
    }
    if (oldProbe == null) {
        AddComponentsCommand cmd = new AddComponentsCommand("add input probe", probeToSet, myMain.getRootModel().getInputProbes());
        myMain.getUndoManager().saveStateAndExecute(cmd);
    }
}
Also used : Displayable(artisynth.core.gui.Displayable) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) ModelComponent(artisynth.core.modelbase.ModelComponent) NumericInputProbe(artisynth.core.probes.NumericInputProbe) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Property(maspack.properties.Property)

Example 3 with NumericInputProbe

use of artisynth.core.probes.NumericInputProbe in project artisynth_core by artisynth.

the class ProbeInfo method clearProbeData.

private void clearProbeData() {
    if (NumericProbeBase.class.isAssignableFrom(getProbe().getClass())) {
        NumericProbeBase numericProbe = (NumericProbeBase) getProbe();
        numericProbe.getNumericList().clear();
        // add empty data, using set if settable
        if (getProbe().isSettable()) {
            getProbe().setData(getProbe().getStartTime());
            getProbe().setData(getProbe().getStopTime());
        } else if (NumericInputProbe.class.isAssignableFrom(getProbe().getClass())) {
            ((NumericInputProbe) getProbe()).loadEmpty();
        }
    } else
        System.out.println("probe is not numeric, cannot clear");
}
Also used : NumericInputProbe(artisynth.core.probes.NumericInputProbe) NumericProbeBase(artisynth.core.probes.NumericProbeBase)

Example 4 with NumericInputProbe

use of artisynth.core.probes.NumericInputProbe in project artisynth_core by artisynth.

the class ProbeInfo method editProbe.

// edit the probe
private void editProbe() {
    NumericProbeEditor dialog;
    if (getProbe().isInput()) {
        dialog = new InputNumericProbeEditor((NumericInputProbe) getProbe());
    } else {
        dialog = new OutputNumericProbeEditor((NumericOutputProbe) getProbe());
    }
    dialog.setVisible(true);
    Point loc = getMain().getFrame().getLocation();
    dialog.setLocation(loc.x + getMain().getFrame().getWidth(), getMain().getFrame().getHeight());
    myController.addProbeEditor(dialog);
}
Also used : InputNumericProbeEditor(artisynth.core.gui.probeEditor.InputNumericProbeEditor) NumericInputProbe(artisynth.core.probes.NumericInputProbe) OutputNumericProbeEditor(artisynth.core.gui.probeEditor.OutputNumericProbeEditor) NumericProbeEditor(artisynth.core.gui.probeEditor.NumericProbeEditor) InputNumericProbeEditor(artisynth.core.gui.probeEditor.InputNumericProbeEditor) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) Point(java.awt.Point) WayPoint(artisynth.core.probes.WayPoint) OutputNumericProbeEditor(artisynth.core.gui.probeEditor.OutputNumericProbeEditor)

Example 5 with NumericInputProbe

use of artisynth.core.probes.NumericInputProbe in project artisynth_core by artisynth.

the class InverseManager method configureTargetForceProbe.

private void configureTargetForceProbe(NumericProbeBase probe, ArrayList<ForceTarget> targets, String filename) {
    // System.out.println ("configuring force probe");
    ArrayList<Property> props = new ArrayList<Property>();
    for (ForceTarget target : targets) {
        props.add(target.getProperty("targetLambda"));
    }
    // probe.setModel(myController.getMech());
    probe.setAttachedFileName(filename);
    if (probe instanceof NumericInputProbe) {
        ((NumericInputProbe) probe).setInputProperties(props.toArray(new Property[props.size()]));
    } else if (probe instanceof NumericOutputProbe) {
        ((NumericOutputProbe) probe).setOutputProperties(props.toArray(new Property[props.size()]));
    }
    if (probe instanceof NumericInputProbe) {
        File file = probe.getAttachedFile();
        if (file == null || !file.exists()) {
            ((NumericInputProbe) probe).loadEmpty();
            probe.setActive(false);
        } else {
            try {
                probe.load();
                probe.setActive(true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : NumericInputProbe(artisynth.core.probes.NumericInputProbe) ArrayList(java.util.ArrayList) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) IOException(java.io.IOException) Property(maspack.properties.Property) File(java.io.File)

Aggregations

NumericInputProbe (artisynth.core.probes.NumericInputProbe)19 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)9 IOException (java.io.IOException)8 Property (maspack.properties.Property)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 ModelComponent (artisynth.core.modelbase.ModelComponent)2 WayPoint (artisynth.core.probes.WayPoint)2 ControlPanel (artisynth.core.gui.ControlPanel)1 Displayable (artisynth.core.gui.Displayable)1 AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)1 InputNumericProbeEditor (artisynth.core.gui.probeEditor.InputNumericProbeEditor)1 NumericProbeEditor (artisynth.core.gui.probeEditor.NumericProbeEditor)1 OutputNumericProbeEditor (artisynth.core.gui.probeEditor.OutputNumericProbeEditor)1 TargetPoint (artisynth.core.inverse.TargetPoint)1 CollisionManager (artisynth.core.mechmodels.CollisionManager)1 Frame (artisynth.core.mechmodels.Frame)1 MechModel (artisynth.core.mechmodels.MechModel)1 Point (artisynth.core.mechmodels.Point)1 NumericProbeBase (artisynth.core.probes.NumericProbeBase)1