Example #1
0
        /**
         * Load sample from file.
         */
        static public List <Vector> LoadSample(
            string fname,
            out List <float> _timeS,
            bool remove_duplicates = false,
            DeviceType deviceType  = default,
            bool isSession         = false)
        {
            RecordingData rd =
                RecordingData.Load(
                    fname,
                    remove_duplicates,
                    deviceType: deviceType,
                    isSession: isSession);

            _timeS = rd.timestamps;

            return(rd.trajectory);
        }
Example #2
0
        public static RecordedSession Load(
            string fname,
            bool removeDuplicates = false,
            DeviceType deviceType = default,
            bool isSession        = false,
            int external_PID      = -1)
        {
            // Read the sample.
            BinaryReader bstream;

            // Open up the binary stream.
            bstream = new BinaryReader(
                new FileStream(
                    fname,
                    FileMode.Open));

            if (bstream == null)
            {
                Debug.Log("Loading the recorded session failed!");
                return(null);
            }

            // Read session name
            string name = bstream.ReadString();

            // Read speed
            int speed = bstream.ReadInt32();

            // Read leader data
            RecordingData leader = RecordingData.Load(
                bstream,
                removeDuplicates,
                deviceType: deviceType,
                external_PID: external_PID,
                isSession: isSession);

            // Read player data and account for removed indices
            HashSet <int> removedIndices = new HashSet <int>();

            RecordingData player = RecordingData.Load(
                bstream: bstream,
                removeDuplicates,
                removedIndices,
                deviceType: deviceType,
                external_PID: external_PID,
                isSession: isSession);

            // Read gid's
            int frameCount = bstream.ReadInt32();
            List <Tuple <int, string> > commands = new List <Tuple <int, string> >();

            for (int i = 0; i < frameCount; i++)
            {
                if (!removedIndices.Contains(i))
                {
                    commands.Add(
                        new Tuple <int, string>(
                            bstream.ReadInt32(),
                            bstream.ReadString()));
                }
            }

            // Clean up.
            bstream.Close();

            return(new RecordedSession(
                       name,
                       leader,
                       player,
                       commands,
                       speed));
        }