diff --git a/vcell-core/src/main/java/cbit/vcell/geometry/CSGObject.java b/vcell-core/src/main/java/cbit/vcell/geometry/CSGObject.java index 039128751c..0b12c8ed7d 100644 --- a/vcell-core/src/main/java/cbit/vcell/geometry/CSGObject.java +++ b/vcell-core/src/main/java/cbit/vcell/geometry/CSGObject.java @@ -11,7 +11,9 @@ package cbit.vcell.geometry; import org.vcell.util.Compare; +import org.vcell.util.Extent; import org.vcell.util.Matchable; +import org.vcell.util.Origin; import org.vcell.util.document.KeyValue; import cbit.image.ImageException; @@ -33,7 +35,18 @@ public CSGObject(CSGObject csgObj) { root = csgObj.root.clone(); } - public boolean compareEqual(Matchable obj) { + public static CSGObject createBackgroundObject(Origin vcOrigin, Extent vcExtent, String name, int handle) { + CSGPrimitive cube = new CSGPrimitive("background", CSGPrimitive.PrimitiveType.CUBE); + CSGScale scale = new CSGScale("scale",new Vect3d(2*vcExtent.getX(),2*vcExtent.getY(), 2*vcExtent.getZ())); + CSGTranslation translation = new CSGTranslation("translate", new Vect3d(-vcOrigin.getX(), -vcOrigin.getY(), -vcOrigin.getZ())); + scale.setChild(translation); + translation.setChild(cube); + CSGObject csgObject = new CSGObject(null ,name, handle); + csgObject.setRoot(scale); + return csgObject; + } + + public boolean compareEqual(Matchable obj) { if (!compareEqual0(obj)){ return false; } diff --git a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLExporter.java b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLExporter.java index 1114df03c1..c2c598e1cc 100644 --- a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLExporter.java +++ b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLExporter.java @@ -2085,7 +2085,8 @@ private void addGeometry() throws SbmlException { if (vcGeomClasses[i] instanceof AnalyticSubVolume) { AnalyticSubVolume vcAnalyticSubVolume = (AnalyticSubVolume) vcGeomClasses[i]; // need to avoid id name clash with structures (compartments) - AnalyticVolume analyticVol = sbmlAnalyticGeomDefinition.createAnalyticVolume(TokenMangler.mangleToSName("AnalyticVol_"+vcAnalyticSubVolume.getName())); + String id = TokenMangler.mangleToSName("AnalyticVol_" + vcAnalyticSubVolume.getName()); + AnalyticVolume analyticVol = sbmlAnalyticGeomDefinition.createAnalyticVolume(id); // analyticVol.setSpatialId(vcGeomClasses[i].getName()); analyticVol.setDomainType(DOMAIN_TYPE_PREFIX+vcAnalyticSubVolume.getName()); analyticVol.setFunctionType(FunctionKind.layered); @@ -2107,19 +2108,30 @@ private void addGeometry() throws SbmlException { // // add CSGeometry // - if (!bAnyAnalyticSubvolumes && !bAnyImageSubvolumes && bAnyCSGSubvolumes){ - CSGeometry sbmlCSGeomDefinition = new CSGeometry(); - sbmlGeometry.addGeometryDefinition(sbmlCSGeomDefinition); +// if (!bAnyAnalyticSubvolumes && !bAnyImageSubvolumes && bAnyCSGSubvolumes){ + if (!bAnyImageSubvolumes && bAnyCSGSubvolumes){ + CSGeometry sbmlCSGeomDefinition = sbmlGeometry.createCSGeometry(); sbmlCSGeomDefinition.setSpatialId(TokenMangler.mangleToSName("CSG_"+vcGeometry.getName())); + sbmlCSGeomDefinition.setIsActive(true); for (int i = 0; i < vcGeomClasses.length; i++) { if (vcGeomClasses[i] instanceof CSGObject) { CSGObject vcellCSGObject = (CSGObject)vcGeomClasses[i]; - org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = new org.sbml.jsbml.ext.spatial.CSGObject(); - sbmlCSGeomDefinition.addCSGObject(sbmlCSGObject); - sbmlCSGObject.setSpatialId(vcellCSGObject.getName()); + String id = TokenMangler.mangleToSName("CSGObject_" + vcellCSGObject.getName()); + org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = sbmlCSGeomDefinition.createCSGObject(id); sbmlCSGObject.setDomainType(DOMAIN_TYPE_PREFIX+vcellCSGObject.getName()); - sbmlCSGObject.setOrdinal(numSubVols - (i+1)); // the ordinal should the the least for the default/background subVolume + sbmlCSGObject.setOrdinal(vcellCSGObject.getHandle()); // numSubVols - (i+1)); // the ordinal should be the least for the default/background subVolume org.sbml.jsbml.ext.spatial.CSGNode sbmlcsgNode = getSBMLCSGNode(vcellCSGObject.getRoot()); + sbmlcsgNode.setParent(sbmlCSGObject); + sbmlCSGObject.setCSGNode(sbmlcsgNode); + }else if (vcGeomClasses[i] instanceof AnalyticSubVolume && ((AnalyticSubVolume)vcGeomClasses[i]).getExpression().isOne()) { + AnalyticSubVolume analyticSubVolume = (AnalyticSubVolume)vcGeomClasses[i]; + String id = TokenMangler.mangleToSName("CSGObject_" + analyticSubVolume.getName()); + org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = sbmlCSGeomDefinition.createCSGObject(id); + sbmlCSGObject.setDomainType(DOMAIN_TYPE_PREFIX+analyticSubVolume.getName()); + sbmlCSGObject.setOrdinal(analyticSubVolume.getHandle()); // the ordinal should be the least for the default/background subVolume + CSGObject backgroundObject = CSGObject.createBackgroundObject(vcOrigin, vcExtent, analyticSubVolume.getName(), analyticSubVolume.getHandle()); + org.sbml.jsbml.ext.spatial.CSGNode sbmlcsgNode = getSBMLCSGNode(backgroundObject.getRoot()); + sbmlcsgNode.setParent(sbmlCSGObject); sbmlCSGObject.setCSGNode(sbmlcsgNode); } } @@ -2315,26 +2327,26 @@ private boolean goodPointer(Object obj, Class clzz, String sourceName) { } private static org.sbml.jsbml.ext.spatial.CSGNode getSBMLCSGNode(cbit.vcell.geometry.CSGNode vcCSGNode) { - String csgNodeName = vcCSGNode.getName(); + String csgNodeName = "CSGObjectNode_"+vcCSGNode.getName(); if (vcCSGNode instanceof cbit.vcell.geometry.CSGPrimitive){ cbit.vcell.geometry.CSGPrimitive vcCSGprimitive = (cbit.vcell.geometry.CSGPrimitive)vcCSGNode; org.sbml.jsbml.ext.spatial.CSGPrimitive sbmlPrimitive = new org.sbml.jsbml.ext.spatial.CSGPrimitive(); sbmlPrimitive.setSpatialId(csgNodeName); switch (vcCSGprimitive.getType()){ case SPHERE: { - sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_SPHERE); + sbmlPrimitive.setPrimitiveType(PrimitiveKind.sphere); break; } case CONE: { - sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_CONE); + sbmlPrimitive.setPrimitiveType(PrimitiveKind.cone); break; } case CUBE: { - sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_CUBE); + sbmlPrimitive.setPrimitiveType(PrimitiveKind.cube); break; } case CYLINDER: { - sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_CYLINDER); + sbmlPrimitive.setPrimitiveType(PrimitiveKind.cylinder); break; } default: { diff --git a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java index 20e67a74f6..145c0a8e48 100644 --- a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java +++ b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java @@ -11,14 +11,11 @@ package org.vcell.sbml.vcell; import cbit.image.VCImage; -import cbit.image.VCImageCompressed; import cbit.image.VCImageUncompressed; import cbit.image.VCPixelClass; import cbit.util.xml.VCLogger; import cbit.util.xml.VCLoggerException; -import cbit.util.xml.XmlUtil; import cbit.vcell.biomodel.BioModel; -import cbit.vcell.biomodel.ModelUnitConverter; import cbit.vcell.biomodel.meta.VCMetaData; import cbit.vcell.geometry.CSGObject; import cbit.vcell.geometry.*; @@ -49,7 +46,6 @@ import cbit.vcell.units.VCUnitDefinition; import cbit.vcell.units.VCUnitSystem; import cbit.vcell.xml.XMLTags; -import jscl.math.function.Exp; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -71,7 +67,6 @@ import org.sbml.jsbml.xml.XMLNode; import org.vcell.sbml.SBMLHelper; import org.vcell.sbml.SBMLUtils; -import org.vcell.sbml.SbmlException; import org.vcell.sbml.vcell.SBMLImportException.Category; import org.vcell.util.*; import org.vcell.util.BeanUtils.CastInfo; @@ -87,7 +82,6 @@ import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; -import java.util.zip.DataFormatException; public class SBMLImporter { @@ -3745,7 +3739,7 @@ private static void addGeometry(org.sbml.jsbml.Model sbmlModel, BioModel vcBioMo // CSGObject[] vcCSGSubVolumes = new CSGObject[n]; for (int i = 0; i < n; i++) { org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = sbmlCSGs.get(i); - CSGObject vcellCSGObject = new CSGObject(null, sbmlCSGObject.getSpatialId(), i); + CSGObject vcellCSGObject = new CSGObject(null, sbmlCSGObject.getDomainType(), i); if (domainTypeId_to_handle_map.get(sbmlCSGObject.getDomainType()) != null){ vcellCSGObject.setHandle(domainTypeId_to_handle_map.get(sbmlCSGObject.getDomainType())); } diff --git a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLSpatialConstants.java b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLSpatialConstants.java deleted file mode 100644 index ecf6b206b6..0000000000 --- a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLSpatialConstants.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.vcell.sbml.vcell; - -public class SBMLSpatialConstants { - public static final String SOLID_SPHERE = "SOLID_SPHERE"; - public static final String SOLID_CYLINDER = "SOLID_CYLINDER"; - public static final String SOLID_CUBE = "SOLID_CUBE"; - public static final String SOLID_CONE = "SOLID_CONE"; - - public static final String UNION = "UNION"; - public static final String DIFFERENCE = "DIFFERENCE"; - public static final String INTERSECTION = "INTERSECTION"; -} diff --git a/vcell-core/src/test/java/org/vcell/sbml/SEDMLExporterTest.java b/vcell-core/src/test/java/org/vcell/sbml/SEDMLExporterTest.java index 9668dd4481..fd10c65c7e 100644 --- a/vcell-core/src/test/java/org/vcell/sbml/SEDMLExporterTest.java +++ b/vcell-core/src/test/java/org/vcell/sbml/SEDMLExporterTest.java @@ -128,7 +128,7 @@ public static Set outOfMemorySet() { public static Map knownFaults() { HashMap faults = new HashMap(); faults.put("biomodel_123269393.vcml", FAULT.MATHOVERRIDES_INVALID); // Kf_r7 - faults.put("biomodel_124562627.vcml", FAULT.NULL_POINTER_EXCEPTION); + faults.put("biomodel_124562627.vcml", FAULT.NULL_POINTER_EXCEPTION); // fails on CSG Geometry faults.put("biomodel_156134818.vcml", FAULT.UNKNOWN_IDENTIFIER); faults.put("biomodel_158495696.vcml", FAULT.EXPRESSIONS_DIFFERENT); // not lumped: faults.put("biomodel_18894555.vcml", FAULT.MATHOVERRIDES_INVALID); // EGF_EC