Search in sources :

Example 1 with SimOuts

use of com.chrisali.javaflightsim.simulation.integration.SimOuts in project j6dof-flight-sim by chris-ali.

the class SimulationPlot method createPlots.

/**
 * Populates the {@link plotLists} List with {@link XYPlot} objects created from the logsOut ArrayList
 * argument. It first creates {@link XYSeries} objects with data from logsOut, adds those to
 * {@link XYSeriesCollection}, adds those series collections to {@link XYPlot} objects, and finally
 * puts the XYPlot objects into {@link plotList}. The types of {@link XYPlot} objects generated
 * comes from settings in {@link SubPlotBundle}
 *
 * @param logsOut
 * @param bundle
 */
private void createPlots(List<Map<SimOuts, Double>> logsOut, SubPlotBundle bundle) {
    for (SubPlotOptions option : bundle.getSubPlots()) {
        XYSeriesCollection collection = new XYSeriesCollection();
        for (SimOuts simout : option.getyData()) {
            XYSeries series = new XYSeries(simout.toString());
            xySeriesData.put(simout, series);
            collection.addSeries(series);
        }
        domainAxis = new NumberAxis(option.getxAxisName());
        rangeAxes.put(option.getTitle(), new NumberAxis(option.getyAxisName()));
        xyCollections.put(option.getTitle(), collection);
    }
    combinedDomPlot = new CombinedDomainXYPlot(domainAxis);
    updateXYSeriesData(logsOut, bundle);
    for (Map.Entry<String, XYSeriesCollection> entry : xyCollections.entrySet()) {
        logger.debug("Creating a subplot called: " + entry.getKey() + "...");
        XYPlot subPlot = new XYPlot(entry.getValue(), domainAxis, rangeAxes.get(entry.getKey()), new StandardXYItemRenderer());
        plotList.add(subPlot);
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SubPlotOptions(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)

Example 2 with SimOuts

use of com.chrisali.javaflightsim.simulation.integration.SimOuts in project j6dof-flight-sim by chris-ali.

the class ReadWriteJsonTest method WriteThenReadPlotConfigurationTest.

@Test
public void WriteThenReadPlotConfigurationTest() {
    PlotConfiguration plots = FileUtilities.readPlotConfiguration();
    String assertion = "Deserialized property should not be null";
    assertNotNull(assertion, plots);
    assertNotNull(assertion, plots.getSubPlotBundles());
    assertTrue("There should be at least one bundle in configuration", plots.getSubPlotBundles().size() > 0);
    for (Map.Entry<String, SubPlotBundle> entry : plots.getSubPlotBundles().entrySet()) {
        SubPlotBundle bundle = entry.getValue();
        assertNotNull(assertion, bundle);
        assertNotNull(assertion, bundle.getSizeXPixels());
        assertNotNull(assertion, bundle.getSizeYPixels());
        assertNotNull(assertion, bundle.getTitle());
        assertNotNull(assertion, bundle.getSubPlots());
        assertTrue("There should be at least one subplot in this bundle", bundle.getSubPlots().size() > 0);
        for (SubPlotOptions subplot : bundle.getSubPlots()) {
            assertNotNull(assertion, subplot);
            assertNotNull(assertion, subplot.getTitle());
            assertNotNull(assertion, subplot.getxAxisName());
            assertNotNull(assertion, subplot.getyAxisName());
            assertNotNull(assertion, subplot.getxData());
            assertNotNull(assertion, subplot.getyData());
            assertTrue("There should be at least one y data in this bundle", subplot.getyData().size() > 0);
            for (SimOuts simout : subplot.getyData()) {
                assertNotNull(assertion, simout);
            }
        }
    }
    plots.save();
    PlotConfiguration readPlots = FileUtilities.readPlotConfiguration();
    assertion = "Deserialized property should not be null";
    assertNotNull(assertion, readPlots);
    assertNotNull(assertion, readPlots.getSubPlotBundles());
    assertTrue("There should be at least one bundle in configuration", readPlots.getSubPlotBundles().size() > 0);
    for (Map.Entry<String, SubPlotBundle> entry : readPlots.getSubPlotBundles().entrySet()) {
        SubPlotBundle bundle = entry.getValue();
        assertNotNull(assertion, bundle);
        assertNotNull(assertion, bundle.getSizeXPixels());
        assertNotNull(assertion, bundle.getSizeYPixels());
        assertNotNull(assertion, bundle.getTitle());
        assertNotNull(assertion, bundle.getSubPlots());
        assertTrue("There should be at least one subplot in this bundle", bundle.getSubPlots().size() > 0);
        for (SubPlotOptions subplot : bundle.getSubPlots()) {
            assertNotNull(assertion, subplot);
            assertNotNull(assertion, subplot.getTitle());
            assertNotNull(assertion, subplot.getxAxisName());
            assertNotNull(assertion, subplot.getyAxisName());
            assertNotNull(assertion, subplot.getxData());
            assertNotNull(assertion, subplot.getyData());
            assertTrue("There should be at least one y data in this bundle", subplot.getyData().size() > 0);
            for (SimOuts simout : subplot.getyData()) {
                assertNotNull(assertion, simout);
            }
        }
    }
}
Also used : SubPlotBundle(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotBundle) PlotConfiguration(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) Map(java.util.Map) SubPlotOptions(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions) Test(org.junit.Test)

Example 3 with SimOuts

use of com.chrisali.javaflightsim.simulation.integration.SimOuts in project j6dof-flight-sim by chris-ali.

the class SimulationPlot method updateXYSeriesData.

/**
 * Update {@link XYSeries} objects with new data from a thread-safe logsOut list
 *
 * @param logsOut
 * @param bundle
 */
protected void updateXYSeriesData(List<Map<SimOuts, Double>> logsOut, SubPlotBundle bundle) {
    // Clear old XV series values
    for (Map.Entry<SimOuts, XYSeries> entry : xySeriesData.entrySet()) entry.getValue().clear();
    // Only notify of a SeriesChangeEvent at the end of the loop
    for (Iterator<Map<SimOuts, Double>> logsOutItr = logsOut.iterator(); logsOutItr.hasNext(); ) {
        Map<SimOuts, Double> simOut = logsOutItr.next();
        for (Map.Entry<SimOuts, XYSeries> entry : xySeriesData.entrySet()) {
            SimOuts yVal = entry.getKey();
            SimOuts xVal = bundle.getSubPlots().get(0).getxData();
            entry.getValue().add(simOut.get(xVal), simOut.get(yVal), !logsOutItr.hasNext());
        }
    }
    // Bound the minimum X Axis value to the first time value in the data series
    for (Map.Entry<SimOuts, XYSeries> entry : xySeriesData.entrySet()) {
        XYSeries series = entry.getValue();
        domainAxis.setRange(series.getMinX(), series.getMaxX());
    }
    // Update with new time axis
    combinedDomPlot.setDomainAxis(domainAxis);
    for (int i = 0; i < combinedDomPlot.getRangeAxisCount(); i++) {
        if (combinedDomPlot.getRangeAxis(i) != null) {
            combinedDomPlot.getRangeAxis(i).setAutoRange(false);
            combinedDomPlot.getRangeAxis(i).resizeRange(3);
        }
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with SimOuts

use of com.chrisali.javaflightsim.simulation.integration.SimOuts in project j6dof-flight-sim by chris-ali.

the class FileUtilities method saveToCSVFile.

/**
 * Writes a CSV file from data contained within the logsOut ArrayList
 *
 * @param file
 * @param logsOut
 * @throws IOException
 */
public static void saveToCSVFile(File file, List<Map<SimOuts, Double>> logsOut) throws IOException {
    logger.debug("Saving configuration file to: " + file.getAbsolutePath());
    BufferedWriter bw = new BufferedWriter(new FileWriter(file.getPath()));
    // First line of CSV file should have the names of each parameter
    StringBuilder sb_line1 = new StringBuilder();
    for (SimOuts simOut : SimOuts.values()) {
        sb_line1.append(simOut.toString()).append(",");
    }
    bw.write(sb_line1.append("\n").toString());
    // Subsequent lines contain data
    for (Map<SimOuts, Double> simOut : logsOut) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<?, Double> entry : simOut.entrySet()) {
            sb.append(entry.getValue().toString()).append(",");
        }
        bw.write(sb.append("\n").toString());
    }
    bw.close();
    logger.debug(file.getName() + " saved successfully!");
}
Also used : FileWriter(java.io.FileWriter) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) Map(java.util.Map) BufferedWriter(java.io.BufferedWriter)

Aggregations

SimOuts (com.chrisali.javaflightsim.simulation.integration.SimOuts)4 Map (java.util.Map)4 SubPlotOptions (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)2 LinkedHashMap (java.util.LinkedHashMap)2 XYSeries (org.jfree.data.xy.XYSeries)2 PlotConfiguration (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration)1 SubPlotBundle (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotBundle)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)1 XYPlot (org.jfree.chart.plot.XYPlot)1 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)1 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)1 Test (org.junit.Test)1