Search in sources :

Example 16 with Point3d

use of javax.vecmath.Point3d in project JMRI by JMRI.

the class RpsTrackingPanel method paint.

@Override
public void paint(Graphics g) {
    // draw everything else
    super.paint(g);
    log.debug("paint invoked");
    // Now show regions
    // First, Graphics2D setup
    Graphics2D g2 = (Graphics2D) g;
    double xscale = this.getWidth() / (xmax - xorigin);
    double yscale = this.getHeight() / (ymax - yorigin);
    Stroke stroke = new BasicStroke((float) (2. / xscale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g2.setStroke(stroke);
    // Save the current transform
    AffineTransform saveAT = g2.getTransform();
    // Install the new one
    currentAT = new AffineTransform();
    currentAT.translate(0, this.getHeight());
    currentAT.scale(xscale, -yscale);
    // put origin in bottom corner
    currentAT.translate(-xorigin, -yorigin);
    g2.setTransform(currentAT);
    if (showRegions) {
        // Draw the regions
        List<Region> l = Model.instance().getRegions();
        for (int i = 0; i < l.size(); i++) {
            g2.setPaint(regionOutlineColor);
            // border (same color)
            g2.draw(l.get(i).getPath());
            g2.setPaint(regionFillColor);
            g2.fill(l.get(i).getPath());
        }
    }
    // Draw the measurements; changes graphics
    for (int i = 0; i < measurementRepList.size(); i++) {
        measurementRepList.get(i).draw(g2);
    }
    if (showReceivers) {
        // draw receivers
        for (int i = 1; i < Engine.instance().getMaxReceiverNumber() + 1; i++) {
            // indexed from 1
            Receiver r = Engine.instance().getReceiver(i);
            Point3d p = Engine.instance().getReceiverPosition(i);
            if (p != null && r != null) {
                if (r.isActive()) {
                    g2.setPaint(Color.BLACK);
                } else {
                    g2.setPaint(Color.GRAY);
                }
                Shape s = new Ellipse2D.Double(p.x - RECEIVER_SIZE / 2, p.y - RECEIVER_SIZE / 2, RECEIVER_SIZE, RECEIVER_SIZE);
                g2.draw(s);
                g2.fill(s);
            }
        }
    }
    // restore original transform
    g2.setTransform(saveAT);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) Point3d(javax.vecmath.Point3d) AffineTransform(java.awt.geom.AffineTransform) Region(jmri.jmrix.rps.Region) Receiver(jmri.jmrix.rps.Receiver) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 17 with Point3d

use of javax.vecmath.Point3d in project JMRI by JMRI.

the class AlignmentPanel method store.

void store() {
    try {
        // request the filename from an open dialog
        fci.rescanCurrentDirectory();
        int retVal = fci.showSaveDialog(this);
        // handle selection or cancel
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = fci.getSelectedFile();
            if (log.isInfoEnabled()) {
                log.info("located file " + file + " for load");
            }
            // handle the file
            PositionFile pf = new PositionFile();
            pf.prepare();
            pf.setReceiver(1, getPoint(x1l, y1l, z1l), true);
            pf.setReceiver(2, getPoint(x2l, y1l, z2l), true);
            pf.setReceiver(3, getPoint(x3l, y1l, z3l), true);
            pf.setReceiver(4, getPoint(x4l, y1l, z4l), true);
            // save the measurements too
            for (int i = 0; i < NREADINGS; i++) {
                Point3d p = lines[i].getPoint();
                p.z = -p.z;
                pf.setCalibrationPoint(p, lines[i].getReading());
            }
            pf.store(file);
        } else {
            log.info("load cancelled in open dialog");
        }
    } catch (Exception e) {
        log.error("exception during load: " + e);
    }
}
Also used : Point3d(javax.vecmath.Point3d) PositionFile(jmri.jmrix.rps.PositionFile) File(java.io.File) PositionFile(jmri.jmrix.rps.PositionFile)

Example 18 with Point3d

use of javax.vecmath.Point3d in project JMRI by JMRI.

the class DebuggerTimePane method setResidual.

void setResidual(int i, Measurement m) {
    if (times[i].getText().equals("")) {
        // just blank out
        residuals[i].setText("");
        return;
    }
    try {
        if (Engine.instance().getReceiver(i) == null) {
            // just blank out
            residuals[i].setText("");
            return;
        }
        Point3d p = Engine.instance().getReceiverPosition(i);
        Point3d x = new Point3d((float) m.getX(), (float) m.getY(), (float) m.getZ());
        double rt = p.distance(x) / Engine.instance().getVSound();
        int res = (int) (rt - m.getReading().getValue(i)) - Engine.instance().getOffset();
        residuals[i].setText("" + res);
        if (log.isDebugEnabled()) {
            log.debug(" residual " + res + " from " + p + " vs " + x);
        }
    } catch (Exception e) {
        // just blank out
        residuals[i].setText("");
    }
}
Also used : Point3d(javax.vecmath.Point3d)

Example 19 with Point3d

use of javax.vecmath.Point3d in project JMRI by JMRI.

the class RpsSensor method notify.

@Override
public void notify(Measurement r) {
    Point3d p = new Point3d(r.getX(), r.getY(), r.getZ());
    Integer id = Integer.valueOf(r.getReading().getID());
    // ignore if code not OK
    if (!r.isOkPoint()) {
        return;
    }
    // ignore if not in Z fiducial volume
    if (r.getZ() > 20 || r.getZ() < -20) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("starting " + getSystemName());
    }
    if (region.isInside(p)) {
        notifyInRegion(id);
    } else {
        notifyOutOfRegion(id);
    }
    if (contents.size() > 0) {
        setOwnState(Sensor.ACTIVE);
    } else {
        setOwnState(Sensor.INACTIVE);
    }
}
Also used : Point3d(javax.vecmath.Point3d)

Example 20 with Point3d

use of javax.vecmath.Point3d in project JMRI by JMRI.

the class InitialAlgorithmTest method testCalc4.

@Test
public void testCalc4() {
    Reading r = new Reading("21", new double[] { 0., 7. / vs, 13. / vs, 13. / vs, 13. / vs });
    Point3d s1 = new Point3d(0.0f, 0.0f, 5.0f);
    Point3d s2 = new Point3d(-3.0f, 4.0f, 0.0f);
    Point3d s3 = new Point3d(-3.0f, -4.0f, 0.0f);
    Point3d s4 = new Point3d(5.0f, 0.0f, 0.0f);
    Calculator c = new InitialAlgorithm(s1, s2, s3, s4, vs);
    Measurement m = c.convert(r, new Point3d(1.f, 1.f, 10.f));
    Assert.assertEquals("ID ok", "21", m.getID());
    Assert.assertEquals("x close", true, Math.abs(m.x - 0.) < 0.001);
    Assert.assertEquals("y close", true, Math.abs(m.y - 0.) < 0.001);
    Assert.assertEquals("z close", true, Math.abs(m.z - 12.) < 0.001);
}
Also used : Point3d(javax.vecmath.Point3d) Test(org.junit.Test)

Aggregations

Point3d (javax.vecmath.Point3d)33 Test (org.junit.Test)16 Ignore (org.junit.Ignore)8 Reading (jmri.jmrix.rps.Reading)4 Receiver (jmri.jmrix.rps.Receiver)4 File (java.io.File)3 Measurement (jmri.jmrix.rps.Measurement)3 Engine (jmri.jmrix.rps.Engine)2 PositionFile (jmri.jmrix.rps.PositionFile)2 Region (jmri.jmrix.rps.Region)2 Element (org.jdom2.Element)2 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 Shape (java.awt.Shape)1 Stroke (java.awt.Stroke)1 AffineTransform (java.awt.geom.AffineTransform)1 BoxLayout (javax.swing.BoxLayout)1 JmriJFrame (jmri.util.JmriJFrame)1