Search in sources :

Example 26 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class FemElement3d method connectToHierarchy.

public void connectToHierarchy() {
    super.connectToHierarchy();
    FemNode3d[] nodes = getNodes();
    for (int i = 0; i < nodes.length; i++) {
        for (int j = 0; j < nodes.length; j++) {
            nodes[i].registerNodeNeighbor(nodes[j]);
        }
        nodes[i].addElementDependency(this);
    }
    setMass(0);
    myNbrs = new FemNodeNeighbor[numNodes()][numNodes()];
    for (int i = 0; i < myNodes.length; i++) {
        FemNode3d node = myNodes[i];
        int cnt = 0;
        for (FemNodeNeighbor nbr : node.getNodeNeighbors()) {
            int j = getLocalNodeIndex(nbr.myNode);
            if (j != -1) {
                myNbrs[i][j] = nbr;
                cnt++;
            }
        }
        if (cnt != myNodes.length) {
            System.out.println("element class " + getClass());
            throw new InternalErrorException("Node " + node.getNumber() + " has " + cnt + " local neighbors, expecting " + myNodes.length);
        }
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException) Point(artisynth.core.mechmodels.Point)

Example 27 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class FemMeshComp method createSurface.

// Throwable throwable = null;
public void createSurface(Collection<FemElement3d> elems) {
    initializeSurfaceBuild();
    // nodeVertexMap is used during the construction of this surface,
    // so we build it during the construction rather then letting
    // it be built in finalizeSurfaceBuild()
    myNodeVertexMap = new HashMap<FemNode3d, Vertex3d>();
    myNumSingleAttachments = 0;
    LinkedList<FaceNodes3d> allFaces = new LinkedList<FaceNodes3d>();
    // faces adjacent to each node
    ArrayList<LinkedList<FaceNodes3d>> nodeFaces = new ArrayList<LinkedList<FaceNodes3d>>(myFem.numNodes());
    for (int i = 0; i < myFem.numNodes(); i++) {
        nodeFaces.add(new LinkedList<FaceNodes3d>());
    }
    PointList<FemNode3d> femNodes = myFem.getNodes();
    // each node, create a list of all the faces it is associated with
    for (FemElement3d e : elems) {
        FaceNodes3d[] faces = e.getFaces();
        for (FaceNodes3d f : faces) {
            addEdgeNodesToFace(f, myFem);
            for (FemNode3d n : f.getAllNodes()) {
                int idx = femNodes.indexOf(n);
                if (idx == -1) {
                    throw new InternalErrorException("Element " + e.getNumber() + ": bad node " + n.getNumber());
                }
                nodeFaces.get(femNodes.indexOf(n)).add(f);
            }
            allFaces.add(f);
        }
    }
    // now for each face, check to see if it is overlapping with other faces
    HashSet<FaceNodes3d> adjacentFaces = new HashSet<FaceNodes3d>();
    for (FaceNodes3d f : allFaces) {
        if (!f.isHidden()) {
            adjacentFaces.clear();
            for (FemNode3d n : f.getAllNodes()) {
                Iterator<FaceNodes3d> it = nodeFaces.get(femNodes.indexOf(n)).iterator();
                while (it.hasNext()) {
                    FaceNodes3d g = it.next();
                    if (g.isHidden()) {
                        it.remove();
                    } else if (g.getElement() != f.getElement()) {
                        adjacentFaces.add(g);
                    }
                }
            }
            for (FaceNodes3d g : adjacentFaces) {
                if (f.isContained(g)) {
                    f.setHidden(true);
                    g.setOverlapping(true);
                }
                if (g.isContained(f)) {
                    g.setHidden(true);
                    f.setOverlapping(true);
                }
            }
        }
    }
    int num = 0;
    for (FaceNodes3d f : allFaces) {
        if (!f.isOverlapping() && !f.isSelfAttachedToFace()) {
            num++;
        }
    }
    // form the surface mesh from the non-overlapping faces
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    for (FaceNodes3d f : allFaces) {
        if (!f.isOverlapping() && !f.hasSelfAttachedNode() && !f.isSelfAttachedToFace()) {
            FemNode3d[][] triangles = f.triangulate();
            boolean triangulatedQuad = (triangles.length == 2 && triangles[0][0] == triangles[1][0]);
            for (int i = 0; i < triangles.length; i++) {
                FemNode3d[] tri = triangles[i];
                Vertex3d[] vtxs = new Vertex3d[3];
                for (int j = 0; j < 3; j++) {
                    FemNode3d node = tri[j];
                    if ((vtxs[j] = myNodeVertexMap.get(node)) == null) {
                        Vertex3d vtx = new Vertex3d(new Point3d(node.getPosition()));
                        mesh.addVertex(vtx);
                        myVertexAttachments.add(new PointParticleAttachment(node, null));
                        myNumSingleAttachments++;
                        myNodeVertexMap.put(node, vtx);
                        vtxs[j] = vtx;
                    }
                }
                Face face = mesh.addFace(vtxs);
                if (triangulatedQuad && i == 0) {
                    face.setFirstQuadTriangle(true);
                }
            }
        }
    }
    finalizeSurfaceBuild();
// throwable = null;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) InternalErrorException(maspack.util.InternalErrorException) PolygonalMesh(maspack.geometry.PolygonalMesh) LinkedList(java.util.LinkedList) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) HashSet(java.util.HashSet)

Example 28 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class NumericProbeRangeSelectorDialog method valueChange.

public void valueChange(ValueChangeEvent e) {
    if (e.getSource() == maxYField || e.getSource() == minYField) {
        if (minYField.getDoubleValue() >= maxYField.getDoubleValue()) {
            double[] range = display.getDisplayRange();
            minYField.removeValueChangeListener(this);
            maxYField.removeValueChangeListener(this);
            minYField.setValue(range[0]);
            maxYField.setValue(range[1]);
            minYField.addValueChangeListener(this);
            maxYField.addValueChangeListener(this);
            JOptionPane.showMessageDialog(this, "Minimum Y must be lower than maximum Y.", "Set Display Range Error!", JOptionPane.ERROR_MESSAGE);
        } else {
            display.setDisplayRange(minYField.getDoubleValue(), maxYField.getDoubleValue());
            if (!maskAutoRangeDisable) {
                autoRangeField.setValue(new Boolean(false));
            }
            display.repaint();
        }
    } else if (e.getSource() == autoRangeField) {
        boolean enabled = autoRangeField.getBooleanValue();
        if (enabled) {
            double[] range = display.getAutoRange();
            maskAutoRangeDisable = true;
            minYField.setValue(range[0]);
            maxYField.setValue(range[1]);
            maskAutoRangeDisable = false;
            display.repaint();
        }
        display.setAutoRanging(enabled);
    } else {
        throw new InternalErrorException("unknown value change source: " + e.getSource());
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 29 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class MuscleBundleEditor method applyAction.

public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
    MuscleBundle bundle;
    if ((bundle = getEditableBundle(selection)) != null) {
        if (actionCommand == "Edit fibres ...") {
            if (myEditManager.acquireEditLock()) {
                MuscleFibreAgent agent = new MuscleFibreAgent(myMain, bundle, getBundleAncestor(bundle));
                agent.setContinuousAdd(true);
                agent.show(popupBounds);
            }
        } else if (actionCommand == "Edit elements ...") {
            if (myEditManager.acquireEditLock()) {
                MuscleElementAgent agent = new MuscleElementAgent(myMain, bundle, getBundleAncestor(bundle));
                agent.show(popupBounds);
            }
        } else if (actionCommand == "Compute element directions") {
            bundle.computeElementDirections();
        } else if (actionCommand == "Add elements near fibres ...") {
            addElementsNearFibres(bundle);
        } else if (actionCommand == "Delete elements") {
            deleteElements(bundle);
        }
    } else if (containsBundleAndFibres(selection)) {
        LinkedList<Muscle> fibres = new LinkedList<Muscle>();
        bundle = null;
        for (ModelComponent c : selection) {
            if (bundle == null && c instanceof MuscleBundle) {
                bundle = (MuscleBundle) c;
            } else if (c instanceof Muscle) {
                fibres.add((Muscle) c);
            } else {
                throw new InternalErrorException("Unexepected item in selection list: " + c.getClass());
            }
        }
        MoveFibresCommand command = new MoveFibresCommand("move Muscles", bundle, fibres);
        myMain.getUndoManager().saveStateAndExecute(command);
    }
}
Also used : MuscleBundle(artisynth.core.femmodels.MuscleBundle) InternalErrorException(maspack.util.InternalErrorException) LinkedList(java.util.LinkedList)

Example 30 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class RigidBodyAgent method initializePrototype.

protected void initializePrototype(ModelComponent comp, Class type) {
    if (type == RigidBody.class) {
        RigidBody mkr = (RigidBody) comp;
        RenderProps.setPointRadius(mkr, getDefaultPointRadius());
    } else {
        throw new InternalErrorException("unimplemented type " + type);
    }
}
Also used : RigidBody(artisynth.core.mechmodels.RigidBody) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

InternalErrorException (maspack.util.InternalErrorException)92 Vector3d (maspack.matrix.Vector3d)9 CompositeProperty (maspack.properties.CompositeProperty)8 Point3d (maspack.matrix.Point3d)7 Property (maspack.properties.Property)7 FemModel3d (artisynth.core.femmodels.FemModel3d)6 Point (artisynth.core.mechmodels.Point)6 ModelComponent (artisynth.core.modelbase.ModelComponent)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Line (maspack.matrix.Line)5 RigidTransform3d (maspack.matrix.RigidTransform3d)5 EditingProperty (maspack.properties.EditingProperty)5 BadLocationException (javax.swing.text.BadLocationException)4 RotationMatrix3d (maspack.matrix.RotationMatrix3d)4 RigidBody (artisynth.core.mechmodels.RigidBody)3 RootModel (artisynth.core.workspace.RootModel)3 File (java.io.File)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 SelectionManager (artisynth.core.gui.selectionManager.SelectionManager)2