Search in sources :

Example 6 with Frame

use of artisynth.core.mechmodels.Frame in project artisynth_core by artisynth.

the class InverseManager method configureTargetMotionProbe.

private void configureTargetMotionProbe(NumericProbeBase probe, ArrayList<MotionTargetComponent> targets, String filename) {
    // System.out.println ("configuring motion probe");
    ArrayList<Property> props = new ArrayList<Property>();
    for (ModelComponent target : targets) {
        if (target instanceof Point) {
            props.add(target.getProperty("position"));
        } else if (target instanceof Frame) {
            props.add(target.getProperty("position"));
            props.add(target.getProperty("orientation"));
        } else {
            System.err.println("Unknown target component type: " + target.getClass().toString());
        }
    }
    // 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 : Frame(artisynth.core.mechmodels.Frame) ModelComponent(artisynth.core.modelbase.ModelComponent) NumericInputProbe(artisynth.core.probes.NumericInputProbe) ArrayList(java.util.ArrayList) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) Point(artisynth.core.mechmodels.Point) WayPoint(artisynth.core.probes.WayPoint) IOException(java.io.IOException) Property(maspack.properties.Property) File(java.io.File)

Example 7 with Frame

use of artisynth.core.mechmodels.Frame 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 8 with Frame

use of artisynth.core.mechmodels.Frame 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 9 with Frame

use of artisynth.core.mechmodels.Frame in project artisynth_core by artisynth.

the class MotionTargetTerm method removeTarget.

/**
 * Removes a target to the term for trajectory error
 * @param source
 */
protected void removeTarget(MotionTargetComponent source) {
    int idx = mySources.indexOf(source);
    if (idx == -1) {
        return;
    }
    if (source instanceof Point) {
        myTargetVelSize -= POINT_VEL_SIZE;
        myTargetPosSize -= POINT_POS_SIZE;
        // remove ref particle created in doAddTarget
        removeTargetPoint((Point) myTargets.get(idx));
    } else if (source instanceof Frame) {
        myTargetVelSize -= FRAME_VEL_SIZE;
        myTargetPosSize -= FRAME_POS_SIZE;
        // remove ref body created in doAddTarget
        removeTargetFrame((Frame) myTargets.get(idx));
    }
    myTargetWeights.remove(idx);
    mySources.remove(idx);
    myTargets.remove(idx);
    updateWeightsVector();
    // set target matrix null, so that it is recreated on demand
    // XXX should be updated on a change event...
    myVelJacobian = null;
// Main.getMain().getInverseManager().configureTargetProbes();
// mySolver.resetVariables();
}
Also used : Frame(artisynth.core.mechmodels.Frame) Point(artisynth.core.mechmodels.Point) Point(artisynth.core.mechmodels.Point)

Example 10 with Frame

use of artisynth.core.mechmodels.Frame in project artisynth_core by artisynth.

the class Main method setDragger.

private void setDragger() {
    translator3d.setVisible(false);
    transrotator3d.setVisible(false);
    scalar3d.setVisible(false);
    rotator3d.setVisible(false);
    constrainedTranslator3d.setVisible(false);
    constrainedTranslator3d.setMesh(null);
    currentDragger = null;
    myDraggableComponents.clear();
    if (mySelectionMode != SelectionMode.Select && mySelectionMode != SelectionMode.EllipticSelect && mySelectionMode != SelectionMode.Pull) {
        Point3d pmin = new Point3d(inf, inf, inf);
        Point3d pmax = new Point3d(-inf, -inf, -inf);
        int n = 0;
        for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
            if (sel instanceof Renderable && sel instanceof TransformableGeometry && !ComponentUtils.isAncestorSelected(sel)) {
                myDraggableComponents.add(sel);
                ((Renderable) sel).updateBounds(pmin, pmax);
                n++;
            }
        }
        if (n > 0) {
            RigidTransform3d TDW = new RigidTransform3d();
            double radius = computeDraggerToWorld(TDW, myDraggableComponents, null);
            // set a minimum radius to about 1/6 of the viewer window width
            radius = Math.max(radius, myViewer.distancePerPixel(myViewer.getCenter()) * myViewer.getScreenWidth() / 6);
            if (mySelectionMode == SelectionMode.Translate) {
                translator3d.setVisible(true);
                translator3d.setDraggerToWorld(TDW);
                translator3d.setSize(radius);
                currentDragger = translator3d;
            } else if (mySelectionMode == SelectionMode.Transrotate) {
                transrotator3d.setVisible(true);
                transrotator3d.setDraggerToWorld(TDW);
                transrotator3d.setSize(radius);
                currentDragger = transrotator3d;
            } else if (mySelectionMode == SelectionMode.Scale) {
                scalar3d.setVisible(true);
                scalar3d.setDraggerToWorld(TDW);
                scalar3d.setSize(radius);
                currentDragger = scalar3d;
            } else if (mySelectionMode == SelectionMode.Rotate) {
                rotator3d.setVisible(true);
                rotator3d.setDraggerToWorld(TDW);
                rotator3d.setSize(radius);
                currentDragger = rotator3d;
            } else if (mySelectionMode == SelectionMode.ConstrainedTranslate) {
                PolygonalMesh mesh = null;
                for (Object sel : mySelectionManager.getCurrentSelection()) {
                    if (sel instanceof FrameMarker) {
                        FrameMarker frameMarker = (FrameMarker) sel;
                        Point3d p = new Point3d(frameMarker.getPosition());
                        constrainedTranslator3d.setLocation(p);
                        Frame frame = frameMarker.getFrame();
                        if (frame instanceof RigidBody) {
                            mesh = ((RigidBody) frame).getMesh();
                        }
                        break;
                    }
                }
                if (mesh != null) {
                    constrainedTranslator3d.setSize(radius);
                    constrainedTranslator3d.setMesh(mesh);
                    constrainedTranslator3d.setVisible(true);
                    currentDragger = constrainedTranslator3d;
                }
            }
        }
    }
}
Also used : TransformableGeometry(artisynth.core.modelbase.TransformableGeometry) OrientedTransformableGeometry(artisynth.core.modelbase.OrientedTransformableGeometry) RigidTransform3d(maspack.matrix.RigidTransform3d) JFrame(javax.swing.JFrame) GLViewerFrame(maspack.render.GL.GLViewerFrame) Frame(artisynth.core.mechmodels.Frame) HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh) WayPoint(artisynth.core.probes.WayPoint)

Aggregations

Frame (artisynth.core.mechmodels.Frame)15 Point (artisynth.core.mechmodels.Point)12 MotionTargetComponent (artisynth.core.mechmodels.MotionTargetComponent)5 VectorNd (maspack.matrix.VectorNd)3 ModelComponent (artisynth.core.modelbase.ModelComponent)2 WayPoint (artisynth.core.probes.WayPoint)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 Vector3d (maspack.matrix.Vector3d)2 Twist (maspack.spatialmotion.Twist)2 ContactPoint (artisynth.core.mechmodels.ContactPoint)1 FrameMarker (artisynth.core.mechmodels.FrameMarker)1 MechModel (artisynth.core.mechmodels.MechModel)1 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 HasCoordinateFrame (artisynth.core.modelbase.HasCoordinateFrame)1 OrientedTransformableGeometry (artisynth.core.modelbase.OrientedTransformableGeometry)1 TransformableGeometry (artisynth.core.modelbase.TransformableGeometry)1 NumericInputProbe (artisynth.core.probes.NumericInputProbe)1 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)1