use of artisynth.core.femmodels.FemFactory.FemElementType in project artisynth_core by artisynth.
the class FemModel3dAgent method updateElemSelector.
private void updateElemSelector() {
FemMeshType value = (FemMeshType) meshSelector.getValue();
geometryPanel.removeWidget(elemSelector);
if (value == FemMeshType.AnsysMesh || value == FemMeshType.TetgenMesh || value == FemMeshType.UCDMesh || value == FemMeshType.SurfaceMesh || value == FemMeshType.Sphere) {
elemSelector.setEnabledAll(false);
} else if (value == FemMeshType.Grid) {
elemSelector = new EnumSelector("element type", FemElementType.values());
} else if (value == FemMeshType.Tube || value == FemMeshType.Torus || value == FemMeshType.Extrusion) {
elemSelector = new EnumSelector("element type", new FemElementType[] { FemElementType.Tet, FemElementType.Hex, FemElementType.QuadTet, FemElementType.QuadHex });
}
elemSelector.addValueChangeListener(this);
geometryPanel.addWidget(elemSelector);
}
use of artisynth.core.femmodels.FemFactory.FemElementType 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();
}
Aggregations