use of org.vcell.util.Range in project vcell by virtualcell.
the class ImagePaneScrollerTest method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) {
// Insert code to start the application here.
// Create default image
int w = Integer.valueOf(args[2]).intValue();
int h = Integer.valueOf(args[3]).intValue();
String type = args[0];
SourceDataInfo sdi = getExampleSDI(type, w, h);
DisplayAdapterService das = null;
if (type.equals("double")) {
das = new DisplayAdapterService();
das.setActiveScaleRange(new Range(0, 450));
das.setValueDomain(new Range(-50, 550));
das.addColorModelForValues(DisplayAdapterService.createGrayColorModel(), DisplayAdapterService.createGraySpecialColors(), DisplayAdapterService.GRAY);
das.addColorModelForValues(DisplayAdapterService.createBlueRedColorModel(), DisplayAdapterService.createBlueRedSpecialColors(), DisplayAdapterService.BLUERED);
das.setActiveColorModelID(DisplayAdapterService.GRAY);
} else if (type.equals("index")) {
das = new DisplayAdapterService();
das.addColorModelForIndexes(DisplayAdapterService.createGrayColorModel(), DisplayAdapterService.GRAY);
das.addColorModelForIndexes(DisplayAdapterService.createBlueRedColorModel(), DisplayAdapterService.BLUERED);
das.setActiveColorModelID(DisplayAdapterService.GRAY);
}
try {
javax.swing.JFrame frame = new javax.swing.JFrame();
ImagePaneScroller aImagePaneScroller;
aImagePaneScroller = new ImagePaneScroller();
aImagePaneScroller.getImagePaneModel().setSourceData(sdi);
aImagePaneScroller.getImagePaneModel().setDisplayAdapterService(das);
// aImagePaneScroller.getImagePaneModel().setBackgroundColor(java.awt.Color.yellow);
if (args[1].equals("true")) {
aImagePaneScroller.getImagePaneModel().setMode(ImagePaneModel.MESH_MODE);
}
javax.swing.JPanel jp = new javax.swing.JPanel();
jp.setLayout(new java.awt.BorderLayout());
jp.add(aImagePaneScroller);
frame.setContentPane(jp);
frame.setSize(aImagePaneScroller.getSize());
frame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
frame.show();
java.awt.Insets insets = frame.getInsets();
frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom);
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JPanel");
exception.printStackTrace(System.out);
}
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class ImagePaneScrollerTest method getExampleSDI.
/**
* Insert the method's description here.
* Creation date: (10/12/00 2:08:24 PM)
* @return cbit.image.SourceDataInfo
*/
public static final SourceDataInfo getExampleSDI(String type, int w, int h) {
int numZ = 20;
SourceDataInfo sdi = null;
if (type.equals("rgb")) {
int[] pixels = new int[w * h * numZ];
for (int z = 0; z < numZ; z += 1) {
for (int y = 0; y < h; y += 1) {
for (int x = 0; x < w; x += 1) {
if (y % 2 == 0) {
if (x % 2 == 0) {
pixels[x + (y * w) + (z * w * h)] = 0x00ff0000;
}
} else {
if (x % 2 != 0) {
pixels[x + (y * w) + (z * w * h)] = 0x00ff0000;
}
}
if (x >= w / 3 && x < w / 2 && y >= h / 3 && y < h / 1.5) {
pixels[x + (y * w) + (z * w * h)] = 0xFF * z / numZ * 0xFFFF;
}
}
}
}
//
sdi = new SourceDataInfo(SourceDataInfo.INT_RGB_TYPE, pixels, new org.vcell.util.Extent(1, 2, 3), new org.vcell.util.Origin(0, -5, 10), null, 0, w, 1, h, w, numZ, h * w);
} else if (type.equals("double")) {
double[] pixels = new double[w * h * numZ];
for (int z = 0; z < numZ; z += 1) {
for (int y = 0; y < h; y += 1) {
for (int x = 0; x < w; x += 1) {
pixels[x + (y * w) + (z * w * h)] = -150 + ((double) x / ((double) w - 1)) * (800);
if (y > h - (h / 4)) {
pixels[x + (y * w) + (z * w * h)] = Double.POSITIVE_INFINITY;
}
if (x >= w / 3 && x < w / 2 && y >= h / 3 && y < h / 1.5) {
pixels[x + (y * w) + (z * w * h)] = 300 * z / numZ;
}
}
}
}
sdi = new SourceDataInfo(SourceDataInfo.RAW_VALUE_TYPE, pixels, new org.vcell.util.Extent(1, 2, 3), new org.vcell.util.Origin(0, -5, 10), new Range(-150, 650), 0, w, 1, h, w, numZ, h * w);
} else if (type.equals("index")) {
byte[] pixels = new byte[w * h * numZ];
for (int i = 0; i < pixels.length; i += 1) {
pixels[i] = (byte) (i % 256);
}
sdi = new SourceDataInfo(SourceDataInfo.INDEX_TYPE, pixels, new org.vcell.util.Extent(1, 2, 3), new org.vcell.util.Origin(0, -5, 10), null, 0, w, 1, h, w, numZ, h * w);
} else if (type.equals("facecube")) {
numZ = 50;
w = 50;
h = 50;
int[] pixels = new int[w * h * numZ];
int[] facePixels = new int[w * h];
java.awt.image.BufferedImage face = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D g2d = face.createGraphics();
g2d.setRenderingHint(java.awt.RenderingHints.KEY_FRACTIONALMETRICS, java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2d.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setFont(new java.awt.Font("SansSerif", java.awt.Font.PLAIN, 6));
// g2d.scale(2,2);
// java.awt.Font smallFont = g2d.getFont().deriveFont(10);
// g2d.setFont(smallFont);
int xStart = 0;
int xEnd = 0;
int xIncr = 0;
int yStart = 0;
int yEnd = 0;
int yIncr = 0;
int zStart = 0;
int zEnd = 0;
int zIncr = 0;
for (int i = 0; i < 2; i += 1) {
g2d.setColor(java.awt.Color.red);
g2d.fillRect(0, 0, w, h);
g2d.setColor(java.awt.Color.white);
switch(i) {
case 0:
xStart = 0;
xEnd = w;
xIncr = 1;
yStart = 0;
yEnd = w * h;
yIncr = w;
zStart = 0;
zEnd = w * h * numZ;
zIncr = w * h;
g2d.drawString("- FRNT(-) +", 0, 15);
g2d.drawString("- FRNT (+) +", 0, h - 2);
break;
case 1:
xStart = 0;
xEnd = w;
xIncr = 1;
yStart = 0;
yEnd = w * h;
yIncr = w;
zStart = 0;
zEnd = w * h * numZ;
zIncr = w * h;
g2d.drawString("- BTM(-) +", 0, 15);
g2d.drawString("- BTM (+) +", 0, h - 2);
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
}
face.getRGB(0, 0, w, h, facePixels, 0, w);
for (int z = zStart; z != zEnd; z += zIncr * (zEnd - zStart < 0 ? -1 : 1)) {
int index = 0;
for (int y = yStart; y != yEnd; y += yIncr * (yEnd - yStart < 0 ? -1 : 1)) {
for (int x = xStart; x != xEnd; x += xIncr * (xEnd - xStart < 0 ? -1 : 1)) {
pixels[x + (y) + (z)] = facePixels[index];
index += 1;
}
}
}
}
sdi = new SourceDataInfo(SourceDataInfo.INT_RGB_TYPE, pixels, new org.vcell.util.Extent(1, 2, 3), new org.vcell.util.Origin(0, -5, 10), null, 0, w, 1, h, w, numZ, h * w);
}
//
return sdi;
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class ScalePanel method setDataRange.
/**
* Sets the dataRange property (cbit.image.Range) value.
* @param dataRange The new value for the property.
* @see #getDataRange
*/
public void setDataRange(Range dataRange) {
Range oldValue = fieldDataRange;
fieldDataRange = dataRange;
firePropertyChange("dataRange", oldValue, dataRange);
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class ScalePanel method setScaleRange.
/**
* Sets the scaleRange property (cbit.image.Range) value.
* @param scaleRange The new value for the property.
* @see #getScaleRange
*/
public void setScaleRange(Range scaleRange) {
Range oldValue = fieldScaleRange;
fieldScaleRange = scaleRange;
firePropertyChange("scaleRange", oldValue, scaleRange);
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class Plot2DPanel method drawTicks.
/**
* Comment
*/
private void drawTicks(Graphics2D g) {
if (!getBCompact()) {
g.setColor(Color.black);
g.setStroke(lineBS_10);
Range xR = getXAuto() ? getXAutoRange() : getXManualRange();
Range yR = getYAuto() ? getYAutoRange() : getYManualRange();
xR = xR == null ? new Range(-1, 1) : xR;
yR = yR == null ? new Range(-1, 1) : yR;
double[] xM = getXMajorTicks();
double[] xm = getXMinorTicks();
double[] yM = getYMajorTicks();
double[] ym = getYMinorTicks();
int xLabelMaxHeight = 0;
int yLabelMaxWidth = 0;
for (int i = 0; i < yM.length; i++) {
String label = Double.toString(yM[i]);
Rectangle2D labelBounds = g.getFontMetrics().getStringBounds(label, g);
yLabelMaxWidth = Math.max(yLabelMaxWidth, (int) labelBounds.getWidth());
}
for (int i = 0; i < xM.length; i++) {
String label = Double.toString(xM[i]);
Rectangle2D labelBounds = g.getFontMetrics().getStringBounds(label, g);
xLabelMaxHeight = Math.max(xLabelMaxHeight, (int) labelBounds.getHeight());
}
setBMargin(xLabelMaxHeight * 4 / 3);
setLMargin(yLabelMaxWidth + xLabelMaxHeight * 2 / 3);
double ymin = yR.getMin();
double xmin = xR.getMin();
Point2D[] xP = new Point2D[xM.length];
Point2D[] xp = new Point2D[xm.length];
Point2D[] yP = new Point2D[yM.length];
Point2D[] yp = new Point2D[ym.length];
for (int i = 0; i < xM.length; i++) {
xP[i] = new Point2D.Double(xM[i], ymin);
}
for (int i = 0; i < xm.length; i++) {
xp[i] = new Point2D.Double(xm[i], ymin);
}
for (int i = 0; i < yM.length; i++) {
yP[i] = new Point2D.Double(xmin, yM[i]);
}
for (int i = 0; i < ym.length; i++) {
yp[i] = new Point2D.Double(xmin, ym[i]);
}
Point2D[] xP1 = new Point2D[xM.length];
getTransform().transform(yP, 0, yP, 0, yP.length);
getTransform().transform(yp, 0, yp, 0, yp.length);
getTransform().transform(xP, 0, xP1, 0, xP1.length);
getTransform().transform(xP, 0, xP, 0, xP.length);
getTransform().transform(xp, 0, xp, 0, xp.length);
for (int i = 0; i < xP.length; i++) {
g.drawLine((int) xP[i].getX(), (int) xP[i].getY(), (int) xP[i].getX(), (int) xP[i].getY() + getTick());
String label = Double.toString(xM[i]);
Rectangle2D labelBounds = g.getFontMetrics().getStringBounds(label, g);
int labelX = (int) xP[i].getX() - (int) labelBounds.getWidth() / 2;
int labelY = (int) xP[i].getY() + getTick() + xLabelMaxHeight;
g.drawString(label, labelX, labelY);
}
for (int i = 0; i < xp.length; i++) {
g.drawLine((int) xp[i].getX(), (int) xp[i].getY(), (int) xp[i].getX(), (int) xp[i].getY() + getTick() / 2);
}
for (int i = 0; i < yP.length; i++) {
g.drawLine((int) yP[i].getX(), (int) yP[i].getY(), (int) yP[i].getX() - getTick(), (int) yP[i].getY());
String label = Double.toString(yM[i]);
Rectangle2D labelBounds = g.getFontMetrics().getStringBounds(label, g);
int labelX = (int) yP[i].getX() - getTick() - (int) labelBounds.getWidth() - xLabelMaxHeight / 3;
int labelY = (int) yP[i].getY() + (int) labelBounds.getHeight() / 3;
g.drawString(label, labelX, labelY);
}
for (int i = 0; i < yp.length; i++) {
g.drawLine((int) yp[i].getX(), (int) yp[i].getY(), (int) yp[i].getX() - getTick() / 2, (int) yp[i].getY());
}
} else {
int maxLeftMargin = Math.max((int) (g.getFontMetrics().getStringBounds(yCompactMinS, g).getWidth()), (int) (g.getFontMetrics().getStringBounds(yCompactMaxS, g).getWidth())) + COMP_TICK_LEN;
if (getLMargin() != maxLeftMargin) {
setLMargin(maxLeftMargin);
}
}
}
Aggregations