use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.
the class GeometryGuiTest method getExampleGeometryCSG.
public static Geometry getExampleGeometryCSG() throws PropertyVetoException, ExpressionException, GeometryException, ImageException {
// translated rotated cube
CSGPrimitive cube = new CSGPrimitive("cube", CSGPrimitive.PrimitiveType.CUBE);
CSGRotation rotatedCube = new CSGRotation("Rotation", new Vect3d(1, 2, 3), Math.PI / 4.0);
rotatedCube.setChild(cube);
// translated sphere
CSGTranslation translatedSphere = new CSGTranslation("translation", new Vect3d(0.5, 0.5, 0.5));
CSGPrimitive sphere = new CSGPrimitive("sphere", CSGPrimitive.PrimitiveType.SPHERE);
translatedSphere.setChild(sphere);
// union
CSGSetOperator csgSetOperator = new CSGSetOperator("difference", OperatorType.DIFFERENCE);
csgSetOperator.addChild(rotatedCube);
csgSetOperator.addChild(translatedSphere);
// scaled union
CSGScale csgScale = new CSGScale("scale", new Vect3d(3, 3, 3));
csgScale.setChild(csgSetOperator);
CSGTranslation csgTranslatedUnion = new CSGTranslation("translationUnion", new Vect3d(5, 5, 5));
csgTranslatedUnion.setChild(csgScale);
Geometry geometry = new Geometry("csg", 3);
CSGObject csgObject = new CSGObject(null, "obj1", 1);
csgObject.setRoot(csgTranslatedUnion);
geometry.getGeometrySpec().addSubVolume(new AnalyticSubVolume("background", new Expression(1.0)));
geometry.getGeometrySpec().addSubVolume(csgObject, true);
geometry.refreshDependencies();
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
return geometry;
}
use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.
the class ComsolModelBuilder method csgVisitor.
private static VCCGeomFeature csgVisitor(CSGNode node, ArrayList<VCCGeomFeature> geomFeatureList, String namePrefix) {
final VCCGeomFeature newFeature;
if (node instanceof CSGPrimitive) {
CSGPrimitive csg = (CSGPrimitive) node;
switch(csg.getType()) {
case CONE:
{
newFeature = new VCCCone(namePrefix + csg.getName());
break;
}
case CUBE:
{
String[] size = new String[] { "2", "2", "2" };
String[] pos = new String[] { "-1", "-1", "-1" };
VCCBlock vccblock = new VCCBlock(namePrefix + csg.getName(), size, pos);
newFeature = vccblock;
break;
}
case CYLINDER:
{
newFeature = new VCCCylinder(namePrefix + csg.getName());
break;
}
case SPHERE:
{
String r = "1";
String[] pos = new String[] { "0", "0", "0" };
newFeature = new VCCSphere(namePrefix + csg.getName(), pos, r);
break;
}
default:
{
throw new RuntimeException("csg primative type '" + csg.getType().name() + "' not yet supported in COMSOL model builder");
}
}
} else if (node instanceof CSGSetOperator) {
CSGSetOperator setOp = (CSGSetOperator) node;
ArrayList<VCCGeomFeature> childSubtrees = new ArrayList<VCCGeomFeature>();
for (CSGNode child : setOp.getChildren()) {
VCCGeomFeature vccChild = csgVisitor(child, geomFeatureList, namePrefix);
childSubtrees.add(vccChild);
}
switch(setOp.getOpType()) {
case DIFFERENCE:
{
if (childSubtrees.size() != 2) {
throw new RuntimeException("expecting exactly two children for CSG difference operator");
}
VCCDifference diff = new VCCDifference(namePrefix + setOp.getName(), Keep.off);
diff.input.add(childSubtrees.get(0));
diff.input2.add(childSubtrees.get(1));
newFeature = diff;
break;
}
case INTERSECTION:
{
if (childSubtrees.size() < 2) {
throw new RuntimeException("expecting two or more children for CSG intersection operator");
}
VCCIntersection intersection = new VCCIntersection(namePrefix + setOp.getName(), Keep.off);
intersection.input.add(childSubtrees.get(0));
newFeature = intersection;
break;
}
case UNION:
{
if (childSubtrees.size() < 2) {
throw new RuntimeException("expecting two or more children for CSG union operator");
}
VCCUnion union = new VCCUnion(namePrefix + setOp.getName(), Keep.off);
union.input.add(childSubtrees.get(0));
newFeature = union;
break;
}
default:
{
throw new RuntimeException("csg set operator '" + setOp.getOpType().name() + "' not yet supported in COMSOL model builder");
}
}
} else if (node instanceof CSGTransformation) {
CSGTransformation transformation = (CSGTransformation) node;
VCCGeomFeature vccChild = csgVisitor(transformation.getChild(), geomFeatureList, namePrefix);
if (transformation instanceof CSGHomogeneousTransformation) {
throw new RuntimeException("unsupported CSG transformation type Homogeneous transformation");
} else if (transformation instanceof CSGRotation) {
CSGRotation rotation = (CSGRotation) transformation;
String[] axis = new String[] { Double.toString(rotation.getAxis().getX()), Double.toString(rotation.getAxis().getY()), Double.toString(rotation.getAxis().getZ()) };
String[] pos = new String[] { "0.0", "0.0", "0.0" };
String rot = Double.toString(rotation.getRotationRadians());
VCCRotate vccrotate = new VCCRotate(namePrefix + rotation.getName(), axis, pos, rot, Keep.off);
vccrotate.input.add(vccChild);
newFeature = vccrotate;
} else if (transformation instanceof CSGScale) {
CSGScale scale = (CSGScale) transformation;
String[] factor = new String[] { Double.toString(scale.getScale().getX()), Double.toString(scale.getScale().getY()), Double.toString(scale.getScale().getZ()) };
String[] pos = new String[] { "0.0", "0.0", "0.0" };
VCCScale vccscale = new VCCScale(namePrefix + scale.getName(), pos, factor, Keep.off);
vccscale.input.add(vccChild);
newFeature = vccscale;
} else if (transformation instanceof CSGTranslation) {
CSGTranslation translation = (CSGTranslation) transformation;
String[] displ = new String[] { Double.toString(translation.getTranslation().getX()), Double.toString(translation.getTranslation().getY()), Double.toString(translation.getTranslation().getZ()) };
VCCMove vccmove = new VCCMove(namePrefix + translation.getName(), displ, Keep.off);
vccmove.input.add(vccChild);
newFeature = vccmove;
} else {
throw new RuntimeException("unsupported CSG transformation type '" + transformation.getClass().getSimpleName() + "'");
}
} else {
throw new RuntimeException("unsupported CSGNode type '" + node.getClass().getSimpleName() + "'");
}
geomFeatureList.add(newFeature);
return newFeature;
}
use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.
the class XmlReader method getCSGTranslation.
private CSGTranslation getCSGTranslation(Element param) throws XmlParseException {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String translateXStr = unMangle(param.getAttributeValue(XMLTags.CSGTranslationXTag));
String translateYStr = unMangle(param.getAttributeValue(XMLTags.CSGTranslationYTag));
String translateZStr = unMangle(param.getAttributeValue(XMLTags.CSGTranslationZTag));
Vect3d translateAxis = new Vect3d(Double.parseDouble(translateXStr), Double.parseDouble(translateYStr), Double.parseDouble(translateZStr));
CSGTranslation csgTranslation = new CSGTranslation(name, translateAxis);
// Retrieve CSGNode - CSGScale element should have one child
Object[] elements = param.getChildren().toArray();
if (elements.length > 1) {
throw new XmlParseException("CSGScale element cannot have more than one child element");
}
CSGNode csgChildNode = getCSGNode((Element) elements[0]);
csgTranslation.setChild(csgChildNode);
return csgTranslation;
}
use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.
the class ClientRequestManager method createNewDocument.
/**
* Insert the method's description here. Creation date: (5/10/2004 3:48:16 PM)
*/
public AsynchClientTask[] createNewDocument(final TopLevelWindowManager requester, final VCDocument.DocumentCreationInfo documentCreationInfo) {
// throws UserCancelException, Exception {
/* asynchronous and not blocking any window */
AsynchClientTask[] taskArray = null;
final int createOption = documentCreationInfo.getOption();
switch(documentCreationInfo.getDocumentType()) {
case BIOMODEL_DOC:
{
AsynchClientTask task1 = new AsynchClientTask("creating biomodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel bioModel = createDefaultBioModelDocument(null);
hashTable.put("doc", bioModel);
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
}
case MATHMODEL_DOC:
{
if ((createOption == VCDocument.MATH_OPTION_NONSPATIAL) || (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS)) {
AsynchClientTask task2 = new AsynchClientTask("creating mathmodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = null;
if (createOption == VCDocument.MATH_OPTION_NONSPATIAL) {
geometry = new Geometry("Untitled", 0);
} else {
geometry = (Geometry) hashTable.get(GEOMETRY_KEY);
}
MathModel mathModel = createMathModel("Untitled", geometry);
mathModel.setName("MathModel" + (getMdiManager().getNumCreatedDocumentWindows() + 1));
hashTable.put("doc", mathModel);
}
};
if (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS) {
AsynchClientTask task1 = createSelectDocTask(requester);
AsynchClientTask task1b = createSelectLoadGeomTask(requester);
taskArray = new AsynchClientTask[] { task1, task1b, task2 };
} else {
taskArray = new AsynchClientTask[] { task2 };
}
break;
} else if (createOption == VCDocument.MATH_OPTION_FROMBIOMODELAPP) {
AsynchClientTask task1 = new AsynchClientTask("select biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// spatial or non-spatial
BioModelInfo bioModelInfo = (BioModelInfo) DialogUtils.getDBTreePanelSelection(requester.getComponent(), getMdiManager().getDatabaseWindowManager().getBioModelDbTreePanel(), "Open", "Select BioModel");
if (bioModelInfo != null) {
// may throw UserCancelException
hashTable.put("bioModelInfo", bioModelInfo);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("find sim contexts in biomodel application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// spatial or non-spatial
// Get the simContexts in the corresponding BioModel
BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
SimulationContext[] simContexts = getDocumentManager().getBioModel(bioModelInfo).getSimulationContexts();
if (simContexts != null) {
// may throw UserCancelException
hashTable.put("simContexts", simContexts);
}
}
};
AsynchClientTask task3 = new AsynchClientTask("create math model from biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
SimulationContext[] simContexts = (SimulationContext[]) hashTable.get("simContexts");
String[] simContextNames = new String[simContexts.length];
if (simContextNames.length == 0) {
throw new RuntimeException("no application is available");
} else {
for (int i = 0; i < simContexts.length; i++) {
simContextNames[i] = simContexts[i].getName();
}
Component component = requester.getComponent();
// Get the simContext names, so that user can choose which simContext math to
// import
String simContextChoice = (String) PopupGenerator.showListDialog(component, simContextNames, "Please select Application");
if (simContextChoice == null) {
throw UserCancelException.CANCEL_DB_SELECTION;
}
SimulationContext chosenSimContext = null;
for (int i = 0; i < simContexts.length; i++) {
if (simContexts[i].getName().equals(simContextChoice)) {
chosenSimContext = simContexts[i];
break;
}
}
Objects.requireNonNull(chosenSimContext);
BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
// Get corresponding mathDesc to create new mathModel and return.
String newName = bioModelInfo.getVersion().getName() + "_" + chosenSimContext.getName();
MathDescription bioMathDesc = chosenSimContext.getMathDescription();
MathDescription newMathDesc = null;
newMathDesc = new MathDescription(newName + "_" + (new Random()).nextInt());
newMathDesc.setGeometry(bioMathDesc.getGeometry());
newMathDesc.read_database(new CommentStringTokenizer(bioMathDesc.getVCML_database()));
newMathDesc.isValid();
MathModel newMathModel = new MathModel(null);
newMathModel.setName(newName);
newMathModel.setMathDescription(newMathDesc);
hashTable.put("doc", newMathModel);
}
}
};
taskArray = new AsynchClientTask[] { task1, task2, task3 };
break;
} else {
throw new RuntimeException("Unknown MathModel Document creation option value=" + documentCreationInfo.getOption());
}
}
case GEOMETRY_DOC:
{
if (createOption == VCDocument.GEOM_OPTION_1D || createOption == VCDocument.GEOM_OPTION_2D || createOption == VCDocument.GEOM_OPTION_3D) {
// analytic
AsynchClientTask task1 = new AsynchClientTask("creating analytic geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), documentCreationInfo.getOption());
geometry.getGeometrySpec().addSubVolume(new AnalyticSubVolume("subdomain0", new Expression(1.0)));
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
hashTable.put("doc", geometry);
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
}
if (createOption == VCDocument.GEOM_OPTION_CSGEOMETRY_3D) {
// constructed solid geometry
AsynchClientTask task1 = new AsynchClientTask("creating constructed solid geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), 3);
Extent extent = geometry.getExtent();
if (extent != null) {
// create a CSGPrimitive of type cube and scale it to the 'extent' components.
// Use this as the default or background CSGObject (subdomain).
// This can be considered as the equivalent of subdomain (with expression) 1.0
// for analyticSubvolume.
// basic cube
CSGPrimitive cube = new CSGPrimitive("cube", CSGPrimitive.PrimitiveType.CUBE);
// scaled cube
double x = extent.getX();
double y = extent.getY();
double z = extent.getZ();
CSGScale scaledCube = new CSGScale("scale", new Vect3d(x / 2.0, y / 2.0, z / 2.0));
scaledCube.setChild(cube);
// translated scaled cube
CSGTranslation translatedScaledCube = new CSGTranslation("translation", new Vect3d(x / 2, y / 2, z / 2));
translatedScaledCube.setChild(scaledCube);
CSGObject csgObject = new CSGObject(null, "subdomain0", 0);
csgObject.setRoot(translatedScaledCube);
geometry.getGeometrySpec().addSubVolume(csgObject, false);
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
hashTable.put("doc", geometry);
}
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
} else {
throw new RuntimeException("Unknown Geometry Document creation option value=" + documentCreationInfo.getOption());
}
}
default:
{
throw new RuntimeException("Unknown default document type: " + documentCreationInfo.getDocumentType());
}
}
return taskArray;
}
use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.
the class CSGObjectTreeCellEditor method getTreeCellEditorComponent.
@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
if (!(value instanceof BioModelNode)) {
return null;
}
Object userObject = ((BioModelNode) value).getUserObject();
CSGObjectTreeCellRenderer.CSGNodeLabel csgNodeLabel = new CSGObjectTreeCellRenderer.CSGNodeLabel();
CSGObjectTreeCellRenderer.getCSGNodeLabel(userObject, csgNodeLabel);
renderer.setOpenIcon(csgNodeLabel.icon);
renderer.setClosedIcon(csgNodeLabel.icon);
renderer.setLeafIcon(csgNodeLabel.icon);
Component component = null;
if (bRenaming) {
realEditor = defaultCellEditor;
component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
if (editingComponent instanceof JTextField) {
String text = null;
JTextField textField = (JTextField) editingComponent;
if (userObject instanceof CSGObject) {
text = ((CSGObject) userObject).getName();
} else if (userObject instanceof CSGNode) {
text = ((CSGNode) userObject).getName();
}
textField.setText(text);
}
} else {
if (userObject instanceof CSGScale || userObject instanceof CSGTranslation) {
realEditor = getVect3dCellEditor();
Vect3d vect3d = null;
if (userObject instanceof CSGScale) {
vect3d = ((CSGScale) userObject).getScale();
} else if (userObject instanceof CSGTranslation) {
vect3d = ((CSGTranslation) userObject).getTranslation();
}
component = super.getTreeCellEditorComponent(tree, vect3d, isSelected, expanded, leaf, row);
} else if (userObject instanceof CSGRotation) {
realEditor = getRotationCellEditor();
component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
}
}
return component;
}
Aggregations