use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshRendererBase method updatePositions.
protected void updatePositions(RenderObject r, MeshBase mesh) {
boolean useRenderData = mesh.isRenderBuffered() && !mesh.isFixed();
int numv = mesh.numVertices();
for (int i = 0; i < numv; i++) {
Vertex3d vtx = mesh.getVertex(i);
Point3d pos = useRenderData ? vtx.myRenderPnt : vtx.pnt;
r.setPosition(i, (float) pos.x, (float) pos.y, (float) pos.z);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class NURBSCurve2d method evalPoints.
/**
* Returns a set of points evaluated along the curve at intervals which are
* evenly spaced with respect to the curve parameter.
*
* @param npnts
* number of points to create
* @return array of evaluated points
*/
public Point2d[] evalPoints(int npnts) {
Point2d[] pnts = new Point2d[npnts];
Point3d pnt3 = new Point3d();
if (npnts == 1) {
eval(pnt3, myUstart);
pnts[0] = new Point2d(pnt3.x, pnt3.y);
}
for (int i = 0; i < npnts; i++) {
eval(pnt3, myUstart + (myUend - myUstart) * i / (npnts - 1));
pnts[i] = new Point2d(pnt3.x, pnt3.y);
}
return pnts;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class NURBSCurve3d method findPoint.
/**
* Finds a u value for a given curve point within a specified interval of the
* curve. If the point is not actually on the specified interval, this
* routine attempts to return the u value for the nearest curve point. It
* should be noted that one point may correspond to multiple u values.
*
* <p>
* This routine uses an iterative golden section search, and so is not
* particularly fast.
*
* @param pnt
* point to search for
* @param umin
* minimum u valu for the interval
* @param umax
* maximum u valu for the interval
* @return u value for the point closest to pnt within the interval.
*/
public double findPoint(Point3d pnt, double umin, double umax) {
double[] dist = new double[1];
double[] uinterval = new double[3];
if (bracket(dist, uinterval, pnt, umin, umax)) {
return golden(dist, uinterval, pnt, dist[0]);
} else {
Point3d pntu = new Point3d();
eval(pntu, umin);
double dmin = pntu.distance(pnt);
eval(pntu, umax);
double dmax = pntu.distance(pnt);
return (dmin < dmax ? umin : umax);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class NURBSCurve3d method evalPoints.
/**
* Returns a set of points evaluated along the curve at intervals which are
* evenly spaced with respect to the curve parameter.
*
* @param npnts
* number of points to create
* @return array of evaluated points
*/
public Point3d[] evalPoints(int npnts) {
Point3d[] pnts = new Point3d[npnts];
if (npnts == 1) {
pnts[0] = new Point3d();
eval(pnts[0], myUstart);
}
for (int i = 0; i < npnts; i++) {
pnts[i] = new Point3d();
eval(pnts[i], myUstart + (myUend - myUstart) * i / (npnts - 1));
}
return pnts;
}
use of maspack.matrix.Point3d 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();
}
Aggregations