Search in sources :

Example 1 with CSGRotation

use of cbit.vcell.geometry.CSGRotation 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;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) CSGTranslation(cbit.vcell.geometry.CSGTranslation) Expression(cbit.vcell.parser.Expression) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGObject(cbit.vcell.geometry.CSGObject) CSGRotation(cbit.vcell.geometry.CSGRotation) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) Vect3d(cbit.vcell.render.Vect3d) CSGScale(cbit.vcell.geometry.CSGScale)

Example 2 with CSGRotation

use of cbit.vcell.geometry.CSGRotation 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;
}
Also used : VCCDifference(org.vcell.solver.comsol.model.VCCGeomFeature.VCCDifference) VCCCone(org.vcell.solver.comsol.model.VCCGeomFeature.VCCCone) VCCUnion(org.vcell.solver.comsol.model.VCCGeomFeature.VCCUnion) CSGTranslation(cbit.vcell.geometry.CSGTranslation) CSGTransformation(cbit.vcell.geometry.CSGTransformation) VCCMove(org.vcell.solver.comsol.model.VCCGeomFeature.VCCMove) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) VCCBlock(org.vcell.solver.comsol.model.VCCGeomFeature.VCCBlock) ArrayList(java.util.ArrayList) CSGNode(cbit.vcell.geometry.CSGNode) VCCSphere(org.vcell.solver.comsol.model.VCCGeomFeature.VCCSphere) VCCIntersection(org.vcell.solver.comsol.model.VCCGeomFeature.VCCIntersection) CSGRotation(cbit.vcell.geometry.CSGRotation) CSGScale(cbit.vcell.geometry.CSGScale) VCCScale(org.vcell.solver.comsol.model.VCCGeomFeature.VCCScale) VCCCylinder(org.vcell.solver.comsol.model.VCCGeomFeature.VCCCylinder) CSGHomogeneousTransformation(cbit.vcell.geometry.CSGHomogeneousTransformation) VCCRotate(org.vcell.solver.comsol.model.VCCGeomFeature.VCCRotate) VCCGeomFeature(org.vcell.solver.comsol.model.VCCGeomFeature) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator)

Example 3 with CSGRotation

use of cbit.vcell.geometry.CSGRotation 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;
}
Also used : CSGTranslation(cbit.vcell.geometry.CSGTranslation) CSGNode(cbit.vcell.geometry.CSGNode) BioModelNode(cbit.vcell.desktop.BioModelNode) JTextField(javax.swing.JTextField) CSGRotation(cbit.vcell.geometry.CSGRotation) CSGScale(cbit.vcell.geometry.CSGScale) Vect3d(cbit.vcell.render.Vect3d) CSGObject(cbit.vcell.geometry.CSGObject) Component(java.awt.Component) CSGObject(cbit.vcell.geometry.CSGObject)

Example 4 with CSGRotation

use of cbit.vcell.geometry.CSGRotation in project vcell by virtualcell.

the class Xmlproducer method getXML.

private Element getXML(CSGTransformation param) {
    Element csgTransformationElement = null;
    // defer it to subclasses to get attributes
    if (param instanceof CSGHomogeneousTransformation) {
        csgTransformationElement = getXML((CSGHomogeneousTransformation) param);
    } else if (param instanceof CSGRotation) {
        csgTransformationElement = getXML((CSGRotation) param);
    } else if (param instanceof CSGScale) {
        csgTransformationElement = getXML((CSGScale) param);
    } else if (param instanceof CSGTranslation) {
        csgTransformationElement = getXML((CSGTranslation) param);
    }
    // add child CSGNode on which the transformation is applied
    Element csgNodeElement = getXML(param.getChild());
    csgTransformationElement.addContent(csgNodeElement);
    return csgTransformationElement;
}
Also used : CSGTranslation(cbit.vcell.geometry.CSGTranslation) CSGHomogeneousTransformation(cbit.vcell.geometry.CSGHomogeneousTransformation) Element(org.jdom.Element) CSGRotation(cbit.vcell.geometry.CSGRotation) CSGScale(cbit.vcell.geometry.CSGScale)

Example 5 with CSGRotation

use of cbit.vcell.geometry.CSGRotation 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;
}
Also used : ColorIcon(org.vcell.util.gui.ColorIcon) CSGTranslation(cbit.vcell.geometry.CSGTranslation) CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGNode(cbit.vcell.geometry.CSGNode) CSGRotation(cbit.vcell.geometry.CSGRotation) Vect3d(cbit.vcell.render.Vect3d) CSGScale(cbit.vcell.geometry.CSGScale) CSGHomogeneousTransformation(cbit.vcell.geometry.CSGHomogeneousTransformation) CSGObject(cbit.vcell.geometry.CSGObject) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator)

Aggregations

CSGRotation (cbit.vcell.geometry.CSGRotation)6 CSGScale (cbit.vcell.geometry.CSGScale)5 CSGTranslation (cbit.vcell.geometry.CSGTranslation)5 CSGNode (cbit.vcell.geometry.CSGNode)4 CSGObject (cbit.vcell.geometry.CSGObject)4 Vect3d (cbit.vcell.render.Vect3d)4 CSGHomogeneousTransformation (cbit.vcell.geometry.CSGHomogeneousTransformation)3 CSGPrimitive (cbit.vcell.geometry.CSGPrimitive)3 CSGSetOperator (cbit.vcell.geometry.CSGSetOperator)3 CSGTransformation (cbit.vcell.geometry.CSGTransformation)2 BioModelNode (cbit.vcell.desktop.BioModelNode)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 Geometry (cbit.vcell.geometry.Geometry)1 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)1 PointObject (cbit.vcell.mapping.spatial.PointObject)1 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)1 SurfaceRegionObject (cbit.vcell.mapping.spatial.SurfaceRegionObject)1 VolumeRegionObject (cbit.vcell.mapping.spatial.VolumeRegionObject)1 Expression (cbit.vcell.parser.Expression)1 Component (java.awt.Component)1