Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

StereoPlot.java

Go to the documentation of this file.
00001 /*
00002  * StereoPlot.java
00003  *
00004  * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/
00005  *
00006  * This file is part of Ikayaki.
00007  *
00008  * Ikayaki is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Ikayaki is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Ikayaki; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021  */
00022 
00023 package ikayaki.gui;
00024 
00025 import ikayaki.MeasurementStep;
00026 import ikayaki.MeasurementValue;
00027 import ikayaki.Project;
00028 
00029 import java.awt.*;
00030 import java.awt.geom.Point2D;
00031 import java.util.Vector;
00032 
00033 
00039 public class StereoPlot extends AbstractPlot {
00040 
00044     private Vector<Point2D> points = new Vector<Point2D>();
00045 
00049     private Vector<Boolean> incSign = new Vector<Boolean>();
00050 
00051     private Project project = null;
00052 
00056     public void add(MeasurementStep step) {
00057         if (step.getProject() != null) {
00058             project = step.getProject();
00059         }
00060         Double incValue = MeasurementValue.INCLINATION.getValue(step);
00061         Double decValue = MeasurementValue.DECLINATION.getValue(step);
00062 
00063         if (incValue != null && decValue != null) {
00064             if (incValue.doubleValue() >= 0) {
00065                 points.add(toXY(decValue, incValue));
00066                 incSign.add(new Boolean(true));
00067             } else {
00068                 points.add(toXY(decValue, incValue));
00069                 incSign.add(new Boolean(false));
00070             }
00071         }
00072     }
00073 
00082     // TODO Now the projection is linear. It should be biased but how much?
00083     private Point2D.Double toXY(Double decValue, Double incValue) {
00084         double inc = Math.toRadians(incValue);
00085         double dec = Math.toRadians(decValue);
00086         double x = 0.5 + ((0.5 - (0.5 / (Math.PI / 2.0)) * Math.abs(inc)) * Math.cos(dec - (Math.PI / 2.0)));
00087         double y = 0.5 + ((0.5 - (0.5 / (Math.PI / 2.0)) * Math.abs(inc)) * Math.sin(dec + (Math.PI / 2.0)));
00088         return new Point2D.Double(x, y);
00089     }
00090 
00094     public void reset() {
00095         points.clear();
00096         incSign.clear();
00097         repaint();
00098     }
00099 
00105     public int getNumMeasurements() {
00106         return points.size();
00107     }
00108 
00116     public void render(int w, int h, Graphics2D g2) {
00117         // margin
00118         int m = 5;
00119         // area for texts on edges
00120         int txtArea = 10;
00121         // minimum dimension of the plot
00122         int dim = Math.min(w, h);
00123         // area for points in x and y direction = width = height of the actual plot
00124         int area = dim - (2 * (m + txtArea));
00125         // font for texts
00126         g2.setFont(new Font("Arial", Font.PLAIN, 8 + (area / 60)));
00127         FontMetrics metrics = g2.getFontMetrics();
00128         // text width for letter W
00129         int txtW = 0;
00130         // text height
00131         int txtH = metrics.getHeight();
00132 
00133         // draw circle
00134         g2.drawOval(m + txtArea, m + txtArea, area, area);
00135         // draw ticks
00136         int tLength = 5; // circle ticks length in degrees
00137         int atLength = (area / 40) + 3; // horizontal and vertical ticks length
00138 
00139         for (int i = 0; i < 360; i = i + 10) {
00140             int x1 = new Double(toXY(new Double(i), new Double(0)).getX() * area).intValue();
00141             int y1 = new Double(toXY(new Double(i), new Double(0)).getY() * area).intValue();
00142             int x2, y2;
00143             if (i % 90 == 0) {
00144                 x2 = new Double(toXY(new Double(i), new Double(tLength * 2)).getX() * area).intValue();
00145                 y2 = new Double(toXY(new Double(i), new Double(tLength * 2)).getY() * area).intValue();
00146             } else {
00147                 x2 = new Double(toXY(new Double(i), new Double(tLength)).getX() * area).intValue();
00148                 y2 = new Double(toXY(new Double(i), new Double(tLength)).getY() * area).intValue();
00149             }
00150             g2.drawLine((m + txtArea) + x1, (m + txtArea) + y1, (m + txtArea) + x2, (m + txtArea) + y2);
00151         }
00152 
00153         for (int i = 10; i <= 90; i = i + 10) {
00154             int x1, y1, x2, y2;
00155             x1 = (new Double(toXY(new Double(0), new Double(i)).getX() * area).intValue()) - (atLength / 2);
00156             y1 = new Double(toXY(new Double(0), new Double(i)).getY() * area).intValue();
00157             x2 = x1 + atLength;
00158             y2 = y1;
00159             g2.drawLine((m + txtArea) + x1, (m + txtArea) + y1, (m + txtArea) + x2, (m + txtArea) + y2);
00160         }
00161         for (int i = 10; i <= 90; i = i + 10) {
00162             int x1, y1, x2, y2;
00163             x1 = new Double(toXY(new Double(90), new Double(i)).getX() * area).intValue();
00164             y1 = new Double(toXY(new Double(90), new Double(i)).getY() * area).intValue() - (atLength / 2);
00165             x2 = x1;
00166             y2 = y1 + atLength;
00167             g2.drawLine((m + txtArea) + x1, (m + txtArea) + y1, (m + txtArea) + x2, (m + txtArea) + y2);
00168         }
00169         for (int i = 10; i <= 90; i = i + 10) {
00170             int x1, y1, x2, y2;
00171             x1 = (new Double(toXY(new Double(180), new Double(i)).getX() * area).intValue()) - (atLength / 2);
00172             y1 = new Double(toXY(new Double(180), new Double(i)).getY() * area).intValue();
00173             x2 = x1 + atLength;
00174             y2 = y1;
00175             g2.drawLine((m + txtArea) + x1, (m + txtArea) + y1, (m + txtArea) + x2, (m + txtArea) + y2);
00176         }
00177         for (int i = 10; i <= 90; i = i + 10) {
00178             int x1, y1, x2, y2;
00179             x1 = new Double(toXY(new Double(270), new Double(i)).getX() * area).intValue();
00180             y1 = (new Double(toXY(new Double(270), new Double(i)).getY() * area).intValue() - (atLength / 2));
00181             x2 = x1;
00182             y2 = y1 + atLength;
00183             g2.drawLine((m + txtArea) + x1, (m + txtArea) + y1, (m + txtArea) + x2, (m + txtArea) + y2);
00184         }
00185 
00186 
00187         // draw symbols
00188         txtW = metrics.stringWidth("N");
00189         g2.drawString("N", m + txtArea + (area / 2) - (txtW / 2), m + (txtArea / 2));
00190         txtW = metrics.stringWidth("W");
00191         g2.drawString("W", m + (txtArea / 2) - txtW, m + txtArea + (area / 2) + (txtH / 2));
00192         txtW = metrics.stringWidth("E");
00193         g2.drawString("E", m + txtArea + area + (txtArea / 2), m + txtArea + (area / 2) + (txtH / 2));
00194         txtW = metrics.stringWidth("S");
00195         g2.drawString("S", m + txtArea + (area / 2) - (txtW / 2), m + txtArea + area + (txtArea / 2) + (txtH / 2));
00196 
00197         // draw points
00198         int ps = (area / 60) + 4; // points size
00199         for (int i = 0; i < points.size(); i++) {
00200             int x = (m + txtArea) + new Double(points.elementAt(i).getX() * area).intValue();
00201             int y = (m + txtArea) + area - new Double(points.elementAt(i).getY() * area).intValue();
00202             if (i == 0) {
00203                 g2.drawString("NRM", x + (area / 50), y - (area / 50));
00204             }
00205 
00206             if (incSign.elementAt(i).booleanValue()) { // positive inclination
00207                 g2.fillOval(x - (ps / 2), y - (ps / 2), ps, ps);
00208             } else { // negative inclination
00209                 g2.drawOval(x - (ps / 2), y - (ps / 2), ps, ps);
00210             }
00211         }
00212 
00213         // draw lines
00214         if (points.size() >= 2) {
00215             for (int i = 1; i < points.size(); i++) {
00216                 int x1 = new Double((points.elementAt(i - 1).getX() * area)).intValue();
00217                 int y1 = new Double((points.elementAt(i - 1).getY() * area)).intValue();
00218                 int x2 = new Double((points.elementAt(i).getX() * area)).intValue();
00219                 int y2 = new Double((points.elementAt(i).getY() * area)).intValue();
00220 
00221                 g2.drawLine((m + txtArea) + x1, (m + txtArea) + area - y1, (m + txtArea) + x2,
00222                         (m + txtArea) + area - y2);
00223             }
00224         }
00225     }
00226 }

Generated on Fri May 6 16:00:32 2005 for Squid by  doxygen 1.4.1