use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class MechSystemBase method copy.
public MechSystemBase copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
MechSystemBase msb = (MechSystemBase) super.copy(flags, copyMap);
// Being overly thorough here since many of these variables will be
// reset anyway by updateDynamicComponents()
msb.myDynamicComponents = null;
msb.myParametricComponents = null;
msb.myOrderedAttachments = null;
msb.myConstrainers = null;
msb.myDynamicSizes = null;
msb.myNumActive = 0;
msb.myNumAttached = 0;
msb.myNumParametric = 0;
msb.myActiveVelStateSize = 0;
msb.myActivePosStateSize = 0;
msb.myParametricVelStateSize = 0;
msb.myParametricPosStateSize = 0;
msb.myProfilingP = myProfilingP;
msb.setUpdateForcesAtStepEndMode(myUpdateForcesAtStepEndMode);
if (myUpdateForcesAtStepEndMode == PropertyMode.Explicit) {
msb.setUpdateForcesAtStepEnd(myUpdateForcesAtStepEnd);
}
msb.myMassMatrix = null;
// msb.myStabilization = myStabilization;
msb.myDynamicsEnabled = myDynamicsEnabled;
msb.allocateSolver(mySolver);
// msb.myPosSolver = new KKTSolver();
msb.myRg = new VectorNd(0);
msb.myBg = new VectorNd(0);
msb.myRn = new VectorNd(0);
msb.myBn = new VectorNd(0);
return msb;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class MechSystemBase method printState.
private synchronized void printState(String fmt, double t) {
if (myPrintInterval != -1) {
// reset last print time if necessary
if (TimeBase.compare(t, myLastPrintTime) < 0) {
myLastPrintTime = ((int) (t / myPrintInterval)) * myPrintInterval;
}
}
if (myPrintInterval == -1 || TimeBase.compare(t, myLastPrintTime + myPrintInterval) >= 0) {
updateDynamicComponentLists();
VectorNd x = new VectorNd(myActivePosStateSize);
VectorNd v = new VectorNd(myActiveVelStateSize);
getActivePosState(x, 0);
// Hack: get vel in body coords until data is converted ...
getActiveVelState(v, 0, /*bodyCoords=*/
false);
if (myPrintStateWriter == null) {
System.out.println("t=" + t + ":");
System.out.println("v: " + v.toString(fmt));
System.out.println("x: " + x.toString(fmt));
} else {
myPrintStateWriter.println("t=" + t + ":");
myPrintStateWriter.println("v: " + v.toString(fmt));
myPrintStateWriter.println("x: " + x.toString(fmt));
myPrintStateWriter.flush();
}
if (myPrintInterval != -1) {
myLastPrintTime += myPrintInterval;
}
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class MechSystemBase method getMassMatrix.
public void getMassMatrix(SparseBlockMatrix M, VectorNd f, double t) {
updateDynamicComponentLists();
if (!checkMatrixSize(M)) {
throw new IllegalArgumentException("M improperly sized; perhaps not created with buildMassMatrix()?");
}
if (f != null) {
f.setSize(mySystemSize);
} else {
// XXX it seems some components require it to exist
f = new VectorNd(mySystemSize);
}
for (int i = 0; i < myDynamicComponents.size(); i++) {
myDynamicComponents.get(i).resetEffectiveMass();
}
for (DynamicAttachment a : getOrderedAttachments()) {
a.addMassToMasters();
}
getMassMatrixValues(M, f, t);
// TODO - need to fix this for non-block diagonal mass matrices:
// for (DynamicAttachment a : getOrderedAttachments()) {
// a.reduceMass (M, f);
// }
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class MechSystemBase method getAttachmentDerivatives.
public VectorNd getAttachmentDerivatives() {
updateDynamicComponentLists();
ArrayList<DynamicAttachment> attachments = getOrderedAttachments();
int csize = 0;
for (int k = 0; k < attachments.size(); k++) {
DynamicAttachment a = attachments.get(k);
csize += myDynamicSizes[a.getSlave().getSolveIndex()];
}
VectorNd g = new VectorNd(csize);
double[] gbuf = g.getBuffer();
int goff = csize;
for (int k = 0; k < attachments.size(); k++) {
DynamicAttachment a = attachments.get(k);
int bj = attachments.size() - 1 - k;
goff -= myDynamicSizes[a.getSlave().getSolveIndex()];
a.getDerivative(gbuf, goff);
}
return g;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class ColorBar method render.
@Override
public void render(Renderer renderer, int flags) {
if (!isSelectable() && renderer.isSelecting()) {
return;
}
RenderObject robj = myRenderObject;
VectorNd labelPos = myLabelPos;
ArrayList<String> labelText = myLabelText;
if (robj == null || labelPos == null || labelText == null) {
System.out.println((robj == null) + " " + (labelPos == null) + " " + (labelText == null));
return;
}
int screenWidth = renderer.getScreenWidth();
int screenHeight = renderer.getScreenHeight();
// turn off shading for the labels
Renderer.Shading savedShadeModel = renderer.getShading();
renderer.setShading(Renderer.Shading.NONE);
double x0 = myLoc.x;
double y0 = myLoc.y;
double w = myLoc.width;
double h = myLoc.height;
if (horizontal) {
h = myLoc.width;
w = myLoc.height;
x0 = myLoc.y;
y0 = myLoc.x;
}
// absolute or normalized -> absolute
if (Math.abs(x0) <= 1) {
x0 = x0 * screenWidth;
}
if (x0 < 0) {
x0 = screenWidth + x0;
}
if (Math.abs(y0) <= 1) {
y0 = y0 * screenHeight;
}
if (y0 < 0) {
y0 = screenHeight + y0;
}
if (w <= 1) {
w = w * screenWidth;
}
if (h <= 1) {
h = h * screenHeight;
}
renderer.pushModelMatrix();
renderer.setModelMatrix2d(0, screenWidth, 0, screenHeight);
// transform so that the colorbar occupies correct location
AffineTransform3d trans = new AffineTransform3d();
if (horizontal) {
trans.setRotation(ROT_Z_270);
trans.applyScaling(h, w, 1);
} else {
trans.applyScaling(w, h, 1);
}
trans.setTranslation(x0, y0, 0);
renderer.mulModelMatrix(trans);
renderer.setVertexColorMixing(ColorMixing.REPLACE);
renderer.drawTriangles(robj, 0);
float savedLineWidth = renderer.getLineWidth();
LineFaceRenderProps props = (LineFaceRenderProps) getRenderProps();
renderer.setLineWidth(props.getLineWidth());
renderer.setLineColoring(props, /*highlight=*/
false);
renderer.setVertexColorMixing(ColorMixing.NONE);
renderer.drawLines(robj, 0);
renderer.popModelMatrix();
// return line width
renderer.setLineWidth(savedLineWidth);
// labels
int nLabels = Math.min(labelPos.size(), labelText.size());
if (nLabels > 0) {
double tx, ty;
// // for consistency, assume line top as 3/4 font size
// double t = myTextSize*0.75;
// double vc = myTextSize* 0.25;
// double b = myTextSize*0.25;
renderer.setFaceColoring(props, isSelected());
float[] loc = new float[3];
for (int i = 0; i < nLabels; i++) {
tx = 0;
ty = 0;
// text orientation computation
String label = labelText.get(i);
Rectangle2D box = renderer.getTextBounds(myFont, label, myTextSize);
double bw = box.getWidth();
double bh = box.getHeight();
double b = box.getY();
double vc = b + bh / 2;
double t = bh + b;
if (horizontal) {
switch(hAlignment) {
case LEFT:
tx = x0 + myTextOffset.x;
break;
case CENTRE:
tx = x0 - bw / 2;
break;
case RIGHT:
tx = x0 - myTextOffset.x - bw;
break;
}
tx += w * labelPos.get(i);
switch(vAlignment) {
case BOTTOM:
ty = y0 - myTextOffset.y - t;
break;
case CENTRE:
ty = y0 - vc + h / 2;
break;
case TOP:
ty = y0 + h + myTextOffset.y + b;
break;
}
} else {
switch(hAlignment) {
case LEFT:
tx = x0 - myTextOffset.x - bw;
break;
case CENTRE:
tx = x0 - bw / 2 + w / 2;
break;
case RIGHT:
tx = x0 + myTextOffset.x + w;
break;
}
switch(vAlignment) {
case BOTTOM:
ty = y0 + myTextOffset.y;
break;
case CENTRE:
ty = y0 - vc;
break;
case TOP:
ty = y0 - myTextOffset.y - t;
break;
}
ty += h * labelPos.get(i);
}
loc[0] = (float) tx;
loc[1] = (float) ty;
renderer.drawText(myFont, label, loc, myTextSize);
}
}
renderer.setShading(savedShadeModel);
}
Aggregations