Search in sources :

Example 26 with Point3d

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

the class PositionFileTest method testRW.

public void testRW() throws IOException, org.jdom2.JDOMException {
    PositionFile fout = new PositionFile();
    fout.prepare();
    fout.setReceiver(2, new Point3d(1.0f, 2.0f, 3.0f), true);
    Reading rout = new Reading("21", new double[] { 11, 12, 13, 14 });
    fout.setCalibrationPoint(new Point3d(-1.0f, -2.0f, -3.0f), rout);
    FileUtil.createDirectory("temp");
    fout.store(new File("temp" + File.separator + "PositionFileTest.xml"));
    PositionFile fin = new PositionFile();
    fin.loadFile(new File("temp" + File.separator + "PositionFileTest.xml"));
    Point3d p;
    p = fin.getReceiverPosition(2);
    checkPoint3d(new Point3d(1.0f, 2.0f, 3.0f), p);
    Assert.assertEquals("no 2nd receiver position", null, fin.getReceiverPosition(3));
    p = fin.getCalibrationPosition(0);
    checkPoint3d(new Point3d(-1.0f, -2.0f, -3.0f), p);
    Assert.assertEquals("no 2nd calibration position", null, fin.getCalibrationPosition(1));
    Reading rin = fin.getCalibrationReading(0);
    checkReading(rout, rin);
    Assert.assertEquals("no 2nd calibration reading", null, fin.getCalibrationReading(1));
}
Also used : Point3d(javax.vecmath.Point3d) File(java.io.File)

Example 27 with Point3d

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

the class RegionTest method testEquals.

public void testEquals() {
    // square
    Region r1 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
    Region r2 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
    Region r3 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(2., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
    Region r4 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.) });
    Assert.assertTrue("r1==r2", r1.equals(r2));
    Assert.assertTrue("r1!=r3", !r1.equals(r3));
    Assert.assertTrue("r1!=r4", !r1.equals(r4));
    Assert.assertTrue("r4==r4", r4.equals(r4));
}
Also used : Point3d(javax.vecmath.Point3d)

Example 28 with Point3d

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

the class RegionTest method testInside2.

public void testInside2() {
    // C chape
    Region r = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(3., 0., 0.), new Point3d(3., 1., 0.), new Point3d(1., 1., 0.), new Point3d(1., 2., 0.), new Point3d(2., 2., 0.), new Point3d(2., 3., 0.), new Point3d(0., 3., 0.), new Point3d(0., 0., 0.) });
    Assert.assertTrue("inside", r.isInside(new Point3d(0.5, 0.5, 0.)));
    Assert.assertTrue("outside", !r.isInside(new Point3d(-0.5, 0.5, 0.)));
    Assert.assertTrue("outside", !r.isInside(new Point3d(0.5, -0.5, 0.)));
    Assert.assertTrue("outside", !r.isInside(new Point3d(1.5, 1.5, 0.)));
    Assert.assertTrue("outside", !r.isInside(new Point3d(3.0, 1.5, 0.)));
}
Also used : Point3d(javax.vecmath.Point3d)

Example 29 with Point3d

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

the class RegionTest method testCtors.

public void testCtors() {
    // square
    new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
    // triangle
    new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.) });
}
Also used : Point3d(javax.vecmath.Point3d)

Example 30 with Point3d

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

the class AlignmentPanel method load.

void load() {
    try {
        // request the filename from an open dialog
        fci.rescanCurrentDirectory();
        int retVal = fci.showOpenDialog(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.loadFile(file);
            Point3d p;
            Reading r;
            for (int i = 0; i < NREADINGS; i++) {
                p = pf.getCalibrationPosition(i);
                if (p != null) {
                    lines[i].setPoint(p);
                } else {
                    lines[i].setPoint(new Point3d(0.f, 0.f, 0.f));
                }
            }
            for (int i = 0; i < NREADINGS; i++) {
                r = pf.getCalibrationReading(i);
                lines[i].reset();
                if (r != null) {
                    lines[i].setReading(r);
                }
            }
        } else {
            log.info("load cancelled in open dialog");
        }
    } catch (Exception e) {
        log.error("exception during load: " + e);
    }
}
Also used : Reading(jmri.jmrix.rps.Reading) Point3d(javax.vecmath.Point3d) PositionFile(jmri.jmrix.rps.PositionFile) File(java.io.File) PositionFile(jmri.jmrix.rps.PositionFile)

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