use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class MathTestingUtilities method resample1DSpatial.
/**
* Insert the method's description here.
* Creation date: (10/27/2003 5:07:42 PM)
* @return double[]
* @param data double[]
* @param sourceMesh cbit.vcell.solvers.CartesianMesh
* @param targetMesh cbit.vcell.solvers.CartesianMesh
*/
public static double[] resample1DSpatial(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
if (sourceData.length != sourceMesh.getNumVolumeElements()) {
throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
}
// for volume samples:
//
// loop through volumeIndexes from refMesh
// Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
// Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
// ....interpolate in z
// start with integer portion of fractionIndex
double[] resampledData = new double[refMesh.getSizeX()];
for (int i = 0; i < resampledData.length; i++) {
Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
int ceil_x;
int floor_x;
if (fractionalIndex.getX() < 0) {
floor_x = 0;
ceil_x = 1;
} else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
floor_x = sourceMesh.getSizeX() - 2;
ceil_x = sourceMesh.getSizeX() - 1;
} else {
ceil_x = (int) Math.ceil(fractionalIndex.getX());
floor_x = (int) Math.floor(fractionalIndex.getX());
}
double fract_x = fractionalIndex.getX() - floor_x;
// ***** SHOULD Y,Z BE 0 OR 1 ???? *****
CoordinateIndex coord_1 = new CoordinateIndex(floor_x, 0, 0);
CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, 0, 0);
int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
boolean bBoth1_2 = false;
boolean bNoneOf1_2 = false;
boolean bOne = false;
boolean bTwo = false;
boolean bOneOf1_2 = false;
// use it to compute a, b, ** Interpolation in X **
if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) == refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
bOneOf1_2 = true;
bOne = true;
volIndx2 = volIndx1;
} else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) == refMesh.getSubVolumeFromVolumeIndex(i)) {
bOneOf1_2 = true;
bTwo = true;
volIndx1 = volIndx2;
} else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
// throw new RuntimeException("Either subvolume in sourceMesh not equal to refMesh subVol cannot be handled at this time!");
bNoneOf1_2 = true;
} else {
bBoth1_2 = true;
}
// Interpolate in X - final resampledSourceData value
if (bBoth1_2) {
resampledData[i] = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
}
if (bOneOf1_2) {
if (bOne) {
resampledData[i] = sourceData[volIndx1];
} else if (bTwo) {
resampledData[i] = sourceData[volIndx2];
}
}
//
if (bNoneOf1_2) {
// resampledData[i] = BLAH_BLAH;
throw new RuntimeException("Cannot handle the case where both points are not in ref subvolume");
}
}
return resampledData;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class MathTestingUtilities method resample2DSpatialSimple.
/**
* Insert the method's description here.
* Creation date: (10/27/2003 5:07:42 PM)
* @return double[]
* @param data double[]
* @param sourceMesh cbit.vcell.solvers.CartesianMesh
* @param targetMesh cbit.vcell.solvers.CartesianMesh
*/
public static double[] resample2DSpatialSimple(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
if (sourceData.length != sourceMesh.getNumVolumeElements()) {
throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
}
// for volume samples:
//
// loop through volumeIndexes from refMesh
// Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
// Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
// ....interpolate in y
// start with integer portion of fractionIndex
double[] resampledData = new double[refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ()];
for (int i = 0; i < resampledData.length; i++) {
Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
int ceil_x;
int floor_x;
int ceil_y;
int floor_y;
if (fractionalIndex.getX() < 0) {
floor_x = 0;
ceil_x = 1;
} else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
floor_x = sourceMesh.getSizeX() - 2;
ceil_x = sourceMesh.getSizeX() - 1;
} else {
ceil_x = (int) Math.ceil(fractionalIndex.getX());
floor_x = (int) Math.floor(fractionalIndex.getX());
}
if (fractionalIndex.getY() < 0) {
floor_y = 0;
ceil_y = 1;
} else if (fractionalIndex.getY() > sourceMesh.getSizeY() - 1) {
floor_y = sourceMesh.getSizeY() - 2;
ceil_y = sourceMesh.getSizeY() - 1;
} else {
ceil_y = (int) Math.ceil(fractionalIndex.getY());
floor_y = (int) Math.floor(fractionalIndex.getY());
}
double fract_x = fractionalIndex.getX() - floor_x;
double fract_y = fractionalIndex.getY() - floor_y;
// ***** SHOULD THIS BE 0 OR 1 ???? *****
CoordinateIndex coord_1 = new CoordinateIndex(floor_x, floor_y, 0);
CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, floor_y, 0);
CoordinateIndex coord_3 = new CoordinateIndex(floor_x, ceil_y, 0);
CoordinateIndex coord_4 = new CoordinateIndex(ceil_x, ceil_y, 0);
int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
int volIndx3 = sourceMesh.getVolumeIndex(coord_3);
int volIndx4 = sourceMesh.getVolumeIndex(coord_4);
// Interpolate in X (first order)
double val_a = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
double val_b = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
// Interpolate in Y - final resampledSourceData value
resampledData[i] = val_a + fract_y * (val_b - val_a);
}
return resampledData;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class MathTestingUtilities method resample2DSpatial.
/**
* Insert the method's description here.
* Creation date: (10/27/2003 5:07:42 PM)
* @return double[]
* @param data double[]
* @param sourceMesh cbit.vcell.solvers.CartesianMesh
* @param targetMesh cbit.vcell.solvers.CartesianMesh
*/
public static double[] resample2DSpatial(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
if (sourceData.length != sourceMesh.getNumVolumeElements()) {
throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
}
// for volume samples:
//
// loop through volumeIndexes from refMesh
// Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
// Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
// ....interpolate in y
// start with integer portion of fractionIndex
double[] resampledData = new double[refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ()];
for (int i = 0; i < resampledData.length; i++) {
Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
int ceil_x;
int floor_x;
int ceil_y;
int floor_y;
if (fractionalIndex.getX() < 0) {
floor_x = 0;
ceil_x = 1;
} else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
floor_x = sourceMesh.getSizeX() - 2;
ceil_x = sourceMesh.getSizeX() - 1;
} else {
ceil_x = (int) Math.ceil(fractionalIndex.getX());
floor_x = (int) Math.floor(fractionalIndex.getX());
}
if (fractionalIndex.getY() < 0) {
floor_y = 0;
ceil_y = 1;
} else if (fractionalIndex.getY() > sourceMesh.getSizeY() - 1) {
floor_y = sourceMesh.getSizeY() - 2;
ceil_y = sourceMesh.getSizeY() - 1;
} else {
ceil_y = (int) Math.ceil(fractionalIndex.getY());
floor_y = (int) Math.floor(fractionalIndex.getY());
}
double fract_x = fractionalIndex.getX() - floor_x;
double fract_y = fractionalIndex.getY() - floor_y;
// ***** SHOULD THIS BE 0 OR 1 ???? *****
CoordinateIndex coord_1 = new CoordinateIndex(floor_x, floor_y, 0);
CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, floor_y, 0);
CoordinateIndex coord_3 = new CoordinateIndex(floor_x, ceil_y, 0);
CoordinateIndex coord_4 = new CoordinateIndex(ceil_x, ceil_y, 0);
int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
int volIndx3 = sourceMesh.getVolumeIndex(coord_3);
int volIndx4 = sourceMesh.getVolumeIndex(coord_4);
boolean bBoth1_2 = false;
boolean bNoneOf1_2 = false;
boolean bOne = false;
boolean bTwo = false;
boolean bOneOf1_2 = false;
boolean bBoth3_4 = false;
boolean bNoneOf3_4 = false;
boolean bThree = false;
boolean bFour = false;
boolean bOneOf3_4 = false;
// use it to compute a, b, ** Interpolation in X **
if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) == refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
bOneOf1_2 = true;
bOne = true;
volIndx2 = volIndx1;
} else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) == refMesh.getSubVolumeFromVolumeIndex(i)) {
bOneOf1_2 = true;
bTwo = true;
volIndx1 = volIndx2;
} else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
// throw new RuntimeException("Either subvolume in sourceMesh not equal to refMesh subVol cannot be handled at this time!");
bNoneOf1_2 = true;
} else {
bBoth1_2 = true;
}
if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx3) == refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx4) != refMesh.getSubVolumeFromVolumeIndex(i)) {
bOneOf3_4 = true;
bThree = true;
volIndx4 = volIndx3;
} else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx3) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx4) == refMesh.getSubVolumeFromVolumeIndex(i)) {
bOneOf3_4 = true;
bFour = true;
volIndx3 = volIndx4;
} else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx3) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx4) != refMesh.getSubVolumeFromVolumeIndex(i)) {
// throw new RuntimeException("Either subvolume in sourceMesh not equal to refMesh subVol cannot be handled at this time!");
bNoneOf3_4 = true;
} else {
bBoth3_4 = true;
}
// First order interpolation if 4, 3, 2 points are within the ref subVolume.
if ((bBoth1_2 && bBoth3_4) || (bBoth1_2 && bOneOf3_4) || (bOneOf1_2 && bBoth3_4) || (bOneOf1_2 && bOneOf3_4)) {
// Interpolate in X (first order)
double val_a = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
double val_b = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
// Interpolate in Y - final resampledSourceData value
resampledData[i] = val_a + fract_y * (val_b - val_a);
}
// 0th order interpolation if only one point is in ref subVol.
if ((bBoth1_2 && bNoneOf3_4)) {
resampledData[i] = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
}
if ((bNoneOf1_2 && bBoth3_4)) {
resampledData[i] = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
}
if ((bOneOf1_2 && bNoneOf3_4)) {
if (bOne) {
resampledData[i] = sourceData[volIndx1];
} else if (bTwo) {
resampledData[i] = sourceData[volIndx2];
}
}
if ((bNoneOf1_2 && bOneOf3_4)) {
if (bThree) {
resampledData[i] = sourceData[volIndx3];
} else if (bFour) {
resampledData[i] = sourceData[volIndx4];
}
}
//
if (bNoneOf1_2 && bNoneOf3_4) {
// resampledData[i] = BLAH_BLAH;
throw new RuntimeException("Cannot handle the case where all 4 points are not in ref subvolume1");
}
}
return resampledData;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class XmlReader method getElectrode.
/**
* This method returns an Electrode object from a XML representation.
* Creation date: (6/6/2002 4:22:55 PM)
* @return cbit.vcell.mapping.Electrode
*/
private Electrode getElectrode(org.jdom.Element elem, SimulationContext currentSimulationContext) {
// retrieve feature
String featureName = unMangle(elem.getAttributeValue(XMLTags.FeatureAttrTag));
Feature feature = (Feature) currentSimulationContext.getModel().getStructure(featureName);
// retrieve position
Coordinate position = getCoordinate(elem.getChild(XMLTags.CoordinateTag, vcNamespace));
Electrode newElect = new Electrode(feature, position);
return newElect;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class GeometrySubVolumePanel method createAnalyticSubVolume.
public static AnalyticSubVolume createAnalyticSubVolume(Component requester, int dimensions, Coordinate center, String newSubVolName) throws UserCancelException {
// Geometry g = getGeometry();
// final int dim = g.getDimension();
AddShapeJPanel addShapeJPanel = new AddShapeJPanel(dimensions);
addShapeJPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
addShapeJPanel.setDefaultCenter(center.getX(), center.getY(), center.getZ());
// (getGeometry().getDimension() > 2?getGeometry().getOrigin().getZ()+getGeometry().getExtent().getZ()/2:null));
while (true) {
try {
final boolean[] acceptFlag = new boolean[] { false };
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
final JDialog d = new LWTitledDialog(lwParent, "Define New Subdomain Shape");
// BeanUtils.centerOnComponent(d, GeometrySubVolumePanel.this);
JPanel main = new JPanel();
BoxLayout mainBoxLayout = new BoxLayout(main, BoxLayout.Y_AXIS);
main.setLayout(mainBoxLayout);
JPanel menuPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
menuPanel.add(LWNamespace.createRightSideIconMenuBar());
main.add(menuPanel);
JPanel addCancelJPanel = new JPanel();
addCancelJPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
BoxLayout addCancelBoxLayout = new BoxLayout(addCancelJPanel, BoxLayout.X_AXIS);
addCancelJPanel.setLayout(addCancelBoxLayout);
{
JButton helpButton = new JButton("Help");
helpButton.addActionListener(ae -> {
VcellHelpViewer.showStandaloneViewer();
});
addCancelJPanel.add(helpButton);
}
JButton addJButton = new JButton("New Subdomain");
addJButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
d.dispose();
acceptFlag[0] = true;
}
});
addCancelJPanel.add(addJButton);
JButton cancelJButton = new JButton("Cancel");
cancelJButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
d.dispose();
}
});
addCancelJPanel.add(cancelJButton);
main.add(addShapeJPanel);
main.add(Box.createVerticalStrut(10));
main.add(addCancelJPanel);
main.add(Box.createVerticalStrut(10));
addShapeJPanel.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(AddShapeJPanel.PROPCHANGE_VALID_ANALYTIC)) {
addJButton.setEnabled(((Boolean) evt.getNewValue()));
}
}
});
d.setModalityType(ModalityType.DOCUMENT_MODAL);
// d.setModal(true);
d.getContentPane().add(main);
d.pack();
d.setSize(new Dimension(400, 400));
d.setVisible(true);
if (acceptFlag[0]) {
// new Expression(addShapeJPanel.getCurrentAnalyticExpression()), -1));
return new AnalyticSubVolume(null, newSubVolName, new Expression(addShapeJPanel.getCurrentAnalyticExpression()), -1);
} else {
throw UserCancelException.CANCEL_GENERIC;
}
} catch (UserCancelException uce) {
throw uce;
} catch (Exception e1) {
e1.printStackTrace();
DialogUtils.showErrorDialog(requester, "Error adding shape:\n" + e1.getMessage(), e1);
}
}
}
Aggregations