Search in sources :

Example 6 with WayPoint

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

the class TimelineController method setRestartTime.

/**
 * Responsible for setting up the model after the mouse has been
 * used to drag the time to Tn.
 */
public void setRestartTime(int dragMode) {
    WayPoint prevWay, nextWay;
    double currentCursorTime = timescale.getTimescaleCursorTime();
    // Find previous waypoint that is valid before or at current cursor time
    WayPoint way = getWayPoints().getValidOnOrBefore(currentCursorTime);
    if (way.getTime() != myScheduler.getTime()) {
        myScheduler.setTime(way);
    }
}
Also used : WayPoint(artisynth.core.probes.WayPoint)

Example 7 with WayPoint

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

the class TimelineController method getWayPointFromUser.

/**
 * Gets waypoint information from the user and adds the waypoint to
 * the waypoint probe.
 */
public void getWayPointFromUser() {
    DoubleField myTimeField = new DoubleField("Time");
    myTimeField.addValueCheckListener(new ValueCheckListener() {

        public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
            Object val = e.getValue();
            if (val instanceof Double && ((Double) val).doubleValue() <= 0) {
                if (errMsg != null) {
                    errMsg.value = "Time value must be positive";
                }
                return Property.IllegalValue;
            } else {
                if (errMsg != null) {
                    errMsg.value = null;
                }
                return val;
            }
        }
    });
    myTimeField.setVoidValueEnabled(true);
    myTimeField.setValue(Property.VoidValue);
    IntegerField myRepeatField = new IntegerField("Repeat", 1);
    myRepeatField.setRange(1, Integer.MAX_VALUE);
    BooleanSelector myBreakpointSelector = new BooleanSelector("Breakpoint", false);
    PropertyPanel addPanel = new PropertyPanel();
    addPanel.addWidget(myTimeField);
    addPanel.addWidget(myRepeatField);
    addPanel.addWidget(myBreakpointSelector);
    PropertyDialog addDialog = new PropertyDialog(this, "Add Waypoints", addPanel, "OK Cancel");
    addDialog.setModal(true);
    GuiUtils.locateCenter(addDialog, this);
    addDialog.setVisible(true);
    if (addDialog.getReturnValue() == OptionPanel.OK_OPTION && !myTimeField.valueIsVoid()) {
        double t = myTimeField.getDoubleValue();
        for (int i = 1; i <= myRepeatField.getIntValue(); i++) {
            addWayPoint(t * i, myBreakpointSelector.getBooleanValue());
        }
        myToolBar.validateFastForward(myMain.getRootModel());
    }
}
Also used : ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) StringHolder(maspack.util.StringHolder) BooleanSelector(maspack.widgets.BooleanSelector) PropertyDialog(maspack.widgets.PropertyDialog) IntegerField(maspack.widgets.IntegerField) DoubleField(maspack.widgets.DoubleField) WayPoint(artisynth.core.probes.WayPoint) PropertyPanel(maspack.widgets.PropertyPanel)

Example 8 with WayPoint

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

the class FemBeamMech method build.

public void build(String[] args) {
    femPath = "models/mech/models/fem/";
    modPath = "models/mech/";
    int nn = 2;
    myFemMod = FemFactory.createTetGrid(null, 0.6, 0.2, 0.2, nn * 3, nn * 1, nn * 1);
    myFemMod.setName("fem");
    myFemMod.setDensity(myDensity);
    myFemMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
    myFemMod.setLinearMaterial(60000, 0.33, true);
    myFemMod.setStiffnessDamping(0.002);
    myFemMod.setImplicitIterations(100);
    myFemMod.setImplicitPrecision(0.001);
    myFemMod.setSurfaceRendering(SurfaceRender.Shaded);
    Renderable elems = myFemMod.getElements();
    RenderProps.setLineWidth(elems, 2);
    RenderProps.setLineColor(elems, Color.BLUE);
    Renderable nodes = myFemMod.getNodes();
    RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(nodes, 0.005);
    RenderProps.setPointColor(nodes, Color.GREEN);
    // fix the leftmost nodes
    double EPS = 1e-9;
    for (FemNode3d n : myFemMod.getNodes()) {
        if (n.getPosition().x < -0.3 + EPS) {
            myLeftNodes.add(n);
        }
    }
    System.out.println("fixed nodes:");
    for (FemNode3d n : myLeftNodes) {
        n.setDynamic(false);
    }
    RenderProps.setFaceColor(myFemMod, new Color(0.4f, 0.4f, 1.0f));
    myFemMod.setProfiling(true);
    RigidBody anchorBox = new RigidBody("anchorBox");
    PolygonalMesh mesh = MeshFactory.createBox(0.1, 0.3, 0.3);
    anchorBox.setMesh(mesh, /* fileName= */
    null);
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(-0.35, 0, 0);
    anchorBox.setPose(X);
    anchorBox.setDynamic(false);
    myMechMod = new MechModel("mech");
    myMechMod.addModel(myFemMod);
    myMechMod.addRigidBody(anchorBox);
    System.out.println("models: " + myMechMod.findComponent("models"));
    System.out.println("models/fem: " + myMechMod.findComponent("models/fem"));
    myMechMod.setIntegrator(Integrator.BackwardEuler);
    addModel(myMechMod);
    myMechMod.setProfiling(true);
    // add marker to lower right corner element
    Point3d corner = new Point3d(0.3, -0.1, -0.1);
    FemElement cornerElem = null;
    for (FemElement e : myFemMod.getElements()) {
        FemNode[] nodeList = e.getNodes();
        for (int i = 0; i < nodeList.length; i++) {
            if (nodeList[i].getPosition().epsilonEquals(corner, 1e-8)) {
                cornerElem = e;
                break;
            }
        }
    }
    if (cornerElem != null) {
        FemMarker mkr = new FemMarker(0.3, -0.07, -0.03);
        myFemMod.addMarker(mkr, cornerElem);
        RenderProps.setPointStyle(mkr, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(mkr, 0.01);
        RenderProps.setPointColor(mkr, Color.WHITE);
        Particle part = new Particle(1, 0.5, -0.07, -0.03);
        RenderProps.setPointStyle(part, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(part, 0.01);
        part.setDynamic(false);
        myMechMod.addParticle(part);
        AxialSpring spr = new AxialSpring(1000, 0, 0);
        myMechMod.attachAxialSpring(part, mkr, spr);
        RenderProps.setLineStyle(spr, Renderer.LineStyle.SPINDLE);
        RenderProps.setLineRadius(spr, 0.01);
        RenderProps.setLineColor(spr, Color.GREEN);
    }
    int numWays = 0;
    double res = 0.2;
    for (int i = 0; i < numWays; i++) {
        addWayPoint(new WayPoint((i + 1) * res, true));
    }
    addControlPanel(myMechMod, myFemMod);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemNode(artisynth.core.femmodels.FemNode) Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh) FemMarker(artisynth.core.femmodels.FemMarker) WayPoint(artisynth.core.probes.WayPoint) AxialSpring(artisynth.core.mechmodels.AxialSpring) Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) Renderable(maspack.render.Renderable) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d) WayPoint(artisynth.core.probes.WayPoint) RigidBody(artisynth.core.mechmodels.RigidBody) FemElement(artisynth.core.femmodels.FemElement)

Example 9 with WayPoint

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

the class RootModel method addWayPoint.

public WayPoint addWayPoint(double t) {
    if (t != 0) {
        WayPoint way = new WayPoint(t);
        addWayPoint(way);
        return way;
    } else {
        return null;
    }
}
Also used : WayPoint(artisynth.core.probes.WayPoint)

Example 10 with WayPoint

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

the class ProbeInfo method toggleProbeActivation.

/**
 * edited by johnty to prevent null exceptions.
 */
private void toggleProbeActivation() {
    WayPointProbe wayProbe = getMain().getRootModel().getWayPoints();
    double earliestTime = getStartTime();
    wayProbe.invalidateAfterTime(getStartTime());
    if (myController.getCurrentTime() > earliestTime) {
        if (getMain().getWorkspace().rootModelHasState()) {
            WayPoint way = wayProbe.getNearestValidBefore(earliestTime);
            if (way != null) {
                getScheduler().setTime(way);
            } else {
                getScheduler().setTime(0);
            }
        } else {
            getScheduler().setTime(earliestTime);
        }
    }
    setActive(!isActive());
    setAppropriateColor();
    myController.requestUpdateWidgets();
}
Also used : WayPointProbe(artisynth.core.probes.WayPointProbe) WayPoint(artisynth.core.probes.WayPoint)

Aggregations

WayPoint (artisynth.core.probes.WayPoint)15 WayPointProbe (artisynth.core.probes.WayPointProbe)2 FemElement (artisynth.core.femmodels.FemElement)1 FemMarker (artisynth.core.femmodels.FemMarker)1 FemNode (artisynth.core.femmodels.FemNode)1 FemNode3d (artisynth.core.femmodels.FemNode3d)1 NumericProbeEditor (artisynth.core.gui.probeEditor.NumericProbeEditor)1 AxialSpring (artisynth.core.mechmodels.AxialSpring)1 MechModel (artisynth.core.mechmodels.MechModel)1 Particle (artisynth.core.mechmodels.Particle)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 Probe (artisynth.core.probes.Probe)1 RootModel (artisynth.core.workspace.RootModel)1 Color (java.awt.Color)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 Point3d (maspack.matrix.Point3d)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 Renderable (maspack.render.Renderable)1 StringHolder (maspack.util.StringHolder)1 BooleanSelector (maspack.widgets.BooleanSelector)1