use of org.vcell.util.Extent in project vcell by virtualcell.
the class RayCaster method createGeometryFromSTL.
public static Geometry createGeometryFromSTL(GeometryThumbnailImageFactory geometryThumbnailImageFactory, SurfaceCollection surfaceCollection, int numSamples) throws ImageException, PropertyVetoException, GeometryException, ExpressionException, IOException {
Node[] nodes = surfaceCollection.getNodes();
double minX = Double.MAX_VALUE;
double maxX = -Double.MAX_VALUE;
double minY = Double.MAX_VALUE;
double maxY = -Double.MAX_VALUE;
double minZ = Double.MAX_VALUE;
double maxZ = -Double.MAX_VALUE;
for (Node node : nodes) {
double nx = node.getX();
double ny = node.getY();
double nz = node.getZ();
minX = Math.min(minX, nx);
maxX = Math.max(maxX, nx);
minY = Math.min(minY, ny);
maxY = Math.max(maxY, ny);
minZ = Math.min(minZ, nz);
maxZ = Math.max(maxZ, nz);
}
Extent extent = new Extent((maxX - minX) * 1.4, (maxY - minY) * 1.4, (maxZ - minZ) * 1.4);
Origin origin = new Origin(minX - 0.2 * extent.getX(), minY - 0.2 * extent.getY(), minZ - 0.2 * extent.getZ());
ISize sampleSize = GeometrySpec.calulateResetSamplingSize(3, extent, numSamples);
Geometry geometry = createGeometry(geometryThumbnailImageFactory, surfaceCollection, origin, extent, sampleSize);
return geometry;
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class NonGUIFRAPTest method runSolver.
/**
* @param args
*/
public static void runSolver(String[] args) throws Exception {
String startingIndexForRecovery = args[0];
String freeDiffusionRateStr = args[1];
String freeMobileFractionStr = args[2];
String complexDiffusionRateStr = args[3];
String complexMobileFractionStr = args[4];
String bleachWhileMonitoringRateString = args[5];
String immobileFractionStr = args[6];
String bindingSiteConcentrationStr = args[7];
String reacOnRateStr = args[8];
String reacOffRateStr = args[9];
String workingDirectoryPath = args[10];
String inputFRAPDataFileName = args[11];
String inputCellROIFileName = args[12];
String inputBleachROIFileName = args[13];
String inputBackgroundROIFileName = args[14];
String outputXMLFileName = args[15];
String commaSepTimeStamps = args[16];
String commaSepExtentXYZ = args[17];
LocalWorkspace localWorkspace = new LocalWorkspace(new File(workingDirectoryPath));
ExternalDataFileContents extDataFileContents = readExternalDataContents(inputFRAPDataFileName, inputCellROIFileName, inputBleachROIFileName, inputBackgroundROIFileName);
ROI cellROI = new ROI(extDataFileContents.cellROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
ROI bleachROI = new ROI(extDataFileContents.bleachROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
ROI backgroundROI = new ROI(extDataFileContents.backgroundROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
// Insert Time information
double[] timeStamps = new double[extDataFileContents.imageData.getAllImages().length];
StringTokenizer commaStringTokenizer = new StringTokenizer(commaSepTimeStamps, ",");
int timeCount = 0;
while (commaStringTokenizer.hasMoreTokens()) {
timeStamps[timeCount] = Double.parseDouble(commaStringTokenizer.nextToken());
timeCount++;
}
ImageDataset frapDataImageDataSet = new ImageDataset(extDataFileContents.imageData.getAllImages(), timeStamps, 1);
// Insert Extent information
commaStringTokenizer = new StringTokenizer(commaSepExtentXYZ, ",");
Extent extent = new Extent(Double.parseDouble(commaStringTokenizer.nextToken()), Double.parseDouble(commaStringTokenizer.nextToken()), Double.parseDouble(commaStringTokenizer.nextToken()));
frapDataImageDataSet.setExtent(extent);
bleachROI.getRoiImages()[0].setExtent(extent);
cellROI.getRoiImages()[0].setExtent(extent);
backgroundROI.getRoiImages()[0].setExtent(extent);
FRAPData frapData = FrapDataUtils.importFRAPDataFromImageDataSet(frapDataImageDataSet);
frapData.addReplaceRoi(bleachROI);
frapData.addReplaceRoi(cellROI);
frapData.addReplaceRoi(backgroundROI);
FRAPStudy frapStudy = new FRAPStudy();
frapStudy.setFrapData(frapData);
// old model parameters, need to rewrite
// FRAPStudy.FRAPModelParameters frapModelParameters = new FRAPStudy.FRAPModelParameters(
// new FRAPStudy.InitialModelParameters(freeDiffusionRateStr, freeMobileFractionStr, bleachWhileMonitoringRateString, startingIndexForRecovery),
// null,
// null);
// frapStudy.setFrapModelParameters(frapModelParameters);
frapStudy.refreshDependentROIs();
ExternalDataInfo imageDatasetExternalDataInfo = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME);
ExternalDataInfo roiExternalDataInfo = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME);
frapStudy.setFrapDataExternalDataInfo(imageDatasetExternalDataInfo);
frapStudy.setRoiExternalDataInfo(roiExternalDataInfo);
frapStudy.saveImageDatasetAsExternalData(localWorkspace, frapStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
frapStudy.saveROIsAsExternalData(localWorkspace, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
// Double bleachWhileMonitoringRate =
// (!bleachWhileMonitoringRateString.equals("-")
// ?Double.parseDouble(bleachWhileMonitoringRateString)
// :null);
double fd, ff, bwmr, cd, cf, imf, bs, on, off;
try {
fd = Double.parseDouble(freeDiffusionRateStr);
ff = Double.parseDouble(freeMobileFractionStr);
bwmr = Double.parseDouble(bleachWhileMonitoringRateString);
cd = Double.parseDouble(complexDiffusionRateStr);
cf = Double.parseDouble(complexMobileFractionStr);
imf = Double.parseDouble(immobileFractionStr);
bs = Double.parseDouble(bindingSiteConcentrationStr);
on = Double.parseDouble(reacOnRateStr);
off = Double.parseDouble(reacOffRateStr);
} catch (NumberFormatException e) {
throw new Exception("Input parameters are not all valid. Check if they are empty or in illegal forms.");
}
BioModel bioModel = FRAPStudy.createNewSimBioModel(frapStudy, createParameterArray(fd, ff, bwmr, cd, cf, imf, bs, on, off), null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), new Integer(frapStudy.getStartingIndexForRecovery()));
frapStudy.setBioModel(bioModel);
// no progress listener, need to change
MicroscopyXmlproducer.writeXMLFile(frapStudy, new File(outputXMLFileName), true, null, false);
FRAPStudy.runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), bioModel.getSimulation(0), imageDatasetExternalDataInfo.getExternalDataIdentifier(), roiExternalDataInfo.getExternalDataIdentifier(), null);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(bioModel.getSimulations()[0].getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
PDEDataManager simulationDataManager = new PDEDataManager(null, localWorkspace.getVCDataManager(), vcSimulationDataIdentifier);
double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
VCDataManager testVCDataManager = localWorkspace.getVCDataManager();
double[] prebleachAverage = testVCDataManager.getSimDataBlock(null, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), "prebleach_avg", 0).getData();
// TODO: need to create parameters here.
Parameter[] parameters = null;
SpatialAnalysisResults spatialAnalysisResults = FRAPStudy.spatialAnalysis(simulationDataManager, new Integer(frapStudy.getStartingIndexForRecovery()), frapDataTimeStamps[new Integer(frapStudy.getStartingIndexForRecovery())], parameters, frapData, prebleachAverage);
dumpSummaryReport(spatialAnalysisResults, frapDataTimeStamps, new Integer(startingIndexForRecovery).intValue(), new File(workingDirectoryPath, "nonguiSpatialResults.txt"));
dumpSpatialResults(spatialAnalysisResults, frapDataTimeStamps, new File(workingDirectoryPath, "nonguiSpatialResults.txt"));
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class FrapDataUtils method saveImageDatasetAsExternalData.
public static void saveImageDatasetAsExternalData(FRAPData frapData, LocalWorkspace localWorkspace, ExternalDataIdentifier newImageExtDataID, int startingIndexForRecovery, CartesianMesh cartesianMesh) throws ObjectNotFoundException, FileNotFoundException {
ImageDataset imageDataset = frapData.getImageDataset();
if (imageDataset.getSizeC() > 1) {
throw new RuntimeException("FRAPData.saveImageDatasetAsExternalData(): multiple channels not yet supported");
}
Extent extent = imageDataset.getExtent();
ISize isize = imageDataset.getISize();
// not include the prebleach
int numImageToStore = imageDataset.getSizeT() - startingIndexForRecovery;
// original fluor data and back ground average
double[][][] pixData = new double[numImageToStore][2][];
double[] timesArray = new double[numImageToStore];
double[] bgAvg = frapData.getAvgBackGroundIntensity();
for (int tIndex = startingIndexForRecovery; tIndex < imageDataset.getSizeT(); tIndex++) {
// images according to zIndex at specific time points(tIndex)
short[] originalData = imageDataset.getPixelsZ(0, tIndex);
double[] doubleData = new double[originalData.length];
double[] expandBgAvg = new double[originalData.length];
for (int i = 0; i < originalData.length; i++) {
doubleData[i] = 0x0000ffff & originalData[i];
expandBgAvg[i] = bgAvg[tIndex];
}
pixData[tIndex - startingIndexForRecovery][0] = doubleData;
pixData[tIndex - startingIndexForRecovery][1] = expandBgAvg;
timesArray[tIndex - startingIndexForRecovery] = imageDataset.getImageTimeStamps()[tIndex] - imageDataset.getImageTimeStamps()[startingIndexForRecovery];
}
// changed in March 2008. Though biomodel is not created, we still let user save to xml file.
Origin origin = new Origin(0, 0, 0);
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.doubleSpecData = pixData;
fdos.specEDI = newImageExtDataID;
fdos.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME, "bg_average" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = timesArray;
fdos.variableTypes = new VariableType[] { VariableType.VOLUME, VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class FrapDataUtils method saveROIsAsExternalData.
public static void saveROIsAsExternalData(FRAPData frapData, LocalWorkspace localWorkspace, ExternalDataIdentifier newROIExtDataID, int startingIndexForRecovery, CartesianMesh cartesianMesh) throws ObjectNotFoundException, FileNotFoundException {
ImageDataset imageDataset = frapData.getImageDataset();
Extent extent = imageDataset.getExtent();
ISize isize = imageDataset.getISize();
int NumTimePoints = 1;
// actually it is total number of ROIs(cell,bleached + 8 rings)+prebleach+firstPostBleach+lastPostBleach
int NumChannels = 13;
// dimensions: time points, channels, whole image ordered by z slices.
double[][][] pixData = new double[NumTimePoints][NumChannels][];
double[] temp_background = frapData.getAvgBackGroundIntensity();
double[] avgPrebleachDouble = calculatePreBleachAverageXYZ(frapData, startingIndexForRecovery);
// average of prebleach with background subtracted
pixData[0][0] = avgPrebleachDouble;
// first post-bleach with background subtracted
pixData[0][1] = createDoubleArray(imageDataset.getPixelsZ(0, startingIndexForRecovery), temp_background[startingIndexForRecovery], true);
// adjustPrebleachAndPostbleachData(avgPrebleachDouble, pixData[0][1]);
// last post-bleach image (at last time point) with background subtracted
pixData[0][2] = createDoubleArray(imageDataset.getPixelsZ(0, imageDataset.getSizeT() - 1), temp_background[imageDataset.getSizeT() - 1], true);
// below are ROIs, we don't need to subtract background for them.
pixData[0][3] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][4] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getBinaryPixelsXYZ(1), 0, false);
if (frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()) == null) {
// throw new RuntimeException("must first generate \"derived masks\"");
pixData[0][5] = new double[imageDataset.getISize().getXYZ()];
pixData[0][6] = new double[imageDataset.getISize().getXYZ()];
pixData[0][7] = new double[imageDataset.getISize().getXYZ()];
pixData[0][8] = new double[imageDataset.getISize().getXYZ()];
pixData[0][9] = new double[imageDataset.getISize().getXYZ()];
pixData[0][10] = new double[imageDataset.getISize().getXYZ()];
pixData[0][11] = new double[imageDataset.getISize().getXYZ()];
pixData[0][12] = new double[imageDataset.getISize().getXYZ()];
} else {
pixData[0][5] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][6] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING2.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][7] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING3.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][8] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING4.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][9] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING5.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][10] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING6.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][11] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING7.name()).getBinaryPixelsXYZ(1), 0, false);
pixData[0][12] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING8.name()).getBinaryPixelsXYZ(1), 0, false);
}
Origin origin = new Origin(0, 0, 0);
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.doubleSpecData = pixData;
fdos.specEDI = newROIExtDataID;
fdos.varNames = new String[] { "prebleach_avg", "postbleach_first", "postbleach_last", "bleached_mask", "cell_mask", "ring1_mask", "ring2_mask", "ring3_mask", "ring4_mask", "ring5_mask", "ring6_mask", "ring7_mask", "ring8_mask" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class MicroscopyXmlReader method getUShortImage.
/**
* This method returns a VCIMage object from a XML representation.
* Creation date: (3/16/2001 3:41:24 PM)
* @param param org.jdom.Element
* @return VCImage
* @throws XmlParseException
*/
private UShortImage getUShortImage(Element param) throws XmlParseException {
// get the attributes
Element tempelement = param.getChild(XMLTags.ImageDataTag);
int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
final int BYTES_PER_SHORT = 2;
int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
// getpixels
String hexEncodedBytes = tempelement.getText();
byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
InputStream rawInputStream = rawByteArrayInputStream;
if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
}
byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
int readCount = 0;
try {
while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
}
} catch (Exception e) {
e.printStackTrace();
throw new XmlParseException("error reading image pixels: ", e);
} finally {
if (rawInputStream != null) {
try {
rawInputStream.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
short[] shortPixels = new short[aNumX * aNumY * aNumZ];
for (int i = 0; i < shortPixels.length; i++) {
shortPixels[i] = byteBuffer.getShort();
}
Element extentElement = param.getChild(XMLTags.ExtentTag);
Extent extent = null;
if (extentElement != null) {
extent = vcellXMLReader.getExtent(extentElement);
}
Element originElement = param.getChild(XMLTags.OriginTag);
Origin origin = null;
if (originElement != null) {
origin = vcellXMLReader.getOrigin(originElement);
}
// //set attributes
// String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
// String annotation = param.getChildText(XMLTags.AnnotationTag);
UShortImage newimage;
try {
newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
} catch (ImageException e) {
e.printStackTrace();
throw new XmlParseException("error reading image", e);
}
return newimage;
}
Aggregations