Search in sources :

Example 6 with CSGSetOperator

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;
}
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 7 with CSGSetOperator

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;
}
Also used : Element(org.jdom.Element) CSGNode(cbit.vcell.geometry.CSGNode) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator) OperatorType(cbit.vcell.geometry.CSGSetOperator.OperatorType)

Example 8 with 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);
}
Also used : CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGObject(cbit.vcell.geometry.CSGObject) PrimitiveType(cbit.vcell.geometry.CSGPrimitive.PrimitiveType) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator) TransformationType(cbit.vcell.geometry.CSGTransformation.TransformationType) Point(java.awt.Point) OperatorType(cbit.vcell.geometry.CSGSetOperator.OperatorType)

Example 9 with CSGSetOperator

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;
}
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

CSGSetOperator (cbit.vcell.geometry.CSGSetOperator)9 CSGObject (cbit.vcell.geometry.CSGObject)7 CSGTransformation (cbit.vcell.geometry.CSGTransformation)7 CSGNode (cbit.vcell.geometry.CSGNode)5 CSGPrimitive (cbit.vcell.geometry.CSGPrimitive)5 BioModelNode (cbit.vcell.desktop.BioModelNode)4 CSGRotation (cbit.vcell.geometry.CSGRotation)3 CSGScale (cbit.vcell.geometry.CSGScale)3 CSGTranslation (cbit.vcell.geometry.CSGTranslation)3 CSGHomogeneousTransformation (cbit.vcell.geometry.CSGHomogeneousTransformation)2 OperatorType (cbit.vcell.geometry.CSGSetOperator.OperatorType)2 Vect3d (cbit.vcell.render.Vect3d)2 Point (java.awt.Point)2 TreeNode (javax.swing.tree.TreeNode)2 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 PrimitiveType (cbit.vcell.geometry.CSGPrimitive.PrimitiveType)1 TransformationType (cbit.vcell.geometry.CSGTransformation.TransformationType)1 Geometry (cbit.vcell.geometry.Geometry)1 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)1 Expression (cbit.vcell.parser.Expression)1