use of maspack.matrix.Vector2d in project artisynth_core by artisynth.
the class CutPlaneProbe method setResolution.
/**
* Sets the resolution fo teh display, integers (nx, ny) corresponding
* to the number of divisions along the x and y axes. This triggers
* a rebuild of the mesh.
*/
public void setResolution(Vector2d res) {
if (!myResolution.equals(res)) {
myResolution = new Vector2d((int) res.x, (int) res.y);
rebuildMesh();
updateMeshDisplay();
}
}
use of maspack.matrix.Vector2d in project artisynth_core by artisynth.
the class PointDistributor method sphereGridFill.
// fills a mesh based on a regular grid of points
public static Point3d[] sphereGridFill(PolygonalMesh mesh, double r) {
ArrayList<Point3d> pnts = new ArrayList<Point3d>();
RigidTransform3d trans = getPrincipalAxes(mesh);
Point3d[] box = getTightBox(mesh, trans);
Point3d center = new Point3d(box[0]);
center.add(box[6]);
center.scale(0.5);
trans.setTranslation(center);
Vector3d l = new Vector3d(box[0]);
l.sub(box[6]);
l.inverseTransform(trans);
double alpha = 2 * Math.sqrt(2) * r;
int nx = (int) Math.ceil(l.x / alpha) + 1;
int ny = (int) Math.ceil(l.y / alpha) + 1;
int nz = (int) Math.ceil(l.z / alpha) + 1;
double xoffset = -(nx - 1) * alpha / 2;
double yoffset = -(ny - 1) * alpha / 2;
double zoffset = -(nz - 1) * alpha / 2;
BVTree bvh = mesh.getBVTree();
Vector2d coords = new Vector2d();
Point3d nearest = new Point3d();
BVFeatureQuery query = new BVFeatureQuery();
Point3d p;
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
double x = i * alpha + xoffset;
double y = j * alpha + yoffset;
double z = k * alpha + zoffset;
p = new Point3d(x, y, z);
p.transform(trans);
addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
}
}
}
return pnts.toArray(new Point3d[pnts.size()]);
}
use of maspack.matrix.Vector2d in project artisynth_core by artisynth.
the class PointDistributor method sphereFCCFill.
// fills a mesh with spheres based on face-centered cubic packing
public static Point3d[] sphereFCCFill(PolygonalMesh mesh, double r) {
ArrayList<Point3d> pnts = new ArrayList<Point3d>();
RigidTransform3d trans = getPrincipalAxes(mesh);
Point3d[] box = getTightBox(mesh, trans);
Point3d center = new Point3d(box[0]);
center.add(box[6]);
center.scale(0.5);
trans.setTranslation(center);
Vector3d l = new Vector3d(box[0]);
l.sub(box[6]);
l.inverseTransform(trans);
double alpha = 2 * Math.sqrt(2) * r;
int nx = (int) Math.ceil(l.x / alpha) + 1;
int ny = (int) Math.ceil(l.y / alpha) + 1;
int nz = (int) Math.ceil(l.z / alpha) + 1;
double xoffset = -(nx - 1) * alpha / 2;
double yoffset = -(ny - 1) * alpha / 2;
double zoffset = -(nz - 1) * alpha / 2;
BVTree bvh = mesh.getBVTree();
Vector2d coords = new Vector2d();
Point3d nearest = new Point3d();
BVFeatureQuery query = new BVFeatureQuery();
Point3d p;
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
double x = i * alpha + xoffset;
double y = j * alpha + yoffset;
double z = k * alpha + zoffset;
p = new Point3d(x, y, z);
p.transform(trans);
addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
// face centers
if (i < nx - 1 && k < nz - 1) {
p = new Point3d(x + alpha / 2, y, z + alpha / 2);
p.transform(trans);
addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
}
if (j < ny - 1 && k < nz - 1) {
p = new Point3d(x, y + alpha / 2, z + alpha / 2);
p.transform(trans);
addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
}
if (i < nx - 1 && j < ny - 1) {
p = new Point3d(x + alpha / 2, y + alpha / 2, z);
p.transform(trans);
addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
}
}
}
}
return pnts.toArray(new Point3d[pnts.size()]);
}
use of maspack.matrix.Vector2d in project artisynth_core by artisynth.
the class DicomLoader method addPlane.
void addPlane() {
if (viewer == null) {
return;
}
DicomImage image = viewer.getImage();
Point3d pmin = new Point3d(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
Point3d pmax = new Point3d(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
viewer.updateBounds(pmin, pmax);
// center transform
RigidTransform3d trans = new RigidTransform3d();
trans.p.interpolate(pmin, 0.5, pmax);
Vector2d size = new Vector2d(pmax.x - pmin.x, pmax.y - pmin.y);
DicomPlaneViewer dpv = new DicomPlaneViewer("plane_" + viewerPlanes.size(), image, trans, size);
addRenderable(dpv);
viewerPlanes.add(dpv);
}
use of maspack.matrix.Vector2d in project artisynth_core by artisynth.
the class GLMouseAdapter method checkForSelection.
private void checkForSelection(MouseEvent e) {
int flags = getSelectionOperation(e);
ViewerSelectionEvent selEvent = new ViewerSelectionEvent();
selEvent.setModifiersEx(e.getModifiersEx());
viewer.selectionEvent = selEvent;
// delimits the pick region (with x, y at the center)
double x, y, w, h;
boolean ignoreDepthTest = false;
Rectangle dragBox = viewer.getDragBox();
if (dragBox != null) {
x = dragBox.x + dragBox.width / 2.0;
y = dragBox.y + dragBox.height / 2.0;
w = dragBox.width;
h = dragBox.height;
flags |= ViewerSelectionEvent.DRAG;
if (!visibleSelectionOnly) {
// Normally true!
ignoreDepthTest = true;
}
} else {
x = e.getX();
y = e.getY();
if (viewer.getEllipticSelection()) {
Vector2d csize = viewer.getEllipticCursorSize();
w = 2 * csize.x;
h = 2 * csize.y;
flags |= ViewerSelectionEvent.DRAG;
} else {
w = 3.0;
h = 3.0;
}
ignoreDepthTest = false;
}
viewer.setPick(x, y, w, h, ignoreDepthTest);
selEvent.setFlags(flags);
// {
// GLSelectionEvent selEvent = new GLSelectionEvent();
// selEvent.myModifiersEx = e.getModifiersEx();
// selEvent.setMode(SelectionType.Clear);
// viewer.selectionEvent = selEvent;
// }
}
Aggregations