Search in sources :

Example 1 with CSGNode

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

use of cbit.vcell.geometry.CSGNode 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;
}
Also used : CSGTranslation(cbit.vcell.geometry.CSGTranslation) CSGNode(cbit.vcell.geometry.CSGNode) VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) PointObject(cbit.vcell.mapping.spatial.PointObject) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject) CSGObject(cbit.vcell.geometry.CSGObject) Vect3d(cbit.vcell.render.Vect3d)

Example 3 with CSGNode

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

the class XmlReader method getCSGObject.

public CSGObject getCSGObject(Element param, KeyValue keyFromDB) throws XmlParseException {
    // retrieve the attributes
    String name = param.getAttributeValue(XMLTags.NameAttrTag);
    int handle = Integer.parseInt(param.getAttributeValue(XMLTags.HandleAttrTag));
    // process the key
    KeyValue key = null;
    String temp = param.getAttributeValue(XMLTags.KeyValueAttrTag);
    if (temp != null && temp.length() > 0 && this.readKeysFlag) {
        key = new KeyValue(temp);
    }
    if (keyFromDB != null) {
        key = keyFromDB;
    }
    // Retrieve CSGObject CSGNode - CSGObject element should have one child (the root node of the CSGObject)
    Object[] elements = param.getChildren().toArray();
    if (elements.length > 1) {
        throw new XmlParseException("CSGObject subvolume element cannot have more than one child element");
    }
    CSGNode csgRootNode = getCSGNode((Element) elements[0]);
    // Create the CSGObject
    CSGObject newCSGObjectSubvol = new CSGObject(key, name, handle);
    newCSGObjectSubvol.setRoot(csgRootNode);
    return newCSGObjectSubvol;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) CSGNode(cbit.vcell.geometry.CSGNode) VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) PointObject(cbit.vcell.mapping.spatial.PointObject) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject) CSGObject(cbit.vcell.geometry.CSGObject) CSGObject(cbit.vcell.geometry.CSGObject)

Example 4 with CSGNode

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

the class CSGObjectPropertiesPanel method transformOrApplySetOperator.

private boolean transformOrApplySetOperator(CSGNode newCsgNode) {
    if (newCsgNode == null) {
        return false;
    }
    Object obj = csgObjectTree.getLastSelectedPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return false;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    Object selectedUserObject = selectedNode.getUserObject();
    if (!(selectedUserObject instanceof CSGNode)) {
        return false;
    }
    CSGNode selectedCSGNode = (CSGNode) selectedUserObject;
    TreeNode parentNode = selectedNode.getParent();
    if (parentNode == null || !(parentNode instanceof BioModelNode)) {
        return false;
    }
    Object parentObject = ((BioModelNode) parentNode).getUserObject();
    if (newCsgNode instanceof CSGTransformation) {
        CSGTransformation csgTransformation = (CSGTransformation) newCsgNode;
        csgTransformation.setChild(selectedCSGNode);
    } else if (newCsgNode instanceof CSGSetOperator) {
        CSGSetOperator csgSetOperator = (CSGSetOperator) newCsgNode;
        csgSetOperator.addChild(selectedCSGNode);
    }
    if (parentObject == csgObject) {
        csgObject.setRoot(newCsgNode);
    } else if (parentObject instanceof CSGSetOperator) {
        CSGSetOperator parentCSGSetOperator = (CSGSetOperator) parentObject;
        int index = parentCSGSetOperator.indexOf(selectedCSGNode);
        if (index >= 0) {
            parentCSGSetOperator.setChild(index, newCsgNode);
            return true;
        }
    } else if (parentObject instanceof CSGTransformation) {
        CSGTransformation parentCSGTransformation = (CSGTransformation) parentObject;
        parentCSGTransformation.setChild(newCsgNode);
        return true;
    }
    return false;
}
Also used : TreeNode(javax.swing.tree.TreeNode) CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGNode(cbit.vcell.geometry.CSGNode) CSGObject(cbit.vcell.geometry.CSGObject) BioModelNode(cbit.vcell.desktop.BioModelNode) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator)

Example 5 with CSGNode

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

the class CSGObjectPropertiesPanel method deleteNode.

private void deleteNode() {
    Object obj = csgObjectTree.getLastSelectedPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    Object selectedUserObject = selectedNode.getUserObject();
    if (!(selectedUserObject instanceof CSGNode)) {
        return;
    }
    CSGNode selectedCSGNode = (CSGNode) selectedUserObject;
    TreeNode parentNode = selectedNode.getParent();
    if (parentNode == null || !(parentNode instanceof BioModelNode)) {
        return;
    }
    Object parentObject = ((BioModelNode) parentNode).getUserObject();
    if (parentObject == csgObject) {
        csgObject.setRoot(null);
    } else if (parentObject instanceof CSGSetOperator) {
        CSGSetOperator csgSetOperator = (CSGSetOperator) parentObject;
        csgSetOperator.removeChild(selectedCSGNode);
    } else if (parentObject instanceof CSGTransformation) {
        CSGTransformation csgTransformation = (CSGTransformation) parentObject;
        csgTransformation.setChild(null);
    }
    updateCSGObject(parentObject);
}
Also used : TreeNode(javax.swing.tree.TreeNode) CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGNode(cbit.vcell.geometry.CSGNode) CSGObject(cbit.vcell.geometry.CSGObject) BioModelNode(cbit.vcell.desktop.BioModelNode) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator)

Aggregations

CSGNode (cbit.vcell.geometry.CSGNode)13 CSGObject (cbit.vcell.geometry.CSGObject)9 CSGSetOperator (cbit.vcell.geometry.CSGSetOperator)5 Vect3d (cbit.vcell.render.Vect3d)5 CSGRotation (cbit.vcell.geometry.CSGRotation)4 CSGScale (cbit.vcell.geometry.CSGScale)4 CSGTransformation (cbit.vcell.geometry.CSGTransformation)4 CSGTranslation (cbit.vcell.geometry.CSGTranslation)4 PointObject (cbit.vcell.mapping.spatial.PointObject)4 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)4 SurfaceRegionObject (cbit.vcell.mapping.spatial.SurfaceRegionObject)4 VolumeRegionObject (cbit.vcell.mapping.spatial.VolumeRegionObject)4 BioModelNode (cbit.vcell.desktop.BioModelNode)3 CSGHomogeneousTransformation (cbit.vcell.geometry.CSGHomogeneousTransformation)2 CSGPrimitive (cbit.vcell.geometry.CSGPrimitive)2 ArrayList (java.util.ArrayList)2 TreeNode (javax.swing.tree.TreeNode)2 Element (org.jdom.Element)2 VCCGeomFeature (org.vcell.solver.comsol.model.VCCGeomFeature)2 VCCDifference (org.vcell.solver.comsol.model.VCCGeomFeature.VCCDifference)2