use of cbit.image.VCImageUncompressed in project vcell by virtualcell.
the class RunRefSimulationOp method saveExternalData.
private static void saveExternalData(Image image, String varName, ExternalDataIdentifier newROIExtDataID, LocalWorkspace localWorkspace) throws ObjectNotFoundException, ImageException, IOException {
Extent extent = image.getExtent();
Origin origin = image.getOrigin();
ISize isize = image.getISize();
VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
int NumTimePoints = 1;
int NumChannels = 1;
// dimensions: time points, channels, whole image ordered by z slices.
double[][][] pixData = new double[NumTimePoints][NumChannels][];
pixData[0][0] = image.getDoublePixels();
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = simpleCartesianMesh;
fdos.doubleSpecData = pixData;
fdos.specEDI = newROIExtDataID;
fdos.varNames = new String[] { varName };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
use of cbit.image.VCImageUncompressed in project vcell by virtualcell.
the class ClientRequestManager method createVCImageFromUnsignedShorts.
public static VCImage createVCImageFromUnsignedShorts(short[] dataToSegment, Extent extent, ISize isize, BitSet uniquePixelBS) throws Exception {
// auto segment
int minVal = dataToSegment[0] & 0x0000FFFF;
int maxVal = minVal;
for (int i = 0; i < dataToSegment.length; i++) {
int usIntVal = (int) (dataToSegment[i] & 0x0000FFFF);
minVal = Math.min(usIntVal, minVal);
maxVal = Math.max(usIntVal, maxVal);
}
byte[] byteData = new byte[dataToSegment.length];
if (maxVal >= MAX_NUMBER_OF_COLORS_IMPORTED_FILE) {
if (uniquePixelBS.cardinality() <= MAX_NUMBER_OF_COLORS_IMPORTED_FILE) {
int index = 0;
int[] indexRef = new int[(int) Math.pow(2, Short.SIZE)];
Arrays.fill(indexRef, -1);
for (int i = 0; i < indexRef.length; i++) {
if (uniquePixelBS.get(i)) {
indexRef[i] = index;
index++;
}
}
for (int i = 0; i < dataToSegment.length; i++) {
byteData[i] = (byte) indexRef[(int) (dataToSegment[i] & 0x0000FFFF)];
}
} else {
for (int i = 0; i < dataToSegment.length; i++) {
byteData[i] = (byte) (0xFF & (int) ((double) (dataToSegment[i] - minVal) / (double) (maxVal - minVal) * (MAX_NUMBER_OF_COLORS_IMPORTED_FILE - 1)));
}
}
} else {
for (int i = 0; i < byteData.length; i++) {
byteData[i] = (byte) (dataToSegment[i] & 0xFF);
}
}
VCImage autoSegmentVCImage = new VCImageUncompressed(null, byteData, extent, isize.getX(), isize.getY(), isize.getZ());
return autoSegmentVCImage;
}
use of cbit.image.VCImageUncompressed in project vcell by virtualcell.
the class VFrapXmlHelper method LoadVFrapSpecialImages.
// // load and compute prebleach average and first postbleach images
// public void LoadVFrapSpecialImages(AnnotatedImageDataset annotatedImages, int startingIndexRecovery)
// {
// // unnormalized prebleach average
// prebleachAvg = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// for(int j = 0; j < prebleachAvg.length; j++)
// {
// double pixelTotal = 0;
// for(int i = 0 ; i < startingIndexRecovery; i++)
// {
// pixelTotal = pixelTotal + (annotatedImages.getImageDataset().getImage(0, 0, i).getPixels()[j] & 0x0000FFFF);
// }
// prebleachAvg[j] = pixelTotal/startingIndexRecovery;
// }
//
// // unnormalized first post bleach
// firstPostBleach = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// short[] pixels = annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getPixels();
// for(int i = 0; i< pixels.length; i++)
// {
// firstPostBleach[i] = pixels[i] & 0x0000FFFF;
// }
// }
//
// Locate the special images within the vFrap files and load them in memory
//
public static boolean LoadVFrapSpecialImages(Hashtable<String, Object> hashTable, Element vFrapRoot) throws IOException, DataAccessException, MathException, ImageException {
// ------ parse the vfrap file and the log/zip files referred within -----
// many channels of 1 timepoint each
int NumTimePoints = 1;
// the channels: prebleach, postbleach, roi1, roi2 ... roiN
int NumChannels = tokenNames.length;
String[] channelNames = new String[NumChannels];
VariableType[] channelTypes = new VariableType[NumChannels];
DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
double[][][] pixData = new double[NumTimePoints][NumChannels][];
// get the path of the file tagged with "ROIExternalDataInfoTag" and open it
Element roiExternalDataInfoElement = vFrapRoot.getChild(MicroscopyXMLTags.ROIExternalDataInfoTag);
if (roiExternalDataInfoElement == null) {
// can't load FieldData for some reason, fall back to importing the biomodel only
return false;
}
// <ROIExternalDataInfo Filename="c:\vFrap\VirtualMicroscopy\SimulationData\SimID_1282941232246_0_.log">
// <ExternalDataIdentifier Name="timeData" KeyValue="1282941232246" OwnerName="SimulationData" OwnerKey="0" />
// </ImageDatasetExternalDataInfo>
// c:\VirtualMicroscopy\SimulationData\SimID_1284149203811_0_.log
String filename = (roiExternalDataInfoElement).getAttributeValue("Filename");
Element childElement = (roiExternalDataInfoElement).getChild("ExternalDataIdentifier");
if (childElement == null) {
// can't load FieldData for some reason, fall back to importing the biomodel only
return false;
}
StringTokenizer tokens = new StringTokenizer(filename, "/\\.");
final ArrayList<String> tokenArray = new ArrayList<String>();
while (tokens.hasMoreElements()) {
tokenArray.add(tokens.nextToken());
}
final String dataID = tokenArray.get(tokenArray.size() - 2);
final String userName = tokenArray.get(tokenArray.size() - 3);
VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public String getID() {
return dataID;
}
public KeyValue getDataKey() {
return null;
}
public User getOwner() {
return new User(userName, new KeyValue("123345432334"));
}
};
// ------- recover simulation data for this user name, load the images in memory ------------
// ex c:\\VirtualMicroscopy\\SimulationData
String userDirName = filename.substring(0, filename.indexOf(dataID) - 1);
File userDir = new File(userDirName);
SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
SimulationData simData = new SimulationData(vcDataIdentifier, userDir, null, simDataAmplistorInfo);
// build a valid mesh in 2 steps, what we have in simData is incomplete
CartesianMesh incompleteMesh = simData.getMesh();
Extent extent = incompleteMesh.getExtent();
ISize isize = new ISize(incompleteMesh.getSizeX(), incompleteMesh.getSizeY(), incompleteMesh.getSizeZ());
Origin origin = new Origin(0, 0, 0);
CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
double[] times = simData.getDataTimes();
for (int i = 0; i < dataIdentifiers.length; i++) {
// ex: prebleach_avg, postbleach_first, postbleach_last, bleached_mask, cell_mask, ring1_mask,... ring8_mask
System.out.println(dataIdentifiers[i].getName());
for (double time : times) {
// this loops only once, we have just 1 timepoint for each "special" image
SimDataBlock simDataBlock = simData.getSimDataBlock(null, dataIdentifiers[i].getName(), time);
channelNames[i] = dataIdentifiers[i].getName();
channelTypes[i] = VariableType.VOLUME;
channelVFrapImageType[i] = SymbolEquivalence.typeFromToken(dataIdentifiers[i].getName());
pixData[0][i] = simDataBlock.getData();
// var = prebleach_avg, time = 0.0, data = { 1.0832530361887216 1.0832530361887216 1.0832530361887216 1.0 .... }
System.out.print("var = " + dataIdentifiers[i].getName() + ", time = " + time + ", data = { ");
// show a few
for (int j = 0; j < 5; j++) {
System.out.print(pixData[0][i][j] + " ");
}
// show a few
;
// show a few
System.out.println(" ... ");
}
}
hashTable.put("mesh", mesh);
hashTable.put("pixData", pixData);
hashTable.put("channelNames", channelNames);
hashTable.put("channelTypes", channelTypes);
hashTable.put("channelVFrapImageType", channelVFrapImageType);
return true;
}
use of cbit.image.VCImageUncompressed in project vcell by virtualcell.
the class ROIMultiPaintManager method createVCImageFromBufferedImages.
public static VCImage createVCImageFromBufferedImages(Extent extent, BufferedImage[] bufferedImages) throws Exception {
// collect z-sections into 1 array for VCImage
ISize isize = new ISize(bufferedImages[0].getWidth(), bufferedImages[0].getHeight(), bufferedImages.length);
int sizeXY = isize.getX() * isize.getY();
byte[] segmentedData = new byte[isize.getXYZ()];
int index = 0;
for (int i = 0; i < bufferedImages.length; i++) {
System.arraycopy(((DataBufferByte) bufferedImages[i].getRaster().getDataBuffer()).getData(), 0, segmentedData, index, sizeXY);
index += sizeXY;
}
return new VCImageUncompressed(null, segmentedData, extent, isize.getX(), isize.getY(), isize.getZ());
}
use of cbit.image.VCImageUncompressed in project vcell by virtualcell.
the class DataSymbolsPanel method addVFrapOriginalImages.
private void addVFrapOriginalImages() {
// add dataset (normal images) from vFrap
AsynchClientTask[] taskArray = new AsynchClientTask[5];
// select the desired vfrap file
taskArray[0] = ChooseVFrapFile();
taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
File vFrapFile = (File) hashTable.get("vFrapFile");
Component requesterComponent = DataSymbolsPanel.this;
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
if (documentManager == null) {
throw new RuntimeException("Not connected to server.");
}
// ex ccc8.vfrap
String vFrapFileNameExtended = vFrapFile.getName();
{
// we want to make sure to reload these strings from the hash later on
String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
// we'll save here the "special" vFrap images (prebleach_avg, ...)
String mixedFieldDataName = initialFieldDataName + "Mx";
hashTable.put("initialFieldDataName", initialFieldDataName);
hashTable.put("mixedFieldDataName", mixedFieldDataName);
}
if (vFrapFileNameExtended.indexOf(".vfrap") <= -1) {
throw new RuntimeException("File extension must be .vfrap");
}
// normal images
checkNameAvailability(hashTable, false, documentManager, requesterComponent);
// ----- read needed info from Virtual FRAP xml file
System.out.println("Loading " + vFrapFileNameExtended + " ...");
String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
// loading frap images
AnnotatedImageDataset annotatedImages = xmlReader.getAnnotatedImageDataset(vFrapRoot, null);
hashTable.put("annotatedImages", annotatedImages);
// loading ROIs for display purposes only (see next task)
ROI[] rois = xmlReader.getPrimaryROIs(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
LoadVFrapDisplayRoi(hashTable, annotatedImages, rois);
// Calendar cal = Calendar.getInstance();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
// DocumentWindow documentWindow = (DocumentWindow)BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
// DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
// VFrapXmlHelper vFrapXmlHelper = new VFrapXmlHelper();
// if(vFrapXmlHelper.isAlreadyImported(vFrapFileName, documentManager)) {
// throw new RuntimeException("FieldData name already in use.");
// }
// // bioModel.setName(vFrapFileName + "-" + sdf.format(cal.getTime()));
// bioModel.setName(vFrapFileName);
// BioModel feedbackModel = documentManager.save(bioModel, null);
// BioModelChildSummary childSummary = BioModelChildSummary.fromDatabaseSerialization(xmlString);
// BioModelInfo biomodelInfo = new BioModelInfo(feedbackModel.getVersion(), feedbackModel.getVersion().getVersionKey(), childSummary );
// documentWindow.getTopLevelWindowManager().getRequestManager().openDocument(biomodelInfo, documentWindow.getTopLevelWindowManager(), true);
}
};
// show the images from the vfrap file in an OverlayEditorPanelJAI dialog
taskArray[2] = new AsynchClientTask("Display images", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
if (initialFieldDataName.equals("")) {
JOptionPane.showMessageDialog(DataSymbolsPanel.this, "Field Data name " + initialFieldDataName + " already in use.");
// prevents the rest of tasks below from running
throw UserCancelException.CANCEL_GENERIC;
}
AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
BufferedImage[] displayROI = (BufferedImage[]) hashTable.get("displayROI");
if (annotatedImages == null || displayROI == null) {
return;
}
// display the images
OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI();
overlayPanel.setAllowAddROI(false);
ImageDataset imageDataset = annotatedImages.getImageDataset();
overlayPanel.setImages(imageDataset, 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200));
overlayPanel.setAllROICompositeImage(displayROI, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
int choice = DialogUtils.showComponentOKCancelDialog(DataSymbolsPanel.this, overlayPanel, "vFrap Field Data");
if (choice != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
}
};
// save the timepoints from memory to the database as field data
taskArray[3] = new AsynchClientTask("Saving time series data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
DocumentManager dm = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
if (dm == null) {
throw new RuntimeException("Not connected to server.");
}
User owner = null;
Version version = simulationContext.getVersion();
if (version == null) {
// new document, so the owner is the user
owner = dm.getUser();
} else {
owner = simulationContext.getVersion().getOwner();
}
// mesh
ImageDataset imageDataset = annotatedImages.getImageDataset();
Extent extent = imageDataset.getExtent();
ISize isize = imageDataset.getISize();
Origin origin = new Origin(0, 0, 0);
CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
// save field data
int NumTimePoints = imageDataset.getImageTimeStamps().length;
int NumChannels = 1;
double[][][] pixData = new double[NumTimePoints][NumChannels][];
for (int i = 0; i < NumTimePoints; i++) {
// images according to zIndex at specific time points(tIndex)
short[] originalData = imageDataset.getPixelsZ(0, i);
double[] doubleData = new double[originalData.length];
for (int j = 0; j < originalData.length; j++) {
doubleData[j] = 0x0000ffff & originalData[j];
}
pixData[i][NumChannels - 1] = doubleData;
}
FieldDataFileOperationSpec timeSeriesFieldDataOpSpec = new FieldDataFileOperationSpec();
timeSeriesFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
timeSeriesFieldDataOpSpec.cartesianMesh = cartesianMesh;
timeSeriesFieldDataOpSpec.doubleSpecData = pixData;
timeSeriesFieldDataOpSpec.specEDI = null;
timeSeriesFieldDataOpSpec.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
timeSeriesFieldDataOpSpec.owner = owner;
timeSeriesFieldDataOpSpec.times = imageDataset.getImageTimeStamps();
timeSeriesFieldDataOpSpec.variableTypes = new VariableType[] { VariableType.VOLUME };
timeSeriesFieldDataOpSpec.origin = origin;
timeSeriesFieldDataOpSpec.extent = extent;
timeSeriesFieldDataOpSpec.isize = isize;
// realignment for the case when first timepoint is not zero
if (timeSeriesFieldDataOpSpec.times[0] != 0) {
double shift = timeSeriesFieldDataOpSpec.times[0];
for (int i = 0; i < NumTimePoints; i++) {
timeSeriesFieldDataOpSpec.times[i] -= shift;
}
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyMMMdd_hhmmss");
String formattedDate = sdf.format(cal.getTime());
hashTable.put("formattedDate", formattedDate);
// ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec,
// initialFieldDataName + "_" + formattedDate);
ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec, initialFieldDataName);
hashTable.put("imageDataset", imageDataset);
hashTable.put("timeSeriesEDI", timeSeriesEDI);
}
};
// create the data symbols for the images saved above and display them in the tree/table
taskArray[4] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// --- create the data symbols associated with the time series
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
ImageDataset imageDataset = (ImageDataset) hashTable.get("imageDataset");
ExternalDataIdentifier timeSeriesEDI = (ExternalDataIdentifier) hashTable.get("timeSeriesEDI");
for (double time : imageDataset.getImageTimeStamps()) {
// String fluorName = TokenMangler.fixTokenStrict("fluor_"+time+"_");
// while (simulationContext.getDataContext().getDataSymbol(fluorName)!=null){
// fluorName = TokenMangler.getNextEnumeratedToken(fluorName);
// }
// max time interval we can display is about 11 days
DecimalFormat df = new DecimalFormat("###000.00");
// String fluorName = "fluor_" + df.format(time) + "_" + formattedDate;
String fluorName = "fluor_" + df.format(time).substring(0, df.format(time).indexOf(".")) + "s" + df.format(time).substring(1 + df.format(time).indexOf(".")) + "_" + initialFieldDataName;
// FieldFunctionArguments fluorFFArgs = new FieldFunctionArguments(timeSeriesEDI.getName(), fluorName, new Expression(time), VariableType.VOLUME);
DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.VFRAP_TIMEPOINT, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), timeSeriesEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), time);
simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
}
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hash, taskArray, false, true, null);
// String name = null;
// try {
// getNewDataSymbolPanel().setSymbolName("");
// getNewDataSymbolPanel().setSymbolExpression("vcField(dataset1,var1,0.0,Volume)");
// int newSettings = org.vcell.util.gui.DialogUtils.showComponentOKCancelDialog(this, getNewDataSymbolPanel(), "New DataSymbol");
// if (newSettings == JOptionPane.OK_OPTION) {
// name = getNewDataSymbolPanel().getSymbolName();
// String expression = getNewDataSymbolPanel().getSymbolExpression();
// Expression exp = new Expression(expression);
// FunctionInvocation[] functionInvocations = exp.getFunctionInvocations(null);
// // DataSymbol ds = new FieldDataSymbol(DataSymbolType.GENERIC_SYMBOL, name, "",
// // simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD,
// // new FieldFunctionArguments(functionInvocations[0]));
// DataSymbol ds = new FieldDataSymbol(name, DataSymbolType.GENERIC_SYMBOL,
// simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD);
// simulationContext.getDataContext().addDataSymbol(ds);
// }
// } catch (java.lang.Throwable ivjExc) {
// DialogUtils.showErrorDialog(this, "Data symbol " + name + " already exists");
// }
}
Aggregations