use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class SimpleCollide method setBottomObject.
private void setBottomObject(Collidable comp, ObjectType type) {
Renderable rcomp = (Renderable) comp;
((TransformableGeometry) comp).transformGeometry(AffineTransform3d.createScaling(myBottomScale));
switch(type) {
case FemEllipsoid:
case FemSphere:
{
RenderProps.setPointColor(rcomp, Color.green);
// fix the lower nodes
Point3d min = new Point3d();
RenderableUtils.getBounds(rcomp, min, null);
FemModel3d fem = (FemModel3d) comp;
fem.getSurfaceMesh();
for (FemNode3d n : fem.getNodes()) {
if (fem.isSurfaceNode(n) && n.getPosition().z <= (min.z + mySize * 0.5)) {
n.setDynamic(false);
}
}
fem.resetRestPosition();
break;
}
case FemCube:
{
RenderProps.setPointColor(rcomp, Color.green);
// fix the lower nodes
Point3d min = new Point3d();
RenderableUtils.getBounds(rcomp, min, null);
FemModel3d fem = (FemModel3d) comp;
fem.getSurfaceMesh();
for (FemNode3d n : fem.getNodes()) {
if (fem.isSurfaceNode(n) && n.getPosition().z <= (min.z + mySize * 0.1)) {
n.setDynamic(false);
}
}
// RenderProps.setAlpha (rcomp, 0.3);
fem.resetRestPosition();
break;
}
case Box:
{
((RigidBody) comp).setDynamic(false);
((RigidBody) comp).setDistanceGridRes(new Vector3i(10, 5, 5));
break;
}
case Molar:
{
((RigidBody) comp).setPose(new RigidTransform3d(0, 0, 0, 0, -1, 0, Math.toRadians(172.09)));
((RigidBody) comp).setDynamic(false);
break;
}
case Bin:
{
((RigidBody) comp).setPose(new RigidTransform3d(0, 0, 0, 0, 0, 0, 0));
((RigidBody) comp).setDynamic(false);
break;
}
case Paw:
case House:
{
((RigidBody) comp).setDynamic(false);
break;
}
default:
{
throw new InternalErrorException("Unimplemented type " + type);
}
}
myBottomObject = comp;
myBottomType = type;
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class SDGridTest method render.
@Override
public void render(Renderer renderer, int flags) {
if (sdgrid != null) {
Shading savedShading = renderer.getShading();
renderer.setShading(Shading.NONE);
renderer.setPointSize(5);
VectorTransformer3d TGL = sdgrid.getGridToLocalTransformer();
Vector3i res = sdgrid.getResolution();
// Draw 4 vertical lines.
renderer.beginDraw(DrawMode.LINES);
renderer.addVertex(gridToLocal(TGL, res.x, res.y, res.z));
renderer.addVertex(gridToLocal(TGL, res.x, res.y, 0));
renderer.addVertex(gridToLocal(TGL, 0, res.y, res.z));
renderer.addVertex(gridToLocal(TGL, 0, res.y, 0));
renderer.addVertex(gridToLocal(TGL, 0, 0, res.z));
renderer.addVertex(gridToLocal(TGL, 0, 0, 0));
renderer.addVertex(gridToLocal(TGL, res.x, 0, res.z));
renderer.addVertex(gridToLocal(TGL, res.x, 0, 0));
// Draw a diagonal line from max to min.
renderer.addVertex(gridToLocal(TGL, 0, 0, 0));
renderer.addVertex(gridToLocal(TGL, res.x, res.y, res.z));
renderer.endDraw();
double[] phi = sdgrid.getDistances();
// Draw the vertices on the grid.
Vector3d coords = new Vector3d();
for (int i = 0; i < phi.length; i++) {
Vector3i vxyz = new Vector3i();
sdgrid.vertexToXyzIndices(vxyz, i);
sdgrid.getLocalVertexCoords(coords, vxyz);
if (phi[i] <= 0) {
renderer.setColor(Color.BLUE);
renderer.drawPoint(coords);
} else {
renderer.setColor(Color.RED);
renderer.drawPoint(coords);
}
}
renderer.setPointSize(1);
renderer.setShading(savedShading);
}
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method createEdgeNode.
protected Vector3i createEdgeNode(Vector3i v0, Vector3i v1) {
Vector3i en = new Vector3i();
en.x = (v0.x + v1.x) / 2;
en.y = (v0.y + v1.y) / 2;
en.z = (v0.z + v1.z) / 2;
return en;
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGridTester method main.
public static void main(String[] args) {
PolygonalMesh boxMesh = MeshFactory.createBox(4.0, 4.0, 4.0);
Vector3i cellDivisions = new Vector3i(25, 25, 25);
RenderProps meshRenderProps = new RenderProps();
meshRenderProps.setFaceStyle(Renderer.FaceStyle.BACK);
boxMesh.setRenderProps(meshRenderProps);
// DistanceGrid boxGrid =
// new DistanceGrid (boxMesh, 0.1, cellDivisions);
// SignedDistanceGridTest test1 =
// new SignedDistanceGridTest (boxMesh, boxGrid, true);
// test1.bruteForcePhiTest();
// test1.colourTest();
// test1.normalCalcTest();
// test1.visualInsideOutsideTest();
// test1.normalCalcTest ();
// boxMesh = MeshFactory.createTriangularSphere(2.0, 16);
PolygonalMesh mesh = null;
if (false) {
try {
mesh = new PolygonalMesh(new File(PathFinder.expand("${srcdir DistanceGrid}/sampleData/molar1.2.obj")));
mesh.scale(3.0);
} catch (Exception e) {
e.printStackTrace();
}
}
if (false) {
mesh = MeshFactory.createSphere(1.0, 12);
mesh.scale(2.0, 1.5, 1.0);
}
if (true) {
mesh = MeshFactory.createPointedCylinder(1.2, 1.2, 0.3, 4);
}
mesh.setRenderProps(meshRenderProps);
DistanceGrid grid;
if (false) {
FunctionTimer timer = new FunctionTimer();
int cnt = 20;
timer.start();
for (int i = 0; i < cnt; i++) {
grid = new DistanceGrid(mesh.getFaces(), 0.1, cellDivisions, /*signed=*/
true);
}
timer.stop();
System.out.println("grid compute time=" + timer.result(cnt));
}
grid = new DistanceGrid(mesh.getFaces(), 0.1, new Vector3i(10, 10, 5), /*signed=*/
true);
DistanceGridTester test = new DistanceGridTester(mesh, grid, useGraphics);
test.bruteForcePhiTest();
test.normalCalcTest();
test.checkPhiIsSet();
// test.checkCellArray ();
test.visualInsideOutsideTest();
if (useGraphics) {
test.viewer.rerender();
}
// checkCellArray ();
// checkSignOfPhi ();
// bruteForcePhiTest ();
// checkPhiIsSet ();
// interpolationTest ();
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGridTester method bruteForcePhiTest.
/**
* This test takes every entry in phi, gets the mesh coordinates for that
* entry, and calculates the distance to all of the faces in the mesh,
* comparing it with the one stored. A smaller distance is an indication of
* failure.
* Rendering:
* Green - Pass
* Blue - The calculated closestFace is correct, but distance calculated is
* wrong (face.nearestPoint is likely the culprit).
* Red - The calculated closestFace is incorrect, and the actual closest face
* is adjacent.
* White - Fail, closestFace is not even adjacent to the actual closest face.
*/
private void bruteForcePhiTest() {
double[] myPhi = g.getDistances();
Point3d closestPoint = new Point3d();
Point3d myPoint = new Point3d();
int badVertexCount = 0;
double maxError = 0;
double avgError = 0;
boolean vertexIsBad = false;
for (int i = 0; i < myPhi.length; i++) {
vertexIsBad = false;
// Extract out the grid coordinates.
Vector3i gidxs = new Vector3i();
// Get the distance from currentPoint to the face.
g.getLocalVertexCoords(myPoint, g.vertexToXyzIndices(gidxs, i));
for (int j = 0; j < m.numFaces(); j++) {
Face face = m.getFace(j);
face.nearestPoint(closestPoint, myPoint);
double distance = myPoint.distance(closestPoint);
double distanceInPhi = myPhi[i];
// Test to see if we've found a smaller distance
if (Math.abs(distance) < Math.abs(distanceInPhi)) {
g.setVertexColor(i, Color.WHITE);
if (!vertexIsBad) {
badVertexCount++;
vertexIsBad = true;
}
int calculatedFaceIndex = ((Face) g.getClosestFeature(i)).getIndex();
// I'm trusting 'distance' over myPhi. This is because it is an
// exhaustive search, and should be as accurate as the method
// used to calculate the closest point, whereas myPhi is
// calculated using a sweep method, which will mismatch
// the closest face.
double tempError = (Math.abs(distanceInPhi) - Math.abs(distance)) / Math.abs(distance) * 100.0f;
avgError += tempError;
if (tempError > maxError) {
maxError = tempError;
}
if (calculatedFaceIndex == j) {
g.setVertexColor(i, Color.BLUE);
} else {
// We want to test if they at least share a vertex.
Face calculatedFace = m.getFace(calculatedFaceIndex);
HalfEdge he, he0;
Vector3d[] calculatedFaceVertices = new Vector3d[3];
he0 = calculatedFace.firstHalfEdge();
he = he0;
calculatedFaceVertices[0] = new Vector3d(he.head.pnt);
he = he.getNext();
calculatedFaceVertices[1] = new Vector3d(he.head.pnt);
he = he.getNext();
calculatedFaceVertices[2] = new Vector3d(he.head.pnt);
Vector3d[] faceVertices = new Vector3d[3];
he0 = face.firstHalfEdge();
he = he0;
faceVertices[0] = new Vector3d(he.head.pnt);
he = he.getNext();
faceVertices[1] = new Vector3d(he.head.pnt);
he = he.getNext();
faceVertices[2] = new Vector3d(he.head.pnt);
boolean areFacesAdjacent = false;
for (int p = 0; p < 2; p++) {
for (int q = 0; q < 2; q++) {
if (faceVertices[q].equals(calculatedFaceVertices[p])) {
areFacesAdjacent = true;
g.setVertexColor(i, Color.RED);
}
}
}
}
}
}
}
avgError /= myPhi.length;
System.out.println("Number of incorrect vertices: " + badVertexCount);
System.out.println("Max error of phi is: " + maxError + "%");
System.out.println("Average error of phi is: " + avgError + "%");
System.out.println("Brute Force Distance Test Complete.");
}
Aggregations