use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshCollisionViewer method render.
public void render(Renderer renderer, int flags) {
ContactInfo cinfo = myContactInfo;
if (contourWidth > 0 && cinfo != null) {
renderer.setShading(Shading.NONE);
renderer.setLineWidth(contourWidth);
renderer.setPointSize(contourWidth);
renderer.setColor(contourColor, /*highlight=*/
false);
if (cinfo.getContours() != null) {
for (IntersectionContour contour : cinfo.getContours()) {
renderer.beginDraw(DrawMode.LINE_LOOP);
for (IntersectionPoint p : contour) {
renderer.addVertex(p);
}
renderer.endDraw();
}
}
Point3d pnt = new Point3d();
renderer.beginDraw(DrawMode.POINTS);
for (PenetratingPoint p : cinfo.getPenetratingPoints(0)) {
pnt.set(p.vertex.pnt);
pnt.transform(myMesh1.getMeshToWorld());
renderer.addVertex(pnt);
}
for (PenetratingPoint p : cinfo.getPenetratingPoints(1)) {
pnt.set(p.vertex.pnt);
pnt.transform(myMesh2.getMeshToWorld());
renderer.addVertex(pnt);
}
renderer.endDraw();
renderer.setShading(Shading.FLAT);
renderer.setLineWidth(1);
renderer.setPointSize(1);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshThicken method applyThickening.
public void applyThickening(Region region, MeshBase mesh, double thickening) {
double margin = region.myMargin;
Point3d pnt = new Point3d();
Vector3d nrm = new Vector3d();
Vector2d p2d = new Vector2d();
ArrayList<Vertex3d> verts = myMesh.getVertices();
ArrayList<Vector3d> nrmls = mesh.getNormals();
if (nrmls == null) {
System.out.println("Mesh does not have normals; thickening ignored");
}
int cnt = 0;
Vector3d regionNrm = new Vector3d();
// region normal in mesh coordinates
region.myFrame.R.getColumn(2, regionNrm);
for (int i = 0; i < verts.size(); i++) {
Vertex3d v = verts.get(i);
pnt.inverseTransform(region.myFrame, v.pnt);
nrm.inverseTransform(region.myFrame, nrmls.get(i));
if (pnt.z <= region.myHeight && pnt.z >= -region.myBackHeight) {
// if (Math.abs(pnt.z) <= region.myHeight) {
p2d.set(pnt.x, pnt.y);
double d = region.myDist.computeInteriorDistance(/*near=*/
null, p2d);
if (d <= 0) {
double dz = computeDeltaZ(-d, margin, thickening);
if (region.myUseNormalZScalingP) {
if (adjacentFacesCrossNormal(v, regionNrm)) {
dz = 0;
} else {
dz *= nrm.z;
}
} else {
dz = (nrm.z >= 0 ? dz : -dz);
}
if (nrm.z >= 0) {
pnt.z += dz;
} else {
if (region.getThickenBackSide()) {
pnt.z += dz;
}
}
v.pnt.transform(region.myFrame, pnt);
cnt++;
}
}
}
System.out.println("count=" + cnt);
myMesh.notifyVertexPositionsModified();
viewer.rerender();
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class IntersectionContour method fitPlane.
/**
* Fits this contour to a plane by first computing the centroid,
* and then forming a normal by summing the cross products of
* adjacent rays between the centroid and the contour points.
* This sum is returned in the optional argument <code>areaVec</code>.
*
* <p>When computing the centroid, points closer to each other
* than <code>pointTol</code> are ignored. The points that are
* actually used are collected into a separate list that is
* returned by this method.
*
* @param areaVec if non-null, returns the computed area vector.
* Normalizing this vector gives the normal for the plane, while
* the length of this vector gives twice the area of the contour
* with respect to the plane.
* @param centroid if non-null, returns the computed centroid.
* @param pointTol minimum distance between contour points used for
* computing the plane
* @return list of contours points with those closer than
* <code>pointTol</code> removed.
*/
public ArrayList<IntersectionPoint> fitPlane(Vector3d areaVec, Vector3d centroid, double pointTol) {
ArrayList<IntersectionPoint> points = new ArrayList<IntersectionPoint>(size());
if (centroid == null) {
centroid = new Vector3d();
} else {
centroid.setZero();
}
if (areaVec == null) {
areaVec = new Vector3d();
} else {
areaVec.setZero();
}
IntersectionPoint plast = get(0);
centroid.set(plast);
points.add(plast);
boolean closeToFirst = false;
for (int i = 1; i < size(); i++) {
IntersectionPoint p = get(i);
if (isClosed() && i == size() - 1) {
// in case contour is closed, check closeness to first point too
closeToFirst = (p.distance(get(0)) < pointTol);
}
if (p.distance(plast) >= pointTol && !closeToFirst) {
centroid.add(p);
points.add(p);
plast = p;
}
}
int nump = points.size();
centroid.scale(1.0 / nump);
if (nump >= 3) {
Vector3d ray0 = new Vector3d();
Vector3d ray1 = new Vector3d();
ray0.sub(points.get(nump - 1), centroid);
for (Point3d p : points) {
ray1.sub(p, centroid);
areaVec.crossAdd(ray0, ray1, areaVec);
ray0.set(ray1);
}
}
return points;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class IntersectionContour method printCornerPoints.
public void printCornerPoints(String name, String fmt, RigidTransform3d T) {
if (name != null) {
System.out.println(name);
}
double tol = computeLength() * 100 * DOUBLE_PREC;
ArrayList<? extends Point3d> corners = getCornerPoints(tol);
Point3d p = new Point3d();
for (int i = 0; i < corners.size(); i++) {
p.set(corners.get(i));
if (T != null) {
p.transform(T);
}
System.out.println(p.toString(fmt));
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class IntersectionContour method computeLength.
/**
* Computes the length of this contour
*
* @return contour length
*/
public double computeLength() {
double length = 0;
if (size() >= 2) {
Point3d pa = get(0);
for (int i = 1; i < size(); i++) {
Point3d pb = get(i);
length += pa.distance(pb);
pa = pb;
}
if (isClosed) {
length += pa.distance(get(0));
}
}
return length;
}
Aggregations