use of artisynth.core.mechmodels.MotionTargetComponent in project artisynth_core by artisynth.
the class MotionTargetComponentAgent method actionPerformed.
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("Add")) {
mySelectionManager.clearSelections();
myMain.rerender();
setState(State.SelectingTargets);
} else if (cmd.equals("Stop")) {
mySelectionManager.clearSelections();
setState(State.Complete);
myMain.rerender();
} else if (cmd.equals("remove target")) {
JComponent[] widgets = myTargetPanel.getSelectedWidgets();
for (int i = 0; i < widgets.length; i++) {
MotionTargetComponent target = (MotionTargetComponent) myTargetPanel.getComponent(widgets[i]);
myController.removeMotionTarget(target);
myTargetPanel.removeWidget(widgets[i]);
}
myTargetPanel.revalidate();
myTargetPanel.repaint();
myMain.rerender();
} else {
super.actionPerformed(e);
}
}
use of artisynth.core.mechmodels.MotionTargetComponent in project artisynth_core by artisynth.
the class MotionTargetTerm method doAddTarget.
/**
* Adds a target to the term for trajectory error
* @param source
* @param weight
* @return the created target body or point
*/
private MotionTargetComponent doAddTarget(MotionTargetComponent source, double weight) {
mySources.add(source);
// myController.sourcePoints.add (source);
source.setTargetActivity(TargetActivity.None);
MotionTargetComponent target = null;
if (source instanceof Point) {
myTargetVelSize += POINT_VEL_SIZE;
myTargetPosSize += POINT_POS_SIZE;
target = addTargetPoint((Point) source);
} else if (source instanceof Frame) {
myTargetVelSize += FRAME_VEL_SIZE;
myTargetPosSize += FRAME_POS_SIZE;
target = addTargetFrame((RigidBody) source);
}
myTargetWeights.add(weight);
updateWeightsVector();
// set target matrix null, so that it is recreated on demand
// XXX should be updated on a change event...
myVelJacobian = null;
// mySolver.resetVariables();
return target;
}
use of artisynth.core.mechmodels.MotionTargetComponent in project artisynth_core by artisynth.
the class MotionTargetTerm method interpolateTargetVelocity.
/*
* calculate target velocity by differencing current and last target positions
*/
private void interpolateTargetVelocity(double h) {
// paranoid
assert myTargets.size() == mySources.size();
updateTargetPos(h);
if (prevTargetPos == null || prevTargetPos.size() != myTargetPosSize) {
prevTargetPos = new VectorNd(myTargetPos);
}
double[] prevPosBuf = prevTargetPos.getBuffer();
int idx = 0;
for (int i = 0; i < myTargets.size(); i++) {
MotionTargetComponent target = myTargets.get(i);
if (target instanceof Point) {
idx = tmpPoint.setPosState(prevPosBuf, idx);
interpolateTargetVelocityFromPositions(tmpPoint, (Point) target, h);
} else if (target instanceof Frame) {
idx = tmpFrame.setPosState(prevPosBuf, idx);
interpolateTargetVelocityFromPositions(tmpFrame, (Frame) target, h);
}
}
prevTargetPos.set(myTargetPos);
}
use of artisynth.core.mechmodels.MotionTargetComponent in project artisynth_core by artisynth.
the class TrackingController method setSourcesVisible.
/**
* Show or hide the sources
*/
public void setSourcesVisible(boolean show) {
ArrayList<MotionTargetComponent> moTargetParticles = myMotionTerm.getSources();
for (MotionTargetComponent p : moTargetParticles) {
if (p instanceof RenderableComponent) {
RenderProps.setVisible((RenderableComponent) p, show);
}
}
sourcesVisible = show;
}
use of artisynth.core.mechmodels.MotionTargetComponent in project artisynth_core by artisynth.
the class TrackingController method setTargetsVisible.
/**
* Show or hide the targets
*/
public void setTargetsVisible(boolean show) {
ArrayList<MotionTargetComponent> moTargetParticles = myMotionTerm.getTargets();
for (MotionTargetComponent p : moTargetParticles) {
if (p instanceof RenderableComponent) {
RenderProps.setVisible((RenderableComponent) p, show);
}
}
targetsVisible = show;
}
Aggregations