use of cbit.vcell.geometry.CSGSetOperator 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.CSGSetOperator in project vcell by virtualcell.
the class XmlReader method getCSGSetOperator.
private CSGSetOperator getCSGSetOperator(Element param) throws XmlParseException {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String operatorTypeStr = unMangle(param.getAttributeValue(XMLTags.CSGSetOperatorTypeTag));
// ---Create the new CSGSetOperator object ---
OperatorType type = CSGSetOperator.OperatorType.valueOf(operatorTypeStr);
CSGSetOperator csgSetOperator = new CSGSetOperator(name, type);
List<Element> children = param.getChildren();
Iterator<Element> iterator = children.iterator();
int count = 0;
while (iterator.hasNext()) {
Element tempElement = iterator.next();
CSGNode csgNode = getCSGNode(tempElement);
csgSetOperator.addChild(csgNode);
}
return csgSetOperator;
}
use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class CSGObjectPropertiesPanel method menuItemClicked.
private void menuItemClicked(Object source) {
boolean bGeometryChanged = false;
boolean bFoundClickedMenuItem = false;
Object objectToBeSelected = null;
if (!bFoundClickedMenuItem) {
PrimitiveType[] values = CSGPrimitive.PrimitiveType.values();
int numTypes = values.length;
for (int i = 0; i < numTypes; i++) {
if (source == addPrimitiveMenuItems[i]) {
bFoundClickedMenuItem = true;
CSGPrimitive csgPrimitive = new CSGPrimitive(csgObject.getFreeName(values[i]), values[i]);
objectToBeSelected = csgPrimitive;
bGeometryChanged = addNode(csgPrimitive);
break;
}
}
}
if (!bFoundClickedMenuItem) {
OperatorType[] values = CSGSetOperator.OperatorType.values();
int numTypes = values.length;
for (int i = 0; i < numTypes; i++) {
if (source == addSetOperatorMenuItems[i]) {
bFoundClickedMenuItem = true;
CSGSetOperator csgSetOperator = new CSGSetOperator(csgObject.getFreeName(values[i]), values[i]);
objectToBeSelected = csgSetOperator;
bGeometryChanged = addNode(csgSetOperator);
break;
}
}
}
if (!bFoundClickedMenuItem) {
TransformationType[] values = CSGTransformation.TransformationType.values();
int numTypes = values.length;
for (int i = 0; i < numTypes; i++) {
if (source == addTranformationMenuItems[i]) {
bFoundClickedMenuItem = true;
CSGTransformation csgTransformation = createNewCSGTransformation(values[i]);
objectToBeSelected = csgTransformation;
bGeometryChanged = addNode(csgTransformation);
break;
}
}
}
if (!bFoundClickedMenuItem) {
TransformationType[] values = CSGTransformation.TransformationType.values();
int numTypes = values.length;
for (int i = 0; i < numTypes; i++) {
if (source == tranformMenuItems[i]) {
bFoundClickedMenuItem = true;
CSGTransformation csgTransformation = createNewCSGTransformation(values[i]);
objectToBeSelected = csgTransformation;
bGeometryChanged = transformOrApplySetOperator(csgTransformation);
break;
}
}
}
if (!bFoundClickedMenuItem) {
OperatorType[] values = CSGSetOperator.OperatorType.values();
int numTypes = values.length;
for (int i = 0; i < numTypes; i++) {
if (source == applySetOperatorMenuItems[i]) {
bFoundClickedMenuItem = true;
CSGSetOperator csgSetOperator = new CSGSetOperator(csgObject.getFreeName(values[i]), values[i]);
objectToBeSelected = csgSetOperator;
bGeometryChanged = transformOrApplySetOperator(csgSetOperator);
break;
}
}
}
if (!bGeometryChanged) {
return;
}
updateCSGObject(objectToBeSelected);
}
use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class CSGObjectTreeCellRenderer method getCSGNodeLabel.
static CSGNodeLabel getCSGNodeLabel(Object object, CSGNodeLabel csgNodeLabel) {
if (object instanceof CSGObject) {
CSGObject csgObject = (CSGObject) object;
csgNodeLabel.text = csgObject.getName();
java.awt.Color handleColor = new java.awt.Color(getColorMap()[csgObject.getHandle()]);
csgNodeLabel.icon = new ColorIcon(15, 15, handleColor);
} else if (object instanceof CSGNode) {
CSGNode csgNode = (CSGNode) object;
csgNodeLabel.text = csgNode.getName();
if (csgNode instanceof CSGPrimitive) {
CSGPrimitive csgPrimitive = (CSGPrimitive) csgNode;
switch(csgPrimitive.getType()) {
case CONE:
csgNodeLabel.icon = VCellIcons.csgConeIcon;
break;
case CUBE:
csgNodeLabel.icon = VCellIcons.csgCubeIcon;
break;
case CYLINDER:
csgNodeLabel.icon = VCellIcons.csgCylinderIcon;
break;
case SPHERE:
csgNodeLabel.icon = VCellIcons.csgSphereIcon;
break;
}
return csgNodeLabel;
}
if (csgNode instanceof CSGSetOperator) {
CSGSetOperator csgSetOperator = (CSGSetOperator) csgNode;
switch(csgSetOperator.getOpType()) {
case DIFFERENCE:
csgNodeLabel.icon = VCellIcons.csgSetDifferenceIcon;
break;
case INTERSECTION:
csgNodeLabel.icon = VCellIcons.csgSetIntersectionIcon;
break;
case UNION:
csgNodeLabel.icon = VCellIcons.csgSetUnionIcon;
break;
}
}
if (csgNode instanceof CSGTransformation) {
if (csgNode instanceof CSGRotation) {
CSGRotation csgRotation = (CSGRotation) csgNode;
Vect3d axis = csgRotation.getAxis();
double radius = csgRotation.getRotationRadians();
csgNodeLabel.text += ", radian=" + radius + ", axis=" + CSGObjectPropertiesPanel.getVect3dDescription(axis);
csgNodeLabel.icon = VCellIcons.csgRotationIcon;
} else if (csgNode instanceof CSGTranslation) {
CSGTranslation csgTranslation = (CSGTranslation) csgNode;
Vect3d translation = csgTranslation.getTranslation();
csgNodeLabel.text += ", Translation=" + CSGObjectPropertiesPanel.getVect3dDescription(translation);
csgNodeLabel.icon = VCellIcons.csgTranslationIcon;
} else if (csgNode instanceof CSGScale) {
CSGScale csgScale = (CSGScale) csgNode;
Vect3d scale = csgScale.getScale();
csgNodeLabel.text += ", Scale=" + CSGObjectPropertiesPanel.getVect3dDescription(scale);
csgNodeLabel.icon = VCellIcons.csgScaleIcon;
} else if (csgNode instanceof CSGHomogeneousTransformation) {
csgNodeLabel.icon = null;
}
}
}
return null;
}
Aggregations