use of org.vcell.util.Extent in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getSimsFromOpenModels.
@Override
public List<SimulationDataSetRef> getSimsFromOpenModels() {
ArrayList<SimulationDataSetRef> simulationDataSetRefs = new ArrayList<SimulationDataSetRef>();
for (TopLevelWindowManager windowManager : vcellClient.getMdiManager().getWindowManagers()) {
Simulation[] simulations = null;
VCDocument modelDocument = null;
if (windowManager instanceof BioModelWindowManager) {
BioModelWindowManager selectedBioWindowManager = (BioModelWindowManager) windowManager;
BioModel bioModel = selectedBioWindowManager.getBioModel();
simulations = bioModel.getSimulations();
modelDocument = bioModel;
// simOwnerCount = bioModel.getNumSimulationContexts();
} else if (windowManager instanceof MathModelWindowManager) {
MathModelWindowManager selectedMathWindowManager = (MathModelWindowManager) windowManager;
MathModel mathModel = selectedMathWindowManager.getMathModel();
simulations = mathModel.getSimulations();
modelDocument = mathModel;
// simOwnerCount = 1;
}
if (simulations != null) {
for (Simulation simulation : simulations) {
if (!isVtkSupported(simulation)) {
continue;
}
Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
Extent extent = simulation.getMathDescription().getGeometry().getExtent();
SimulationInfo simInfo = simulation.getSimulationInfo();
SimulationStatus simStatus = vcellClient.getRequestManager().getServerSimulationStatus(simInfo);
for (int jobIndex = 0; jobIndex < simulation.getScanCount(); jobIndex++) {
if (simStatus != null && simStatus.getHasData()) {
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simulation, modelDocument, jobIndex, false);
simulationDataSetRefs.add(simulationDataSetReference);
}
}
}
}
}
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
String[] simtaskFilenames = localSimDir.list((dir, name) -> (name.endsWith(".simtask.xml")));
for (String simtaskFilename : simtaskFilenames) {
try {
SimulationTask simTask = XmlHelper.XMLToSimTask(org.apache.commons.io.FileUtils.readFileToString(new File(localSimDir, simtaskFilename)));
VCDocument modelDocument = null;
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simTask.getSimulation(), modelDocument, simTask.getSimulationJob().getJobIndex(), true);
simulationDataSetRefs.add(simulationDataSetReference);
} catch (ExpressionException | XmlParseException | IOException e) {
e.printStackTrace();
}
}
return simulationDataSetRefs;
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class ClientRequestManager method createNewDocument.
/**
* Insert the method's description here. Creation date: (5/10/2004 3:48:16 PM)
*/
public AsynchClientTask[] createNewDocument(final TopLevelWindowManager requester, final VCDocument.DocumentCreationInfo documentCreationInfo) {
// throws UserCancelException, Exception {
/* asynchronous and not blocking any window */
AsynchClientTask[] taskArray = null;
final int createOption = documentCreationInfo.getOption();
switch(documentCreationInfo.getDocumentType()) {
case BIOMODEL_DOC:
{
AsynchClientTask task1 = new AsynchClientTask("creating biomodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel bioModel = createDefaultBioModelDocument(null);
hashTable.put("doc", bioModel);
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
}
case MATHMODEL_DOC:
{
if ((createOption == VCDocument.MATH_OPTION_NONSPATIAL) || (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS)) {
AsynchClientTask task2 = new AsynchClientTask("creating mathmodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = null;
if (createOption == VCDocument.MATH_OPTION_NONSPATIAL) {
geometry = new Geometry("Untitled", 0);
} else {
geometry = (Geometry) hashTable.get(GEOMETRY_KEY);
}
MathModel mathModel = createMathModel("Untitled", geometry);
mathModel.setName("MathModel" + (getMdiManager().getNumCreatedDocumentWindows() + 1));
hashTable.put("doc", mathModel);
}
};
if (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS) {
AsynchClientTask task1 = createSelectDocTask(requester);
AsynchClientTask task1b = createSelectLoadGeomTask(requester);
taskArray = new AsynchClientTask[] { task1, task1b, task2 };
} else {
taskArray = new AsynchClientTask[] { task2 };
}
break;
} else if (createOption == VCDocument.MATH_OPTION_FROMBIOMODELAPP) {
AsynchClientTask task1 = new AsynchClientTask("select biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// spatial or non-spatial
BioModelInfo bioModelInfo = (BioModelInfo) DialogUtils.getDBTreePanelSelection(requester.getComponent(), getMdiManager().getDatabaseWindowManager().getBioModelDbTreePanel(), "Open", "Select BioModel");
if (bioModelInfo != null) {
// may throw UserCancelException
hashTable.put("bioModelInfo", bioModelInfo);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("find sim contexts in biomodel application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// spatial or non-spatial
// Get the simContexts in the corresponding BioModel
BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
SimulationContext[] simContexts = getDocumentManager().getBioModel(bioModelInfo).getSimulationContexts();
if (simContexts != null) {
// may throw UserCancelException
hashTable.put("simContexts", simContexts);
}
}
};
AsynchClientTask task3 = new AsynchClientTask("create math model from biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
SimulationContext[] simContexts = (SimulationContext[]) hashTable.get("simContexts");
String[] simContextNames = new String[simContexts.length];
if (simContextNames.length == 0) {
throw new RuntimeException("no application is available");
} else {
for (int i = 0; i < simContexts.length; i++) {
simContextNames[i] = simContexts[i].getName();
}
Component component = requester.getComponent();
// Get the simContext names, so that user can choose which simContext math to
// import
String simContextChoice = (String) PopupGenerator.showListDialog(component, simContextNames, "Please select Application");
if (simContextChoice == null) {
throw UserCancelException.CANCEL_DB_SELECTION;
}
SimulationContext chosenSimContext = null;
for (int i = 0; i < simContexts.length; i++) {
if (simContexts[i].getName().equals(simContextChoice)) {
chosenSimContext = simContexts[i];
break;
}
}
Objects.requireNonNull(chosenSimContext);
BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
// Get corresponding mathDesc to create new mathModel and return.
String newName = bioModelInfo.getVersion().getName() + "_" + chosenSimContext.getName();
MathDescription bioMathDesc = chosenSimContext.getMathDescription();
MathDescription newMathDesc = null;
newMathDesc = new MathDescription(newName + "_" + (new Random()).nextInt());
newMathDesc.setGeometry(bioMathDesc.getGeometry());
newMathDesc.read_database(new CommentStringTokenizer(bioMathDesc.getVCML_database()));
newMathDesc.isValid();
MathModel newMathModel = new MathModel(null);
newMathModel.setName(newName);
newMathModel.setMathDescription(newMathDesc);
hashTable.put("doc", newMathModel);
}
}
};
taskArray = new AsynchClientTask[] { task1, task2, task3 };
break;
} else {
throw new RuntimeException("Unknown MathModel Document creation option value=" + documentCreationInfo.getOption());
}
}
case GEOMETRY_DOC:
{
if (createOption == VCDocument.GEOM_OPTION_1D || createOption == VCDocument.GEOM_OPTION_2D || createOption == VCDocument.GEOM_OPTION_3D) {
// analytic
AsynchClientTask task1 = new AsynchClientTask("creating analytic geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), documentCreationInfo.getOption());
geometry.getGeometrySpec().addSubVolume(new AnalyticSubVolume("subdomain0", new Expression(1.0)));
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
hashTable.put("doc", geometry);
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
}
if (createOption == VCDocument.GEOM_OPTION_CSGEOMETRY_3D) {
// constructed solid geometry
AsynchClientTask task1 = new AsynchClientTask("creating constructed solid geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), 3);
Extent extent = geometry.getExtent();
if (extent != null) {
// create a CSGPrimitive of type cube and scale it to the 'extent' components.
// Use this as the default or background CSGObject (subdomain).
// This can be considered as the equivalent of subdomain (with expression) 1.0
// for analyticSubvolume.
// basic cube
CSGPrimitive cube = new CSGPrimitive("cube", CSGPrimitive.PrimitiveType.CUBE);
// scaled cube
double x = extent.getX();
double y = extent.getY();
double z = extent.getZ();
CSGScale scaledCube = new CSGScale("scale", new Vect3d(x / 2.0, y / 2.0, z / 2.0));
scaledCube.setChild(cube);
// translated scaled cube
CSGTranslation translatedScaledCube = new CSGTranslation("translation", new Vect3d(x / 2, y / 2, z / 2));
translatedScaledCube.setChild(scaledCube);
CSGObject csgObject = new CSGObject(null, "subdomain0", 0);
csgObject.setRoot(translatedScaledCube);
geometry.getGeometrySpec().addSubVolume(csgObject, false);
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
hashTable.put("doc", geometry);
}
}
};
taskArray = new AsynchClientTask[] { task1 };
break;
} else {
throw new RuntimeException("Unknown Geometry Document creation option value=" + documentCreationInfo.getOption());
}
}
default:
{
throw new RuntimeException("Unknown default document type: " + documentCreationInfo.getDocumentType());
}
}
return taskArray;
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class ClientRequestManager method createFDOSWithChannels.
public static FieldDataFileOperationSpec createFDOSWithChannels(ImageDataset[] imagedataSets, Integer saveOnlyThisTimePointIndex) {
final FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
// [time][var][data]
int numXY = imagedataSets[0].getISize().getX() * imagedataSets[0].getISize().getY();
int numXYZ = imagedataSets[0].getSizeZ() * numXY;
fdos.variableTypes = new VariableType[imagedataSets.length];
fdos.varNames = new String[imagedataSets.length];
short[][][] shortData = new short[(saveOnlyThisTimePointIndex != null ? 1 : imagedataSets[0].getSizeT())][imagedataSets.length][numXYZ];
for (int c = 0; c < imagedataSets.length; c += 1) {
fdos.variableTypes[c] = VariableType.VOLUME;
fdos.varNames[c] = "Channel" + c;
for (int t = 0; t < imagedataSets[c].getSizeT(); t += 1) {
if (saveOnlyThisTimePointIndex != null && saveOnlyThisTimePointIndex.intValue() != t) {
continue;
}
int zOffset = 0;
for (int z = 0; z < imagedataSets[c].getSizeZ(); z += 1) {
UShortImage ushortImage = imagedataSets[c].getImage(z, 0, t);
System.arraycopy(ushortImage.getPixels(), 0, shortData[(saveOnlyThisTimePointIndex != null ? 0 : t)][c], zOffset, numXY);
// shortData[t][c] = ushortImage.getPixels();
zOffset += numXY;
}
}
}
fdos.shortSpecData = shortData;
fdos.times = imagedataSets[0].getImageTimeStamps();
if (fdos.times == null) {
fdos.times = new double[imagedataSets[0].getSizeT()];
for (int i = 0; i < fdos.times.length; i += 1) {
fdos.times[i] = i;
}
}
fdos.origin = (imagedataSets[0].getAllImages()[0].getOrigin() != null ? imagedataSets[0].getAllImages()[0].getOrigin() : new Origin(0, 0, 0));
fdos.extent = (imagedataSets[0].getExtent() != null) ? (imagedataSets[0].getExtent()) : (new Extent(1, 1, 1));
fdos.isize = imagedataSets[0].getISize();
return fdos;
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class MeshSpecificationPanel method autoUpdateSizes.
private void autoUpdateSizes(DocumentEvent e) {
if (bInProgress) {
return;
}
final int dimension = getMeshSpecification().getGeometry().getDimension();
if (!getAutoMeshSizeCheckBox().isSelected()) {
updateTotalSizeAndSpatialStep();
return;
}
JTextField input = null;
try {
bInProgress = true;
Extent extent = getMeshSpecification().getGeometry().getExtent();
if (e.getDocument() == getXTextField().getDocument()) {
input = getXTextField();
String xtext = getXTextField().getText();
if (xtext == null || xtext.trim().length() == 0) {
getYTextField().setText(xtext);
getZTextField().setText(xtext);
clearTotalSizeAndSpatialStep();
return;
}
int numX = Integer.parseInt(xtext);
if (dimension > 1) {
double yxRatio = extent.getY() / extent.getX();
long numY = computeAnotherSizeWRTAspectRatio(numX, yxRatio);
getYTextField().setText("" + numY);
if (dimension > 2) {
double zxRatio = extent.getZ() / extent.getX();
long numZ = computeAnotherSizeWRTAspectRatio(numX, zxRatio);
getZTextField().setText("" + numZ);
}
}
} else if (e.getDocument() == getYTextField().getDocument()) {
input = getYTextField();
String ytext = getYTextField().getText();
if (ytext == null || ytext.trim().length() == 0) {
getXTextField().setText(ytext);
getZTextField().setText(ytext);
clearTotalSizeAndSpatialStep();
return;
}
int numY = Integer.parseInt(ytext);
double xyRatio = extent.getX() / extent.getY();
long numX = computeAnotherSizeWRTAspectRatio(numY, xyRatio);
getXTextField().setText("" + numX);
if (dimension > 2) {
double zyRatio = extent.getZ() / extent.getY();
long numZ = computeAnotherSizeWRTAspectRatio(numY, zyRatio);
getZTextField().setText("" + numZ);
}
} else if (e.getDocument() == getZTextField().getDocument()) {
input = getZTextField();
String ztext = getZTextField().getText();
if (ztext == null || ztext.trim().length() == 0) {
getXTextField().setText(ztext);
getYTextField().setText(ztext);
clearTotalSizeAndSpatialStep();
return;
}
int numZ = Integer.parseInt(ztext);
if (dimension > 2) {
double xzRatio = extent.getX() / extent.getZ();
double yzRatio = extent.getY() / extent.getZ();
long numX = computeAnotherSizeWRTAspectRatio(numZ, xzRatio);
long numY = computeAnotherSizeWRTAspectRatio(numZ, yzRatio);
getXTextField().setText("" + numX);
getYTextField().setText("" + numY);
}
}
input.setBorder(UIManager.getBorder("TextField.border"));
updateTotalSizeAndSpatialStep();
} catch (NumberFormatException ex) {
DialogUtils.showErrorDialog(this, "Wrong number format " + ex.getMessage().toLowerCase());
input.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
clearTotalSizeAndSpatialStep();
} finally {
bInProgress = false;
}
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class ChomboMeshSpecificationPanel method updateDisplay.
private void updateDisplay(boolean bSolverChanged) throws ChomboGeometryException, ChomboInvalidGeometryException {
if (!simulation.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
setVisible(false);
return;
}
Geometry geometry = simulation.getMathDescription().getGeometry();
Extent extent = geometry.getExtent();
int dimension = geometry.getDimension();
switch(dimension) {
case 0:
setVisible(false);
break;
case 1:
getGeometrySizeTextField().setText("" + extent.getX());
NyLabel.setVisible(false);
NyComboBox.setVisible(false);
NzLabel.setVisible(false);
NzComboBox.setVisible(false);
break;
case 2:
getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ")");
NzLabel.setVisible(false);
NzComboBox.setVisible(false);
break;
case 3:
getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")");
break;
}
String error;
ChomboMeshRecommendation meshRecommendation = new ChomboMeshValidator(geometry.getDimension(), geometry.getExtent(), simulation.getSolverTaskDescription().getChomboSolverSpec().getBlockFactor()).computeMeshSpecs();
if (meshRecommendation.validate()) {
// remove ActionListener, here we only want to set values
removeComboBoxListener();
HComboBox.removeAll();
NxComboBox.removeAll();
NyComboBox.removeAll();
NzComboBox.removeAll();
for (ChomboMeshSpec meshSpec : meshRecommendation.validMeshSpecList) {
HComboBox.addItem((float) meshSpec.H);
NxComboBox.addItem(meshSpec.Nx[0]);
if (geometry.getDimension() > 1) {
NyComboBox.addItem(meshSpec.Nx[1]);
if (geometry.getDimension() == 3) {
NzComboBox.addItem(meshSpec.Nx[2]);
}
}
}
addComboBoxListener();
if (bSolverChanged) {
NxComboBox.setSelectedIndex(0);
} else {
ISize samplingSize = simulation.getMeshSpecification().getSamplingSize();
NxComboBox.setSelectedItem(samplingSize.getX());
// double check if existing mesh size is an option in drop down
Integer selectedNx = (Integer) NxComboBox.getSelectedItem();
Integer selectedNy = geometry.getDimension() > 1 ? (Integer) NyComboBox.getSelectedItem() : 1;
Integer selectedNz = geometry.getDimension() > 2 ? (Integer) NzComboBox.getSelectedItem() : 1;
boolean bMatchFound = selectedNx == samplingSize.getX() && (dimension < 2 || selectedNy == samplingSize.getY()) && (dimension < 3 || selectedNz == samplingSize.getZ());
if (!bMatchFound) {
NxComboBox.setSelectedIndex(0);
throw new ChomboGeometryException(ChomboMeshValidator.ERROR_MESSAGE_INCOMPATIBLE_MESH_SIZE);
}
}
} else {
throw new ChomboInvalidGeometryException(meshRecommendation);
}
}
Aggregations