src/org/math/plot/plots/BoxPlot3D.java

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                 // double[] datasMin = Array.min(XY);
00031                 // double[] datasMax = Array.max(XY);
00032                 // double[] widthsMax = Array.max(widths);
00033                 // double[] min = { datasMin[0] - widthsMax[0] / 2, datasMin[1] -
00034                 // widthsMax[1] / 2, datasMin[2] - widthsMax[2] / 2 };
00035                 // double[] max = { datasMax[0] + widthsMax[0] / 2, datasMax[1] +
00036                 // widthsMax[1] / 2, datasMax[2] + widthsMax[2] / 2 };
00037                 // base.includeInBounds(min);
00038                 // base.includeInBounds(max);
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 }

Generated on Wed Sep 5 21:44:01 2007 for jmathplot by  doxygen 1.5.1