use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSViewer method addNURBS.
public void addNURBS(File file) throws IOException {
WavefrontReader wfr = new WavefrontReader(file);
wfr.parse();
Vector4d[] allControlPnts = wfr.getHomogeneousPoints();
for (WavefrontReader.Curve curve : wfr.getCurveList()) {
NURBSCurve3d curveCopy = new NURBSCurve3d();
try {
curveCopy.set(curve, allControlPnts);
} catch (IllegalArgumentException e) {
throw new IOException(e.getMessage());
}
addNURBS(curveCopy);
}
for (WavefrontReader.Surface surf : wfr.getSurfaceList()) {
NURBSSurface surfCopy = new NURBSSurface();
try {
surfCopy.set(surf, allControlPnts);
} catch (IllegalArgumentException e) {
throw new IOException(e.getMessage());
}
addNURBS(surfCopy);
}
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSCurve2d method eval.
/**
* {@inheritDoc}
*/
public void eval(Point3d pnt, double u) {
int numc = numControlPoints();
if (numc == 0) {
throw new IllegalStateException("curve does not contain control points");
}
int k = getKnotIndex(u);
double[] bvals = new double[this.myDegree + 1];
basisValues(bvals, k, u);
pnt.setZero();
double w = 0;
for (int i = 0; i <= myDegree; i++) {
Vector4d cpnt = myCtrlPnts.get(getCtrlIndex(k, i, numc));
double wb = cpnt.w * bvals[i];
pnt.x += wb * cpnt.x;
pnt.y += wb * cpnt.y;
w += wb;
}
pnt.z = 0;
pnt.scale(1 / w);
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSCurveBase method setCircle.
/**
* Sets this curve to an eight-point circle formed using rational cubics.
*
* @param x
* center x coordinate
* @param y
* center y coordinate
* @param radius
* circle radius
* @throws IllegalArgumentException
* if radius is non-positive
*/
public void setCircle(double x, double y, double radius) {
if (radius <= 0) {
throw new IllegalArgumentException("radius must be positive");
}
Vector4d[] cpnts = new Vector4d[8];
double w = Math.sqrt(2) / 4;
cpnts[0] = new Vector4d(1, 0, 0, 1);
cpnts[1] = new Vector4d(1, 1, 0, w);
cpnts[2] = new Vector4d(0, 1, 0, 1);
cpnts[3] = new Vector4d(-1, 1, 0, w);
cpnts[4] = new Vector4d(-1, 0, 0, 1);
cpnts[5] = new Vector4d(-1, -1, 0, w);
cpnts[6] = new Vector4d(0, -1, 0, 1);
cpnts[7] = new Vector4d(1, -1, 0, w);
for (int i = 0; i < cpnts.length; i++) {
cpnts[i].x = radius * cpnts[i].x + x;
cpnts[i].y = radius * cpnts[i].y + y;
}
set(3, CLOSED, cpnts, null);
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSCurveBase method render.
/**
* {@inheritDoc}
*/
public void render(Renderer renderer, RenderProps props, int flags) {
boolean selecting = renderer.isSelecting();
int numc = numControlPoints();
if (numc == 0) {
return;
}
renderer.pushModelMatrix();
if (myXObjToWorld != RigidTransform3d.IDENTITY) {
RigidTransform3d XOW = new RigidTransform3d(myXObjToWorld);
renderer.mulModelMatrix(XOW);
}
renderer.setShading(Shading.NONE);
if (myDrawControlShapeP) {
// draw the control polygon
if (props.getDrawEdges()) {
renderer.setLineWidth(props.getEdgeWidth());
if (!selecting) {
renderer.setColor(props.getEdgeOrLineColorF());
}
if (myClosedP) {
renderer.beginDraw(DrawMode.LINE_LOOP);
} else {
renderer.beginDraw(DrawMode.LINE_STRIP);
}
for (int i = 0; i < numc; i++) {
Vector4d cpnt = myCtrlPnts.get(i);
renderer.addVertex(cpnt.x, cpnt.y, cpnt.z);
}
renderer.endDraw();
}
// draw the control points
drawControlPoints(renderer, props, flags);
}
// draw the curve itself
if (!selecting) {
renderer.setColor(props.getLineColorF());
}
double len = computeControlPolygonLength();
double res = myResolution * renderer.distancePerPixel(myXObjToWorld.p);
int nsegs = (int) Math.max(10, len / res);
Point3d pnt = new Point3d();
renderer.setLineWidth(props.getLineWidth());
renderer.beginDraw(DrawMode.LINE_LOOP);
double[] urange = new double[2];
getRange(urange);
for (int i = 0; i < nsegs + 1; i++) {
eval(pnt, urange[0] + (urange[1] - urange[0]) * i / nsegs);
renderer.addVertex(pnt);
}
renderer.endDraw();
renderer.setLineWidth(1);
renderer.setShading(Shading.FLAT);
renderer.popModelMatrix();
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSObject method set.
protected void set(NURBSObject nobj) {
myCtrlPnts.clear();
for (Vector4d cpnt : nobj.myCtrlPnts) {
myCtrlPnts.add(new Vector4d(cpnt));
}
myCtrlPntSelected = (ArrayList<Boolean>) nobj.myCtrlPntSelected.clone();
if (nobj.myXObjToWorld.isIdentity()) {
myXObjToWorld = RigidTransform3d.IDENTITY;
} else {
myXObjToWorld = new RigidTransform3d(nobj.myXObjToWorld);
}
myRenderProps = nobj.myRenderProps.clone();
}
Aggregations