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