use of org.vcell.util.ISize in project vcell by virtualcell.
the class ClientDocumentManager method saveAsNew.
/**
* Insert the method's description here.
* Creation date: (2/5/01 4:58:40 PM)
*/
public VCImage saveAsNew(VCImage vcImage, java.lang.String newName) throws DataAccessException {
try {
String vcImageXML = null;
try {
vcImageXML = XmlHelper.imageToXML(vcImage);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
String savedVCImageXML = sessionManager.getUserMetaDbServer().saveVCImageAs(new BigString(vcImageXML), newName).toString();
VCImage savedVCImage = null;
try {
savedVCImage = XmlHelper.XMLToImage(savedVCImageXML);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
savedVCImage.refreshDependencies();
KeyValue savedKey = savedVCImage.getVersion().getVersionKey();
if (xmlHash.get(savedKey) == null) {
xmlHash.put(savedKey, savedVCImageXML);
}
try {
ISize size = new ISize(savedVCImage.getNumX(), savedVCImage.getNumY(), savedVCImage.getNumZ());
GIFImage browseData = BrowseImage.makeBrowseGIFImage(savedVCImage);
VCImageInfo savedVCImageInfo = new VCImageInfo(savedVCImage.getVersion(), size, savedVCImage.getExtent(), browseData, VCellSoftwareVersion.fromSystemProperty());
imgInfoHash.put(savedKey, savedVCImageInfo);
fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, savedVCImageInfo));
} catch (Exception e) {
e.printStackTrace(System.out);
}
return savedVCImage;
} catch (RemoteProxyException e) {
e.printStackTrace(System.out);
throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ClientDocumentManager method updateGeometryRelatedHashes.
private void updateGeometryRelatedHashes(Geometry savedGeometry) {
if (savedGeometry == null || (savedGeometry.getVersion() != null && geoInfoHash.get(savedGeometry.getVersion().getVersionKey()) != null)) {
return;
}
KeyValue imageRef = (savedGeometry.getGeometrySpec().getImage() != null) ? (savedGeometry.getGeometrySpec().getImage().getKey()) : (null);
if (imageRef != null && imgInfoHash.get(imageRef) == null) {
VCImage savedVCImage = savedGeometry.getGeometrySpec().getImage();
ISize size = new ISize(savedVCImage.getNumX(), savedVCImage.getNumY(), savedVCImage.getNumZ());
VCImageInfo savedVCImageInfo = new VCImageInfo(savedVCImage.getVersion(), size, savedVCImage.getExtent(), null, VCellSoftwareVersion.fromSystemProperty());
imgInfoHash.put(savedVCImage.getVersion().getVersionKey(), savedVCImageInfo);
}
GeometryInfo savedGeometryInfo = new GeometryInfo(savedGeometry.getVersion(), savedGeometry.getDimension(), savedGeometry.getExtent(), savedGeometry.getOrigin(), imageRef, VCellSoftwareVersion.fromSystemProperty());
geoInfoHash.put(savedGeometry.getVersion().getVersionKey(), savedGeometryInfo);
fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, geoInfoHash.get(savedGeometry.getVersion().getVersionKey())));
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class GeometrySpec method calulateResetSamplingSize.
public static ISize calulateResetSamplingSize(int dim, Extent extent, long total) {
long numX = 1;
long numY = 1;
long numZ = 1;
switch(dim) {
case 1:
{
numX = total;
numY = 1;
numZ = 1;
break;
}
case 2:
{
//
// choose so that the aspect ratio is correct
//
// so x * y = total and x/y = extentX/extentY = xyRatio
//
// thus y = sqrt(total/xyRatio);
// x = total/y;
//
double aspectRatio = extent.getX() / extent.getY();
numY = Math.max(3, Math.round(Math.sqrt(total / aspectRatio)));
numX = Math.max(3, Math.round(total / numY));
numZ = 1;
break;
}
case 3:
{
//
// choose so that the aspect ratio is correct
//
// x * y * z = total
// z / x = extentZ/extentX = zxRatio
// z / y = extentZ/extentY = zyRatio
//
// thus z = pow(total*zxRatio*zyRatio,1/3)
// x = z/zxRatio;
// y = z/zyRatio;
//
double aspectRatioZX = extent.getZ() / extent.getX();
double aspectRatioZY = extent.getZ() / extent.getY();
numZ = Math.max(3, Math.round(Math.pow(total * aspectRatioZX * aspectRatioZY, 1.0 / 3.0)));
numX = Math.max(3, Math.round(numZ / aspectRatioZX));
numY = Math.max(3, Math.round(numZ / aspectRatioZY));
break;
}
}
ISize samplingSize = new ISize((int) numX, (int) numY, (int) numZ);
return samplingSize;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class DistanceMapGenerator method computeDistanceMaps.
public static SubvolumeSignedDistanceMap[] computeDistanceMaps(Geometry geometry, VCImage subvolumeHandleImage, boolean bCellCentered, boolean insideOnly) throws ImageException {
double[] samplesX = new double[subvolumeHandleImage.getNumX()];
double[] samplesY = new double[subvolumeHandleImage.getNumY()];
double[] samplesZ = new double[subvolumeHandleImage.getNumZ()];
ISize sampleSize = new ISize(subvolumeHandleImage.getNumX(), subvolumeHandleImage.getNumY(), subvolumeHandleImage.getNumZ());
byte[] pixels = subvolumeHandleImage.getPixels();
boolean[] ignoreMask = new boolean[sampleSize.getXYZ()];
Origin origin = geometry.getOrigin();
Extent extent = geometry.getExtent();
RayCaster.sampleXYZCoordinates(sampleSize, origin, extent, samplesX, samplesY, samplesZ, bCellCentered);
ArrayList<SubvolumeSignedDistanceMap> distanceMaps = new ArrayList<SubvolumeSignedDistanceMap>();
int count = 0;
for (SubVolume subVolume : geometry.getGeometrySpec().getSubVolumes()) {
//
// find surfaces that bound the current SubVolume
//
ArrayList<Surface> surfaces = new ArrayList<Surface>();
for (GeometricRegion geometricRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions()) {
if (geometricRegion instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion surfaceGeometricRegion = (SurfaceGeometricRegion) geometricRegion;
for (GeometricRegion adjacentRegion : ((SurfaceGeometricRegion) geometricRegion).getAdjacentGeometricRegions()) {
if (adjacentRegion instanceof VolumeGeometricRegion && ((VolumeGeometricRegion) adjacentRegion).getSubVolume() == subVolume) {
surfaces.add(geometry.getGeometrySurfaceDescription().getSurfaceCollection().getSurface(surfaceGeometricRegion));
}
}
}
}
// find unsigned distances in a narrow band for surfaces that bound this SubVolume (expensive)
// values outside the band are assumed to be initialized to MAX_NUMBER
long t1 = System.currentTimeMillis();
double[] distanceMap = localUnsignedDistanceMap(surfaces, samplesX, samplesY, samplesZ, 3);
long t2 = System.currentTimeMillis();
System.out.println(" Distance to triangle: " + (int) ((t2 - t1) / 1000) + " sec.");
// extend signed distance map using fast marching method from narrow band to all points.
// will do it in 2 steps, positive growth first towards inside, then change the sign of the whole
// distance map, then positive growth towards the exterior
// this way, the interior distances will end negative and the exterior distances positive
// 2 step growth saves memory and reduces the number of elements present at any given time in the binary
// heap (binary heap manipulation is the most time consuming factor and it depends on the # of elements)
Arrays.fill(ignoreMask, true);
int subvolumeHandle = subVolume.getHandle();
for (int i = 0; i < ignoreMask.length; i++) {
if (pixels[i] == subvolumeHandle) {
// inside
ignoreMask[i] = false;
} else {
// outside
if (distanceMap[i] < MAX_NUMBER) {
// make negative the part of narrow band which is outside
distanceMap[i] = -distanceMap[i];
}
}
}
// // step 1, we compute distances for the points "inside"
// // the points outside are cold (we don't compute their distances this step)
double deltaX = samplesX[1] - samplesX[0];
double deltaY = samplesY[1] - samplesY[0];
double deltaZ = samplesZ[1] - samplesZ[0];
FastMarchingMethodHA fmm = new FastMarchingMethodHA(samplesX.length, samplesY.length, samplesZ.length, deltaX, deltaY, deltaZ, distanceMap, ignoreMask);
fmm.march();
if (!insideOnly) {
// sign change of the half-completed distance map, the "interior" will become negative as it should be
for (int i = 0; i < distanceMap.length; i++) {
if (distanceMap[i] < MAX_NUMBER) {
distanceMap[i] = -distanceMap[i];
}
}
// step 2, we compute distances for the points "outside"
// no cold points (points we don't care about) this time, they are already frozen
fmm = new FastMarchingMethodHA(samplesX.length, samplesY.length, samplesZ.length, deltaX, deltaY, deltaZ, distanceMap, null);
fmm.march();
} else {
// sign change of the half-completed distance map, the "interior" will become negative as it should be
for (int i = 0; i < distanceMap.length; i++) {
if (distanceMap[i] < MAX_NUMBER) {
if (pixels[i] != subvolumeHandle) {
// need to filter out the part of the narrow band which is not inside
distanceMap[i] = MAX_NUMBER;
} else {
distanceMap[i] = -distanceMap[i];
}
}
}
}
// try { // save some points in a VisIt compatible format
// int xm = samplesX.length;
// int ym = samplesY.length;
// BufferedWriter out = new BufferedWriter(new FileWriter("c:\\TEMP\\2D_circle" + count + ".3D"));
// out.write("x y z value\n");
//
// for(int j=0; j<distanceMap.length; j++) {
// int x = getX(j,xm,ym);
// int y = getY(j,xm,ym);
// int z = getZ(j,xm,ym);
// if(distanceMap[j] < MAX_NUMBER) {
// if((j%2 == 0 || j%3 == 0) && (distanceMap[j] <= -2)) {
// out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*10) + "\n");
// } else if((j%17 == 0 || j%23 == 0) && (distanceMap[j] <= 0.5) && (distanceMap[j] > -2)) {
// out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*10) + "\n");
// } else if((j%31 == 0 || j%41 == 0) && (distanceMap[j] > 0.5)) {
// out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*10) + "\n");
// }
// }
// if(distanceMap[j] < MAX_NUMBER) {
// if(j%2 == 0) {
// out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*100) + "\n");
// }
// }
// if(x==50 && y==50 && z==25) { // on the surface
// out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*100) + "\n");
// }
// if(x==0 && y==0 && z==0) {
// out.write(x + " " + y + " " + z + " " + 0 + "\n");
// }
// if(x==100 && y==100 && z==100) {
// out.write(x + " " + y + " " + z + " " + 0 + "\n");
// }
//
// }
// out.close();
// } catch (IOException e) {
// }
SubvolumeSignedDistanceMap subvolumeSignedDistanceMap = new SubvolumeSignedDistanceMap(subVolume, samplesX, samplesY, samplesZ, distanceMap);
distanceMaps.add(subvolumeSignedDistanceMap);
count++;
}
return distanceMaps.toArray(new SubvolumeSignedDistanceMap[distanceMaps.size()]);
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class GeometrySurfaceDescription method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() == this && evt.getPropertyName().equals("volumeSampleSize")) {
ISize oldValue = (ISize) evt.getOldValue();
ISize newValue = (ISize) evt.getNewValue();
if (!oldValue.compareEqual(newValue)) {
try {
// nobody listens to this, updateAll() will propagate changes
getRegionImage0().setDirty();
getSurfaceCollection0().setDirty();
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
if (evt.getSource() == this && evt.getPropertyName().equals("filterCutoffFrequency")) {
Double oldValue = (Double) evt.getOldValue();
Double newValue = (Double) evt.getNewValue();
if (!oldValue.equals(newValue)) {
try {
getSurfaceCollection0().setDirty();
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
if (evt.getSource() == this && evt.getPropertyName().equals(PROPERTY_NAME_GEOMETRIC_REGIONS)) {
refreshSurfaceClasses();
}
if (evt.getSource() == getGeometry().getGeometrySpec() && (evt.getPropertyName().equals("extent") || evt.getPropertyName().equals("origin"))) {
Matchable oldExtentOrOrigin = (Matchable) evt.getOldValue();
Matchable newExtentOrOrigin = (Matchable) evt.getNewValue();
if (!Compare.isEqual(oldExtentOrOrigin, newExtentOrOrigin)) {
try {
// nobody listens to this, updateAll() will propagate changes
getRegionImage0().setDirty();
getSurfaceCollection0().setDirty();
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
if (evt.getSource() instanceof AnalyticSubVolume && evt.getPropertyName().equals("expression")) {
Expression oldExpression = (Expression) evt.getOldValue();
Expression newExpression = (Expression) evt.getNewValue();
if (!Compare.isEqual(oldExpression, newExpression)) {
try {
// nobody listens to this, updateAll() will propagate changes
getRegionImage0().setDirty();
getSurfaceCollection0().setDirty();
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
if (evt.getSource() instanceof CSGObject && evt.getPropertyName().equals(CSGObject.PROPERTY_NAME_ROOT)) {
try {
// nobody listens to this, updateAll() will propagate changes
getRegionImage0().setDirty();
getSurfaceCollection0().setDirty();
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
if (evt.getSource() instanceof SubVolume && evt.getPropertyName().equals("name")) {
String oldName = (String) evt.getOldValue();
String newName = (String) evt.getNewValue();
if (!Compare.isEqual(oldName, newName)) {
try {
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
if (evt.getSource() == getGeometry().getGeometrySpec() && evt.getPropertyName().equals("subVolumes")) {
SubVolume[] oldValue = (SubVolume[]) evt.getOldValue();
SubVolume[] newValue = (SubVolume[]) evt.getNewValue();
//
for (int i = 0; oldValue != null && i < oldValue.length; i++) {
oldValue[i].removePropertyChangeListener(this);
}
for (int i = 0; newValue != null && i < newValue.length; i++) {
newValue[i].addPropertyChangeListener(this);
}
//
if (oldValue == null || newValue == null || !Compare.isEqualStrict(oldValue, newValue)) {
try {
// nobody listens to this, updateAll() will propagate changes
getRegionImage0().setDirty();
getSurfaceCollection0().setDirty();
fieldGeometricRegions.setDirty();
} catch (Exception e) {
e.printStackTrace(System.out);
}
} else if (fieldGeometricRegions.getCurrentValue() != null && oldValue != newValue) {
//
for (int i = 0; i < newValue.length; i++) {
SubVolume subVolume = newValue[i];
for (int j = 0; j < fieldGeometricRegions.getCurrentValue().length; j++) {
if (fieldGeometricRegions.getCurrentValue()[j] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion volumeRegion = (VolumeGeometricRegion) fieldGeometricRegions.getCurrentValue()[j];
//
if (volumeRegion.getSubVolume().compareEqual(subVolume) && volumeRegion.getSubVolume() != subVolume) {
volumeRegion.setSubVolume(subVolume);
}
}
}
}
}
}
}
Aggregations