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);
}
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);
}
}
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");
}
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);
}
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();
}
}
}
}
Aggregations