Search in sources :

Example 31 with PolygonalMesh

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);
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 32 with PolygonalMesh

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;
}
Also used : Point3d(maspack.matrix.Point3d) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 33 with PolygonalMesh

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");
            }
        }
    }
}
Also used : MeshComponent(artisynth.core.mechmodels.MeshComponent) MechModel(artisynth.core.mechmodels.MechModel) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 34 with PolygonalMesh

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);
            }
        }
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) EditablePolygonalMeshComp(artisynth.core.renderables.EditablePolygonalMeshComp) FrameMarker(artisynth.core.mechmodels.FrameMarker) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 35 with PolygonalMesh

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);
    }
}
Also used : RegionType(maspack.collision.SurfaceMeshIntersector.RegionType) MeshCollider(maspack.collision.MeshCollider) ContactInfo(maspack.collision.ContactInfo) SurfaceMeshIntersector(maspack.collision.SurfaceMeshIntersector) Method(artisynth.core.mechmodels.CollisionBehavior.Method) SignedDistanceCollider(maspack.collision.SignedDistanceCollider) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

PolygonalMesh (maspack.geometry.PolygonalMesh)128 Point3d (maspack.matrix.Point3d)30 Vertex3d (maspack.geometry.Vertex3d)24 Vector3d (maspack.matrix.Vector3d)23 RigidTransform3d (maspack.matrix.RigidTransform3d)21 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 File (java.io.File)14 Face (maspack.geometry.Face)14 ContactPoint (artisynth.core.mechmodels.ContactPoint)11 Point (artisynth.core.mechmodels.Point)11 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)10 Color (java.awt.Color)10 MeshBase (maspack.geometry.MeshBase)10 RigidBody (artisynth.core.mechmodels.RigidBody)9 MechModel (artisynth.core.mechmodels.MechModel)8 BufferedReader (java.io.BufferedReader)8 AxisAngle (maspack.matrix.AxisAngle)8 RenderProps (maspack.render.RenderProps)8 HashMap (java.util.HashMap)7