00001 package org.math.plot.plots;
00002
00003 import java.awt.*;
00004
00005 import org.math.plot.render.*;
00006
00007 public class BoxPlot3D extends Plot {
00008
00009 double[] Xmin;
00010
00011 double[] Xmax;
00012
00013 double[] Ymin;
00014
00015 double[] Ymax;
00016
00017 double[] Zmin;
00018
00019 double[] Zmax;
00020
00021 double[][] widths;
00022
00023 double[][] XY;
00024
00025 public BoxPlot3D(double[][] _XY, double[][] w, Color c, String n) {
00026 super(n, c);
00027 XY = _XY;
00028 widths = w;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 Xmin = new double[XY.length];
00041 Xmax = new double[XY.length];
00042 Ymin = new double[XY.length];
00043 Ymax = new double[XY.length];
00044 Zmin = new double[XY.length];
00045 Zmax = new double[XY.length];
00046 for (int i = 0; i < XY.length; i++) {
00047 Xmin[i] = XY[i][0] - widths[i][0] / 2;
00048 Xmax[i] = XY[i][0] + widths[i][0] / 2;
00049 Ymin[i] = XY[i][1] - widths[i][1] / 2;
00050 Ymax[i] = XY[i][1] + widths[i][1] / 2;
00051 Zmin[i] = XY[i][2] - widths[i][2] / 2;
00052 Zmax[i] = XY[i][2] + widths[i][2] / 2;
00053 }
00054 }
00055
00056 public void plot(AbstractDrawer draw, Color c) {
00057 if (!visible)
00058 return;
00059
00060 draw.setColor(c);
00061 draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
00062 for (int i = 0; i < XY.length; i++) {
00063 draw.drawLine(new double[] { Xmin[i], Ymin[i], Zmin[i] }, new double[] { Xmax[i], Ymin[i], Zmin[i] });
00064 draw.drawLine(new double[] { Xmax[i], Ymin[i], Zmin[i] }, new double[] { Xmax[i], Ymax[i], Zmin[i] });
00065 draw.drawLine(new double[] { Xmax[i], Ymax[i], Zmin[i] }, new double[] { Xmin[i], Ymax[i], Zmin[i] });
00066 draw.drawLine(new double[] { Xmin[i], Ymax[i], Zmin[i] }, new double[] { Xmin[i], Ymin[i], Zmin[i] });
00067
00068 draw.drawLine(new double[] { Xmin[i], Ymin[i], Zmax[i] }, new double[] { Xmax[i], Ymin[i], Zmax[i] });
00069 draw.drawLine(new double[] { Xmax[i], Ymin[i], Zmax[i] }, new double[] { Xmax[i], Ymax[i], Zmax[i] });
00070 draw.drawLine(new double[] { Xmax[i], Ymax[i], Zmax[i] }, new double[] { Xmin[i], Ymax[i], Zmax[i] });
00071 draw.drawLine(new double[] { Xmin[i], Ymax[i], Zmax[i] }, new double[] { Xmin[i], Ymin[i], Zmax[i] });
00072
00073 draw.drawLine(new double[] { Xmin[i], Ymin[i], Zmin[i] }, new double[] { Xmin[i], Ymin[i], Zmax[i] });
00074 draw.drawLine(new double[] { Xmax[i], Ymin[i], Zmin[i] }, new double[] { Xmax[i], Ymin[i], Zmax[i] });
00075 draw.drawLine(new double[] { Xmin[i], Ymax[i], Zmin[i] }, new double[] { Xmin[i], Ymax[i], Zmax[i] });
00076 draw.drawLine(new double[] { Xmax[i], Ymax[i], Zmin[i] }, new double[] { Xmax[i], Ymax[i], Zmax[i] });
00077
00078 draw.drawDot(XY[i]);
00079 }
00080 }
00081
00082 @Override
00083 public void setData(double[][] d) {
00084 XY = d;
00085 }
00086
00087 @Override
00088 public double[][] getData() {
00089 return XY;
00090 }
00091
00092 public void setDataWidth(double[][] w) {
00093 widths = w;
00094 }
00095
00096 public double[][] getDataWidth() {
00097 return widths;
00098 }
00099
00100 public void setData(double[][] d, double[][] w) {
00101 XY = d;
00102 widths = w;
00103 }
00104
00105 public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
00106 for (int i = 0; i < XY.length; i++) {
00107 int[] screenCoord = draw.project(XY[i]);
00108
00109 if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
00110 && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1]))
00111 return XY[i];
00112 }
00113 return null;
00114 }
00115 }