use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class OBB method containsPoint.
public boolean containsPoint(Point3d pnt) {
Point3d p = new Point3d(pnt);
p.inverseTransform(myX);
Vector3d hw = myHalfWidths;
boolean status = (-hw.x <= p.x && p.x <= hw.x && -hw.y <= p.y && p.y <= hw.y && -hw.z <= p.z && p.z <= hw.z);
return status;
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class OBB method computeBoundsFromPoints.
private void computeBoundsFromPoints(Point3d min, Point3d max, Point3d[] pnts) {
Vector3d xpnt = new Point3d();
for (Point3d pnt : pnts) {
xpnt.inverseTransform(myX, pnt);
xpnt.updateBounds(min, max);
}
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class OBBTree method computeOBBNode.
private OBB computeOBBNode(ElemData[] edata, int num, OBB parent) {
meanCentroid.setZero();
for (int i = 0; i < num; i++) {
meanCentroid.add(edata[i].myCentroid);
}
meanCentroid.scale(1 / (double) num);
// OBB obb = new OBB (edata, num, myMargin);
Boundable[] elems = createElementArray(edata, num);
OBB node = new OBB();
node.set(elems, num, myMargin, myMethod);
node.setParent(parent);
node.getSortedAxes(obbAxes);
if (num > myMaxLeafElements) {
// subdivide the box
ElemData[] elemsU = new ElemData[num];
ElemData[] elemsL = new ElemData[num];
int numU = 0;
int numL = 0;
// start with long axis
int axisIdx = 0;
do {
numU = 0;
numL = 0;
Vector3d axis = obbAxes[axisIdx];
for (int i = 0; i < num; i++) {
// face.computeCentroid (elemCentroid);
tmpPnt.sub(edata[i].myCentroid, meanCentroid);
// tmpPnt.sub (elemCentroid, meanCentroid);
if (axis.dot(tmpPnt) >= 0) {
elemsU[numU++] = edata[i];
} else {
elemsL[numL++] = edata[i];
}
}
// potentially move to next axis
axisIdx++;
} while (axisIdx < 3 && (numL == 0 || numU == 0));
if (numU < num && numL < num) {
// System.out.println ("numU=" + numU);
OBB nodeU = computeOBBNode(elemsU, numU, node);
// System.out.println ("numL=" + numL);
OBB nodeL = computeOBBNode(elemsL, numL, node);
node.addChild(nodeL);
node.addChild(nodeU);
} else {
// createElementArray (edata, num));
node.setElements(elems);
}
} else {
// createElementArray (edata, num));
node.setElements(elems);
}
return node;
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class PointMesh method write.
/**
* Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file
* format. Vertices are printed first, each starting with the letter "v" and
* followed by x, y, and z coordinates. Normals, if present, are printed
* next, starting with the letter "vn" and followed by x, y, and z
* coordinates.
*
* <p>
* The format used to print vertex coordinates is specified by a
* {@link maspack.util.NumberFormat NumberFormat}.
*
* @param pw
* PrintWriter to write this mesh to
* @param fmt
* (optional) format for writing the vertex and normals coordinates. If <code>null</code>,
* a format of <code>"%.8g"</code> is assumed.
* @param zeroIndexed
* if true, index numbering for mesh vertices starts at 0. Otherwise,
* numbering starts at 1.
*/
public void write(PrintWriter pw, NumberFormat fmt, boolean zeroIndexed) throws IOException {
if (fmt == null) {
fmt = new NumberFormat("%.8g");
}
for (Vertex3d vertex : myVertices) {
Point3d pnt = vertex.pnt;
pw.println("v " + fmt.format(pnt.x) + " " + fmt.format(pnt.y) + " " + fmt.format(pnt.z));
}
if (myNormals != null) {
for (Vector3d nrm : myNormals) {
pw.println("vn " + fmt.format(nrm.x) + " " + fmt.format(nrm.y) + " " + fmt.format(nrm.z));
}
}
pw.flush();
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class PointMeshRenderer method buildRenderObject.
@Override
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
RenderObject r = super.buildRenderObject(mesh, props);
PointMesh pmesh = (PointMesh) mesh;
int[] nidxs = pmesh.hasNormals() ? pmesh.getNormalIndices() : null;
int[] cidxs = pmesh.hasColors() ? pmesh.getColorIndices() : null;
int[] tidxs = pmesh.hasTextureCoords() ? pmesh.getTextureIndices() : null;
int numv = pmesh.numVertices();
for (int i = 0; i < numv; i++) {
r.addVertex(i, nidxs != null ? nidxs[i] : -1, cidxs != null ? cidxs[i] : -1, tidxs != null ? tidxs[i] : -1);
r.addPoint(i);
}
Point3d tip = new Point3d();
double normalLen = pmesh.getNormalRenderLen();
if (normalLen > 0 && pmesh.hasNormals()) {
ArrayList<Vector3d> nrmls = pmesh.getNormals();
for (int i = 0; i < numv; i++) {
Point3d pnt = pmesh.getVertex(i).pnt;
tip.scaledAdd(normalLen, nrmls.get(nidxs[i]), pnt);
r.addPosition((float) tip.x, (float) tip.y, (float) tip.z);
r.addVertex(numv + i, nidxs[i], -1, -1);
r.addLine(i, numv + i);
}
}
return r;
}
Aggregations