Search in sources :

Example 1 with GeometryThumbnailImageFactoryAWT

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

the class MathModelWindowManager method actionPerformed.

/**
 * Invoked when an action occurs.
 */
public void actionPerformed(java.awt.event.ActionEvent e) {
    String actionCommand = e.getActionCommand();
    final Object source = e.getSource();
    if (source instanceof GeometryViewer && actionCommand.equals(GuiConstants.ACTIONCMD_CREATE_GEOMETRY) || actionCommand.equals(GuiConstants.ACTIONCMD_EDITCURRENTSPATIAL_GEOMETRY)) {
        AsynchClientTask geomRegionsTask = new AsynchClientTask("Update Geometric regions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                Geometry newGeom = (Geometry) hashTable.get("doc");
                ClientRequestManager.continueAfterMathModelGeomChangeWarning(MathModelWindowManager.this, newGeom);
                newGeom.precomputeAll(new GeometryThumbnailImageFactoryAWT());
            }
        };
        AsynchClientTask applyGeomTask = new AsynchClientTask("Apply Geometry", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                Geometry newGeom = (Geometry) hashTable.get("doc");
                if (newGeom.getName() == null) {
                    newGeom.setName(getMathModel().getName() + "_" + BeanUtils.generateDateTimeString());
                }
                ((MathModel) getVCDocument()).getMathDescription().setGeometry(newGeom);
            }
        };
        createGeometry(getMathModel().getMathDescription().getGeometry(), new AsynchClientTask[] { /*editSelectTask,*/
        geomRegionsTask, applyGeomTask }, TopLevelWindowManager.DEFAULT_CREATEGEOM_SELECT_DIALOG_TITLE, TopLevelWindowManager.APPLY_GEOMETRY_BUTTON_TEXT, (actionCommand.equals(GuiConstants.ACTIONCMD_EDITCURRENTSPATIAL_GEOMETRY) ? new DocumentWindowManager.GeometrySelectionInfo() : null));
    }
    if (source instanceof GeometryViewer && actionCommand.equals(GuiConstants.ACTIONCMD_CHANGE_GEOMETRY)) {
        Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
        hashTable.put(SELECT_GEOM_POPUP, new Boolean(true));
        getRequestManager().changeGeometry(this, null, hashTable);
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) GeometryViewer(cbit.vcell.geometry.gui.GeometryViewer) Hashtable(java.util.Hashtable)

Example 2 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);
            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 3 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 4 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 5 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.isWarnEnabled()) {
                                    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)

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)10 CSGObject (cbit.vcell.geometry.CSGObject)10 SimulationContext (cbit.vcell.mapping.SimulationContext)9 SubVolume (cbit.vcell.geometry.SubVolume)8 VCImage (cbit.image.VCImage)7 Expression (cbit.vcell.parser.Expression)7 ExpressionException (cbit.vcell.parser.ExpressionException)7 PropertyVetoException (java.beans.PropertyVetoException)7 ISize (org.vcell.util.ISize)7 ImageException (cbit.image.ImageException)5 GeometrySpec (cbit.vcell.geometry.GeometrySpec)5 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)5 SurfaceClass (cbit.vcell.geometry.SurfaceClass)5 Extent (org.vcell.util.Extent)5 BioModel (cbit.vcell.biomodel.BioModel)4 GeometryException (cbit.vcell.geometry.GeometryException)4