use of maspack.geometry.DistanceGrid.TetDesc in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method getFeatureAdjacentTets.
protected int getFeatureAdjacentTets(TetDesc tdesc, TetFeature feat, Plane plane, HashSet<TetDesc> visited) {
createConnectivityIfNecessary();
Point3d[] vpnts = new Point3d[] { new Point3d(), new Point3d(), new Point3d(), new Point3d() };
if (feat instanceof TetFace) {
TetDesc adjDesc = myFaceTets.get((TetFace) feat);
TetDesc adesc = new TetDesc(adjDesc);
adesc.addOffset(tdesc);
if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
getVertexCoords(vpnts, adesc);
TetPlaneIntersection isect = getIsect(0);
if (intersectTetAndPlane(isect, adesc, vpnts, plane)) {
return 1;
}
}
return 0;
} else {
TetDesc[] adjDescs = null;
if (feat instanceof TetNode) {
adjDescs = myNodeTets.get(((TetNode) feat).getNode());
} else {
// feat instanceof TetEdge
adjDescs = myEdgeTets.get((TetEdge) feat);
}
int numi = 0;
for (int i = 0; i < adjDescs.length; i++) {
TetDesc adesc = new TetDesc(adjDescs[i]);
adesc.addOffset(tdesc);
if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
// different from that of tdesc
if ((feat instanceof TetNode && !adesc.cellEquals(tdesc)) || (feat instanceof TetEdge && !adesc.equals(tdesc))) {
getVertexCoords(vpnts, adesc);
TetPlaneIntersection isect = getIsect(numi);
if (intersectTetAndPlane(isect, adesc, vpnts, plane)) {
numi++;
}
}
}
}
return numi;
}
}
use of maspack.geometry.DistanceGrid.TetDesc in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method createConnectivity.
private void createConnectivity() {
myFaceTets = new HashMap<TetFace, TetDesc>();
ArrayList<HashSet<TetDesc>> nodeTets = new ArrayList<HashSet<TetDesc>>();
for (int i = 0; i < 8; i++) {
nodeTets.add(new HashSet<TetDesc>());
}
HashMap<TetEdge, HashSet<TetDesc>> edgeTets = new HashMap<TetEdge, HashSet<TetDesc>>();
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
for (int k = -1; k <= 1; k++) {
for (TetID tetId : TetID.values()) {
TetDesc tdesc = new TetDesc(new Vector3i(i, j, k), tetId);
Vector3i[] verts = tdesc.getVertices();
for (int vi = 0; vi < verts.length; vi++) {
int refVtx = findRefVertex(verts[vi]);
if (refVtx != -1) {
nodeTets.get(refVtx).add(tdesc);
}
}
maybeAddFace(myFaceTets, verts[0], verts[1], verts[2], tdesc);
maybeAddFace(myFaceTets, verts[0], verts[2], verts[3], tdesc);
maybeAddFace(myFaceTets, verts[2], verts[1], verts[3], tdesc);
maybeAddFace(myFaceTets, verts[1], verts[0], verts[3], tdesc);
maybeAddEdge(edgeTets, verts[0], verts[1], tdesc);
maybeAddEdge(edgeTets, verts[1], verts[2], tdesc);
maybeAddEdge(edgeTets, verts[2], verts[0], tdesc);
maybeAddEdge(edgeTets, verts[0], verts[3], tdesc);
maybeAddEdge(edgeTets, verts[1], verts[3], tdesc);
maybeAddEdge(edgeTets, verts[2], verts[3], tdesc);
}
}
}
}
myNodeTets = new ArrayList<TetDesc[]>();
for (int i = 0; i < nodeTets.size(); i++) {
myNodeTets.add(nodeTets.get(i).toArray(new TetDesc[0]));
}
myEdgeTets = new HashMap<TetEdge, TetDesc[]>();
for (TetEdge edge : edgeTets.keySet()) {
myEdgeTets.put(edge, edgeTets.get(edge).toArray(new TetDesc[0]));
}
}
use of maspack.geometry.DistanceGrid.TetDesc in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method findQuadSurfaceIntersectionLoc.
/**
* Find the nearest quad surface intersection to p0, in the direction dir,
* and return the result in ps. It is assumed that dir lies in the
* plane. Input and output parameters are all given in grid local
* coordinates. The method returns a descriptor of the tet/plane
* intersection for the tet containing ps, unless ps is not found, in which
* case null is returned.
*/
public TetDesc findQuadSurfaceIntersectionLoc(Point3d ps, Point3d p0, Vector3d dir) {
TetDesc tdesc = null;
// find the quadratic cell containing p0
Vector3i vxyz = new Vector3i();
Vector3d xyz = new Vector3d();
if (myGrid.getQuadCellCoords(xyz, vxyz, p0, myGrid.myQuadGridToLocal) == -1) {
// shouldn't happen - grid should have enough margin to prevent this
if (myDebug > 0) {
System.out.println("Not found: no quad cell found for p0");
}
return null;
}
// find the tet containing p0 within the quadratic cell
tdesc = new TetDesc(vxyz, TetID.findSubTet(xyz.x, xyz.y, xyz.z));
// now transform p0 and dir to quad grid coordinates
Point3d p0Quad = new Point3d();
Vector3d dirQuad = new Vector3d();
myGrid.myQuadGridToLocal.inverseTransformPnt(p0Quad, p0);
myGrid.myQuadGridToLocal.inverseTransformVec(dirQuad, dir);
if (myDebug > 0) {
System.out.println("looking for ps starting from " + tdesc);
}
// Find the interval (srng[0], srng[1]) within which the ray (p0, dir)
// intersects tet/plane intersection defined by isect. This interval is
// used to seed the surface intersection search. The edge of the
// intersection boundary which clips the upper value of the range is
// returned in edgeIdx, and the intersection parameter along that edge is
// placed in edgeS.
double[] srng = new double[] { 0, Double.MAX_VALUE };
tdesc.clipLineSegment(srng, p0Quad, dirQuad);
if (srng[0] > srng[1]) {
// shouldn't happen - p0 should be in the tet
if (myDebug > 0) {
System.out.println("Not found: p0 tet does not intersect ray (p0,dir)");
}
return null;
}
// Find the tet boundary feature associated with the upper bound of the
// ray intersection. This will be used to search for adjacent tets in
// case the surface intersection does not occur within the current tet.
Point3d px = new Point3d();
px.scaledAdd(srng[1], dir, p0);
// TetFeature lastFeat = isect.getFeature (edgeS.value, edgeIdx);
TetFeature lastFeat = findNearestFeature(tdesc, px, 1e-10);
myVisitedTets.clear();
myVisitedTets.add(tdesc);
// first point ps at which (p0, dir) intersects the quadratic surface.
while (findSurfaceIntersectionInTet(ps, tdesc, srng, p0Quad, dirQuad) == CONTINUE) {
// A return value of CONTINUE means that the surface intersection was
// not found in the current tet, and that we should look for the
// intersection in adjacent tets.
ArrayList<TetDesc> adescs = new ArrayList<TetDesc>();
int ntets = getFeatureAdjacentTets(adescs, tdesc, lastFeat, myVisitedTets);
TetDesc tbest = null;
double bestLen = 0;
if (myDebug > 0) {
System.out.println("checking " + ntets + " adjacent tets for feature " + lastFeat);
System.out.print(" ");
for (int k = 0; k < ntets; k++) {
System.out.print(adescs.get(k) + " ");
}
System.out.println("");
}
// intersection intersects the ray over the longest length.
for (int k = 0; k < ntets; k++) {
TetDesc adesc = adescs.get(k);
double[] irng = new double[] { 0, Double.MAX_VALUE };
adesc.clipLineSegment(irng, p0Quad, dirQuad);
double ilen = irng[1] - irng[0];
if (myDebug > 0) {
System.out.println(" ilen=" + ilen);
}
if (ilen > bestLen) {
bestLen = ilen;
tbest = adesc;
srng[0] = irng[0];
srng[1] = irng[1];
}
}
if (tbest == null) {
if (myDebug > 0) {
System.out.println("Not found: no adjacent tets intersect the ray");
}
return null;
} else {
px.scaledAdd(srng[1], dir, p0);
// lastFeat = ibest.getFeature (bestS, bestEdgeIdx);
lastFeat = findNearestFeature(tbest, px, 1e-10);
tdesc = tbest;
myVisitedTets.add(tdesc);
}
}
myGrid.myQuadGridToLocal.transformPnt(ps, ps);
return tdesc;
}
use of maspack.geometry.DistanceGrid.TetDesc in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method printConnectivity.
void printConnectivity() {
System.out.println("Nodes:");
for (int i = 0; i < 8; i++) {
TetDesc[] tdescs = myNodeTets.get(i);
System.out.print(" " + i + "(" + tdescs.length + ") : ");
for (TetDesc tdesc : tdescs) {
System.out.print(tdesc + " ");
}
System.out.println("");
}
System.out.println("Edges:");
for (TetEdge edge : myEdgeTets.keySet()) {
System.out.print(" " + edge + ": ");
for (TetDesc tdesc : myEdgeTets.get(edge)) {
System.out.print(tdesc + " ");
}
System.out.println("");
}
System.out.println("Faces:");
for (TetFace face : myFaceTets.keySet()) {
System.out.println(" " + face + ": " + myFaceTets.get(face));
}
}
use of maspack.geometry.DistanceGrid.TetDesc in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method getFeatureAdjacentTets.
protected int getFeatureAdjacentTets(ArrayList<TetDesc> adescs, TetDesc tdesc, TetFeature feat, HashSet<TetDesc> visited) {
createConnectivityIfNecessary();
if (feat instanceof TetFace) {
TetDesc adjDesc = myFaceTets.get((TetFace) feat);
TetDesc adesc = new TetDesc(adjDesc);
adesc.addOffset(tdesc);
if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
adescs.add(adesc);
return 1;
} else {
return 0;
}
} else {
TetDesc[] adjDescs = null;
if (feat instanceof TetNode) {
adjDescs = myNodeTets.get(((TetNode) feat).getNode());
} else {
// feat instanceof TetEdge
adjDescs = myEdgeTets.get((TetEdge) feat);
}
int numi = 0;
for (int i = 0; i < adjDescs.length; i++) {
TetDesc adesc = new TetDesc(adjDescs[i]);
adesc.addOffset(tdesc);
if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
// different from that of tdesc
if ((feat instanceof TetNode && !adesc.cellEquals(tdesc)) || (feat instanceof TetEdge && !adesc.equals(tdesc))) {
adescs.add(adesc);
numi++;
}
}
}
return numi;
}
}
Aggregations