use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class MeshDisplayAdapter method generateMeshRegionSurfaces.
/**
* Insert the method's description here.
* Creation date: (9/18/2005 10:42:24 AM)
*/
public MeshRegionSurfaces generateMeshRegionSurfaces(ClientTaskStatusSupport clientTaskStatusSupport) throws cbit.image.ImageException, UserCancelException {
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setMessage("Generating region image...");
}
RegionImage meshRegionImage = generateRegionImage(getMesh(), clientTaskStatusSupport);
cbit.vcell.geometry.surface.SurfaceCollection surfaceCollection = meshRegionImage.getSurfacecollection();
MembraneElement[] membraneElements = (MembraneElement[]) getMesh().getMembraneElements().clone();
int[][] surface_polygon_MembraneIndexes = new int[surfaceCollection.getSurfaceCount()][];
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setMessage("Generating surfaces...");
}
int totalPolygons = surfaceCollection.getTotalPolygonCount();
int counter = 0;
// Assign membraneIndexes to Polygons
for (int i = 0; i < surfaceCollection.getSurfaceCount(); i += 1) {
cbit.vcell.geometry.surface.Surface surface = surfaceCollection.getSurfaces(i);
surface_polygon_MembraneIndexes[i] = new int[surface.getPolygonCount()];
for (int j = 0; j < surface.getPolygonCount(); j += 1) {
if (clientTaskStatusSupport != null && (j % 1000 == 0)) {
if (clientTaskStatusSupport.isInterrupted()) {
throw UserCancelException.CANCEL_GENERIC;
}
clientTaskStatusSupport.setProgress(counter * 100 / totalPolygons);
}
counter++;
cbit.vcell.geometry.surface.Quadrilateral quad = (cbit.vcell.geometry.surface.Quadrilateral) surface.getPolygons(j);
int membraneIndex = -1;
for (int k = 0; k < membraneElements.length; k += 1) {
if (membraneElements[k] == null) {
continue;
}
if ((membraneElements[k].getInsideVolumeIndex() == quad.getVolIndexNeighbor1() && membraneElements[k].getOutsideVolumeIndex() == quad.getVolIndexNeighbor2()) || (membraneElements[k].getInsideVolumeIndex() == quad.getVolIndexNeighbor2() && membraneElements[k].getOutsideVolumeIndex() == quad.getVolIndexNeighbor1())) {
membraneIndex = k;
break;
}
}
if (membraneIndex == -1) {
throw new RuntimeException("Couldn't find membraneIndex for quad=" + quad);
} else if (membraneElements[membraneIndex] == null) {
throw new RuntimeException("More than 1 MembraneElement found for quad=" + quad);
}
surface_polygon_MembraneIndexes[i][j] = membraneIndex;
membraneElements[membraneIndex] = null;
}
}
// All MembraneElements should have been assigned
for (int i = 0; i < membraneElements.length; i += 1) {
if (membraneElements[i] != null) {
throw new RuntimeException("Some MembraneElements were not assigned to surface");
}
}
return new MeshRegionSurfaces(surfaceCollection, surface_polygon_MembraneIndexes);
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class FunctionRangeGenerator method main.
public static void main(String[] args) {
try {
Expression exp = new Expression("a+log(b)+c");
VarStatistics[] varStats = new VarStatistics[3];
varStats[0] = new VarStatistics("a", new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.0, 3.0 });
varStats[1] = new VarStatistics("b", new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.0, 3.0 });
varStats[2] = new VarStatistics("c", new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.0, 3.0 });
double[] times = new double[] { 0.0, 1.0, 2.0 };
Extent extent = new Extent(5, 5, 5);
Origin origin = new Origin(0, 0, 0);
// int numSamplesPerDim = 10;
byte[] pixels = new byte[3 * 3 * 3];
BitSet indomain = new BitSet(pixels.length);
for (int i = 0; i < pixels.length; i++) {
indomain.set(i);
}
VCImageUncompressed vcImage = new VCImageUncompressed(null, pixels, extent, 3, 3, 3);
RegionImage regionImage = new RegionImage(vcImage, 3, extent, origin, RegionImage.NO_SMOOTHING);
CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, new ISize(regionImage.getNumX(), regionImage.getNumY(), regionImage.getNumZ()), regionImage, true);
FunctionStatistics results = FunctionRangeGenerator.getFunctionStatistics(exp, varStats, times, mesh, indomain, VariableType.VOLUME);
System.out.println(results.getDefaultDatasetRange().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class FieldDataGUIPanel method addNewExternalData.
public static AsynchClientTask[] addNewExternalData(final Component requester, final FieldDataGUIPanel fieldDataGUIPanel, final boolean isFromSimulation) {
final RequestManager clientRequestManager = fieldDataGUIPanel.fieldDataWindowManager.getLocalRequestManager();
AsynchClientTask task1 = new AsynchClientTask("creating field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
String initialExtDataName = (String) hashTable.get("initFDName");
fdos.specEDI = null;
FieldDataInfoPanel fdip = new FieldDataInfoPanel();
fdip.setSimulationMode(isFromSimulation);
fdip.initISize(fdos.isize);
fdip.initIOrigin(fdos.origin);
fdip.initIExtent(fdos.extent);
fdip.initTimes(fdos.times);
fdip.initNames(TokenMangler.fixTokenStrict(initialExtDataName), fdos.varNames);
fdip.setAnnotation(fdos.annotation);
FieldDataFileOperationSpec userDefinedFDOS = new FieldDataFileOperationSpec();
while (true) {
int choice = PopupGenerator.showComponentOKCancelDialog(requester, fdip, "Create new field data");
if (choice == JOptionPane.OK_OPTION) {
// Check values
try {
userDefinedFDOS.extent = fdip.getExtent();
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Problem with Extent values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
continue;
}
try {
userDefinedFDOS.origin = fdip.getOrigin();
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Problem with Origin values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
continue;
}
try {
userDefinedFDOS.varNames = fdip.getVariableNames();
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Problem with Variable names. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
continue;
}
userDefinedFDOS.annotation = fdip.getAnnotation();
userDefinedFDOS.times = fdip.getTimes();
try {
if (fdip.getFieldName() == null || fdip.getFieldName().length() == 0 || !fdip.getFieldName().equals(TokenMangler.fixTokenStrict(fdip.getFieldName()))) {
throw new Exception("Field Data names can contain only letters,digits and underscores");
}
// Check to see if this name is already used
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) fieldDataGUIPanel.getJTree1().getModel().getRoot();
for (int i = 0; i < rootNode.getChildCount(); i += 1) {
ExternalDataIdentifier extDataID = ((FieldDataMainList) ((DefaultMutableTreeNode) rootNode.getChildAt(i)).getUserObject()).externalDataIdentifier;
if (fdip.getFieldName().equals(extDataID.getName())) {
throw new Exception("New Field Data name " + fdip.getFieldName() + " already used.");
}
}
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Error saving Field Data Name to Database. Try again.\n" + e.getMessage(), e);
continue;
}
hashTable.put("userDefinedFDOS", userDefinedFDOS);
hashTable.put("fieldName", fdip.getFieldName());
break;
} else {
throw UserCancelException.CANCEL_GENERIC;
}
}
}
};
AsynchClientTask task2 = new AsynchClientTask("saving field data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// Add to Server Disk
// save Database
FieldDataFileOperationSpec tempFDOS = (FieldDataFileOperationSpec) hashTable.get("userDefinedFDOS");
String fieldName = (String) hashTable.get("fieldName");
FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
DocumentManager documentManager = clientRequestManager.getDocumentManager();
FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(documentManager.getUser(), fieldName, tempFDOS.annotation);
tempFDOS.specEDI = documentManager.fieldDataDBOperation(newExtDataIDSpec).extDataID;
fdos.specEDI = tempFDOS.specEDI;
fdos.annotation = tempFDOS.annotation;
try {
if (!isFromSimulation) {
fdos.extent = tempFDOS.extent;
fdos.origin = tempFDOS.origin;
fdos.varNames = tempFDOS.varNames;
fdos.times = tempFDOS.times;
//
// Subvolumes and Regions NOT implemented now
//
fdos.cartesianMesh = CartesianMesh.createSimpleCartesianMesh(fdos.origin, fdos.extent, fdos.isize, new RegionImage(new // empty regions
VCImageUncompressed(// empty regions
null, // empty regions
new byte[fdos.isize.getXYZ()], fdos.extent, fdos.isize.getX(), fdos.isize.getY(), fdos.isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
}
// Add to Server Disk
documentManager.fieldDataFileOperation(fdos);
} catch (Exception e) {
try {
// try to cleanup new ExtDataID
documentManager.fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI));
} catch (Exception e2) {
// ignore
}
fdos.specEDI = null;
throw e;
}
}
};
AsynchClientTask task3 = new AsynchClientTask("refreshing field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
DefaultMutableTreeNode root = ((DefaultMutableTreeNode) fieldDataGUIPanel.getJTree1().getModel().getRoot());
if (root.getChildCount() == 0) {
fieldDataGUIPanel.updateJTree(clientRequestManager);
} else {
int alphabeticalIndex = -1;
for (int i = 0; i < root.getChildCount(); i += 1) {
if ((((FieldDataMainList) ((DefaultMutableTreeNode) root.getChildAt(i)).getUserObject())).externalDataIdentifier.getName().compareToIgnoreCase(fdos.specEDI.getName()) > 0) {
alphabeticalIndex = i;
break;
}
}
if (alphabeticalIndex == -1) {
alphabeticalIndex = root.getChildCount();
}
DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(fdos.specEDI, fdos.annotation));
mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList()));
((DefaultTreeModel) fieldDataGUIPanel.getJTree1().getModel()).insertNodeInto(mainNode, root, alphabeticalIndex);
}
}
};
return new AsynchClientTask[] { task1, task2, task3 };
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class FRAPStudy method getPSFFieldData.
public static FieldDataIdentifierSpec getPSFFieldData(LocalWorkspace localWorkspace) {
// create ROI image
short[] psfFieldData = null;
psfFieldData = new short[9];
psfFieldData[4] = (short) 1;
// create field data
int NumTimePoints = 1;
// 8 rois integrated into 1 image
int NumChannels = 1;
short[][][] pixData = new short[NumTimePoints][NumChannels][1];
pixData[0][0] = psfFieldData;
// get extental data id
ExternalDataIdentifier newPsfExtDataID = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.PSF_DATA_NAME).getExternalDataIdentifier();
CartesianMesh cartesianMesh;
try {
Origin origin = new Origin(0, 0, 0);
Extent ext = new Extent(1, 1, 1);
ISize isize = new ISize(3, 3, 1);
cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, ext, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], ext, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.shortSpecData = pixData;
fdos.specEDI = newPsfExtDataID;
fdos.varNames = new String[] { "psfVar" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = ext;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
FieldFunctionArguments psfFieldFunc = new FieldFunctionArguments(PSF_DATA_NAME, "psfVar", new Expression(0.0), VariableType.VOLUME);
FieldDataIdentifierSpec fdis = new FieldDataIdentifierSpec(psfFieldFunc, newPsfExtDataID);
return fdis;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class FRAPStudy method getCartesianMesh.
public CartesianMesh getCartesianMesh() throws Exception {
CartesianMesh cartesianMesh = null;
ImageDataset imgDataSet = getFrapData().getImageDataset();
Extent extent = imgDataSet.getExtent();
ISize isize = imgDataSet.getISize();
Origin origin = new Origin(0, 0, 0);
if (getBioModel() == null) {
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));
} else {
RegionImage regionImage = getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().getRegionImage();
if (regionImage == null) {
getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().updateAll();
regionImage = getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().getRegionImage();
}
cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
}
return cartesianMesh;
}
Aggregations