use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSObject method updateBounds.
public void updateBounds(Vector3d pmin, Vector3d pmax) {
Point3d tmp = new Point3d();
for (int i = 0; i < myCtrlPnts.size(); i++) {
Vector4d cpnt = myCtrlPnts.get(i);
tmp.set(cpnt.x, cpnt.y, cpnt.z);
if (myXObjToWorld != RigidTransform3d.IDENTITY) {
tmp.transform(myXObjToWorld);
}
tmp.updateBounds(pmin, pmax);
}
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSObject method addControlPoint.
protected void addControlPoint(int idx, Vector4d pnt) {
myCtrlPnts.add(idx, new Vector4d(pnt));
myCtrlPntSelected.add(idx, false);
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSSurface method render.
/**
* {@inheritDoc}
*/
public void render(Renderer renderer, RenderProps props, int flags) {
boolean selecting = renderer.isSelecting();
if (numControlPoints() == 0) {
return;
}
evalRenderVertices();
renderer.setShading(Shading.NONE);
// draw the control points
if (myDrawControlShapeP) {
drawControlPoints(renderer, props, flags);
}
// draw the surface as quads
if (!selecting) {
renderer.setColor(contourColor);
}
renderer.beginDraw(DrawMode.LINES);
for (int i = 0; i < urenderSize - 1; i++) {
for (int j = 0; j < vrenderSize - 1; j++) {
Point3d p0 = renderVertices[i * vrenderSize + j];
Point3d p1 = renderVertices[(i + 1) * vrenderSize + j];
Point3d p2 = renderVertices[(i + 1) * vrenderSize + (j + 1)];
Point3d p3 = renderVertices[i * vrenderSize + (j + 1)];
renderer.addVertex(p0);
renderer.addVertex(p1);
renderer.addVertex(p1);
renderer.addVertex(p2);
renderer.addVertex(p2);
renderer.addVertex(p3);
renderer.addVertex(p3);
renderer.addVertex(p0);
}
}
renderer.endDraw();
// draw the control polygon
if (myDrawControlShapeP) {
if (!selecting) {
renderer.setColor(edgeColor);
}
for (int i = 0; i < numCtrlPntsU; i++) {
if (vcurve.isClosed()) {
renderer.beginDraw(DrawMode.LINE_LOOP);
} else {
renderer.beginDraw(DrawMode.LINE_STRIP);
}
for (int j = 0; j < numCtrlPntsV; j++) {
// pnt.setFromHomogeneous
// (ctrlPnts[i*numCtrlPntsV+j]);
Vector4d cpnt = myCtrlPnts.get(i * numCtrlPntsV + j);
renderer.addVertex(cpnt.x, cpnt.y, cpnt.z);
}
renderer.endDraw();
}
for (int j = 0; j < numCtrlPntsV; j++) {
if (ucurve.isClosed()) {
renderer.beginDraw(DrawMode.LINE_LOOP);
} else {
renderer.beginDraw(DrawMode.LINE_STRIP);
}
for (int i = 0; i < numCtrlPntsU; i++) {
Vector4d cpnt = myCtrlPnts.get(i * numCtrlPntsV + j);
renderer.addVertex(cpnt.x, cpnt.y, cpnt.z);
}
renderer.endDraw();
}
}
renderer.setShading(Shading.FLAT);
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSSurface method eval.
/**
* Evaluates the point on this surface corresponding to u and v. These values
* are clipped, if necessary, to the range [ustart, uend] and [vstart, vend].
*
* @param pnt
* returns the surface point value
* @param u
* u parameter value
* @param v
* v parameter value
*/
public void eval(Point3d pnt, double u, double v) {
double[] uBasisVals = new double[ucurve.myDegree + 1];
double[] vBasisVals = new double[vcurve.myDegree + 1];
int k = ucurve.getKnotIndex(u);
ucurve.basisValues(uBasisVals, k, u);
int l = vcurve.getKnotIndex(v);
vcurve.basisValues(vBasisVals, l, v);
int dv = vcurve.getDegree();
int du = ucurve.getDegree();
//
// the i, j control point is located at ctrlPnts[i*numCtrlPntsV+j]
//
pnt.setZero();
double w = 0;
for (int i = 0; i <= du; i++) {
int d_i = ucurve.getCtrlIndex(k, i, numCtrlPntsU);
double B_i = uBasisVals[i];
for (int j = 0; j <= dv; j++) {
int d_j = vcurve.getCtrlIndex(l, j, numCtrlPntsV);
double B_j = vBasisVals[j];
Vector4d cpnt = myCtrlPnts.get(d_i * numCtrlPntsV + d_j);
double wbb = cpnt.w * B_i * B_j;
pnt.x += wbb * cpnt.x;
pnt.y += wbb * cpnt.y;
pnt.z += wbb * cpnt.z;
w += wbb;
}
}
pnt.scale(1 / w);
}
use of maspack.matrix.Vector4d in project artisynth_core by artisynth.
the class NURBSCurve2d method getOrientation.
/**
* For closed curves, return 1 if it is oriented counter-clockwise and -1 if
* clockwise. Returns 0 is the curve is open, or the orientation can't be
* determined because of self-intersection.
*/
public int getOrientation() {
if (!myClosedP) {
return 0;
}
int numc = numControlPoints();
double area = 0;
Vector4d p0 = getControlPoint(numc - 1);
for (int i = 0; i < numc; i++) {
Vector4d p1 = getControlPoint(i);
area += (p1.x - p0.x) * (p1.y + p0.y);
p0 = p1;
}
if (area == 0) {
return 0;
} else {
return area < 0 ? 1 : -1;
}
}
Aggregations