Search in sources :

Example 1 with CSGPrimitive

use of cbit.vcell.geometry.CSGPrimitive 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 2 with CSGPrimitive

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

the class CSGObjectPropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    if (popupMenu == null) {
        popupMenu = new JPopupMenu();
    }
    if (popupMenu.isShowing()) {
        return;
    }
    selectClickPath(e);
    TreePath[] selectedPaths = csgObjectTree.getSelectionPaths();
    boolean bShowPopup = true;
    boolean bTransform = false;
    boolean bApplySetOperator = false;
    boolean bAddPrimitive = false;
    boolean bAddTransformation = false;
    boolean bAddOperator = false;
    boolean bEdit = false;
    boolean bDelete = true;
    if (selectedPaths == null) {
        return;
    }
    for (TreePath tp : selectedPaths) {
        Object obj = tp.getLastPathComponent();
        if (obj == null || !(obj instanceof BioModelNode)) {
            continue;
        }
        BioModelNode selectedNode = (BioModelNode) obj;
        Object userObject = selectedNode.getUserObject();
        if (userObject == csgObject) {
            bDelete = false;
            if (csgObject.getRoot() == null) {
                bAddPrimitive = true;
                bAddOperator = true;
                bAddTransformation = true;
            }
        } else if (userObject instanceof CSGPrimitive) {
            bApplySetOperator = true;
            bTransform = true;
            bAddPrimitive = false;
            bAddOperator = false;
            bAddTransformation = false;
        } else if (userObject instanceof CSGSetOperator) {
            bApplySetOperator = true;
            bTransform = true;
            bAddPrimitive = true;
            bAddOperator = true;
            bAddTransformation = true;
        } else if (userObject instanceof CSGTransformation) {
            bApplySetOperator = true;
            bTransform = true;
            bEdit = true;
            if (((CSGTransformation) userObject).getChild() == null) {
                bAddPrimitive = true;
                bAddOperator = true;
                bAddTransformation = true;
            }
        }
    }
    if (bShowPopup) {
        popupMenu.removeAll();
        if (bAddPrimitive || bAddTransformation || bAddOperator) {
            getAddPrimitiveMenu().setEnabled(bAddPrimitive);
            getAddTransformationMenu().setEnabled(bAddTransformation);
            getAddSetOperatorMenu().setEnabled(bAddOperator);
            popupMenu.add(getAddMenu());
        }
        if (popupMenu.getComponents().length > 0) {
            popupMenu.add(new JSeparator());
        }
        // everything can be renamed
        popupMenu.add(getRenameMenuItem());
        if (bEdit) {
            popupMenu.add(getEditMenuItem());
        }
        if (bDelete) {
            popupMenu.add(getDeleteMenuItem());
        }
        if (bTransform) {
            if (popupMenu.getComponents().length > 0) {
                popupMenu.add(new JSeparator());
            }
            popupMenu.add(getTransformMenu());
        }
        if (bApplySetOperator) {
            if (popupMenu.getComponents().length > 0 && !bTransform) {
                popupMenu.add(new JSeparator());
            }
            popupMenu.add(getApplySetOperatorMenu());
        }
        Point mousePoint = e.getPoint();
        popupMenu.show(csgObjectTree, mousePoint.x, mousePoint.y);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGObject(cbit.vcell.geometry.CSGObject) BioModelNode(cbit.vcell.desktop.BioModelNode) Point(java.awt.Point) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator)

Example 3 with CSGPrimitive

use of cbit.vcell.geometry.CSGPrimitive 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 4 with CSGPrimitive

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

the class XmlReader method getCSGPrimitive.

private CSGPrimitive getCSGPrimitive(Element param) {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String primitiveTypeStr = unMangle(param.getAttributeValue(XMLTags.CSGPrimitiveTypeTag));
    // ---Create the new CSGPrimitive object ---
    PrimitiveType type = CSGPrimitive.PrimitiveType.valueOf(primitiveTypeStr);
    CSGPrimitive csgPrimitive = new CSGPrimitive(name, type);
    return csgPrimitive;
}
Also used : CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) PrimitiveType(cbit.vcell.geometry.CSGPrimitive.PrimitiveType)

Example 5 with CSGPrimitive

use of cbit.vcell.geometry.CSGPrimitive 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)

Aggregations

CSGPrimitive (cbit.vcell.geometry.CSGPrimitive)7 CSGObject (cbit.vcell.geometry.CSGObject)5 CSGSetOperator (cbit.vcell.geometry.CSGSetOperator)5 CSGScale (cbit.vcell.geometry.CSGScale)4 CSGTransformation (cbit.vcell.geometry.CSGTransformation)4 CSGTranslation (cbit.vcell.geometry.CSGTranslation)4 CSGRotation (cbit.vcell.geometry.CSGRotation)3 Vect3d (cbit.vcell.render.Vect3d)3 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)2 CSGHomogeneousTransformation (cbit.vcell.geometry.CSGHomogeneousTransformation)2 CSGNode (cbit.vcell.geometry.CSGNode)2 PrimitiveType (cbit.vcell.geometry.CSGPrimitive.PrimitiveType)2 Geometry (cbit.vcell.geometry.Geometry)2 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)2 Expression (cbit.vcell.parser.Expression)2 Point (java.awt.Point)2 ImageException (cbit.image.ImageException)1 BioModel (cbit.vcell.biomodel.BioModel)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 SetMathDescription (cbit.vcell.client.task.SetMathDescription)1