FromFile(string datafile, bool extrainfo, out TimedState estimate, out TimedArray xodometry, out TimedMeasurements xmeasurements) { string tmpdir = Util.TemporaryDir(); string datadir = Path.Combine(tmpdir, "data"); ZipFile.ExtractToDirectory(datafile, datadir); string scenefile = Path.Combine(datadir, "scene.world"); string trajectoryfile = Path.Combine(datadir, "trajectory.out"); string estimatefile = Path.Combine(datadir, "estimate.out"); string odometryfile = Path.Combine(datadir, "odometry.out"); string measurefile = Path.Combine(datadir, "measurements.out"); string vismapfile = Path.Combine(datadir, "vismaps.out"); string tagfile = Path.Combine(datadir, "tags.out"); if (!File.Exists(scenefile)) { throw new ArgumentException("Missing scene file"); } if (extrainfo && !File.Exists(estimatefile)) { throw new ArgumentException("Missing estimate file"); } if (!File.Exists(trajectoryfile)) { throw new ArgumentException("Missing trajectory file"); } if (!File.Exists(odometryfile)) { throw new ArgumentException("Missing odometry file"); } if (!File.Exists(measurefile)) { throw new ArgumentException("Missing measurement file"); } if (!File.Exists(vismapfile)) { vismapfile = ""; } if (!File.Exists(tagfile)) { tagfile = ""; } RecordVehicle <MeasurerT, PoseT, MeasurementT> explorer; TimedState trajectory; TimedArray odometry; TimedMeasurements measurements; TimedMapModel vismap; TimedMessage tags; var template = SimulatedVehicle <MeasurerT, PoseT, MeasurementT> . FromFile(File.ReadAllText(scenefile)); trajectory = FP.TimedArrayFromDescriptor(File.ReadAllLines(trajectoryfile), StateSize); odometry = FP.TimedArrayFromDescriptor(File.ReadAllLines(odometryfile), OdoSize); measurements = FP.MeasurementsFromDescriptor(File.ReadAllText(measurefile), MeasureSize); if (!string.IsNullOrEmpty(vismapfile)) { vismap = FP.MapHistoryFromDescriptor(File.ReadAllText(vismapfile), 3); for (int i = vismap.Count; i < trajectory.Count; i++) { vismap.Add(Tuple.Create(trajectory[i].Item1, new Map(3))); } } else { vismap = new TimedMapModel(); foreach (var entry in trajectory) { vismap.Add(Tuple.Create(entry.Item1, new Map(3))); } } if (!string.IsNullOrEmpty(tagfile)) { tags = FP.TimedMessageFromDescriptor(File.ReadAllLines(tagfile)); } else { tags = new TimedMessage(); } explorer = new RecordVehicle <MeasurerT, PoseT, MeasurementT>(trajectory, odometry, measurements, tags, template.Landmarks, template.Measurer); explorer.WayVisibleMaps = vismap; if (extrainfo) { TimedTrajectory fullestimate = FP.TrajectoryHistoryFromDescriptor(File.ReadAllText(estimatefile), StateSize, false); estimate = fullestimate[fullestimate.Count - 1].Item2; explorer.WayPoints = trajectory; xodometry = odometry; xmeasurements = measurements; } else { estimate = null; xodometry = null; xmeasurements = null; } Directory.Delete(tmpdir, true); return(explorer); }
/// <summary> /// Save all the state history to a file. /// </summary> /// <param name="filename">Output file name.</param> /// <param name="includesidebar">If false, skip the sidebar video.</param> public void SaveToFile(string filename, bool includesidebar = true, bool verbose = true) { string tmp = Util.TemporaryDir(); string output = Path.Combine(tmp, "out"); Directory.CreateDirectory(output); if (verbose) { Console.WriteLine("writing output"); } // with artificial data, the scene file has useful information // with real sensors only write pose and focal characteristics if (verbose) { Console.WriteLine(" -- writing scene file"); } string scenedata = InitVehicle.ToString(); File.WriteAllText(Path.Combine(output, "scene.world"), scenedata); if (verbose) { Console.WriteLine(" -- writing trajectory history"); } File.WriteAllText(Path.Combine(output, "trajectory.out"), SerializedTrajectory); if (verbose) { Console.WriteLine(" -- writing odometry history"); } File.WriteAllText(Path.Combine(output, "odometry.out"), SerializedOdometry); if (verbose) { Console.WriteLine(" -- writing estimate history"); } File.WriteAllText(Path.Combine(output, "estimate.out"), SerializedEstimate); if (verbose) { Console.WriteLine(" -- writing map model history"); } File.WriteAllText(Path.Combine(output, "maps.out"), SerializedMaps); if (verbose) { Console.WriteLine(" -- writing visible map history"); } File.WriteAllText(Path.Combine(output, "vismaps.out"), SerializedVisibleMaps); if (verbose) { Console.WriteLine(" -- writing measurements history"); } File.WriteAllText(Path.Combine(output, "measurements.out"), SerializedMeasurements); if (verbose) { Console.WriteLine(" -- writing tags"); } File.WriteAllText(Path.Combine(output, "tags.out"), SerializedTags); if (verbose) { Console.WriteLine(" -- writing config"); } File.WriteAllText(Path.Combine(output, "config.cfg"), Config.ToString()); if (Explorer.HasSidebar && includesidebar) { if (verbose) { Console.WriteLine(" -- writing sidebar video"); } Util.SaveAsAvi(SidebarHistory, SideBuffer.Width, SideBuffer.Height, Path.Combine(output, "sidebar.avi")); } if (verbose) { Console.WriteLine(" -- compressing"); } if (File.Exists(filename)) { File.Delete(filename); } string dirpath = Path.GetDirectoryName(filename); if (dirpath != "") { Directory.CreateDirectory(dirpath); } ZipFile.CreateFromDirectory(output, filename); if (verbose) { Console.WriteLine(" -- cleaning up"); } Directory.Delete(tmp, true); }
/// <summary> /// Create a visualization object from a pair of formatted description files. /// </summary> /// <param name="datafile">Compressed prerecorded data file.</param> /// <param name="filterhistory">If true, show the filtered trajectory history, otherwise, the smooth one, /// i.e. the smooth history may change retroactively from future knowledge. Note however that the /// recorded vehicle may not support smoothing and may perform the same in both modes. /// Note also that this is not the algorithm mode, only the visualization; the algorithm /// could still take past information into account, but it won't be visualized.</param> /// <param name="screenshotmode">If true, skip to the screenshot tags, /// set the camera, take the shots and close the file.</param> /// <param name="tmpdir">Temporary data directory, to be removed after use.</param> /// <returns>Prepared visualization object.</returns> /// <remarks>All file must be previously sorted by time value. This property is assumed.</remarks> public static Viewer <MeasurerT, PoseT, MeasurementT> FromFiles(string datafile, bool filterhistory, double reftime, bool screenshotmode, out string tmpdir) { tmpdir = Util.TemporaryDir(); string datadir = Path.Combine(tmpdir, "data"); ZipFile.ExtractToDirectory(datafile, datadir); string scenefile = Path.Combine(datadir, "scene.world"); string vehiclefile = Path.Combine(datadir, "trajectory.out"); string estimatefile = Path.Combine(datadir, "estimate.out"); string mapfile = Path.Combine(datadir, "maps.out"); string measurefile = Path.Combine(datadir, "measurements.out"); string tagfile = Path.Combine(datadir, "tags.out"); string sidebarfile = Path.Combine(datadir, "sidebar.avi"); if (!File.Exists(scenefile)) { scenefile = ""; } if (!File.Exists(measurefile)) { measurefile = ""; } if (!File.Exists(tagfile)) { tagfile = ""; } if (!File.Exists(sidebarfile)) { sidebarfile = ""; } SimulatedVehicle <MeasurerT, PoseT, MeasurementT> explorer; TimedState trajectory; TimedTrajectory estimate; TimedMapModel map; TimedMeasurements measurements; TimedMessage tags; PoseT dummyP = new PoseT(); MeasurementT dummyM = new MeasurementT(); trajectory = FP.TimedArrayFromDescriptor(File.ReadAllLines(vehiclefile), dummyP.StateSize); estimate = FP.TrajectoryHistoryFromDescriptor(File.ReadAllText(estimatefile), dummyP.StateSize, filterhistory); map = FP.MapHistoryFromDescriptor(File.ReadAllText(mapfile), 3); if (!string.IsNullOrEmpty(measurefile)) { measurements = FP.MeasurementsFromDescriptor(File.ReadAllText(measurefile), dummyM.Size); } else { measurements = new TimedMeasurements(); } if (!string.IsNullOrEmpty(tagfile)) { tags = FP.TimedMessageFromDescriptor(File.ReadAllLines(tagfile)); } else { tags = new TimedMessage(); } if (!string.IsNullOrEmpty(scenefile)) { explorer = SimulatedVehicle <MeasurerT, PoseT, MeasurementT> . FromFile(File.ReadAllText(scenefile)); } else { explorer = new SimulatedVehicle <MeasurerT, PoseT, MeasurementT>(new PoseT().IdentityP(), new List <double[]>()); } bool online = (estimate[0].Item2.Count < estimate[estimate.Count - 1].Item2.Count && estimate.Count == trajectory.Count); return(new Viewer <MeasurerT, PoseT, MeasurementT>("monorfs - viewing " + datafile, explorer, trajectory, estimate, map, measurements, tags, reftime, online, 30, sidebarfile, screenshotmode)); }