Exemple #1
0
        public Dictionary <TimeSpan, Vector3[]> read()
        {
            if (m_Reader == null)
            {
                throw new NullReferenceException("m_Reader is Null");
            }

            Dictionary <TimeSpan, Vector3[]> list = new Dictionary <TimeSpan, Vector3[]>();
            int   i           = 0;
            float lastProcent = -1;

            try
            {
                //for (int i = 0; i < Math.Abs(reader.GetParameter<Int16>("POINT:FRAMES")); i++)

                while (true)
                {
                    // returns an array of all points, it is necessary to call this method in each cycle

                    Vector3[] array = m_Reader.ReadFrame();

                    if (array == null)
                    {
                        break;
                    }
                    TimeSpan t = TimeSpan.FromMilliseconds(i * 10);

                    list.Add(t, array);

                    //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);
                    if (m_Reader.GetProcent() > lastProcent)
                    {
                        lastProcent = m_Reader.GetProcent();
                        nextMesssage(this, "" + lastProcent.ToString() + "%");
                    }
                    i++;
                }

                // Don't forget to close the reader
                // - it updates the frames count information in the c3d file header and parameters section
                return(list);
            }
            catch
            {
                return(null);
            }
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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();
        }