use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class FemMeshBase method initializeSurfaceBuild.
/**
* Initialize data structures prior to adding vertices and faces to
* this surface.
*/
protected void initializeSurfaceBuild() {
PolygonalMesh mesh = new PolygonalMesh();
doSetMesh(mesh, null, null);
mesh.setFixed(false);
mesh.setColorsFixed(false);
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class Cell method buildUnstructuredMesh_surface.
static PolygonalMesh buildUnstructuredMesh_surface(VtkData vtkData) throws IOException {
PolygonalMesh mesh = new PolygonalMesh();
mesh.setName(vtkData.name);
ArrayList<Point3d> points = vtkData.points;
ArrayList<Cell> cells = vtkData.cells;
// now, compile the FEM
for (Point3d p : points) mesh.addVertex(p);
// for (Cell c : cells)
for (int a = 0; a < cells.size(); a++) {
Cell c = cells.get(a);
if (// vertex
c.vtkType == 1)
;
else if (// line
c.vtkType == 3)
;
else if (// polyline
c.vtkType == 4)
;
else if (// triangle
c.vtkType == 5)
mesh.addFace(c.indices);
else if (// polygon
c.vtkType == 7)
mesh.addFace(c.indices);
else if (// quad
c.vtkType == 9)
mesh.addFace(c.indices);
else if (// tet (vtk and artisynth agree)
c.vtkType == 10)
;
else if (// hex (vtk and artisynth disagree)
c.vtkType == 12)
;
else if (// wedge (vtk and artisynth disagree)
c.vtkType == 13)
;
else if (// pyramid (vtk and artisynth agree)
c.vtkType == 14)
;
}
return mesh;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MeshBodyEditor method addActions.
public void addActions(EditActionMap actions, SelectionManager selManager) {
LinkedList<ModelComponent> selection = selManager.getCurrentSelection();
if (containsMultipleSelection(selection, MeshComponent.class)) {
if (containsSingleSelection(selection, MeshComponent.class)) {
MeshComponent body = (MeshComponent) selection.get(0);
actions.add(this, "Save local mesh as ...");
actions.add(this, "Save world mesh as ...");
if (body.getMesh() instanceof PolygonalMesh && body.getGrandParent() instanceof MechModel) {
actions.add(this, "Add mesh inspector");
}
}
}
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class RigidBodyEditor method applyAction.
public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
if (containsMultipleSelection(selection, RigidBody.class)) {
if (actionCommand == "Select markers") {
LinkedList<ModelComponent> list = (LinkedList<ModelComponent>) selection.clone();
for (ModelComponent c : list) {
FrameMarker[] mkrs = ((RigidBody) c).getFrameMarkers();
for (int i = 0; i < mkrs.length; i++) {
myMain.getSelectionManager().addSelected(mkrs[i]);
}
myMain.getSelectionManager().removeSelected(c);
}
}
if (containsSingleSelection(selection, RigidBody.class)) {
if (actionCommand == "Edit geometry and inertia ...") {
if (myEditManager.acquireEditLock()) {
RigidBody body = (RigidBody) selection.get(0);
RigidBodyGeometryAgent agent = new RigidBodyGeometryAgent(myMain, body);
agent.show(popupBounds);
}
} else if (actionCommand == "Save mesh as ...") {
RigidBody body = (RigidBody) selection.get(0);
PolygonalMesh mesh = body.getMesh();
EditorUtils.saveMesh(mesh, mesh != null ? mesh.getMeshToWorld() : null);
} else if (actionCommand == "Attach particles ...") {
if (myEditManager.acquireEditLock()) {
RigidBody body = (RigidBody) selection.get(0);
// XXX should be more general than this ... what if mechModel
// is a sub model?
MechModel mech = (MechModel) body.getGrandParent();
myMain.getSelectionManager().clearSelections();
AttachParticleBodyAgent agent = new AttachParticleBodyAgent(myMain, mech, body);
agent.show(popupBounds);
}
} else if (actionCommand == "Add mesh inspector") {
RigidBody body = (RigidBody) selection.get(0);
MechModel mech = (MechModel) body.getGrandParent();
EditablePolygonalMeshComp editMesh = new EditablePolygonalMeshComp(body.getSurfaceMesh());
double size = RenderableUtils.getRadius(editMesh);
RenderProps.setVisible(editMesh, true);
RenderProps.setPointStyle(editMesh, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(editMesh, 0.05 * size);
mech.addRenderable(editMesh);
}
}
}
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class CollisionManager method checkForContact.
void checkForContact(CollidableBody c0, CollidableBody c1, CollisionBehavior behav, boolean testMode) {
if (c0.getCollidableIndex() > c1.getCollidableIndex()) {
CollidableBody tmp = c0;
c0 = c1;
c1 = tmp;
}
PolygonalMesh mesh0 = c0.getCollisionMesh();
PolygonalMesh mesh1 = c1.getCollisionMesh();
ContactInfo cinfo;
if (testMode) {
cinfo = new ContactInfo(mesh0, mesh1);
} else {
ColliderType colliderType = behav.getColliderType();
if (colliderType == ColliderType.SIGNED_DISTANCE) {
// must be rigid and support signed distance grids
if ((c0.isDeformable() || !c0.hasDistanceGrid()) && (c1.isDeformable() || !c1.hasDistanceGrid())) {
colliderType = ColliderType.AJL_CONTOUR;
}
}
// timer.start();
switch(colliderType) {
case AJL_CONTOUR:
{
if (myAjlIntersector == null) {
myAjlIntersector = new SurfaceMeshIntersector();
}
// types of regions that we need to compute for mesh0 and mesh1
RegionType regions0 = RegionType.INSIDE;
RegionType regions1 = RegionType.INSIDE;
Method method = behav.getMethod();
if (method != Method.VERTEX_EDGE_PENETRATION && method != Method.CONTOUR_REGION && behav.getBodyFaceContact() == false) {
// regions for both meshes
if (CollisionHandler.isRigid(c0) && !CollisionHandler.isRigid(c1)) {
regions0 = RegionType.NONE;
} else if (CollisionHandler.isRigid(c1) && !CollisionHandler.isRigid(c0)) {
regions1 = RegionType.NONE;
}
}
cinfo = myAjlIntersector.findContoursAndRegions(mesh0, regions0, mesh1, regions1);
break;
}
case TRI_INTERSECTION:
{
if (myTriTriCollider == null) {
myTriTriCollider = new MeshCollider();
}
cinfo = myTriTriCollider.getContacts(mesh0, mesh1);
break;
}
case SIGNED_DISTANCE:
{
if (mySDCollider == null) {
mySDCollider = new SignedDistanceCollider();
}
cinfo = mySDCollider.getContacts(mesh0, c0.getDistanceGrid(), mesh1, c1.getDistanceGrid());
break;
}
default:
{
throw new UnsupportedOperationException("Unimplemented collider type " + colliderType);
}
}
// timer.stop();
// System.out.println ("time=" + timer.getTimeUsec());
// cinfo = myCollider.getContacts (mesh0, mesh1);
}
if (cinfo != null) {
addOrUpdateHandler(cinfo, c0, c1, behav);
}
}
Aggregations