use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class ClientRequestManager method createFDOSFromSurfaceFile.
public static FieldDataFileOperationSpec createFDOSFromSurfaceFile(File surfaceFile) throws Exception {
SurfaceCollection surfaceCollection = createSurfaceCollectionFromSurfaceFile(surfaceFile);
if (surfaceCollection != null) {
Geometry geometry = RayCaster.createGeometryFromSTL(new GeometryThumbnailImageFactoryAWT(), surfaceCollection, 1000000);
FieldDataFileOperationSpec fdfos = new FieldDataFileOperationSpec();
fdfos.origin = geometry.getOrigin();
fdfos.extent = geometry.getExtent();
VCImage image = geometry.getGeometrySpec().getImage();
if (image.getNumPixelClasses() == 1) {
throw new Exception("STL import failed during processing, pixelclass count=1");
}
fdfos.isize = new ISize(image.getNumX(), image.getNumY(), image.getNumZ());
byte[] pixels = image.getPixels();
short[] dataToSegment = new short[image.getNumXYZ()];
for (int i = 0; i < pixels.length; i++) {
dataToSegment[i] = pixels[i];
}
fdfos.shortSpecData = new short[][][] { { dataToSegment } };
return fdfos;
}
return null;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class OptXmlWriter method getModelXML.
public static Element getModelXML(PdeObjectiveFunction pdeObjectiveFunction, String[] parameterNames) {
Element modelElement = new Element(OptXmlTags.Model_Tag);
try {
SpatialReferenceData refData = pdeObjectiveFunction.getReferenceData();
double refDataEndTime = refData.getDataByRow(refData.getNumDataRows() - 1)[0];
//
// post the problem either as an IDA or CVODE model
//
org.vcell.util.document.SimulationVersion simVersion = new org.vcell.util.document.SimulationVersion(new KeyValue("12345"), "name", new org.vcell.util.document.User("user", new KeyValue("123")), new org.vcell.util.document.GroupAccessNone(), // versionBranchPointRef
null, // branchID
new java.math.BigDecimal(1.0), new java.util.Date(), org.vcell.util.document.VersionFlag.Archived, "", null);
Simulation simulation = new Simulation(simVersion, pdeObjectiveFunction.getMathDescription());
simulation.getMeshSpecification().setSamplingSize(refData.getDataISize());
double[] times = refData.getDataByColumn(0);
double minDt = Double.POSITIVE_INFINITY;
for (int i = 1; i < times.length; i++) {
minDt = Math.min(minDt, times[i] - times[i - 1]);
}
simulation.getSolverTaskDescription().setTimeBounds(new cbit.vcell.solver.TimeBounds(0.0, refDataEndTime));
simulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolume);
simulation.getSolverTaskDescription().setTimeStep(new TimeStep(minDt / 5, minDt / 5, minDt / 5));
// clone and resample geometry
Geometry resampledGeometry = null;
try {
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simulation.getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, pdeObjectiveFunction.getFieldDataIDSs()), 0);
StringWriter simulationInputStringWriter = new StringWriter();
FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter, true), simTask, resampledGeometry, pdeObjectiveFunction.getWorkingDirectory());
fvFileWriter.write(parameterNames);
simulationInputStringWriter.close();
modelElement.setAttribute(OptXmlTags.ModelType_Attr, OptXmlTags.ModelType_Attr_FVSOLVER);
CDATA simulationInputText = new CDATA(simulationInputStringWriter.getBuffer().toString());
modelElement.addContent(simulationInputText);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new OptimizationException("failed to create fv input file: " + e.getMessage());
}
return modelElement;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class XmlHelper method simToXML.
public static String simToXML(Simulation sim) throws XmlParseException {
String simString = null;
if (sim == null) {
throw new XmlParseException("Invalid input for Simulation: " + sim);
}
Xmlproducer xmlProducer = new Xmlproducer(true);
// cannot be null
MathDescription md = sim.getMathDescription();
Geometry geom = md.getGeometry();
Element container = new Element(SIM_CONTAINER);
Element mathElement = xmlProducer.getXML(md);
Element simElement = xmlProducer.getXML(sim);
if (geom != null) {
Element geomElement = xmlProducer.getXML(geom);
container.addContent(geomElement);
} else {
System.err.println("No corresponding geometry for the simulation: " + sim.getName());
}
container.addContent(mathElement);
container.addContent(simElement);
container = XmlUtil.setDefaultNamespace(container, Namespace.getNamespace(XMLTags.VCML_NS));
simString = XmlUtil.xmlToString(container);
return simString;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class XmlHelper method simTaskToXML.
public static String simTaskToXML(SimulationTask simTask) throws XmlParseException {
String simTaskString = null;
if (simTask == null) {
throw new XmlParseException("Invalid input for SimulationTask: " + simTask);
}
Xmlproducer xmlProducer = new Xmlproducer(true);
SimulationJob simJob = simTask.getSimulationJob();
Simulation sim = simJob.getSimulation();
Element container = new Element(SimulationTask_tag);
int taskId = simTask.getTaskID();
container.setAttribute(TaskId_attr, "" + taskId);
int jobIndex = simJob.getJobIndex();
container.setAttribute(JobIndex_attr, "" + jobIndex);
String computeResource = simTask.getComputeResource();
if (computeResource != null) {
Element computeResourceElement = new Element(ComputeResource_tag);
Text text = new Text(computeResource);
computeResourceElement.addContent(text);
container.addContent(computeResourceElement);
}
FieldDataIdentifierSpec[] fdisSpecs = simJob.getFieldDataIdentifierSpecs();
if (fdisSpecs != null) {
for (FieldDataIdentifierSpec fdisSpec : fdisSpecs) {
Element fdisElement = new Element(FieldFunctionIdentifierSpec_tag);
fdisElement.setText(fdisSpec.toCSVString());
container.addContent(fdisElement);
}
}
MathDescription md = sim.getMathDescription();
Element mathElement = xmlProducer.getXML(md);
container.addContent(mathElement);
Element simElement = xmlProducer.getXML(sim);
container.addContent(simElement);
Geometry geom = md.getGeometry();
if (geom != null) {
Element geomElement = xmlProducer.getXML(geom);
container.addContent(geomElement);
} else {
System.err.println("No corresponding geometry for the simulation: " + sim.getName());
}
container = XmlUtil.setDefaultNamespace(container, Namespace.getNamespace(XMLTags.VCML_NS));
simTaskString = XmlUtil.xmlToString(container);
return simTaskString;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class XmlHelper method XMLToGeometry.
static Geometry XMLToGeometry(XMLSource xmlSource, boolean printkeys) throws XmlParseException {
Geometry geometry = null;
if (xmlSource == null) {
throw new XmlParseException("Invalid xml for Geometry.");
}
Document xmlDoc = xmlSource.getXmlDoc();
// NOTES:
// * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
// * With the old-style vcml, the namespace was " "
// * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
// was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
// "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
// <biomdel>, etc. was " "
// * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
// for <vcml> and all children elements.
// The code below attempts to take care of this situation.
Element root = xmlDoc.getRootElement();
Namespace ns = null;
if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
// NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
ns = root.getNamespace();
Element geoRoot = root.getChild(XMLTags.GeometryTag, ns);
if (geoRoot == null) {
geoRoot = root.getChild(XMLTags.GeometryTag);
// geoRoot was null, so obtained the <Geometry> element with namespace " ";
// Re-set the namespace so that the correct XMLReader constructor is invoked.
ns = null;
}
root = geoRoot;
}
// else - root is assumed to be old-style vcml with <Geometry> as root.
// common for both new-style (with xml declaration, vcml element, etc) and old-style (geometry is root)
// If namespace is null, xml is the old-style xml with geometry as root, so invoke XMLReader without namespace argument.
XmlReader reader = null;
if (ns == null) {
reader = new XmlReader(printkeys);
} else {
reader = new XmlReader(printkeys, ns);
}
geometry = reader.getGeometry(root);
geometry.refreshDependencies();
return geometry;
}
Aggregations