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);
}
}
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);
}
}
}
}
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);
}
}
}
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!");
}
Aggregations