use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class GeometryGuiTest method main.
public static void main(java.lang.String[] args) {
try {
javax.swing.JFrame frame = new javax.swing.JFrame();
GeometryViewer aGeometryViewer;
aGeometryViewer = new GeometryViewer();
frame.setContentPane(aGeometryViewer);
frame.setSize(aGeometryViewer.getSize());
frame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
Geometry csGeometry = getExampleGeometryCSG();
// try to convert this CSG geometry to image
ISize imageSize = csGeometry.getGeometrySpec().getDefaultSampledImageSize();
Geometry imageGeometry = RayCaster.resampleGeometry(new GeometryThumbnailImageFactoryAWT(), csGeometry, imageSize);
// aGeometryViewer.setGeometry(csGeometry);
aGeometryViewer.setGeometry(imageGeometry);
frame.setSize(600, 600);
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JPanel");
exception.printStackTrace(System.out);
}
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class GeometryGuiTest method getExampleGeometryCSG.
public static Geometry getExampleGeometryCSG() throws PropertyVetoException, ExpressionException, GeometryException, ImageException {
// translated rotated cube
CSGPrimitive cube = new CSGPrimitive("cube", CSGPrimitive.PrimitiveType.CUBE);
CSGRotation rotatedCube = new CSGRotation("Rotation", new Vect3d(1, 2, 3), Math.PI / 4.0);
rotatedCube.setChild(cube);
// translated sphere
CSGTranslation translatedSphere = new CSGTranslation("translation", new Vect3d(0.5, 0.5, 0.5));
CSGPrimitive sphere = new CSGPrimitive("sphere", CSGPrimitive.PrimitiveType.SPHERE);
translatedSphere.setChild(sphere);
// union
CSGSetOperator csgSetOperator = new CSGSetOperator("difference", OperatorType.DIFFERENCE);
csgSetOperator.addChild(rotatedCube);
csgSetOperator.addChild(translatedSphere);
// scaled union
CSGScale csgScale = new CSGScale("scale", new Vect3d(3, 3, 3));
csgScale.setChild(csgSetOperator);
CSGTranslation csgTranslatedUnion = new CSGTranslation("translationUnion", new Vect3d(5, 5, 5));
csgTranslatedUnion.setChild(csgScale);
Geometry geometry = new Geometry("csg", 3);
CSGObject csgObject = new CSGObject(null, "obj1", 1);
csgObject.setRoot(csgTranslatedUnion);
geometry.getGeometrySpec().addSubVolume(new AnalyticSubVolume("background", new Expression(1.0)));
geometry.getGeometrySpec().addSubVolume(csgObject, true);
geometry.refreshDependencies();
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
return geometry;
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class GeometrySubVolumeTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (rowIndex < 0 || rowIndex >= getRowCount()) {
throw new RuntimeException("GeometrySubVolumeTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
}
if (columnIndex < 0 || columnIndex >= getColumnCount()) {
throw new RuntimeException("GeometrySubVolumeTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
}
final SubVolume subVolume = getValueAt(rowIndex);
try {
switch(columnIndex) {
case COLUMN_NAME:
{
final String newName = (String) aValue;
final String oldName = subVolume.getName();
subVolume.setName(newName);
AsynchClientTask task1 = new AsynchClientTask("changing the name", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
GeometrySpec gs = getGeometry().getGeometrySpec();
if (gs != null) {
gs.geometryNameChanged(oldName, newName);
} else {
if (lg.isEnabledFor(Level.WARN)) {
lg.warn(getGeometry().getDescription() + " has no GeometrySpec?");
}
}
}
};
ClientTaskDispatcher.dispatch(ownerTable, new Hashtable<String, Object>(), new AsynchClientTask[] { task1 }, false);
break;
}
case COLUMN_VALUE:
{
if (subVolume instanceof AnalyticSubVolume) {
final AnalyticSubVolume analyticSubVolume = (AnalyticSubVolume) subVolume;
if (aValue instanceof ScopedExpression) {
throw new RuntimeException("unexpected value type ScopedExpression");
} else if (aValue instanceof String) {
final String newExpressionString = (String) aValue;
analyticSubVolume.setExpression(new Expression(newExpressionString));
AsynchClientTask task1 = new AsynchClientTask("changing the expression", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
}
};
ClientTaskDispatcher.dispatch(ownerTable, new Hashtable<String, Object>(), new AsynchClientTask[] { task1 }, false);
}
}
break;
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(ownerTable, e.getMessage(), e);
}
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class BioModelEditorApplicationPanel method setSimulationContext.
public void setSimulationContext(SimulationContext newValue) {
if (simulationContext == newValue) {
return;
}
final boolean respondingToSelectionManager = selectionManager.isBusy();
final Object[] selectedObj = selectionManager.getSelectedObjects();
SimulationContext oldValue = simulationContext;
if (oldValue != null) {
oldValue.removePropertyChangeListener(eventHandler);
}
if (newValue != null) {
newValue.addPropertyChangeListener(eventHandler);
}
simulationContext = newValue;
AsynchClientTask task1 = new AsynchClientTask("loading application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
simulationContext.getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
}
};
AsynchClientTask task2 = new AsynchClientTask("showing application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
applicationGeometryPanel.setSimulationContext(simulationContext);
applicationSpecificationsPanel.setSimulationContext(simulationContext);
applicationProtocolsPanel.setSimulationContext(simulationContext);
applicationSimulationsPanel.setSimulationContext(simulationContext);
parameterEstimationPanel.setSelectionManager(null);
showOrHideFittingPanel();
parameterEstimationPanel.setSelectionManager(selectionManager);
// showOrHideProtocolsPanel();
if (respondingToSelectionManager) {
selectionManager.setSelectedObjects(new Object[0]);
selectionManager.setSelectedObjects(selectedObj);
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
use of cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT in project vcell by virtualcell.
the class SimulationContext method copySimulationContext.
public static SimulationContext copySimulationContext(SimulationContext srcSimContext, String newSimulationContextName, boolean bSpatial, Application simContextType) throws java.beans.PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException {
Geometry newClonedGeometry = new Geometry(srcSimContext.getGeometry());
newClonedGeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
// if stoch copy to ode, we need to check is stoch is using particles. If yes, should convert particles to concentraton.
// the other 3 cases are fine. ode->ode, ode->stoch, stoch-> stoch
SimulationContext destSimContext = new SimulationContext(srcSimContext, newClonedGeometry, simContextType);
if (srcSimContext.getApplicationType() == Application.NETWORK_STOCHASTIC && !srcSimContext.isUsingConcentration() && simContextType == Application.NETWORK_DETERMINISTIC) {
try {
destSimContext.convertSpeciesIniCondition(true);
} catch (MappingException e) {
e.printStackTrace();
throw new java.beans.PropertyVetoException(e.getMessage(), null);
}
}
if (srcSimContext.getGeometry().getDimension() > 0 && !bSpatial) {
// copy the size over
destSimContext.setGeometry(new Geometry("nonspatial", 0));
StructureMapping[] srcStructureMappings = srcSimContext.getGeometryContext().getStructureMappings();
StructureMapping[] destStructureMappings = destSimContext.getGeometryContext().getStructureMappings();
for (StructureMapping destStructureMapping : destStructureMappings) {
for (StructureMapping srcStructureMapping : srcStructureMappings) {
if (destStructureMapping.getStructure() == srcStructureMapping.getStructure()) {
if (srcStructureMapping.getUnitSizeParameter() != null) {
Expression sizeRatio = srcStructureMapping.getUnitSizeParameter().getExpression();
GeometryClass srcGeometryClass = srcStructureMapping.getGeometryClass();
GeometricRegion[] srcGeometricRegions = srcSimContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions(srcGeometryClass);
if (srcGeometricRegions != null) {
double size = 0;
for (GeometricRegion srcGeometricRegion : srcGeometricRegions) {
size += srcGeometricRegion.getSize();
}
destStructureMapping.getSizeParameter().setExpression(Expression.mult(sizeRatio, new Expression(size)));
}
}
break;
}
}
}
// If changing spatial to non-spatial
// set diffusion to 0, velocity and boundary to null
// srcSimContext.getReactionContext().getspe
Parameter[] allParameters = destSimContext.getAllParameters();
if (allParameters != null && allParameters.length > 0) {
for (int i = 0; i < allParameters.length; i++) {
if (allParameters[i] instanceof SpeciesContextSpecParameter) {
SpeciesContextSpecParameter speciesContextSpecParameter = (SpeciesContextSpecParameter) allParameters[i];
int role = speciesContextSpecParameter.getRole();
if (role == SpeciesContextSpec.ROLE_DiffusionRate) {
speciesContextSpecParameter.setExpression(new Expression(0));
} else if (role == SpeciesContextSpec.ROLE_BoundaryValueXm || role == SpeciesContextSpec.ROLE_BoundaryValueXp || role == SpeciesContextSpec.ROLE_BoundaryValueYm || role == SpeciesContextSpec.ROLE_BoundaryValueYp || role == SpeciesContextSpec.ROLE_BoundaryValueZm || role == SpeciesContextSpec.ROLE_BoundaryValueZp) {
speciesContextSpecParameter.setExpression(null);
} else if (role == SpeciesContextSpec.ROLE_VelocityX || role == SpeciesContextSpec.ROLE_VelocityY || role == SpeciesContextSpec.ROLE_VelocityZ) {
speciesContextSpecParameter.setExpression(null);
}
}
}
}
}
destSimContext.fixFlags();
destSimContext.setName(newSimulationContextName);
return destSimContext;
}
Aggregations