private void GenerateEmgTimeline(TextWriter writer) { C3dReader reader = new C3dReader(); reader.Open(_c3dFile); int samples = (reader.FramesCount * reader.Header.AnalogSamplingRate); double step = (PAGE_WIDTH) / samples; reader.Close(); for (int i = 0; i < samples; i += 5000) { int seconds = i / 1000; writer.WriteLine("<path style=\"fill:none;stroke:#eeeeee;stroke-width:0.20px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\" " + "d=\"m " + (20 + (step * i)).ToString("F5", CultureInfo.InvariantCulture) + ",150 v 30\" />"); writer.WriteLine("<text style=\"font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1.5px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:Ubuntu;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#cccccc;fill-opacity:1;stroke:none;stroke-width:0.26458332\"" + " x=\"" + (20 + (step * i)).ToString("F5", CultureInfo.InvariantCulture) + "\" y=\"181.7\">" + (seconds.ToString() + " s") + "</text>"); writer.WriteLine("<path style=\"fill:none;stroke:#eeeeee;stroke-width:0.20px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\" " + "d=\"m " + (20 + (step * i)).ToString("F5", CultureInfo.InvariantCulture) + ",192.64585 v 30\" />"); writer.WriteLine("<text style=\"font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1.5px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:Ubuntu;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#cccccc;fill-opacity:1;stroke:none;stroke-width:0.26458332\"" + " x=\"" + (20 + (step * i)).ToString("F5", CultureInfo.InvariantCulture) + "\" y=\"224.3\">" + (seconds.ToString() + " s") + "</text>"); writer.WriteLine("<path style=\"fill:none;stroke:#eeeeee;stroke-width:0.20px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\" " + "d=\"m " + (20 + (step * i)).ToString("F5", CultureInfo.InvariantCulture) + ",248.5 v 2\" />"); writer.WriteLine("<text style=\"font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1.5px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:Ubuntu;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#cccccc;fill-opacity:1;stroke:none;stroke-width:0.26458332\"" + " x=\"" + (20 + (step * i)).ToString("F5", CultureInfo.InvariantCulture) + "\" y=\"251.7\">" + (seconds.ToString() + " s") + "</text>"); } }
public void open(out Boolean pIsComplete, out String pError) { ArrayListSerializable list = new ArrayListSerializable(); try { m_Reader = new C3dReader(); if (!m_Reader.Open(m_FileName)) { pError = "Error: Unable to open file " + m_FileName; pIsComplete = false; } else { pError = "Okay"; pIsComplete = true; } } catch (Exception e) { pError = e.Message; pIsComplete = false; } }
private void GenerateEMGStats() { double lengthActivationsEmg1 = 0; double lengthActivationsEmg2 = 0; C3dReader reader = new C3dReader(); reader.Open(_c3dFile); int activation1Started = -1; int activation2Started = -1; int count = 0; for (int i = 0; i < reader.FramesCount; i++) { reader.ReadFrame(); var data = reader.AnalogData.Data; for (int j = 0; j < data.GetLength(1); j++) { if (data[2, j] != 0) { if (activation1Started == -1) { activation1Started = count; } } else { if (activation1Started != -1) { lengthActivationsEmg1 += count - activation1Started; activation1Started = -1; numActivationsEmg1++; } } if (data[3, j] != 0) { if (activation2Started == -1) { activation2Started = count; } } else { if (activation2Started != -1) { lengthActivationsEmg2 += count - activation2Started; activation2Started = -1; numActivationsEmg2++; } } count++; } } averageActivationsEmg1 = lengthActivationsEmg1 / numActivationsEmg1; averageActivationsEmg2 = lengthActivationsEmg2 / numActivationsEmg2; }
private void FillLevel(TextWriter writer) { C3dReader reader = new C3dReader(); reader.Open(_c3dFile); writer.Write("Level: " + reader.GetParameter <Int16>("INFO:GAME_LEVEL").ToString()); reader.Close(); }
private void FillDate(TextWriter writer) { C3dReader reader = new C3dReader(); reader.Open(_c3dFile); string[] dateTime = reader.GetParameter <string[]>("INFO:TIME"); writer.Write("Date: " + int.Parse(dateTime[2]).ToString() + "/" + int.Parse(dateTime[1]).ToString() + "/" + int.Parse(dateTime[0]).ToString() + " " + int.Parse(dateTime[3]).ToString() + ":" + dateTime[4]); reader.Close(); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Wrong number of arguments"); return; } try { C3dReader reader = new C3dReader(); if (!reader.Open(args[0])) { Console.Error.WriteLine("Error: Unable to open file " + args[0]); return; } for (int i = 0; i < /*reader.GetParameter<Int16>("POINT:FRAMES")*/ 100000; i++) { // returns an array of all points, it is necessary to call this method in each cycle Vector4[] array = reader.ReadFrame(); //Vector3 e = reader["Spine"]; // we can ask for specific point - you can check labels in reader.Labels Vector4 spine = array[1]; // get analog data for this frame //float value = reader.AnalogData["Fx1", 0 /* from 0 to reader.AnalogChannels*/]; // OR // value = reader.AnalogData[0, 0]; // OR //float [,] analogData = reader.AnalogData.Data; //Console.WriteLine("Frame " + i + ": Spine.X " + spine.X + ", Spine.Y " + spine.Y + ": Spine.Z " + spine.Z); } // Don't forget to close the reader // - it updates the frames count information in the c3d file header and parameters section reader.Close(); } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Wrong number of arguments"); return; } try { C3dReader reader = new C3dReader(); if (!reader.Open(args[0])) { Console.Error.WriteLine("Error: Unable to open file " + args[0]); return; } for (int i = 0; i < /*reader.GetParameter<Int16>("POINT:FRAMES")*/ 100000; i++) { // returns an array of all points, it is necessary to call this method in each cycle Vector3[] array = reader.ReadFrame(); //Vector3 e = reader["Spine"]; // we can ask for specific point - you can check labels in reader.Labels Vector3 spine = array[1]; // get analog data for this frame //float value = reader.AnalogData["Fx1", 0 /* from 0 to reader.AnalogChannels*/]; // OR // value = reader.AnalogData[0, 0]; // OR //float [,] analogData = reader.AnalogData.Data; //Console.WriteLine("Frame " + i + ": Spine.X " + spine.X + ", Spine.Y " + spine.Y + ": Spine.Z " + spine.Z); } // Don't forget to close the reader // - it updates the frames count information in the c3d file header and parameters section reader.Close(); } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } }
private void GenerateEMGGraph(TextWriter writer, int datastream) { double max = 0; double min = 0; C3dReader reader = new C3dReader(); reader.Open(_c3dFile); for (int i = 0; i < reader.FramesCount; i++) { reader.ReadFrame(); var data = reader.AnalogData.Data; for (int j = 0; j < data.GetLength(1); j++) { max = Math.Max(data[datastream, j], max); min = Math.Min(data[datastream, j], min); } } reader.Close(); double scale = EMG_HALF_HEIGHT / Math.Max(Math.Abs(max), Math.Abs(min)); reader = new C3dReader(); reader.Open(_c3dFile); double previous = 0; double step = (PAGE_WIDTH) / (reader.FramesCount * reader.Header.AnalogSamplingRate); var culture = CultureInfo.InvariantCulture; for (int i = 0; i < reader.FramesCount; i++) { Vector4[] frame = reader.ReadFrame(); var data = reader.AnalogData.Data; double sum = 0; for (int j = 0; j < data.GetLength(1); j++) { double y = (-data[datastream, j] * scale); writer.Write("l " + step.ToString("F7", culture) + " " + (y - previous).ToString("F7", culture)); previous = y; } } reader.Close(); }
private void GenerateLevelLayout(TextWriter writer) { double maxx = 0; double halt = 0; double running = 0; var culture = CultureInfo.InvariantCulture; C3dReader reader = new C3dReader(); reader.Open(_c3dFile); float previous = 0; Int16[] pos = new Int16[reader.FramesCount]; for (int i = 0; i < reader.FramesCount; i++) { Vector4[] frame = reader.ReadFrame(); if (frame[0].Z == 0) { halt++; } else { running++; } previous = frame[0].X; if (frame[0].X > maxx) { maxx = frame[0].X; } } int levelNum = -1; try { if ((levelNum = reader.GetParameter <Int16>("INFO:GAME_LEVEL")) < 1) { return; } } catch (ApplicationException e) { return; } finally { reader.Close(); } List <string> map = new List <string>(); var assembly = Assembly.GetCallingAssembly(); string templateName = assembly.GetManifestResourceNames() .Single(str => str.EndsWith("map" + levelNum + ".txt")); using (StreamReader mapReader = new StreamReader(assembly.GetManifestResourceStream(templateName))) { for (int i = 0; i < LEVEL_LINES && !mapReader.EndOfStream; i++) { map.Add(mapReader.ReadLine()); } } double tileSpace = PAGE_WIDTH * (running / (halt + running)); double tile = tileSpace / (maxx / TILE_PIXEL_WIDTH); StringBuilder playerPath = new StringBuilder(); reader = new C3dReader(); reader.Open(_c3dFile); double step = PAGE_WIDTH / reader.FramesCount; int lastTile = -1; double currentPosition = 0; double lastTilePosition = 0; int lastx = 0; for (int i = 0; i < reader.FramesCount; i++) { Vector4[] frame = reader.ReadFrame(); int x = (int)(frame[0].X / TILE_PIXEL_WIDTH); if (x > lastTile) { lastTile = x; if (currentPosition > (lastTilePosition + tile)) { double width = currentPosition - (lastTilePosition + tile); writer.WriteLine("<rect x=\"" + (20 + lastTilePosition + tile).ToString("F7", culture) + "\" y=\"" + (235 + (0 * tile)).ToString("F7", culture) + "\" width=\"" + width.ToString("F7", culture) + "\" height=\"" + (18 * tile).ToString("F7", culture) + "\" rx=\"" + (tile / 10).ToString("F7", culture) + "\" style=\"fill: rgb(222, 222, 222)\" />"); } for (int y = 0; y < map.Count; y++) { if (map[y].Length > x && (map[y][x] == 'l' || map[y][x] == 'm' || map[y][x] == 'r' || map[y][x] == '\\')) { writer.WriteLine("<rect x=\"" + (20 + currentPosition).ToString("F7", culture) + "\" y=\"" + (235 + (y * tile)).ToString("F7", culture) + "\" width=\"" + tile.ToString("F7", culture) + "\" height=\"" + tile.ToString("F7", culture) + "\" rx=\"" + (tile / 10).ToString("F7", culture) + "\" style=\"fill: rgb(102,102,102)\" />"); lastTilePosition = currentPosition; if (lastx < x) { lastx = x; } } } currentPosition += tile; } if (frame[0].Z == 0) { currentPosition += step; } } PAGE_WIDTH = currentPosition; reader.Close(); }