Search in sources :

Example 26 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class DatabaseServerImpl method getVCImageXML.

/**
 * getVersionable method comment.
 */
public BigString getVCImageXML(User user, KeyValue key) throws DataAccessException, ObjectNotFoundException {
    try {
        if (lg.isTraceEnabled())
            lg.trace("DatabaseServerImpl.getVCImageXML(user=" + user + ", Key=" + key + ")");
        boolean bCheckPermission = true;
        VCImage image = dbTop.getVCImage(new QueryHashtable(), user, key, bCheckPermission);
        return new BigString(XmlHelper.imageToXML(image));
    } catch (ObjectNotFoundException e) {
        lg.error(e.getMessage(), e);
        throw new ObjectNotFoundException(e.getMessage());
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCImage(cbit.image.VCImage) BigString(org.vcell.util.BigString) DataAccessException(org.vcell.util.DataAccessException)

Example 27 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class GeomDbDriver method insertGeometry.

/**
 * This method was created in VisualAge.
 */
private void insertGeometry(InsertHashtable hash, QueryHashtable dbc, Connection con, User user, Geometry geom, KeyValue updatedImageKey, Version newVersion, boolean bVersionChildren) throws ImageException, SQLException, DataAccessException, RecordChangedException {
    // log.print("GeomDbDriver.insertGeometry(" + geom + ")");
    // everybody needs to be in synch 'cause children may be manipulated...
    geom.refreshDependencies();
    KeyValue extentKey = null;
    GeometrySpec geometrySpec = geom.getGeometrySpec();
    if (geometrySpec.getImage() != null) {
        // //try {
        // imageVersionKey = hash.getDatabaseKey(geometrySpec.getImage());
        // if (imageVersionKey==null){
        // if(geometrySpec.getImage().getVersion()!=null && geometrySpec.getImage().getVersion().getVersionKey() != null){
        // imageVersionKey = updateVersionable(hash, con, user, geometrySpec.getImage(), bVersionChildren);
        // }else{
        // String imageName = geometrySpec.getImage().getName(); // + "_image";
        // while (isNameUsed(con,VersionableType.VCImage,user,imageName)){
        // imageName = cbit.util.TokenMangler.getNextRandomToken(imageName);
        // }
        // imageVersionKey = insertVersionable(hash, con, user, geometrySpec.getImage(),imageName ,bVersionChildren);
        // }
        // try{
        // geometrySpec.setImage(getVCImage(con,user,imageVersionKey));
        // }catch(PropertyVetoException e){
        // e.printStackTrace();
        // throw new DataAccessException(e.getMessage());
        // }
        // }
        // //} catch (RecordChangedException rce) {
        // //	throw rce;
        // //}
        extentKey = getExtentRefKeyFromImage(con, updatedImageKey);
    }
    // 
    if (extentKey == null) {
        extentKey = keyFactory.getNewKey(con);
        insertExtentSQL(con, extentKey, geometrySpec.getExtent().getX(), geometrySpec.getExtent().getY(), geometrySpec.getExtent().getZ());
    }
    // 
    insertGeometrySQL(con, geom, updatedImageKey, extentKey, newVersion, user);
    hash.put(geom, newVersion.getVersionKey());
    if (updatedImageKey != null && !updatedImageKey.equals(geom.getGeometrySpec().getImage().getKey())) {
        VCImage resavedImage = getVCImage(dbc, con, user, updatedImageKey, true);
        try {
            geom.getGeometrySpec().setImage(resavedImage);
        } catch (PropertyVetoException e) {
            e.printStackTrace();
            throw new DataAccessException(e.getMessage());
        }
    }
    insertSubVolumesSQL(hash, con, geom, newVersion.getVersionKey());
    insertSurfaceClassesSQL(hash, con, geom, newVersion.getVersionKey());
    if (geom.getDimension() > 0) {
        insertGeometrySurfaceDescriptionSQL(hash, con, geom, newVersion.getVersionKey());
        insertFilamentsSQL(con, geom, newVersion.getVersionKey());
    }
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) PropertyVetoException(java.beans.PropertyVetoException) KeyValue(org.vcell.util.document.KeyValue) VCImage(cbit.image.VCImage) DataAccessException(org.vcell.util.DataAccessException)

Example 28 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class GeomDbDriver method getVCImage.

/**
 * getModel method comment.
 */
private VCImage getVCImage(QueryHashtable dbc, Connection con, User user, KeyValue imageKey, boolean bCheckPermission) throws SQLException, DataAccessException, ObjectNotFoundException {
    // log.print("GeomDbDriver.getImage(user="+user+", id="+imageKey+")");
    String sql;
    Field[] f = { new StarField(imageTable), userTable.userid, imageDataTable.data, new StarField(extentTable) };
    Table[] t = { imageTable, userTable, imageDataTable, extentTable };
    String condition = imageTable.id.getQualifiedColName() + " = " + imageKey + " AND " + imageTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName() + " AND " + imageTable.id.getQualifiedColName() + " = " + imageDataTable.imageRef.getQualifiedColName() + " AND " + imageTable.extentRef.getQualifiedColName() + " = " + extentTable.id.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax, bCheckPermission);
    // System.out.println(sql);
    // Connection con = conFact.getConnection();
    VCImage vcImage = null;
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            vcImage = imageTable.getImage(rset, con, imageDataTable, dbSyntax);
            getImageRegionsForVCImage(dbc, con, vcImage);
        } else {
            throw new ObjectNotFoundException("Image id=" + imageKey + " not found for user '" + user + "'");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    return vcImage;
}
Also used : StarField(cbit.sql.StarField) StarField(cbit.sql.StarField) Field(cbit.sql.Field) Table(cbit.sql.Table) Statement(java.sql.Statement) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet) VCImage(cbit.image.VCImage)

Example 29 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class ServerDocumentManager method saveGeometry.

/**
 * Insert the method's description here.
 * Creation date: (10/28/00 12:08:30 AM)
 */
public String saveGeometry(QueryHashtable dbc, User user, String geometryXML, String newName) throws DataAccessException, cbit.vcell.xml.XmlParseException, java.sql.SQLException {
    Geometry geometry = XmlHelper.XMLToGeometry(new XMLSource(geometryXML));
    forceDeepDirtyIfForeign(user, geometry);
    // 
    if (newName != null) {
        try {
            geometry.setName(newName);
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException("couldn't set new name for Geometry: " + e.getMessage());
        }
    }
    // 
    // if geometry has an image, save it if necessary
    // 
    KeyValue updatedImageKey = null;
    if (geometry.getGeometrySpec().getImage() != null) {
        VCImage image = geometry.getGeometrySpec().getImage();
        if (image.getKey() == null || !image.getVersion().getName().equals(image.getName())) {
            // 
            try {
                fixNullImageName(image);
                int count = 0;
                while (dbServer.getDBTopLevel().isNameUsed(user, VersionableType.VCImage, image.getName(), true)) {
                    try {
                        image.setName(TokenMangler.getNextRandomToken(image.getName()));
                    } catch (java.beans.PropertyVetoException e) {
                        e.printStackTrace(System.out);
                    }
                    if (count++ > 5) {
                        throw new DataAccessException("failed to find unique image name '" + image.getName() + "' is last name tried");
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
                throw new DataAccessException(ex.getMessage(), ex);
            }
            updatedImageKey = dbServer.getDBTopLevel().insertVersionable(user, image, image.getName(), false, true);
        } else {
            // 
            // Image has been saved previously, get old image from database
            // 
            VCImage origImage = dbServer.getDBTopLevel().getVCImage(dbc, user, image.getKey(), false);
            if (origImage == null || !origImage.compareEqual(image)) {
                updatedImageKey = dbServer.getDBTopLevel().updateVersionable(user, image, false, true);
            } else {
                // image didn't need to be saved
                updatedImageKey = image.getKey();
            }
        }
    }
    // 
    // save geometry
    // 
    KeyValue geometryKey = null;
    if (geometry.getVersion() != null && geometry.getName().equals(geometry.getVersion().getName())) {
        geometryKey = dbServer.getDBTopLevel().updateVersionable(dbc, user, geometry, updatedImageKey, false, true);
    } else {
        geometryKey = dbServer.getDBTopLevel().insertVersionable(dbc, user, geometry, updatedImageKey, geometry.getName(), false, true);
    }
    return dbServer.getGeometryXML(user, geometryKey).toString();
}
Also used : Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) KeyValue(org.vcell.util.document.KeyValue) VCImage(cbit.image.VCImage) XMLSource(cbit.vcell.xml.XMLSource) DataAccessException(org.vcell.util.DataAccessException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) PropertyVetoException(java.beans.PropertyVetoException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) MappingException(cbit.vcell.mapping.MappingException)

Example 30 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class ROIMultiPaintManager method showGUI.

public Geometry showGUI(final String okButtonText, final String sourceDataName, final Component parentComponent, String initalAnnotation, final VCPixelClass[] vcPixelClasses, UserPreferences userPreferences) {
    originalAnnotation = initalAnnotation;
    final Geometry[] finalGeometryHolder = new Geometry[1];
    if (overlayEditorPanelJAI == null) {
        overlayEditorPanelJAI = new OverlayEditorPanelJAI();
        overlayEditorPanelJAI.setCalcCoords(new CalcCoords());
        overlayEditorPanelJAI.setUserPreferences(userPreferences);
        overlayEditorPanelJAI.setMinimumSize(new Dimension(700, 600));
        overlayEditorPanelJAI.setPreferredSize(new Dimension(700, 600));
        overlayEditorPanelJAI.addPropertyChangeListener(ROIMultiPaintManager.this);
    }
    // delete all names
    overlayEditorPanelJAI.deleteROIName(null);
    // when user selects image "from DB" or "from current geometry"
    applyPixelClasses(vcPixelClasses, parentComponent);
    if (getImageDataset().length > 1) {
        String[] channelNames = new String[getImageDataset().length];
        for (int i = 0; i < channelNames.length; i++) {
            channelNames[i] = "channel " + i;
        }
        overlayEditorPanelJAI.setChannelNames(channelNames);
    } else {
        overlayEditorPanelJAI.setChannelNames(null);
    }
    updateUnderlayHistogramDisplay();
    overlayEditorPanelJAI.setContrastToMinMax();
    overlayEditorPanelJAI.setAllROICompositeImage(roiComposite, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
    final JDialog jDialog = new JDialog(JOptionPane.getFrameForComponent(parentComponent));
    jDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    jDialog.setTitle("Geometry Editor (" + sourceDataName + ")");
    jDialog.setModal(true);
    final JButton cancelJButton = new JButton("Cancel");
    cancelJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final String QUIT_ANSWER = "Quit Geometry Editor";
            String result = DialogUtils.showWarningDialog(jDialog, "Confirm cancel", "Quit geometry editor and lose all changes?", new String[] { QUIT_ANSWER, "back" }, QUIT_ANSWER);
            if (result != null && result.equals(QUIT_ANSWER)) {
                jDialog.dispose();
            }
        }
    });
    jDialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            super.windowOpened(e);
            if (bHasOriginalData) {
                calculateHistogram();
            }
            updateUndoAfter(false);
            if (vcPixelClasses == null) {
                askInitialize(false);
            }
        }

        @Override
        public void windowClosing(WindowEvent e) {
            // TODO Auto-generated method stub
            super.windowClosing(e);
            cancelJButton.doClick();
        }
    });
    final JPanel okCancelJPanel = new JPanel(new FlowLayout());
    JButton okJButton = new JButton(okButtonText);
    okJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                VCImage finalImage = checkAll();
                finalImage.setDescription((editedGeometryAttributes != null ? editedGeometryAttributes.annotation : originalAnnotation));
                finalGeometryHolder[0] = new Geometry((String) null, finalImage);
                finalGeometryHolder[0].getGeometrySpec().setOrigin((editedGeometryAttributes != null ? editedGeometryAttributes.origin : originalOrigin));
                finalGeometryHolder[0].getGeometrySpec().setExtent((editedGeometryAttributes != null ? editedGeometryAttributes.extent : originalExtent));
                finalGeometryHolder[0].setDescription((editedGeometryAttributes != null ? editedGeometryAttributes.annotation : originalAnnotation));
                jDialog.dispose();
            } catch (UserCancelException uce) {
            } catch (Exception exc) {
                DialogUtils.showErrorDialog(overlayEditorPanelJAI, "Error validating compartments.\n" + exc.getMessage(), exc);
            }
        }
    });
    JButton attributesJButton = new JButton("Attributes...");
    attributesJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                editedGeometryAttributes = showEditGeometryAttributes(jDialog, editedGeometryAttributes);
            } catch (UserCancelException uce) {
            // ignore
            }
        }
    });
    // JButton surfaceButton = new JButton("View Surfaces...");
    // surfaceButton.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // showDataValueSurfaceViewer(geomAttr);
    // }
    // });
    JButton exportJButton = new JButton("Export...");
    exportJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            export();
        }
    });
    JButton importJButton = new JButton("Import stl...");
    importJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser importJFC = new JFileChooser(ClientRequestManager.getPreferredPath(UserPreferences.getLastUserPreferences()));
            importJFC.setDialogTitle("Choose .stl file(s) to import");
            importJFC.setMultiSelectionEnabled(true);
            int result = importJFC.showOpenDialog(overlayEditorPanelJAI);
            if (result == JFileChooser.APPROVE_OPTION) {
                File[] selectedFiles = importJFC.getSelectedFiles();
                if (selectedFiles != null && selectedFiles.length > 0) {
                    ClientRequestManager.setPreferredPath(UserPreferences.getLastUserPreferences(), selectedFiles[0]);
                    Vect3d sampleSize = new Vect3d(getImageDataset()[0].getISize().getX(), getImageDataset()[0].getISize().getY(), getImageDataset()[0].getISize().getZ());
                    ArrayList<AsynchClientTask> stlImportTasks = getImportSTLtasks(selectedFiles, sampleSize, new Vect3d(0, 0, 0));
                    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<>(), stlImportTasks.toArray(new AsynchClientTask[0]));
                } else {
                    DialogUtils.showErrorDialog(overlayEditorPanelJAI, "Select at least 1 .stl file for import.");
                }
            }
        }
    });
    okCancelJPanel.add(okJButton);
    okCancelJPanel.add(attributesJButton);
    okCancelJPanel.add(exportJButton);
    okCancelJPanel.add(importJButton);
    // okCancelJPanel.add(surfaceButton);
    okCancelJPanel.add(cancelJButton);
    jDialog.getContentPane().add(overlayEditorPanelJAI, BorderLayout.CENTER);
    jDialog.getContentPane().add(okCancelJPanel, BorderLayout.SOUTH);
    jDialog.setSize(700, 600);
    DialogUtils.showModalJDialogOnTop(jDialog, parentComponent);
    if (finalGeometryHolder[0] == null) {
        throw UserCancelException.CANCEL_GENERIC;
    }
    return finalGeometryHolder[0];
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) Hashtable(java.util.Hashtable) JButton(javax.swing.JButton) UserCancelException(org.vcell.util.UserCancelException) ArrayList(java.util.ArrayList) WindowAdapter(java.awt.event.WindowAdapter) VCImage(cbit.image.VCImage) Dimension(java.awt.Dimension) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) Vect3d(cbit.vcell.render.Vect3d) Geometry(cbit.vcell.geometry.Geometry) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) WindowEvent(java.awt.event.WindowEvent) JDialog(javax.swing.JDialog)

Aggregations

VCImage (cbit.image.VCImage)54 Geometry (cbit.vcell.geometry.Geometry)22 Extent (org.vcell.util.Extent)20 ISize (org.vcell.util.ISize)19 VCImageUncompressed (cbit.image.VCImageUncompressed)18 ImageException (cbit.image.ImageException)16 PropertyVetoException (java.beans.PropertyVetoException)15 DataAccessException (org.vcell.util.DataAccessException)15 KeyValue (org.vcell.util.document.KeyValue)15 SubVolume (cbit.vcell.geometry.SubVolume)14 Origin (org.vcell.util.Origin)13 RegionImage (cbit.vcell.geometry.RegionImage)11 SurfaceClass (cbit.vcell.geometry.SurfaceClass)11 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)11 UserCancelException (org.vcell.util.UserCancelException)11 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)10 Expression (cbit.vcell.parser.Expression)10 VCPixelClass (cbit.image.VCPixelClass)9 BioModel (cbit.vcell.biomodel.BioModel)8 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)8