Esempio n. 1
0
        void ServerController_Connected(VIServerController serverController, EventArgs e)
        {
            // run on UI thread
            Application.Current.Dispatcher.Invoke(() =>
            {
                // Disable the Connect Button since, at this time, we can't disconnect/reconnect
                ConnectPB.IsEnabled = false;

                // get the list of cameras on this server
                ObservableCollection <Videoinsight.LIB.Camera> cameraList;
                m_serverController.GetCameraList(out cameraList);

                // Set the camera list to the View Model for this app
                vm.CameraList = cameraList;

                // open dialog that allows you to select the cameras that you want to stream
                CameraSelection dlg = new CameraSelection(cameraList);
                dlg.ShowDialog();

                // After the dialog is closed, build ViewModel's ActiveDictionary, which is the dictionary that contains the list of the cameras that were marked to be streamed
                // in the dialog above (the cameras that were checked)
                vm.ResetActiveDictionary(); // clear the ActiveDictionary
                foreach (CheckedListItem <Videoinsight.LIB.Camera> cam in dlg.vm.CameraList)
                {
                    if (cam.IsChecked)
                    {
                        vm.ActiveDictionary.Add(cam.Item.CameraID, new CameraParams(cam.Item, 0, 0, 0, 0, -1, IntPtr.Zero));
                    }
                }

                // Figure out the size of the array of display panels needed to show all the cameras in the Active Dictionary
                int cols = 0;
                int rows = 0;
                GetMatrixDimensions(vm.ActiveDictionary.Count, ref rows, ref cols); // this is a really dumb function that sets the number of rows and cols depending on the number of cameras to be displayed

                if (m_surfArray != null)
                {
                    m_surfArray.Shutdown();
                    m_surfArray = null;
                }

                // build the SurfArray = this is the 2D "array" of D3D9 panels that are used to display the decoded images
                m_surfArray = new SurfArray(rows, cols, DisplayContainer);

                // configure the behavior and look of the Surface Array
                Color panelSelectedColor       = Colors.Red;
                Color panelUnselectedColor     = Colors.Gray;
                Color panelTitleTextColor      = Colors.White;
                Color surfArrayBackgroundColor = Colors.Gray;
                double titleFontSize           = 12.0;
                double panelMargin             = 10.0;
                m_surfArray.SetDisplayParams(panelSelectedColor, panelUnselectedColor, panelTitleTextColor, titleFontSize, surfArrayBackgroundColor, panelMargin);
                m_surfArray.SetPanelsSelectable(true);  // if true, the callback function is called when a panel is clicked

                // set the callback function that is called whenever a particular panel is clicked
                m_surfArray.SetCallback(CallbackFunction);


                // assign each camera to a position in the SurfArray
                int index = 0;
                foreach (KeyValuePair <int, CameraParams> entry in vm.ActiveDictionary)
                {
                    int id = entry.Key;
                    //CameraParams cp = entry.Value;

                    if (index >= vm.ActiveDictionary.Count)
                    {
                        break;
                    }
                    int r = index / cols;
                    int c = index - (r * cols);

                    Videoinsight.LIB.Camera cam = vm.GetCamera(id);
                    if (cam != null)
                    {
                        m_surfArray.AssignCameraToPosition(r, c, (uint)cam.CameraID, m_defaultWidth, m_defaultHeight, cam.CameraName, false);
                    }


                    entry.Value.DisplayRow   = r;
                    entry.Value.DisplayCol   = c;
                    entry.Value.SurfaceIndex = m_surfArray.GetSurfaceIndex(r, c);

                    uint w        = m_defaultWidth;
                    uint h        = m_defaultHeight;
                    bool useAlpha = false;
                    IntPtr pSurf  = IntPtr.Zero;
                    m_surfArray.GetSurface_Params(entry.Value.SurfaceIndex, out pSurf, out w, out h, out useAlpha);

                    entry.Value.Width    = (int)w;
                    entry.Value.Height   = (int)h;
                    entry.Value.pSurface = pSurf;

                    entry.Value.d3dImage = m_surfArray.GetD3DImage(entry.Value.DisplayRow, entry.Value.DisplayCol);

                    bool success = CudaTools.DX_GpuAddD3DSurface(m_cudaUtil, id, entry.Value.pSurface, entry.Value.Width, entry.Value.Height);

                    //if (vm.ActiveDictionary.ContainsKey(id))
                    //    vm.ActiveDictionary[id] = cp;
                    //else
                    //    Debug.Print("Shit");

                    index++;
                }


                // See how much memory is left on GPU
                ulong totMem  = 0;
                ulong freeMem = 0;
                CudaTools.Cuda_GetDeviceMemory64(m_cudaUtil, out totMem, out freeMem);
                //MessageBox.Show("Total = " + totMem.ToString() + "   Free = " + freeMem.ToString());



                // command server to start streaming
                List <int> cameraIDList = new List <int>();
                foreach (int id in vm.ActiveDictionary.Keys)
                {
                    cameraIDList.Add(id);
                }
                m_serverController.GetLive(cameraIDList);
            });
        }
Esempio n. 2
0
        void ServerController_Connected(VIServerController serverController, EventArgs e)
        {
            // run on UI thread
            Application.Current.Dispatcher.Invoke(() =>
            {
                // Disable the Connect Button since, at this time, we can't disconnect/reconnect
                ConnectPB.IsEnabled       = false;
                vm.ControlPanelVisibility = Visibility.Visible;

                // get the list of cameras on this server
                ObservableCollection <Videoinsight.LIB.Camera> cameraList;
                m_serverController.GetCameraList(out cameraList);

                // Set the camera list to the View Model for this app
                vm.CameraList = cameraList;

                // open dialog that allows you to select the cameras that you want to stream
                CameraSelection dlg = new CameraSelection(cameraList);
                dlg.ShowDialog();
                int selectedCameraID = dlg.vm.SelectedCamera.ID;

                // After the dialog is closed, build ViewModel's ActiveDictionary, which is the dictionary that contains the list of the cameras that were marked to be streamed
                // in the dialog above (the cameras that were checked)

                foreach (Videoinsight.LIB.Camera cam in cameraList)
                {
                    if (cam.CameraID == selectedCameraID)
                    {
                        vm.TestCamera = new CameraParams(cam, 0, 0, 0, 0, -1, IntPtr.Zero, null, -1);
                        vm.RefCamera  = new CameraParams(cam, 0, 0, 0, 0, -1, IntPtr.Zero, null, -1);
                        break;
                    }
                }


                if (m_surfArray != null)
                {
                    m_surfArray.Shutdown();
                    m_surfArray = null;
                }

                // build the SurfArray = this is the 2D "array" of D3D9 panels that are used to display the decoded images
                m_surfArray = new SurfArray(1, 2, DisplayContainer);

                // configure the behavior and look of the Surface Array
                Color panelSelectedColor       = Colors.Red;
                Color panelUnselectedColor     = Colors.Gray;
                Color panelTitleTextColor      = Colors.White;
                Color surfArrayBackgroundColor = Colors.Gray;
                double titleFontSize           = 12.0;
                double panelMargin             = 10.0;
                m_surfArray.SetDisplayParams(panelSelectedColor, panelUnselectedColor, panelTitleTextColor, titleFontSize, surfArrayBackgroundColor, panelMargin);
                m_surfArray.SetPanelsSelectable(false);  // if true, the callback function is called when a panel is clicked

                // set the callback function that is called whenever a particular panel is clicked
                m_surfArray.SetCallback(CallbackFunction);


                // assign each camera to a position in the SurfArray
                uint w        = m_defaultWidth;
                uint h        = m_defaultHeight;
                bool useAlpha = false;
                IntPtr pSurf  = IntPtr.Zero;
                bool success  = false;

                // Reference Image
                m_surfArray.AssignCameraToPosition(0, 0, (uint)selectedCameraID + 1, m_defaultWidth, m_defaultHeight, "Reference Image", false);
                vm.RefCamera.SurfaceIndex = m_surfArray.GetSurfaceIndex(0, 0);
                pSurf = IntPtr.Zero;
                m_surfArray.GetSurface_Params(vm.RefCamera.SurfaceIndex, out pSurf, out w, out h, out useAlpha);
                vm.RefCamera.DisplayRow = 0;
                vm.RefCamera.DisplayCol = 0;
                vm.RefCamera.Width      = (int)w;
                vm.RefCamera.Height     = (int)h;
                vm.RefCamera.pSurface   = pSurf;
                vm.RefCamera.d3dImage   = m_surfArray.GetD3DImage(vm.RefCamera.DisplayRow, vm.RefCamera.DisplayCol);
                vm.RefCamera.ID         = selectedCameraID + 1;
                success = CudaTools.DX_GpuAddD3DSurface(m_cudaUtil, vm.RefCamera.SurfaceIndex, vm.RefCamera.pSurface, vm.RefCamera.Width, vm.RefCamera.Height);

                // Test Image
                m_surfArray.AssignCameraToPosition(0, 1, (uint)selectedCameraID, m_defaultWidth, m_defaultHeight, "Test Image", false);
                vm.TestCamera.SurfaceIndex = m_surfArray.GetSurfaceIndex(0, 1);
                pSurf = IntPtr.Zero;
                m_surfArray.GetSurface_Params(vm.TestCamera.SurfaceIndex, out pSurf, out w, out h, out useAlpha);
                vm.TestCamera.DisplayRow = 0;
                vm.TestCamera.DisplayCol = 1;
                vm.TestCamera.Width      = (int)w;
                vm.TestCamera.Height     = (int)h;
                vm.TestCamera.pSurface   = pSurf;
                vm.TestCamera.d3dImage   = m_surfArray.GetD3DImage(vm.TestCamera.DisplayRow, vm.TestCamera.DisplayCol);
                vm.TestCamera.ID         = selectedCameraID;
                success = CudaTools.DX_GpuAddD3DSurface(m_cudaUtil, vm.TestCamera.SurfaceIndex, vm.TestCamera.pSurface, vm.TestCamera.Width, vm.TestCamera.Height);


                m_refCanvas  = m_surfArray.GetCanvas((uint)vm.RefCamera.ID);
                m_testCanvas = m_surfArray.GetCanvas((uint)vm.TestCamera.ID);
                InitRoiSelectionControls();


                // See how much memory is left on GPU
                ulong totMem  = 0;
                ulong freeMem = 0;
                CudaTools.Cuda_GetDeviceMemory64(m_cudaUtil, out totMem, out freeMem);
                //MessageBox.Show("Total = " + totMem.ToString() + "   Free = " + freeMem.ToString());



                // command server to start streaming
                List <int> cameraIDList = new List <int>();
                cameraIDList.Add(vm.TestCamera.ID);
                m_serverController.GetLive(cameraIDList);
            });
        }