Search in sources :

Example 6 with GeometryThumbnailImageFactoryAWT

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

the class GeometryGuiTest method main.

public static void main(java.lang.String[] args) {
    try {
        javax.swing.JFrame frame = new javax.swing.JFrame();
        GeometryViewer aGeometryViewer;
        aGeometryViewer = new GeometryViewer();
        frame.setContentPane(aGeometryViewer);
        frame.setSize(aGeometryViewer.getSize());
        frame.addWindowListener(new java.awt.event.WindowAdapter() {

            public void windowClosing(java.awt.event.WindowEvent e) {
                System.exit(0);
            }
        });
        Geometry csGeometry = getExampleGeometryCSG();
        // try to convert this CSG geometry to image
        ISize imageSize = csGeometry.getGeometrySpec().getDefaultSampledImageSize();
        Geometry imageGeometry = RayCaster.resampleGeometry(new GeometryThumbnailImageFactoryAWT(), csGeometry, imageSize);
        // aGeometryViewer.setGeometry(csGeometry);
        aGeometryViewer.setGeometry(imageGeometry);
        frame.setSize(600, 600);
        frame.setVisible(true);
    } catch (Throwable exception) {
        System.err.println("Exception occurred in main() of javax.swing.JPanel");
        exception.printStackTrace(System.out);
    }
}
Also used : ISize(org.vcell.util.ISize) Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)

Example 7 with GeometryThumbnailImageFactoryAWT

use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT 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 8 with GeometryThumbnailImageFactoryAWT

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

the class GeometrySubVolumeTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (rowIndex < 0 || rowIndex >= getRowCount()) {
        throw new RuntimeException("GeometrySubVolumeTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
    }
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("GeometrySubVolumeTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    final SubVolume subVolume = getValueAt(rowIndex);
    try {
        switch(columnIndex) {
            case COLUMN_NAME:
                {
                    final String newName = (String) aValue;
                    final String oldName = subVolume.getName();
                    subVolume.setName(newName);
                    AsynchClientTask task1 = new AsynchClientTask("changing the name", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
                            GeometrySpec gs = getGeometry().getGeometrySpec();
                            if (gs != null) {
                                gs.geometryNameChanged(oldName, newName);
                            } else {
                                if (lg.isEnabledFor(Level.WARN)) {
                                    lg.warn(getGeometry().getDescription() + " has no GeometrySpec?");
                                }
                            }
                        }
                    };
                    ClientTaskDispatcher.dispatch(ownerTable, new Hashtable<String, Object>(), new AsynchClientTask[] { task1 }, false);
                    break;
                }
            case COLUMN_VALUE:
                {
                    if (subVolume instanceof AnalyticSubVolume) {
                        final AnalyticSubVolume analyticSubVolume = (AnalyticSubVolume) subVolume;
                        if (aValue instanceof ScopedExpression) {
                            throw new RuntimeException("unexpected value type ScopedExpression");
                        } else if (aValue instanceof String) {
                            final String newExpressionString = (String) aValue;
                            analyticSubVolume.setExpression(new Expression(newExpressionString));
                            AsynchClientTask task1 = new AsynchClientTask("changing the expression", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                                @Override
                                public void run(Hashtable<String, Object> hashTable) throws Exception {
                                    getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
                                }
                            };
                            ClientTaskDispatcher.dispatch(ownerTable, new Hashtable<String, Object>(), new AsynchClientTask[] { task1 }, false);
                        }
                    }
                    break;
                }
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        DialogUtils.showErrorDialog(ownerTable, e.getMessage(), e);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) GeometrySpec(cbit.vcell.geometry.GeometrySpec) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) ScopedExpression(cbit.gui.ScopedExpression) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) CSGObject(cbit.vcell.geometry.CSGObject) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume)

Example 9 with GeometryThumbnailImageFactoryAWT

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

the class BioModelEditorApplicationPanel method setSimulationContext.

public void setSimulationContext(SimulationContext newValue) {
    if (simulationContext == newValue) {
        return;
    }
    final boolean respondingToSelectionManager = selectionManager.isBusy();
    final Object[] selectedObj = selectionManager.getSelectedObjects();
    SimulationContext oldValue = simulationContext;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(eventHandler);
    }
    if (newValue != null) {
        newValue.addPropertyChangeListener(eventHandler);
    }
    simulationContext = newValue;
    AsynchClientTask task1 = new AsynchClientTask("loading application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            simulationContext.getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("showing application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            applicationGeometryPanel.setSimulationContext(simulationContext);
            applicationSpecificationsPanel.setSimulationContext(simulationContext);
            applicationProtocolsPanel.setSimulationContext(simulationContext);
            applicationSimulationsPanel.setSimulationContext(simulationContext);
            parameterEstimationPanel.setSelectionManager(null);
            showOrHideFittingPanel();
            parameterEstimationPanel.setSelectionManager(selectionManager);
            // showOrHideProtocolsPanel();
            if (respondingToSelectionManager) {
                selectionManager.setSelectedObjects(new Object[0]);
                selectionManager.setSelectedObjects(selectedObj);
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 10 with GeometryThumbnailImageFactoryAWT

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

the class SimulationContext method copySimulationContext.

public static SimulationContext copySimulationContext(SimulationContext srcSimContext, String newSimulationContextName, boolean bSpatial, Application simContextType) throws java.beans.PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException {
    Geometry newClonedGeometry = new Geometry(srcSimContext.getGeometry());
    newClonedGeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
    // if stoch copy to ode, we need to check is stoch is using particles. If yes, should convert particles to concentraton.
    // the other 3 cases are fine. ode->ode, ode->stoch, stoch-> stoch
    SimulationContext destSimContext = new SimulationContext(srcSimContext, newClonedGeometry, simContextType);
    if (srcSimContext.getApplicationType() == Application.NETWORK_STOCHASTIC && !srcSimContext.isUsingConcentration() && simContextType == Application.NETWORK_DETERMINISTIC) {
        try {
            destSimContext.convertSpeciesIniCondition(true);
        } catch (MappingException e) {
            e.printStackTrace();
            throw new java.beans.PropertyVetoException(e.getMessage(), null);
        }
    }
    if (srcSimContext.getGeometry().getDimension() > 0 && !bSpatial) {
        // copy the size over
        destSimContext.setGeometry(new Geometry("nonspatial", 0));
        StructureMapping[] srcStructureMappings = srcSimContext.getGeometryContext().getStructureMappings();
        StructureMapping[] destStructureMappings = destSimContext.getGeometryContext().getStructureMappings();
        for (StructureMapping destStructureMapping : destStructureMappings) {
            for (StructureMapping srcStructureMapping : srcStructureMappings) {
                if (destStructureMapping.getStructure() == srcStructureMapping.getStructure()) {
                    if (srcStructureMapping.getUnitSizeParameter() != null) {
                        Expression sizeRatio = srcStructureMapping.getUnitSizeParameter().getExpression();
                        GeometryClass srcGeometryClass = srcStructureMapping.getGeometryClass();
                        GeometricRegion[] srcGeometricRegions = srcSimContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions(srcGeometryClass);
                        if (srcGeometricRegions != null) {
                            double size = 0;
                            for (GeometricRegion srcGeometricRegion : srcGeometricRegions) {
                                size += srcGeometricRegion.getSize();
                            }
                            destStructureMapping.getSizeParameter().setExpression(Expression.mult(sizeRatio, new Expression(size)));
                        }
                    }
                    break;
                }
            }
        }
        // If changing spatial to non-spatial
        // set diffusion to 0, velocity and boundary to null
        // srcSimContext.getReactionContext().getspe
        Parameter[] allParameters = destSimContext.getAllParameters();
        if (allParameters != null && allParameters.length > 0) {
            for (int i = 0; i < allParameters.length; i++) {
                if (allParameters[i] instanceof SpeciesContextSpecParameter) {
                    SpeciesContextSpecParameter speciesContextSpecParameter = (SpeciesContextSpecParameter) allParameters[i];
                    int role = speciesContextSpecParameter.getRole();
                    if (role == SpeciesContextSpec.ROLE_DiffusionRate) {
                        speciesContextSpecParameter.setExpression(new Expression(0));
                    } else if (role == SpeciesContextSpec.ROLE_BoundaryValueXm || role == SpeciesContextSpec.ROLE_BoundaryValueXp || role == SpeciesContextSpec.ROLE_BoundaryValueYm || role == SpeciesContextSpec.ROLE_BoundaryValueYp || role == SpeciesContextSpec.ROLE_BoundaryValueZm || role == SpeciesContextSpec.ROLE_BoundaryValueZp) {
                        speciesContextSpecParameter.setExpression(null);
                    } else if (role == SpeciesContextSpec.ROLE_VelocityX || role == SpeciesContextSpec.ROLE_VelocityY || role == SpeciesContextSpec.ROLE_VelocityZ) {
                        speciesContextSpecParameter.setExpression(null);
                    }
                }
            }
        }
    }
    destSimContext.fixFlags();
    destSimContext.setName(newSimulationContextName);
    return destSimContext;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) Expression(cbit.vcell.parser.Expression) Parameter(cbit.vcell.model.Parameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Aggregations

GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)28 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)17 Hashtable (java.util.Hashtable)17 Geometry (cbit.vcell.geometry.Geometry)16 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)11 CSGObject (cbit.vcell.geometry.CSGObject)10 SubVolume (cbit.vcell.geometry.SubVolume)9 SimulationContext (cbit.vcell.mapping.SimulationContext)9 VCImage (cbit.image.VCImage)8 Expression (cbit.vcell.parser.Expression)7 PropertyVetoException (java.beans.PropertyVetoException)7 ISize (org.vcell.util.ISize)7 ImageException (cbit.image.ImageException)6 Extent (org.vcell.util.Extent)6 GeometryException (cbit.vcell.geometry.GeometryException)5 GeometrySpec (cbit.vcell.geometry.GeometrySpec)5 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)5 SurfaceClass (cbit.vcell.geometry.SurfaceClass)5 ArrayList (java.util.ArrayList)5 Origin (org.vcell.util.Origin)5