use of maspack.geometry.KDTree in project artisynth_core by artisynth.
the class MFreeFactory method computeNodeRadii.
private static double[] computeNodeRadii(Point3d[] nodes, Point3d[] ipnts, MeshBase mesh, int minK, double marginScale) {
Point3d min = new Point3d(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
Point3d max = new Point3d(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
for (Point3d node : nodes) {
node.updateBounds(min, max);
}
for (Point3d ipnt : ipnts) {
ipnt.updateBounds(min, max);
}
Vector3d widths = new Vector3d(max);
widths.sub(min);
IndexedPoint3d[] inodes = new IndexedPoint3d[nodes.length];
for (int i = 0; i < nodes.length; ++i) {
inodes[i] = new IndexedPoint3d(nodes[i], i);
}
KDTree<IndexedPoint3d> kdtree = new KDTree<IndexedPoint3d>(3, Arrays.asList(inodes), new MyKdComparator());
// KPointDistanceGrid grid = new KPointDistanceGrid(minK, trans, new int[] {30, 30, 30}, widths);
// for (Point3d node : nodes) {
// grid.addPoint(node);
// }
double[] r = new double[nodes.length];
// int[] closest = new int[minK];
// double[] dists = new double[minK];
IndexedPoint3d idpnt = new IndexedPoint3d(null, 0);
for (Point3d node : nodes) {
idpnt.pnt = node;
List<IndexedPoint3d> nearest = kdtree.nearestNeighbourSearch(idpnt, minK, 0);
// check for coplanarity
int kk = minK;
while (isCoplanar(nearest)) {
kk += 1;
nearest = kdtree.nearestNeighbourSearch(idpnt, kk, 0);
}
for (IndexedPoint3d nbr : nearest) {
double rl = nbr.pnt.distance(node) * marginScale;
if (rl > r[nbr.idx]) {
r[nbr.idx] = rl;
}
}
}
for (Point3d ipnt : ipnts) {
idpnt.pnt = ipnt;
List<IndexedPoint3d> nearest = kdtree.nearestNeighbourSearch(idpnt, minK, 0);
// check for coplanarity
int kk = minK;
while (isCoplanar(nearest)) {
kk += 1;
nearest = kdtree.nearestNeighbourSearch(idpnt, kk, 0);
}
for (IndexedPoint3d nbr : nearest) {
double rl = nbr.pnt.distance(ipnt) * marginScale;
if (rl > r[nbr.idx]) {
r[nbr.idx] = rl;
}
}
}
for (Vertex3d vtx : mesh.getVertices()) {
idpnt.pnt = vtx.getWorldPoint();
List<IndexedPoint3d> nearest = kdtree.nearestNeighbourSearch(idpnt, minK, 0);
// check for coplanarity
int kk = minK;
while (isCoplanar(nearest)) {
kk += 1;
nearest = kdtree.nearestNeighbourSearch(idpnt, kk, 0);
}
for (IndexedPoint3d nbr : nearest) {
double rl = nbr.pnt.distance(idpnt.pnt) * marginScale;
if (rl > r[nbr.idx]) {
r[nbr.idx] = rl;
}
}
}
return r;
}
Aggregations