use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class GeometryViewer method resample.
private void resample() {
AsynchClientTask precomputeCurrentGeometryTask = new AsynchClientTask("computing surfaces for existing geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (getGeometry().getGeometrySurfaceDescription().getRegionImage() == null) {
getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT(), true, true);
}
}
};
AsynchClientTask sampleSizeTask = new AsynchClientTask("specify sample size", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
VCImage currSampledImage = getGeometry().getGeometrySpec().getSampledImage().getCurrentValue();
int currNumSamples = currSampledImage.getNumXYZ();
ISize currSize = new ISize(currSampledImage.getNumX(), currSampledImage.getNumY(), currSampledImage.getNumZ());
ISize sampleSize_times_ten = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), currNumSamples * 10);
ISize sampleSize_div_ten = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), currNumSamples / 10);
ISize sampleSize_1e2 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e2);
ISize sampleSize_1e3 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e3);
ISize sampleSize_1e4 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e4);
ISize sampleSize_1e5 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e5);
ISize sampleSize_1e6 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e6);
ISize sampleSize_1e7 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e7);
ISize sampleSize_1e8 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e8);
String[] columnNames = new String[] { "description", "num samples", "(X,Y,Z)" };
Object[][] rowData = new Object[][] { new Object[] { "same size", new Integer(currSize.getXYZ()), currSize }, new Object[] { "10 times smaller", new Integer(sampleSize_div_ten.getXYZ()), sampleSize_div_ten }, new Object[] { "10 times bigger", new Integer(sampleSize_times_ten.getXYZ()), sampleSize_times_ten }, new Object[] { " 100 samples", new Integer(sampleSize_1e2.getXYZ()), sampleSize_1e2 }, new Object[] { " 1,000 samples", new Integer(sampleSize_1e3.getXYZ()), sampleSize_1e3 }, new Object[] { " 10,000 samples", new Integer(sampleSize_1e4.getXYZ()), sampleSize_1e4 }, new Object[] { " 100,000 samples", new Integer(sampleSize_1e5.getXYZ()), sampleSize_1e5 }, new Object[] { " 1,000,000 samples", new Integer(sampleSize_1e6.getXYZ()), sampleSize_1e6 }, new Object[] { " 10,000,000 samples", new Integer(sampleSize_1e7.getXYZ()), sampleSize_1e7 }, new Object[] { "100,000,000 samples", new Integer(sampleSize_1e8.getXYZ()), sampleSize_1e8 } };
int[] selectedRows = DialogUtils.showComponentOKCancelTableList(GeometryViewer.this, "sample size", columnNames, rowData, ListSelectionModel.SINGLE_SELECTION);
ISize sampleSize = (ISize) rowData[selectedRows[0]][2];
hashTable.put("sampleSize", sampleSize);
}
};
AsynchClientTask resampleTask = new AsynchClientTask("resample geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ISize sampleSize = (ISize) hashTable.get("sampleSize");
Geometry newGeometry = RayCaster.resampleGeometry(new GeometryThumbnailImageFactoryAWT(), getGeometry(), sampleSize);
hashTable.put("newGeometry", newGeometry);
}
};
AsynchClientTask setGeometryTask = new AsynchClientTask("loading geometry", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry newGeometry = (Geometry) hashTable.get("newGeometry");
if (getGeometryOwner() instanceof SimulationContext) {
((SimulationContext) getGeometryOwner()).setGeometry(newGeometry);
} else if (getGeometryOwner() instanceof MathModel) {
((MathModel) getGeometryOwner()).getMathDescription().setGeometry(newGeometry);
} else {
throw new RuntimeException("unexpected geometry owner, could not set resampled geometry");
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { precomputeCurrentGeometryTask, sampleSizeTask, resampleTask, setGeometryTask }, false);
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class CSGObjectPropertiesPanel method updateCSGObject.
private void updateCSGObject(final Object objectToBeSelected) {
if (csgObject.getRoot() != null) {
csgObject.setRoot(csgObject.getRoot().clone());
}
AsynchClientTask task1 = new AsynchClientTask("regenerating geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
simulationContext.getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT(), true, true);
}
};
AsynchClientTask task2 = new AsynchClientTask("refreshing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
csgObjectTreeModel.select(objectToBeSelected);
}
};
ClientTaskDispatcher.dispatch(CSGObjectPropertiesPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class GeometrySizeDialog method Ok.
/**
* Comment
*/
private void Ok() throws PropertyVetoException {
final double worldExtentX = Double.valueOf(getSizeXTextField().getText()).doubleValue();
final double worldExtentY = Double.valueOf(getSizeYTextField().getText()).doubleValue();
final double worldExtentZ = Double.valueOf(getSizeZTextField().getText()).doubleValue();
final double worldOriginX = Double.valueOf(getOriginXTextField().getText()).doubleValue();
final double worldOriginY = Double.valueOf(getOriginYTextField().getText()).doubleValue();
final double worldOriginZ = Double.valueOf(getOriginZTextField().getText()).doubleValue();
final GeometrySpec geometrySpec = getGeometry().getGeometrySpec();
AsynchClientTask extentOriginTask = new AsynchClientTask("Changing domain", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
geometrySpec.setExtent(new Extent(worldExtentX, worldExtentY, worldExtentZ));
geometrySpec.setOrigin(new Origin(worldOriginX, worldOriginY, worldOriginZ));
getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
}
};
ClientTaskDispatcher.dispatch(this.getParent(), new Hashtable<String, Object>(), new AsynchClientTask[] { extentOriginTask }, false);
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class BioModelWindowManager method actionPerformed.
/**
* Invoked when an action occurs.
*/
public void actionPerformed(java.awt.event.ActionEvent e) {
String actionCommand = e.getActionCommand();
final Object source = e.getSource();
if (source instanceof GeometryViewer && (actionCommand.equals(GuiConstants.ACTIONCMD_CREATE_GEOMETRY) || actionCommand.equals(GuiConstants.ACTIONCMD_EDITCURRENTSPATIAL_GEOMETRY))) {
final GeometryViewer geometryViewer = (GeometryViewer) source;
AsynchClientTask precomputeAllTask = new AsynchClientTask("precomputeAll geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry newGeom = (Geometry) hashTable.get("doc");
if (newGeom != null) {
newGeom.precomputeAll(new GeometryThumbnailImageFactoryAWT());
}
}
};
AsynchClientTask setGeomOnSimContextTask = new AsynchClientTask("Setting geometry on application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry newGeom = (Geometry) hashTable.get("doc");
for (SimulationContext simulationContext : getBioModel().getSimulationContexts()) {
if (simulationContext == geometryViewer.getGeometryOwner()) {
if (newGeom.getName() == null) {
newGeom.setName(getBioModel().getName() + "_" + (simulationContext.getName() + "_" + BeanUtils.generateDateTimeString()));
}
simulationContext.setGeometry(newGeom);
return;
}
}
Geometry origGeom = geometryViewer.getGeometryOwner().getGeometry();
throw new IllegalArgumentException("Couldn't find matching application editor for orig geom '" + origGeom.getName() + "' key=" + origGeom.getKey() + " in application hash.");
}
};
Geometry currentGeometry = geometryViewer.getGeometryOwner().getGeometry();
createGeometry(currentGeometry, new AsynchClientTask[] { /*oldEditorTask,*/
precomputeAllTask, setGeomOnSimContextTask }, TopLevelWindowManager.DEFAULT_CREATEGEOM_SELECT_DIALOG_TITLE, TopLevelWindowManager.APPLY_GEOMETRY_BUTTON_TEXT, (actionCommand.equals(GuiConstants.ACTIONCMD_EDITCURRENTSPATIAL_GEOMETRY) ? new DocumentWindowManager.GeometrySelectionInfo() : null));
}
if (source instanceof MathematicsPanel && actionCommand.equals(GuiConstants.ACTIONCMD_CREATE_MATH_MODEL)) {
SimulationContext sc = ((MathematicsPanel) source).getSimulationContext();
getRequestManager().createMathModelFromApplication(this, "Untitled", sc);
}
if (source instanceof GeometryViewer && actionCommand.equals(GuiConstants.ACTIONCMD_CHANGE_GEOMETRY)) {
final GeometryViewer geometryViewer = (GeometryViewer) source;
getRequestManager().changeGeometry(this, (SimulationContext) geometryViewer.getGeometryOwner());
}
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT 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;
}
Aggregations