Search in sources :

Example 1 with MotionTargetComponent

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);
    }
}
Also used : JComponent(javax.swing.JComponent) MotionTargetComponent(artisynth.core.mechmodels.MotionTargetComponent)

Example 2 with MotionTargetComponent

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;
}
Also used : Frame(artisynth.core.mechmodels.Frame) Point(artisynth.core.mechmodels.Point) MotionTargetComponent(artisynth.core.mechmodels.MotionTargetComponent)

Example 3 with MotionTargetComponent

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);
}
Also used : Frame(artisynth.core.mechmodels.Frame) VectorNd(maspack.matrix.VectorNd) Point(artisynth.core.mechmodels.Point) MotionTargetComponent(artisynth.core.mechmodels.MotionTargetComponent) Point(artisynth.core.mechmodels.Point)

Example 4 with MotionTargetComponent

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;
}
Also used : RenderableComponent(artisynth.core.modelbase.RenderableComponent) MotionTargetComponent(artisynth.core.mechmodels.MotionTargetComponent)

Example 5 with MotionTargetComponent

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;
}
Also used : RenderableComponent(artisynth.core.modelbase.RenderableComponent) MotionTargetComponent(artisynth.core.mechmodels.MotionTargetComponent)

Aggregations

MotionTargetComponent (artisynth.core.mechmodels.MotionTargetComponent)11 Point (artisynth.core.mechmodels.Point)6 Frame (artisynth.core.mechmodels.Frame)5 VectorNd (maspack.matrix.VectorNd)3 RenderableComponent (artisynth.core.modelbase.RenderableComponent)2 ForceTarget (artisynth.core.inverse.ForceTarget)1 ForceTargetTerm (artisynth.core.inverse.ForceTargetTerm)1 TrackingController (artisynth.core.inverse.TrackingController)1 LinearAxialMuscle (artisynth.core.materials.LinearAxialMuscle)1 AxialSpring (artisynth.core.mechmodels.AxialSpring)1 Muscle (artisynth.core.mechmodels.Muscle)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 JComponent (javax.swing.JComponent)1 Vector3d (maspack.matrix.Vector3d)1 Twist (maspack.spatialmotion.Twist)1 DoubleField (maspack.widgets.DoubleField)1