use of java.awt.geom.Point2D in project vcell by virtualcell.
the class ODESolverPlotSpecificationPanel method regeneratePlot2D.
/**
* Comment
*/
private void regeneratePlot2D() throws ExpressionException, ObjectNotFoundException {
if (getMyDataInterface() == null) {
return;
}
if (!getMyDataInterface().isMultiTrialData()) {
if (getXAxisComboBox_frm().getSelectedIndex() < 0) {
return;
} else {
// double[] xData = getOdeSolverResultSet().extractColumn(getPlottableColumnIndices()[getXIndex()]);
// getUnfilteredSortedXAxisNames
double[] xData = getMyDataInterface().extractColumn((String) getXAxisComboBox_frm().getSelectedItem());
double[][] allData = new double[((DefaultListModel) getYAxisChoice().getModel()).size() + 1][xData.length];
String[] yNames = new String[((DefaultListModel) getYAxisChoice().getModel()).size()];
allData[0] = xData;
double[] yData = new double[xData.length];
double currParamValue = 0.0;
double deltaParamValue = 0.0;
// Extrapolation calculations!
if (getSensitivityParameter() != null) {
int val = getSensitivityParameterSlider().getValue();
double nominalParamValue = getSensitivityParameter().getConstantValue();
double pMax = nominalParamValue * 1.1;
double pMin = nominalParamValue * 0.9;
int iMax = getSensitivityParameterSlider().getMaximum();
int iMin = getSensitivityParameterSlider().getMinimum();
double slope = (pMax - pMin) / (iMax - iMin);
currParamValue = slope * val + pMin;
deltaParamValue = currParamValue - nominalParamValue;
getMaxLabel().setText(Double.toString(pMax));
getMinLabel().setText(Double.toString(pMin));
getCurLabel().setText(Double.toString(currParamValue));
}
if (!getLogSensCheckbox().getModel().isSelected()) {
// When log sensitivity check box is not selected.
for (int i = 0; i < allData.length - 1; i++) {
// If sensitivity analysis is enabled, extrapolate values for State vars and non-sensitivity functions
if (getSensitivityParameter() != null) {
ColumnDescription cd = getMyDataInterface().getColumnDescription((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
double[] sens = getSensValues(cd);
yData = getMyDataInterface().extractColumn(cd.getName());
// sens array != null for non-sensitivity state vars and functions, so extrapolate
if (sens != null) {
for (int j = 0; j < sens.length; j++) {
if (Math.abs(yData[j]) > 1e-6) {
// away from zero, exponential extrapolation
allData[i + 1][j] = yData[j] * Math.exp(deltaParamValue * sens[j] / yData[j]);
} else {
// around zero - linear extrapolation
allData[i + 1][j] = yData[j] + sens[j] * deltaParamValue;
}
}
// sens array == null for sensitivity state vars and functions, so don't change their original values
} else {
allData[i + 1] = getMyDataInterface().extractColumn((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
}
} else {
// No sensitivity analysis case, so do not alter the original values for any variable or function
allData[i + 1] = getMyDataInterface().extractColumn((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
}
yNames[i] = (String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i);
}
} else {
// When log sensitivity checkbox is selected.
// Get sensitivity parameter and its value to compute log sensitivity
Constant sensParam = getSensitivityParameter();
double sensParamValue = sensParam.getConstantValue();
getJLabelSensitivityParameter().setText("Sensitivity wrt Parameter " + sensParam.getName());
//
for (int i = 0; i < allData.length - 1; i++) {
// Finding sensitivity var column for each column in result set.
ColumnDescription cd = getMyDataInterface().getColumnDescription((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
String sensVarName = null;
ColumnDescription[] allColumnDescriptions = getMyDataInterface().getAllColumnDescriptions();
for (int j = 0; j < allColumnDescriptions.length; j++) {
String obj = "sens_" + cd.getName() + "_wrt_" + sensParam.getName();
if (allColumnDescriptions[j].getName().equals(obj)) {
sensVarName = obj;
break;
}
}
int sensIndex = -1;
if (sensVarName != null) {
for (int j = 0; j < ((DefaultListModel) getYAxisChoice().getModel()).getSize(); j++) {
if (((String) ((DefaultListModel) getYAxisChoice().getModel()).get(j)).equals(sensVarName)) {
sensIndex = j;
break;
}
}
}
yData = getMyDataInterface().extractColumn(cd.getName());
// If sensitivity var exists, compute log sensitivity
if (sensVarName != null) {
double[] sens = getMyDataInterface().extractColumn(sensVarName);
for (int k = 0; k < yData.length; k++) {
// Extrapolated statevars and functions
if (Math.abs(yData[k]) > 1e-6) {
// away from zero, exponential extrapolation
allData[i + 1][k] = yData[k] * Math.exp(deltaParamValue * sens[k] / yData[k]);
} else {
// around zero - linear extrapolation
allData[i + 1][k] = yData[k] + sens[k] * deltaParamValue;
}
// Log sensitivity for the state variables and functions
// default if floating point problems
double logSens = 0.0;
if (Math.abs(yData[k]) > 0) {
double tempLogSens = sens[k] * sensParamValue / yData[k];
if (tempLogSens != Double.NEGATIVE_INFINITY && tempLogSens != Double.POSITIVE_INFINITY && tempLogSens != Double.NaN) {
logSens = tempLogSens;
}
}
if (sensIndex > -1) {
allData[sensIndex + 1][k] = logSens;
}
}
// If sensitivity var does not exist, retain original value of column (var or function).
} else {
if (!cd.getName().startsWith("sens_")) {
allData[i + 1] = yData;
}
}
yNames[i] = (String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i);
}
}
String title = "";
String xLabel = (String) getXAxisComboBox_frm().getSelectedItem();
String yLabel = "";
if (yNames.length == 1) {
yLabel = yNames[0];
}
// Update Sensitivity parameter label depending on whether Log sensitivity check box is checked or not.
if (!getLogSensCheckbox().getModel().isSelected()) {
getJLabelSensitivityParameter().setText("");
}
SymbolTableEntry[] symbolTableEntries = null;
if (getSymbolTable() != null && yNames != null && yNames.length > 0) {
symbolTableEntries = new SymbolTableEntry[yNames.length];
for (int i = 0; i < yNames.length; i += 1) {
SymbolTableEntry ste = getSymbolTable().getEntry(yNames[i]);
symbolTableEntries[i] = ste;
}
}
SingleXPlot2D plot2D = new SingleXPlot2D(symbolTableEntries, getMyDataInterface().getDataSymbolMetadataResolver(), xLabel, yNames, allData, new String[] { title, xLabel, yLabel });
refreshVisiblePlots(plot2D);
// here fire "singleXPlot2D" event, ODEDataViewer's event handler listens to it.
setPlot2D(plot2D);
}
} else // end of none MultitrialData
// multitrial data
{
// a column of data get from ODESolverRestultSet, which is actually the results for a specific variable during multiple trials
double[] rowData = new double[getMyDataInterface().getRowCount()];
PlotData[] plotData = new PlotData[((DefaultListModel) getYAxisChoice().getModel()).size()];
for (int i = 0; i < plotData.length; i++) {
ColumnDescription cd = getMyDataInterface().getColumnDescription((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
rowData = getMyDataInterface().extractColumn(cd.getName());
Point2D[] histogram = generateHistogram(rowData);
double[] x = new double[histogram.length];
double[] y = new double[histogram.length];
for (int j = 0; j < histogram.length; j++) {
x[j] = histogram[j].getX();
y[j] = histogram[j].getY();
}
plotData[i] = new PlotData(x, y);
}
SymbolTableEntry[] symbolTableEntries = null;
if (getSymbolTable() != null && ((DefaultListModel) getYAxisChoice().getModel()).size() > 0) {
symbolTableEntries = new SymbolTableEntry[((DefaultListModel) getYAxisChoice().getModel()).size()];
for (int i = 0; i < symbolTableEntries.length; i += 1) {
symbolTableEntries[i] = getSymbolTable().getEntry((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
}
}
String title = "Probability Distribution of Species";
String xLabel = "Number of Particles";
String yLabel = "";
String[] yNames = new String[((DefaultListModel) getYAxisChoice().getModel()).size()];
((DefaultListModel) getYAxisChoice().getModel()).copyInto(yNames);
Plot2D plot2D = new Plot2D(symbolTableEntries, getMyDataInterface().getDataSymbolMetadataResolver(), yNames, plotData, new String[] { title, xLabel, yLabel });
refreshVisiblePlots(plot2D);
setPlot2D(plot2D);
}
}
use of java.awt.geom.Point2D in project vcell by virtualcell.
the class UShortImage method createCircularBinaryKernel.
public static KernelJAI createCircularBinaryKernel(int radius) {
int enclosingBoxSideLength = radius * 2 + 1;
float[] kernalData = new float[enclosingBoxSideLength * enclosingBoxSideLength];
Point2D kernalPoint = new Point2D.Float(0f, 0f);
int index = 0;
for (int y = -radius; y <= radius; y++) {
for (int x = -radius; x <= radius; x++) {
if (kernalPoint.distance(x, y) <= radius) {
kernalData[index] = 1.0f;
}
index++;
}
}
return new KernelJAI(enclosingBoxSideLength, enclosingBoxSideLength, radius, radius, kernalData);
}
use of java.awt.geom.Point2D in project vcell by virtualcell.
the class EdgeShape method getParameterAtArcLength.
protected static double getParameterAtArcLength(CubicCurve2D curve, double startT, double endT, double arcLength, int numIntervals) {
double currentT = startT;
double totalLength = 0.0;
double deltaT = (endT - startT) / numIntervals;
Point2D curr = evaluate(curve, currentT);
for (int i = 0; i < numIntervals && totalLength < arcLength; i++) {
currentT = startT + i * deltaT;
Point2D next = evaluate(curve, currentT);
double dx = next.getX() - curr.getX();
double dy = next.getY() - curr.getY();
totalLength += Math.sqrt(dx * dx + dy * dy);
curr = next;
}
return currentT;
}
use of java.awt.geom.Point2D in project vcell by virtualcell.
the class BioPaxShape method paintSelf.
@Override
public void paintSelf(Graphics2D g, int absPosX, int absPosY) {
RenderingHints oldRenderingHints = g.getRenderingHints();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int shapeHeight = getSpaceManager().getSize().height;
int shapeWidth = getSpaceManager().getSize().width;
int offsetX = (shapeWidth - getPreferredWidth()) / 2;
int offsetY = (shapeHeight - getPreferredHeight()) / 2;
Graphics2D g2D = g;
if (icon == null) {
icon = new Area();
icon.add(new Area(new Ellipse2D.Double(offsetX, offsetY, getPreferredWidth(), getPreferredHeight())));
}
Area movedIcon = icon.createTransformedArea(AffineTransform.getTranslateInstance(absPosX, absPosY));
g.setColor((!hasPCLink() && !isSelected() ? darkerBackground : backgroundColor));
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color exterior = !hasPCLink() && !isSelected() ? darkerBackground : backgroundColor;
Color interior = exterior.brighter();
exterior = exterior.darker();
Point2D center = new Point2D.Float(absPosX + getPreferredWidth() / 2, absPosY + getPreferredWidth() / 2);
float radius = getPreferredWidth() * 0.5f;
Point2D focus = new Point2D.Float(absPosX + getPreferredWidth() / 2 - 2, absPosY + getPreferredWidth() / 2 - 2);
float[] dist = { 0.1f, 1.0f };
// Color[] colors = {Color.white, exterior};
Color[] colors = { interior, exterior };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2D.setPaint(p);
g2D.fill(movedIcon);
g.setColor(forgroundColor);
g2D.draw(movedIcon);
// draw label
if (getLabel() != null && getLabel().length() > 0) {
if (isSelected()) {
// clear background and outline to make selected label stand out
drawRaisedOutline(getLabelPos().x + absPosX - 5, getLabelPos().y + absPosY - getLabelSize().height + 3, getLabelSize().width + 10, getLabelSize().height, g, Color.white, forgroundColor, Color.gray);
}
g.setColor(forgroundColor);
g.drawString((isSelected() || smallLabel == null ? getLabel() : smallLabel), (isSelected() || smallLabel == null ? getLabelPos().x : smallLabelPos.x) + absPosX, getLabelPos().y + absPosY);
}
if (hasRelationships) {
ShapePaintUtil.paintLinkMark(g2D, this, Color.BLACK);
}
g.setRenderingHints(oldRenderingHints);
}
use of java.awt.geom.Point2D in project vcell by virtualcell.
the class MolecularTypeSmallShape method paintSpecies.
// --------------------------------------------------------------------------------------
// paintComponent is being overridden in the renderer
//
private void paintSpecies(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Color primaryColor = null;
Color border = Color.black;
int finalHeight = baseHeight;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (mt == null && mtp == null) {
if (shapeManager == null) {
primaryColor = Color.green.darker().darker();
} else {
primaryColor = shapeManager.isEditable() ? Color.green.darker().darker() : Color.gray;
}
finalHeight = baseHeight + 3;
Point2D center = new Point2D.Float(xPos + finalHeight / 3, yPos + finalHeight / 3);
float radius = finalHeight * 0.5f;
Point2D focus = new Point2D.Float(xPos + finalHeight / 3 - 1, yPos + finalHeight / 3 - 1);
float[] dist = { 0.1f, 1.0f };
Color[] colors = { Color.white, primaryColor };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(p);
Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, finalHeight, finalHeight);
g2.fill(circle);
Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, finalHeight, finalHeight);
g2.setPaint(getDefaultColor(Color.darkGray));
g2.draw(circle2);
g.setColor(colorOld);
return;
} else {
// molecular type, species pattern, observable
if (mt == null || mt.getModel() == null) {
primaryColor = Color.blue.darker().darker();
} else {
if (shapeManager != null) {
if (shapeManager.isShowMoleculeColor()) {
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
primaryColor = MolecularTypeLargeShape.colorTable[index].darker().darker();
} else {
primaryColor = Color.gray;
}
border = shapeManager.isEditable() ? Color.black : LargeShapeCanvas.uneditableShape;
} else {
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
primaryColor = MolecularTypeLargeShape.colorTable[index].darker().darker();
}
}
if (owner instanceof MolecularType && hasErrorIssues(owner, mt)) {
primaryColor = Color.red;
}
}
GradientPaint p = new GradientPaint(xPos, yPos, primaryColor, xPos, yPos + finalHeight / 2, Color.WHITE, true);
g2.setPaint(p);
RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, width, finalHeight, cornerArc, cornerArc);
g2.fill(rect);
RoundRectangle2D inner = new RoundRectangle2D.Float(xPos + 1, yPos + 1, width - 2, finalHeight - 2, cornerArc - 3, cornerArc - 3);
g2.setPaint(border);
g2.draw(rect);
g.setColor(colorOld);
for (MolecularComponentSmallShape mcss : componentShapes) {
mcss.paintSelf(g);
}
g.setColor(colorOld);
}
Aggregations