use of maspack.matrix.Point2d in project artisynth_core by artisynth.
the class TextComponent2d method setDefaults.
protected void setDefaults() {
setFont(new Font(defaultFontName, 0, defaultFontSize));
myRenderProps = createDefaultRenderProps();
hAlignment = defaultHAlignment;
vAlignment = defaultVAlignment;
myTextSize = defaultTextSize;
myFontSize = defaultFontSize;
myText = "";
myPos = new Point2d(defaultPos);
myOrientation = 0;
}
use of maspack.matrix.Point2d in project artisynth_core by artisynth.
the class DicomViewer method buildRenderObject.
protected RenderObject buildRenderObject() {
RenderObject robj = new RenderObject();
float x = (float) getX();
float y = (float) getY();
float z = (float) getZ();
float[][] coords = { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 1, 0 } };
// xy-slice
Point2d[] texcoords = texture.getTextureCoordinates(DicomTextureContent.COL_ROW_PLANE);
robj.addNormal(0, 0, 1);
for (int i = 0; i < 4; ++i) {
robj.addPosition(coords[i][0], coords[i][1], z);
robj.addTextureCoord(texcoords[i]);
robj.addVertex();
}
// xz-slice
texcoords = texture.getTextureCoordinates(DicomTextureContent.COL_SLICE_PLANE);
robj.addNormal(0, 1, 0);
for (int i = 0; i < 4; ++i) {
robj.addPosition(coords[i][0], y, coords[i][1]);
robj.addTextureCoord(texcoords[i]);
robj.addVertex();
}
// yz-slice
texcoords = texture.getTextureCoordinates(DicomTextureContent.ROW_SLICE_PLANE);
robj.addNormal(1, 0, 0);
for (int i = 0; i < 4; ++i) {
robj.addPosition(x, coords[i][0], coords[i][1]);
robj.addTextureCoord(texcoords[i]);
robj.addVertex();
}
// three planes
for (int i = 0; i < 3; ++i) {
robj.createTriangleGroup();
int baseIdx = 4 * i;
robj.addTriangle(baseIdx, baseIdx + 1, baseIdx + 2);
robj.addTriangle(baseIdx, baseIdx + 2, baseIdx + 3);
}
// box coordinates
int vidx = robj.vertex(0, 0, 0);
robj.vertex(0, 1, 0);
robj.vertex(1, 1, 0);
robj.vertex(1, 0, 0);
robj.vertex(0, 0, 1);
robj.vertex(0, 1, 1);
robj.vertex(1, 1, 1);
robj.vertex(1, 0, 1);
final int[][] edges = { { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, { 0, 4 }, { 1, 5 }, { 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 }, { 2, 6 }, { 3, 7 } };
for (int[] edge : edges) {
robj.addLine(edge[0] + vidx, edge[1] + vidx);
}
return robj;
}
use of maspack.matrix.Point2d in project artisynth_core by artisynth.
the class MeshIntersectingProbe method findFaces.
// finds faces near a points
private ArrayList<Face> findFaces(Point3d p, OBBTree obbt, Vector3d vx, Vector3d vy, Point3d o, double tol) {
ArrayList<Face> faces = new ArrayList<Face>();
ArrayList<BVNode> nodes = new ArrayList<BVNode>();
obbt.intersectPoint(nodes, p);
Point2d p2d = Intersector2d.get2dCoordinate(p, vx, vy, o);
Point3d uvw = new Point3d();
for (BVNode obbn : nodes) {
for (int i = 0; i < obbn.getNumElements(); i++) {
Boundable ps = obbn.getElements()[i];
if (ps instanceof Face) {
Face f = (Face) ps;
Vertex3d[] vtxs = f.getVertices();
Point2d p0 = Intersector2d.get2dCoordinate(vtxs[0].getWorldPoint(), vx, vy, o);
Point2d p1 = Intersector2d.get2dCoordinate(vtxs[1].getWorldPoint(), vx, vy, o);
Point2d p2 = Intersector2d.get2dCoordinate(vtxs[2].getWorldPoint(), vx, vy, o);
Intersector2d.getBarycentric(p2d, p0, p1, p2, uvw);
if (uvw.x > -tol && uvw.y > -tol && uvw.z > -tol) {
faces.add(f);
}
}
}
}
return faces;
}
use of maspack.matrix.Point2d in project artisynth_core by artisynth.
the class MeshIntersectingProbe method findNextEdge.
// NOTE: only works for convex faces (so, triangular is okay)
// finds the next edge while clipping around in a circle
private static HalfEdge findNextEdge(LinkedList<Point3d> contour, ArrayList<Face> faceList, Intersector2d ti, SplitStorage info, Vector3d vx, Vector3d vy, Point3d o) {
Vector3d dir = new Vector3d();
Point3d vtxp = info.vtx.getWorldPoint();
Point2d vtx2d = Intersector2d.get2dCoordinate(vtxp, vx, vy, o);
dir.sub(contour.get(info.idx + 1), contour.get(info.idx));
for (Face face : faceList) {
HalfEdge he0 = face.getEdge(0);
HalfEdge he = he0;
do {
if (info.vtx != he.head && info.vtx != he.tail) {
Point2d p1 = Intersector2d.get2dCoordinate(he.head.getWorldPoint(), vx, vy, o);
Point2d p2 = Intersector2d.get2dCoordinate(he.tail.getWorldPoint(), vx, vy, o);
ArrayList<Point2d> pnts = new ArrayList<Point2d>();
Vector2d lineDir = Intersector2d.get2dVector(dir, vx, vy);
int npoints = ti.intersectLineLineSegment(vtx2d, lineDir, p1, p2, pnts);
if (npoints == 1) {
Point3d p = Intersector2d.get3dCoordinate(pnts.get(0), vx, vy, o);
Vector3d ldir = new Vector3d(p.x - vtxp.x, p.y - vtxp.y, p.z - vtxp.z);
// check direction
if (ldir.dot(dir) > -ti.epsilon) {
// check if we passed the next point
Point3d pNext = contour.get(info.idx + 1);
if (ldir.norm() < pNext.distance(vtxp) + ti.epsilon) {
if (p.distance(pNext) < ti.epsilon) {
// move to next point
info.idx++;
}
info.vtx = createOrGetVertex(p, face.getVertices(), ti.epsilon);
return he;
} else {
// advance to next vertex
info.vtx = createOrGetVertex(pNext, face.getVertices(), ti.epsilon);
info.face = face;
// move to next point
info.idx++;
return null;
}
}
}
}
he = he.getNext();
} while (he != he0);
}
info.face = null;
return null;
}
use of maspack.matrix.Point2d in project artisynth_core by artisynth.
the class Intersector2d method intersectTriangleLineSegment.
public int intersectTriangleLineSegment(Point2d v0, Point2d v1, Point2d v2, Point2d l0, Point2d l1, ArrayList<Point2d> points) {
ArrayList<Point2d> pnts2d = new ArrayList<Point2d>();
// check if endpoints are inside
Point3d uvw = new Point3d();
getBarycentric(l0, v0, v1, v2, uvw);
if (uvw.x > -epsilon && uvw.y > -epsilon && uvw.z > -epsilon) {
pnts2d.add(l0);
}
getBarycentric(l1, v0, v1, v2, uvw);
if (uvw.x > -epsilon && uvw.y > -epsilon && uvw.z > -epsilon) {
pnts2d.add(l1);
}
// check line-line intersections
intersectLineSegmentLineSegment(v0, v1, l0, l1, pnts2d);
intersectLineSegmentLineSegment(v1, v2, l0, l1, pnts2d);
intersectLineSegmentLineSegment(v2, v0, l0, l1, pnts2d);
// reduce
pnts2d = getUnique(pnts2d, epsilon);
points.addAll(pnts2d);
return pnts2d.size();
}
Aggregations