Ejemplo n.º 1
0
 private void SetupFilePipeline(String fileName)
 {
     pipeline = new Pipeline();
     using (var cfg = FromFile(new Config(), fileName))
         using (var pp = pipeline.Start(cfg))
             using (var dev = pp.Device)
                 using (playback = PlaybackDevice.FromDevice(dev))
                 {
                     Console.WriteLine("Reading from : " + playback.FileName);
                     playback.Realtime = false;
                 }
 }
Ejemplo n.º 2
0
        static void runFromFile(String fileName)
        {
            using (var pipe = new Pipeline())
                using (var cfg = FromFile(new Config(), fileName))
                    using (var pp = pipe.Start(cfg))
                        using (var dev = pp.Device)
                            using (var playback = PlaybackDevice.FromDevice(dev))
                            {
                                Console.WriteLine("Reading from : " + playback.FileName);
                                playback.Realtime = false;

                                while (playback.Status != PlaybackStatus.Stopped)
                                {
                                    runCycle(pipe);
                                }
                            }
        }
Ejemplo n.º 3
0
        public static Pipeline FromFile(string filename)
        {
            if (!File.Exists(filename))
            {
                Console.WriteLine("Error: file {0} does not exists.", filename); return(null);
            }

            Pipeline        pipeline = new Pipeline();
            Config          config   = ConfigFile(new Config(), filename);
            PipelineProfile profile  = pipeline.Start(config);

            Device         device   = profile.Device;
            PlaybackDevice playback = PlaybackDevice.FromDevice(device);

            DateTime begins = DateTime.Now;

            Console.WriteLine("Reading file {0}\nDuration time: {1}\nCamera name: {2}\nSerial number: {3}\nFirmware version: {4}\n", filename, TimeSpan.FromMilliseconds(playback.Duration * 1e-6), device.Info[CameraInfo.Name], device.Info[CameraInfo.SerialNumber], device.Info[CameraInfo.FirmwareVersion]);
            playback.Realtime = false;

            return(pipeline);
        }
    // string[] names = { };
    // string[] serials;
    // int selectedSerial = 0;


    // private void PopuplateDevices()
    // {
    //     using (var ctx = new Context())
    //     using (var device_list = ctx.QueryDevices())
    //     {
    //         serials = device_list.Select(d => d.Info[CameraInfo.SerialNumber]).ToArray();
    //         var _names = device_list.Select(d => d.Info[CameraInfo.Name]);
    //         var m = _names.Max(d => d.Length);
    //         names = _names.Select((n, i) => string.Format("{0}    SN: {1}", n.PadRight(m), serials[i])).ToArray();
    //     }
    // }

    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        // EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script"), true);

        var device = target as RsDevice;
        // bool isStreaming = device.ActiveProfile != null;
        bool isStreaming = device.isActiveAndEnabled && device.ActiveProfile != null;

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.Space();
        EditorGUI.BeginDisabledGroup(isStreaming);
        mode.enumValueIndex = GUILayout.Toolbar(mode.enumValueIndex, mode.enumDisplayNames);

        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("processMode"));
        EditorGUILayout.Space();
        EditorGUI.EndDisabledGroup();


        // EditorGUILayout.PropertyField(serializedObject.FindProperty("DeviceConfiguration"), true);

        switch ((RsConfiguration.Mode)mode.enumValueIndex)
        {
        case RsConfiguration.Mode.Live:
            // EditorGUILayout.BeginHorizontal();
            // var sn = config.FindPropertyRelative("RequestedSerialNumber");
            // selectedSerial = EditorGUILayout.Popup(selectedSerial, names);
            // if (serials != null && serials.Length != 0)
            //     sn.stringValue = serials[selectedSerial];

            // if (GUILayout.Button("Update", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
            // {
            //     PopuplateDevices();
            // }
            // EditorGUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(isStreaming);
            EditorGUILayout.PropertyField(config.FindPropertyRelative("RequestedSerialNumber"));

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(config.FindPropertyRelative("Profiles"), true);
            // EditorGUILayout.Space();
            // EditorGUILayout.PropertyField(serializedObject.FindProperty("_processingPipe"), false);
            EditorGUILayout.Space();
            EditorGUI.EndDisabledGroup();
            break;

        case RsConfiguration.Mode.Playback:
        {
            EditorGUI.BeginDisabledGroup(isStreaming);
            EditorGUILayout.BeginHorizontal();
            var prop = config.FindPropertyRelative("PlaybackFile");
            EditorGUILayout.PropertyField(prop);
            if (GUILayout.Button("Open", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
            {
                var path = EditorUtility.OpenFilePanel("Recorded sequence", "", "bag");
                if (path.Length != 0)
                {
                    prop.stringValue = path;
                }
            }
            EditorGUILayout.EndHorizontal();
            // EditorGUILayout.Space();
            // EditorGUILayout.PropertyField(serializedObject.FindProperty("_processingPipe"), false);
            EditorGUILayout.Space();
            EditorGUI.EndDisabledGroup();

            if (isStreaming)
            {
                using (var playback = PlaybackDevice.FromDevice(device.ActiveProfile.Device))
                {
                    bool isPlaying = playback.Status == PlaybackStatus.Playing;

                    //TODO: cache icons (in OnEnable)
                    var playBtnStyle = EditorGUIUtility.IconContent("PlayButton", "|Play");
                    // var playBtnStyle = EditorGUIUtility.IconContent("Animation.Play");

                    var pauseBtnStyle = EditorGUIUtility.IconContent("PauseButton", "|Pause");

                    // var stepBtnStyle = EditorGUIUtility.IconContent("StepButton", "|Step");

                    // var rewindBtnStyle = EditorGUIUtility.IconContent("Animation.PrevKey");
                    var rewindBtnStyle = EditorGUIUtility.IconContent("animation.firstkey.png");

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button(rewindBtnStyle, "CommandLeft"))
                    {
                        playback.Position = 0;
                    }

                    if (GUILayout.Button(isPlaying ? pauseBtnStyle : playBtnStyle, "CommandRight"))
                    {
                        if (isPlaying)
                        {
                            playback.Pause();
                        }
                        else
                        {
                            playback.Resume();
                        }
                    }

                    // bool play = GUILayout.Toggle(isPlaying, playBtnStyle, "CommandMid");
                    // if (play && !isPlaying)
                    //     playback.Resume();

                    // bool pause = GUILayout.Toggle(!isPlaying, pauseBtnStyle, "CommandRight");
                    // if (pause && isPlaying)
                    //     playback.Pause();

                    // if (GUILayout.Button(stepBtnStyle, "CommandRight"))
                    // {
                    // }

                    //TODO: no getter...
                    // playback.Speed = EditorGUILayout.FloatField(playback.Speed);

                    GUILayout.EndHorizontal();

                    if (!isPlaying)
                    {
                        // var t = TimeSpan.FromMilliseconds(playback.Position * 1e-6);
                        // playback.Position = (ulong)EditorGUILayout.Slider(t.ToString(), playback.Position, 0, playback.Duration);
                        playback.Position = (ulong)EditorGUILayout.Slider(playback.Position, 0, playback.Duration);
                    }


                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.Space();
                    EditorGUILayout.PropertyField(config.FindPropertyRelative("Profiles"), true);
                    EditorGUI.EndDisabledGroup();
                }
            }
        }
        break;

        case RsConfiguration.Mode.Record:
        {
            EditorGUILayout.BeginHorizontal();
            var prop = config.FindPropertyRelative("RecordPath");
            EditorGUILayout.PropertyField(prop);
            if (GUILayout.Button("Choose", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
            {
                var path = EditorUtility.SaveFilePanel("Recorded sequence", "", System.DateTime.Now.ToString("yyyyMMdd_hhmmss"), "bag");
                if (path.Length != 0)
                {
                    prop.stringValue = path;
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(config.FindPropertyRelative("Profiles"), true);
            // EditorGUILayout.Space();
            // EditorGUILayout.PropertyField(serializedObject.FindProperty("_processingPipe"), false);
            EditorGUILayout.Space();
            EditorGUI.EndDisabledGroup();
        }
        break;
        }


        serializedObject.ApplyModifiedProperties();

        EditorGUI.EndChangeCheck();
    }