use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class VariableVectorField method updateInternalValue.
protected boolean updateInternalValue(Object value) {
if (!valuesEqual(value, myValue)) {
if (value instanceof Vector) {
// make a defensive copy of the
// supplied vector
Vector vecValue = (Vector) value;
if (myResultHolder != null) {
// use the result holder as the value
// itself. Reason
// is that the result holder can be guaranteed to
// have the Vector sub-type, since it was supplied
// by the user.
myResultHolder.set(vecValue);
value = myResultHolder;
} else {
// make a defensive copy of the supplied vector
value = new VectorNd(vecValue);
}
}
myValue = value;
return true;
} else {
return false;
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class VectorField method setVectorSize.
/**
* Sets the size of the vector associated with this vector field. Changing
* the vector size will cause the result holder to be cleared, and the
* current vector value to be reset to a zero vector of the indicated size.
* The number of columns in the field will also be reset.
*
* @param size
* new vector size
*/
public void setVectorSize(int size) {
if (size < 1) {
throw new IllegalArgumentException("size must be greater than 1");
}
if (size != myVectorSize) {
setColumns(5 * size);
myResultHolder = null;
myVectorSize = size;
setValue(new VectorNd(size));
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class VectorField method textToValue.
public Object textToValue(String text, BooleanHolder corrected, StringHolder errMsg) {
corrected.value = false;
if (isBlank(text)) {
return setVoidIfPossible(errMsg);
}
ReaderTokenizer rtok = new ReaderTokenizer(new StringReader(text));
VectorNd tmp = new VectorNd(myVectorSize);
try {
for (int i = 0; i < myVectorSize; i++) {
if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
if (rtok.ttype == ReaderTokenizer.TT_EOF) {
return illegalValue("Missing elements (there should be " + myVectorSize + ")", errMsg);
} else {
return illegalValue("Malformed number for element " + i, errMsg);
}
}
tmp.set(i, rtok.nval);
}
if (rtok.nextToken() != ReaderTokenizer.TT_EOF) {
if (rtok.ttype == ReaderTokenizer.TT_NUMBER) {
return illegalValue("Too many elements (there should be " + myVectorSize + ")", errMsg);
} else {
return illegalValue("Extra characters after last element", errMsg);
}
}
return validValue(tmp, errMsg);
} catch (Exception e) {
return illegalValue("Improperly formed vector", errMsg);
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class VectorMultiField method updateInternalValue.
protected boolean updateInternalValue(Object value) {
if (!valuesEqual(value, myValue)) {
if (value instanceof Vector) {
// make a defensive copy of the
// supplied vector
VectorNd vecValue = new VectorNd((Vector) value);
if (myResultHolder != null) {
for (int i = 0; i < myVectorSize; i++) {
myResultHolder.set(i, vecValue.get(i));
}
}
value = vecValue;
}
myValue = value;
return true;
} else {
return false;
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class SymmetricMatrix3dField method textToValue.
public Object textToValue(String text, BooleanHolder corrected, StringHolder errMsg) {
corrected.value = false;
Object value = super.textToValue(text, corrected, errMsg);
if (value == Property.IllegalValue) {
return Property.IllegalValue;
}
if (value instanceof VectorNd) {
VectorNd tmp = (VectorNd) value;
value = new SymmetricMatrix3d(tmp.get(0), tmp.get(1), tmp.get(2), tmp.get(3), tmp.get(4), tmp.get(5));
}
return validValue(value, errMsg);
}
Aggregations