Search in sources :

Example 61 with InternalErrorException

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

the class FemElement3d method copy.

@Override
public FemElement3d copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
    FemElement3d e = (FemElement3d) super.copy(flags, copyMap);
    e.myNodes = new FemNode3d[numNodes()];
    for (int i = 0; i < numNodes(); i++) {
        FemNode3d n = myNodes[i];
        FemNode3d newn = (FemNode3d) ComponentUtils.maybeCopy(flags, copyMap, n);
        if (newn == null) {
            throw new InternalErrorException("No duplicated node found for node number " + n.getNumber());
        }
        e.myNodes[i] = newn;
    }
    e.myNbrs = null;
    // e.myAvgGNx = null;
    e.myIncompressConstraints = null;
    // e.myIncompressConstraints1 = null;
    // e.myIncompressConstraints2 = null;
    // Note that frame information is not presently duplicated
    e.myIntegrationData = null;
    e.myIntegrationDataValid = false;
    // protected SymmetricMatrix3d myAvgStress = new SymmetricMatrix3d();
    e.myLagrangePressures = new double[numPressureVals()];
    // e.myLagrangePressure = 0;
    e.myWarper = null;
    e.myIncompressIdx = -1;
    // e.myLocalIncompressIdx = -1;
    e.setElementWidgetSizeMode(myElementWidgetSizeMode);
    if (myElementWidgetSizeMode == PropertyMode.Explicit) {
        e.setElementWidgetSize(myElementWidgetSize);
    }
    e.myAuxMaterials = null;
    if (myAuxMaterials != null) {
        for (AuxiliaryMaterial a : myAuxMaterials) {
            try {
                e.addAuxiliaryMaterial((AuxiliaryMaterial) a.clone());
            } catch (Exception ex) {
                throw new InternalErrorException("Can't clone " + a.getClass());
            }
        }
    }
    return e;
}
Also used : InternalErrorException(maspack.util.InternalErrorException) Point(artisynth.core.mechmodels.Point) InternalErrorException(maspack.util.InternalErrorException)

Example 62 with InternalErrorException

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

the class ExcitationUtils method combineWithAncestor.

public static double combineWithAncestor(ExcitationComponent ecomp, ExcitationSourceList sources, int height, CombinationRule rule) {
    double net = ecomp.getExcitation();
    double ea = getAncestorNetExcitation(ecomp, height);
    switch(rule) {
        case Sum:
            {
                net += ea;
                if (sources != null) {
                    for (int i = 0; i < sources.size(); i++) {
                        ExcitationSource src = sources.get(i);
                        net += src.myGain * src.myComp.getNetExcitation();
                    }
                }
                break;
            }
        default:
            {
                throw new InternalErrorException("combination method not implemented for " + rule);
            }
    }
    return net;
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 63 with InternalErrorException

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

the class MeshBase method clone.

/**
 * Creates a clone of this mesh.
 */
public MeshBase clone() {
    MeshBase mesh = null;
    try {
        mesh = (MeshBase) super.clone();
    } catch (CloneNotSupportedException e) {
        throw new InternalErrorException("Can't clone MeshBase: " + e);
    }
    mesh.myVertices = new ArrayList<Vertex3d>();
    for (int i = 0; i < myVertices.size(); i++) {
        mesh.addVertex(myVertices.get(i).pnt);
    }
    mesh.XMeshToWorld = new RigidTransform3d(XMeshToWorld);
    // will regenerate
    mesh.myIndexOffsets = null;
    if (myNormals != null) {
        mesh.myNormals = new ArrayList<Vector3d>();
        for (int i = 0; i < myNormals.size(); i++) {
            mesh.myNormals.add(new Vector3d(myNormals.get(i)));
        }
    }
    if (myNormalIndices != null) {
        // should be same as myNormals != null
        mesh.myNormalIndices = Arrays.copyOf(myNormalIndices, myNormalIndices.length);
    }
    mesh.myRenderNormalsValidP = false;
    if (myTextureCoords != null) {
        mesh.myTextureCoords = new ArrayList<Vector3d>();
        for (int i = 0; i < myTextureCoords.size(); i++) {
            mesh.myTextureCoords.add(new Vector3d(myTextureCoords.get(i)));
        }
        mesh.myTextureIndices = Arrays.copyOf(myTextureIndices, myTextureIndices.length);
    }
    mesh.myVertexColoringP = myVertexColoringP;
    mesh.myFeatureColoringP = myFeatureColoringP;
    if (myColors != null) {
        mesh.myColors = new ArrayList<float[]>();
        for (int i = 0; i < myColors.size(); i++) {
            mesh.myColors.add(copyColor(myColors.get(i)));
        }
        int[] colorIndices = getColorIndices();
        mesh.myColorIndices = Arrays.copyOf(colorIndices, colorIndices.length);
    }
    if (myRenderProps != null) {
        mesh.setRenderProps(myRenderProps);
    } else {
        mesh.myRenderProps = null;
    }
    mesh.setFixed(isFixed());
    mesh.setColorsFixed(isColorsFixed());
    mesh.setTextureCoordsFixed(isTextureCoordsFixed());
    mesh.setColorInterpolation(getColorInterpolation());
    mesh.setRenderBuffered(isRenderBuffered());
    mesh.myLocalMinCoords = new Point3d();
    mesh.myLocalMaxCoords = new Point3d();
    mesh.myLocalBoundsValid = false;
    mesh.myWorldMinCoords = new Point3d();
    mesh.myWorldMaxCoords = new Point3d();
    mesh.myWorldBoundsValid = false;
    mesh.myWorldRadius = -1;
    mesh.myXMeshToWorldRender = null;
    mesh.setName(getName());
    return mesh;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) InternalErrorException(maspack.util.InternalErrorException)

Example 64 with InternalErrorException

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

the class ProbeInfo method duplicateProbe.

/**
 * duplicate the probe
 */
private void duplicateProbe() {
    // don't need to supply a copyMap to copy because it won't be used
    Probe oldProbe = getProbe();
    if (!(oldProbe.getParent() instanceof MutableCompositeComponent)) {
        throw new InternalErrorException("Probe's parent is not editable");
    }
    Probe newProbe = null;
    try {
        newProbe = (Probe) getProbe().clone();
    } catch (Exception e) {
        e.printStackTrace();
        throw new InternalErrorException("Cannot clone probe of type " + getProbe().getClass());
    }
    // set start time so that probe follows right after this one ...
    double startTime = getProbe().getStartTime();
    double stopTime = getProbe().getStopTime();
    newProbe.setStartTime(stopTime);
    newProbe.setStopTime(stopTime + (stopTime - startTime));
    AddComponentsCommand cmd = new AddComponentsCommand("duplicate probe", newProbe, (MutableCompositeComponent) oldProbe.getParent());
    getMain().getUndoManager().saveStateAndExecute(cmd);
    SelectionManager selman = getMain().getSelectionManager();
    selman.removeSelected(oldProbe);
    selman.addSelected(newProbe);
// myController.deselectAllProbes(); XXX need to fix?
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) InternalErrorException(maspack.util.InternalErrorException) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) WayPointProbe(artisynth.core.probes.WayPointProbe) Probe(artisynth.core.probes.Probe) NumericInputProbe(artisynth.core.probes.NumericInputProbe) InternalErrorException(maspack.util.InternalErrorException) IOException(java.io.IOException)

Example 65 with InternalErrorException

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

the class FemModel3dAgent method createPreviewModel.

private void createPreviewModel() {
    fem = new FemModel3d();
    setProperties(fem, getPrototypeComponent(myComponentType));
    setProperties(myPrototype, myPrototype);
    FemElementType elemType = null;
    FemMeshType meshType = (FemMeshType) meshSelector.getValue();
    if (elemSelector.isEnabledAll()) {
        elemType = (FemElementType) elemSelector.getValue();
    }
    switch(meshType) {
        case Grid:
            {
                VectorBase dims = gridDimField.getVectorValue();
                int[] divs = gridDivField.getVectorValue();
                FemFactory.createGrid(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
                break;
            }
        case Tube:
            {
                VectorBase dims = tubeDimField.getVectorValue();
                int[] divs = tubeDivField.getVectorValue();
                FemFactory.createTube(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
                break;
            }
        case Torus:
            {
                VectorBase dims = torusDimField.getVectorValue();
                int[] divs = torusDivField.getVectorValue();
                FemFactory.createTorus(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
                break;
            }
        case Sphere:
            {
                int nodes = (Integer) sphereNodesField.getValue();
                String meshPath;
                if (nodes == SPHERE_NODE_OPTIONS[0]) {
                    meshPath = ArtisynthPath.getHomeRelativePath(SPHERE_54_MESH_PATH, ".");
                } else if (nodes == SPHERE_NODE_OPTIONS[1]) {
                    meshPath = ArtisynthPath.getHomeRelativePath(SPHERE_196_MESH_PATH, ".");
                } else {
                    EditorUtils.showError(myDisplay, "Invalid number of nodes for sphere");
                    return;
                }
                try {
                    TetGenReader.read(fem, 1000, meshPath + ".node", meshPath + ".ele", new Vector3d(1, 1, 1));
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case Extrusion:
            {
                double d = extrusDepthField.getDoubleValue();
                int n = extrusLayersField.getIntValue();
                String meshFileName = extrusFileField.getStringValue();
                try {
                    PolygonalMesh mesh = new PolygonalMesh(new File(meshFileName));
                    FemFactory.createExtrusion(fem, elemType, n, d, 0, mesh);
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case AnsysMesh:
            {
                String nodeFileName = ansysNodeFileField.getStringValue();
                String elemFileName = ansysElemFileField.getStringValue();
                try {
                    AnsysReader.read(fem, nodeFileName, elemFileName, 1000, null, /*options=*/
                    0);
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case TetgenMesh:
            {
                String nodeFileName = tetgenNodeFileField.getStringValue();
                String eleFileName = tetgenEleFileField.getStringValue();
                try {
                    TetGenReader.read(fem, 1000, nodeFileName, eleFileName, new Vector3d(1, 1, 1));
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case UCDMesh:
            {
                String ucdFileName = ucdMeshFileField.getStringValue();
                try {
                    UCDReader.read(fem, ucdFileName, 1000);
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case SurfaceMesh:
            {
                String objFileName = surfaceMeshFileField.getStringValue();
                PolygonalMesh surfaceMesh = null;
                try {
                    surfaceMesh = new PolygonalMesh(new File(objFileName));
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                try {
                    FemFactory.createFromMesh(fem, surfaceMesh, /*quality=*/
                    2.0);
                } catch (Exception e) {
                    e.printStackTrace();
                    EditorUtils.showError(myDisplay, "Error tessellating mesh: " + e.getMessage());
                    return;
                }
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented mesh type");
            }
    }
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(positionField.getVectorValue());
    X.R.setAxisAngle(orientationField.getAxisAngleValue());
    PolygonalMesh mesh = fem.getSurfaceMesh();
    RenderProps props = mesh.createRenderProps();
    props.setFaceStyle(Renderer.FaceStyle.NONE);
    props.setDrawEdges(true);
    props.setLineColor(Color.LIGHT_GRAY);
    mesh.setRenderProps(props);
    mesh.setMeshToWorld(X);
    mesh.setFixed(false);
    mesh.setRenderBuffered(false);
    if (meshPropPanel.getComponentIndex(scaleField) != -1) {
        scaleField.maskValueChangeListeners(true);
        scaleField.setValue(1.0);
        scaleField.maskValueChangeListeners(false);
        lastScale = 1.0;
    }
    myMain.getWorkspace().getViewerManager().addRenderable(mesh);
    rotator = new Transrotator3d();
    GLViewer viewer = myMain.getMain().getViewer();
    rotator.setDraggerToWorld(X);
    rotator.setSize(viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6);
    rotator.addListener(new FemModelDraggerListener());
    myMain.getWorkspace().getViewerManager().addDragger(rotator);
    myMain.rerender();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemModel3d(artisynth.core.femmodels.FemModel3d) FemElementType(artisynth.core.femmodels.FemFactory.FemElementType) RenderProps(maspack.render.RenderProps) Transrotator3d(maspack.render.Transrotator3d) InternalErrorException(maspack.util.InternalErrorException) PolygonalMesh(maspack.geometry.PolygonalMesh) InternalErrorException(maspack.util.InternalErrorException) GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d) VectorBase(maspack.matrix.VectorBase) File(java.io.File)

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