use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class BVFeatureQueryTest method nearestFaceTiming.
private void nearestFaceTiming(PolygonalMesh mesh) {
RigidTransform3d X = new RigidTransform3d();
OBBTree obbTree = new OBBTree(mesh, 2);
AABBTree aabbTree = new AABBTree(mesh);
Point3d center = new Point3d();
double diameter = 2 * aabbTree.getRadius();
aabbTree.getCenter(center);
X.setRandom();
BVFeatureQuery query = new BVFeatureQuery();
mesh.setMeshToWorld(X);
obbTree.setBvhToWorld(X);
aabbTree.setBvhToWorld(X);
int numcases = 100;
int timingcnt = 1000;
Point3d pnt = new Point3d();
Vector3d dir = new Vector3d();
Point3d near = new Point3d();
Vector2d coords = new Vector2d();
Vector3d duv = new Vector3d();
FunctionTimer obbFaceTimer = new FunctionTimer();
FunctionTimer aabbFaceTimer = new FunctionTimer();
// FunctionTimer oldFaceTimer = new FunctionTimer();
FunctionTimer obbRayTimer = new FunctionTimer();
FunctionTimer aabbRayTimer = new FunctionTimer();
// FunctionTimer oldRayTimer = new FunctionTimer();
TriangleIntersector ti = new TriangleIntersector();
for (int i = 0; i < numcases; i++) {
pnt.setRandom();
pnt.scale(2 * diameter);
pnt.add(center);
pnt.transform(X, pnt);
dir.setRandom();
dir.normalize();
obbFaceTimer.restart();
for (int j = 0; j < timingcnt; j++) {
query.nearestFaceToPoint(near, coords, obbTree, pnt);
}
obbFaceTimer.stop();
aabbFaceTimer.restart();
for (int j = 0; j < timingcnt; j++) {
query.nearestFaceToPoint(near, coords, aabbTree, pnt);
}
aabbFaceTimer.stop();
// oldFaceTimer.restart();
// for (int j=0; j<timingcnt; j++) {
// obbTree.nearestFace (pnt, null, near, coords, ti);
// }
// oldFaceTimer.stop();
obbRayTimer.restart();
for (int j = 0; j < timingcnt; j++) {
query.nearestFaceAlongRay(near, duv, obbTree, center, dir);
}
obbRayTimer.stop();
aabbRayTimer.restart();
for (int j = 0; j < timingcnt; j++) {
query.nearestFaceAlongRay(near, duv, aabbTree, center, dir);
}
aabbRayTimer.stop();
// oldRayTimer.restart();
// for (int j=0; j<timingcnt; j++) {
// obbTree.intersect (center, dir, duv, ti);
// }
// oldRayTimer.stop();
}
int cnt = numcases * timingcnt;
System.out.println("nearestFace with OBB: " + obbFaceTimer.result(cnt));
System.out.println("nearestFace with AABB: " + aabbFaceTimer.result(cnt));
// System.out.println (
// "nearestFace with old OBB: " + oldFaceTimer.result(cnt));
System.out.println("nearestRay with OBB: " + obbRayTimer.result(cnt));
System.out.println("nearestRay with AABB: " + aabbRayTimer.result(cnt));
// System.out.println (
// "nearestRay with old OBB: " + oldRayTimer.result(cnt));
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class BVFeatureQueryTest method getNearestVerticesToPoint.
private ArrayList<Vertex3d> getNearestVerticesToPoint(MeshBase mesh, Point3d pnt) {
Point3d loc = new Point3d();
loc.inverseTransform(mesh.getMeshToWorld(), pnt);
ArrayList<Vertex3d> verts = mesh.getVertices();
double mind = Double.POSITIVE_INFINITY;
for (int i = 0; i < verts.size(); i++) {
double d = verts.get(i).pnt.distance(loc);
if (d < mind) {
mind = d;
}
}
ArrayList<Vertex3d> nearestVerts = new ArrayList<Vertex3d>();
for (int i = 0; i < verts.size(); i++) {
double d = verts.get(i).pnt.distance(loc);
if (d == mind) {
nearestVerts.add(verts.get(i));
}
}
return nearestVerts;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class BVFeatureQueryTest method pointInsideTest.
private void pointInsideTest(PolygonalMesh mesh, BVTree bvh, RigidTransform3d X, double radius, Point3d center) {
int numtrials = 10000;
Point3d pnt = new Point3d();
double tol = EPS * (center.norm() + radius);
TriangleIntersector intersector = new TriangleIntersector();
BVFeatureQuery query = new BVFeatureQuery();
mesh.setMeshToWorld(X);
bvh.setBvhToWorld(X);
tol = 0;
int numInside = 0;
for (int i = 0; i < numtrials; i++) {
pnt.setRandom();
pnt.scale(2 * radius);
pnt.add(center);
pnt.transform(X, pnt);
if (pointInsideCheck(pnt, tol, mesh, bvh, query, intersector)) {
numInside++;
}
}
double avgEdgeLength = mesh.computeAverageEdgeLength();
int numv = mesh.numVertices();
for (int i = 0; i < numtrials / numv; i++) {
for (int j = 0; j < numv; j++) {
pnt.setRandom();
pnt.scale(avgEdgeLength / 10);
pnt.add(mesh.getVertex(j).pnt);
pnt.transform(X, pnt);
if (pointInsideCheck(pnt, tol, mesh, bvh, query, intersector)) {
numInside++;
}
}
}
if (printInsideOutsideCounts) {
System.out.println("numInside=" + numInside);
System.out.println("numOutside=" + (numtrials - numInside));
System.out.println("cases: V=" + query.numVertexCases + " E=" + query.numEdgeCases + " F=" + query.numFaceCases);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class BVFeatureQueryTest method getNearestFacesToRay.
private ArrayList<NearestFaceInfo> getNearestFacesToRay(PolygonalMesh mesh, Point3d pnt, Vector3d dir, double tol) {
Point3d lpnt = new Point3d();
Vector3d ldir = new Vector3d();
lpnt.inverseTransform(mesh.getMeshToWorld(), pnt);
ldir.inverseTransform(mesh.getMeshToWorld(), dir);
ArrayList<Face> faces = mesh.getFaces();
NearestFaceInfo[] faceInfo = new NearestFaceInfo[faces.size()];
TriangleIntersector intersector = new TriangleIntersector();
double mind = Double.POSITIVE_INFINITY;
for (int i = 0; i < faces.size(); i++) {
NearestFaceInfo ninfo = new NearestFaceInfo();
faceInfo[i] = ninfo;
double d = ninfo.computeDistanceToRay(faces.get(i), lpnt, ldir, intersector);
ninfo.myNear.transform(mesh.getMeshToWorld());
if (d >= 0 && d < Double.POSITIVE_INFINITY) {
if (d < mind) {
mind = d;
}
}
}
ArrayList<NearestFaceInfo> nearestFaces = new ArrayList<NearestFaceInfo>();
if (mind < Double.POSITIVE_INFINITY) {
for (int i = 0; i < faces.size(); i++) {
double d = faceInfo[i].myDist;
if (d >= 0 && d < Double.POSITIVE_INFINITY) {
if (Math.abs(d - mind) < tol) {
nearestFaces.add(faceInfo[i]);
}
}
}
}
return nearestFaces;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class BVFeatureQueryTest method getNearestFacesToPoint.
private ArrayList<NearestFaceInfo> getNearestFacesToPoint(PolygonalMesh mesh, Point3d pnt, double tol) {
Point3d loc = new Point3d();
loc.inverseTransform(mesh.getMeshToWorld(), pnt);
ArrayList<Face> faces = mesh.getFaces();
NearestFaceInfo[] faceInfo = new NearestFaceInfo[faces.size()];
TriangleIntersector intersector = new TriangleIntersector();
double mind = Double.POSITIVE_INFINITY;
for (int i = 0; i < faces.size(); i++) {
NearestFaceInfo ninfo = new NearestFaceInfo();
faceInfo[i] = ninfo;
double d = ninfo.computeDistanceToPoint(faces.get(i), loc, intersector);
ninfo.myNear.transform(mesh.getMeshToWorld());
if (d < mind) {
mind = d;
}
}
ArrayList<NearestFaceInfo> nearestFaces = new ArrayList<NearestFaceInfo>();
for (int i = 0; i < faces.size(); i++) {
if (Math.abs(faceInfo[i].myDist - mind) < tol) {
nearestFaces.add(faceInfo[i]);
}
}
return nearestFaces;
}
Aggregations