Пример #1
0
        public void LoadSuite(string configDirectory, Type suiteType)
        {
            if (configDirectory == null)
            {
                throw new Exception("ConfigDirectory is null");
            }

            string filename = configDirectory + "/" + suiteType.ToString() + CMSConstants.SUITE_CONFIG_SUFFIX;

            if (File.Exists(filename))
            {
                try
                {
                    StreamReader     inFile        = new StreamReader(filename);
                    XmlSerializer    xmSer         = new XmlSerializer(suiteType);
                    CMSTrackingSuite trackingSuite = xmSer.Deserialize(inFile) as CMSTrackingSuite;
                    if (trackingSuite == null)
                    {
                        throw new Exception();
                    }
                    AddSuite(trackingSuite);
                    inFile.Close();
                }
                catch (Exception e)
                {
                }
            }
        }
Пример #2
0
        /******************** Other Functions ****************/

        private void SetState(CMSState state)
        {
            lock (mutex)
            {
                /*
                 * if (state.Equals(CMSState.Tracking))
                 * {
                 *  videoDisplay.SetTrackingControlMessage(false, "");
                 * }
                 * else if (state.Equals(CMSState.ControlTracking))
                 * {
                 *  videoDisplay.SetTrackingControlMessage(true, "");
                 * }
                 * else if (state.Equals(CMSState.Setup))
                 * {
                 *  videoDisplay.ReceiveMessage("", Color.Black);
                 *  //videoDisplay.SetTrackingControlMessage(false, false);
                 * }*/
                controllerState = state;
                CMSTrackingSuite curSuite = model.SelectedSuite;
                if (curSuite != null)
                {
                    curSuite.StateChange(state);
                }

                if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStateChangeEvent"))
                {
                    CMSLogStateChangeEvent stateChangeEvent = new CMSLogStateChangeEvent();
                    stateChangeEvent.State = state.ToString();
                    CMSLogger.SendLogEvent(stateChangeEvent);
                }
            }
        }
Пример #3
0
        public void Close()
        {
            lock (mutex)
            {
                if (controllerState.Equals(CMSState.Quitting))
                {
                    return;
                }

                if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogEndEvent"))
                {
                    CMSLogEndEvent endEvent = new CMSLogEndEvent();
                    endEvent.SetDateTime(DateTime.Now);
                    if (endEvent != null)
                    {
                        CMSLogger.SendLogEvent(endEvent);
                    }
                }

                videoSource.StopSource();
                controllerState = CMSState.Quitting;
                CMSTrackingSuite selectedSuite = model.SelectedSuite;
                if (selectedSuite != null)
                {
                    selectedSuite.Clean();
                }
                videoDisplay.Quit();
                controlToggler.Stop();
                CMSLogger.StopLogging();
            }
        }
Пример #4
0
        public void SetSelectedTrackingSuite(string newTrackingSuiteName)
        {
            lock (mutex)
            {
                if (newTrackingSuiteName == null)
                {
                    return;
                }
                if (newTrackingSuiteName.Equals(model.SelectedSuiteName))
                {
                    return;
                }

                CMSTrackingSuite oldTrackingSuite = this.model.SelectedSuite;
                if (oldTrackingSuite != null)
                {
                    //oldTrackingSuite.ToggleControl(false);
                    oldTrackingSuite.Clean();
                }

                model.SelectedSuiteName = newTrackingSuiteName;
                ToggleSetup(true);
                CMSTrackingSuite newTrackingSuite = this.model.SelectedSuite;
                newTrackingSuite.CMSTrackingSuiteAdapter = new CMSStandardTrackingSuiteAdapter(model, this, this.videoDisplay);
                newTrackingSuite.Init(model.FrameDims);
                newTrackingSuite.SendSuiteLogEvent();
                ReceiveMessagesFromTracker(null, null);
            }
        }
Пример #5
0
        public void LoadCurrentSuite()
        {
            CMSTrackingSuite currentSuite = SelectedSuite;

            if (currentSuite == null)
            {
                return;
            }
            trackingDirectory.LoadSuite(suiteConfigDirectory, currentSuite.GetType());
        }
Пример #6
0
        private void buttonRestore_Click(object sender, EventArgs e)
        {
            CMSTrackingSuite curTrackingSuite     = viewAdapter.GetCurrentTrackingSuite();
            CMSTrackingSuite defaultTrackingSuite = System.Activator.CreateInstance(curTrackingSuite.GetType()) as CMSTrackingSuite;

            viewAdapter.UpdateTrackingSuite(defaultTrackingSuite);
            viewAdapter.ControlTogglerConfig = new CMSControlTogglerConfig();
            viewAdapter.GetCurrentTrackingSuite().SendSuiteLogEvent();
            SendTogglerConfigLogEvent();
            AdjustDisplaysToTracker();
        }
Пример #7
0
        public PointF GetCursorPos()
        {
            lock (mutex)
            {
                CMSTrackingSuite selectedSuite = model.SelectedSuite;
                if (selectedSuite == null || selectedSuite.MouseControlModule == null)
                {
                    return(PointF.Empty);
                }

                return(selectedSuite.MouseControlModule.MousePointer);
            }
        }
Пример #8
0
        private void AddSuite(CMSTrackingSuite trackingSuite)
        {
            if (trackingSuites == null)
            {
                return;
            }

            if (this.trackingSuites.ContainsKey(trackingSuite.Name))
            {
                CMSTrackingSuite originalSuite = trackingSuites[trackingSuite.Name];
                originalSuite.Update(trackingSuite);
            }
            else
            {
                trackingSuites[trackingSuite.Name] = trackingSuite;
            }
        }
Пример #9
0
        //public abstract CMSTrackingSuite Clone();

        public void Update(CMSTrackingSuite newSuite)
        {
            lock (mutex)
            {
                if (trackingModule != null)
                {
                    this.trackingModule.Update(newSuite.TrackingModule);
                }
                if (mouseControlModule != null)
                {
                    this.mouseControlModule.Update(newSuite.MouseControlModule);
                }
                if (clickControlModule != null)
                {
                    this.clickControlModule.Update(newSuite.ClickControlModule);
                }
            }
        }
Пример #10
0
        public void SaveSuite(string configDirectory, string suiteName)
        {
            CMSTrackingSuite ts = trackingSuites[suiteName];

            if (ts == null)
            {
                return;
            }
            try
            {
                lock (saveSuiteMutex)
                {
                    Type          curType  = ts.GetType();
                    string        filename = configDirectory + "/" + curType.ToString() + CMSConstants.SUITE_CONFIG_SUFFIX;
                    XmlSerializer xmSer    = new XmlSerializer(curType);
                    StreamWriter  outFile  = new StreamWriter(filename);
                    xmSer.Serialize(outFile, ts);
                    outFile.Close();
                }
            }
            catch (Exception e)
            {
            }
        }
Пример #11
0
        /// <summary>
        /// Toggles Whether or not the advanced view shows a tracker.
        /// </summary>
        /// <param name="trackerSelected"></param>
        public void SetTrackerSelected(bool trackerSelected)
        {
            if (trackerSelectionControl == null)
            {
                return;
            }

            this.SuspendLayout();
            this.tabControl.SuspendLayout();
            tabPageAdvancedView.SuspendLayout();

            trackerSelectionControl.SetActive(!trackerSelected);
            if (trackerSelected)
            {
                CMSTrackingSuite currentTracker = viewAdapter.GetCurrentTrackingSuite();

                if (currentTracker == null)
                {
                    throw new Exception("No current tracker");
                }

                if (currentTracker.Name.Equals(selectedSuiteName))
                {
                    foreach (Control control in tabPageAdvancedView.Controls)
                    {
                        CMSConfigPanel configPanel = control as CMSConfigPanel;
                        if (configPanel != null)
                        {
                            configPanel.Init(SendTrackerLog);
                            configPanel.LoadFromControls();
                        }
                    }
                }
                else
                {
                    selectedSuiteName = currentTracker.Name;

                    tabPageAdvancedView.Controls.Clear();
                    int maxWidth    = trackerSelectionControl.Width;
                    int totalHeight = 3 + trackerSelectionControl.Height + this.bottomActiveControl.Height;
                    CMSConfigPanel[] trackerPanels = currentTracker.GetPanels();

                    foreach (CMSConfigPanel configPanel in trackerPanels)
                    {
                        if (configPanel == null)
                        {
                            continue;
                        }
                        configPanel.Init(SendTrackerLog);
                        Control trackerPanel = configPanel as Control;
                        if (trackerPanel == null)
                        {
                            continue;
                        }
                        if (trackerPanel.Width > maxWidth)
                        {
                            maxWidth = trackerPanel.Width;
                        }
                        totalHeight += trackerPanel.Height;
                    }
                    totalHeight += 3;
                    int totalWidth = 12 + maxWidth;
                    tabPageAdvancedView.Size = new Size(totalWidth, totalHeight);
                    tabControl.Size          = new Size(totalWidth + 8, totalHeight + 26);
                    Size = new Size(totalWidth + 19, totalHeight + 55);

                    Point trackerSelectionControlPt = new Point((totalWidth - trackerSelectionControl.Width) / 2, 3);
                    trackerSelectionControl.Location = trackerSelectionControlPt;

                    int curHeight = 3 + trackerSelectionControl.Height;

                    tabPageAdvancedView.Controls.Add(trackerSelectionControl);

                    foreach (Control trackerPanel in trackerPanels)
                    {
                        if (trackerPanel == null)
                        {
                            continue;
                        }
                        Point curPt = new Point((totalWidth - trackerPanel.Width) / 2, curHeight);
                        trackerPanel.Location = curPt;
                        tabPageAdvancedView.Controls.Add(trackerPanel);
                        curHeight += trackerPanel.Height;
                    }
                    Point bottomActivePt = new Point((totalWidth - this.bottomActiveControl.Width) / 2, curHeight);
                    bottomActiveControl.Location = bottomActivePt;
                    tabPageAdvancedView.Controls.Add(bottomActiveControl);
                }
            }
            else
            {
                tabPageAdvancedView.Controls.Clear();
                selectedSuiteName = null;
                trackerSelectionControl.Location = new Point(6, 3);
                tabPageAdvancedView.Controls.Add(trackerSelectionControl);
                Size                     = new Size(697, 435);
                tabControl.Size          = new Size(686, 406);
                tabPageAdvancedView.Size = new Size(678, 380);
                tabPageAdvancedView.Controls.Add(bottomInActiveControl);
            }
            this.ResumeLayout(false);
            this.tabControl.ResumeLayout(false);
            tabPageAdvancedView.ResumeLayout(false);
            tabPageAdvancedView.PerformLayout();
            Invalidate();
        }
Пример #12
0
        public void Load(string configDirectory, string libDirectory)
        {
            if (libDirectory == null)
            {
                throw new Exception("SuiteDirectory is null");
            }
            if (configDirectory == null)
            {
                throw new Exception("ConfigDirectory is null");
            }

            SortedList <Type, string> types = new SortedList <Type, string>(new TypeComparer());

            ArrayList trackingSuitesList = new ArrayList();

            Type trackingType = typeof(CMSTrackingSuite);

            DirectoryInfo info = new DirectoryInfo(libDirectory);

            assemblies = new SortedList <string, Assembly>();
            foreach (FileInfo fileInfo in info.GetFiles())
            {
                if (!fileInfo.Extension.Equals(".dll"))
                {
                    continue;
                }
                try
                {
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(fileInfo.FullName);
                    AppDomain.CurrentDomain.Load(assembly.GetName());
                    assemblies[assembly.FullName] = assembly;
                }
                catch (Exception e)
                {
                }
            }


            {
                DirectoryInfo userLibInfo = new DirectoryInfo(CMSConstants.USER_LIB_DIRECTORY);
                foreach (FileInfo fileInfo in userLibInfo.GetFiles())
                {
                    if (!fileInfo.Extension.Equals(".dll"))
                    {
                        continue;
                    }
                    try
                    {
                        Assembly a = System.Reflection.Assembly.LoadFile(fileInfo.FullName);
                        AppDomain.CurrentDomain.Load(a.GetName());
                        assemblies[a.FullName] = a;
                        //foreach (AssemblyName an in a.GetReferencedAssemblies())
                        //AppDomain.CurrentDomain.Load(an);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            foreach (Assembly assembly in assemblies.Values)
            {
                try
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (type.IsSubclassOf(trackingType))
                        {
                            bool cont = false;

                            foreach (Attribute curAttr in System.Attribute.GetCustomAttributes(type))
                            {
                                if (curAttr is CMSIgnoreSuiteAtt)
                                {
                                    cont = true;
                                    break;
                                }
                            }
                            if (cont)
                            {
                                continue;
                            }
                            types[type] = assembly.FullName;
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }

            types[typeof(CMSTrackingSuiteStandard)] = null;
            types[typeof(CMSEmptyTrackingSuite)]    = null;



            foreach (Type type in types.Keys)
            {
                if (!type.IsSubclassOf(typeof(CMSTrackingSuite)))
                {
                    continue;
                }

                string filename   = configDirectory + "/" + type.ToString() + CMSConstants.SUITE_CONFIG_SUFFIX;
                bool   fileExists = false;
                if (File.Exists(filename))
                {
                    fileExists = true;
                    StreamReader inFile = null;
                    try
                    {
                        inFile = new StreamReader(filename);
                        XmlSerializer    xmSer         = new XmlSerializer(type);
                        CMSTrackingSuite trackingSuite = xmSer.Deserialize(inFile) as CMSTrackingSuite;
                        if (trackingSuite == null)
                        {
                            throw new Exception();
                        }
                        AddSuite(trackingSuite);
                        inFile.Close();
                    }
                    catch (Exception e)
                    {
                        if (inFile != null)
                        {
                            inFile.Close();
                        }
                        fileExists = false;
                        File.Delete(filename);
                    }
                }


                if (!fileExists)
                {
                    try
                    {
                        CMSTrackingSuite trackingSuite = System.Activator.CreateInstance(type) as CMSTrackingSuite;

                        if (trackingSuite == null)
                        {
                            continue;
                        }
                        XmlSerializer xmSer = new XmlSerializer(type);
                        if (!Directory.Exists(Path.GetDirectoryName(filename)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        }
                        FileStream   fs      = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Delete | FileShare.ReadWrite);
                        StreamWriter outFile = new StreamWriter(fs);
                        xmSer.Serialize(outFile, trackingSuite);
                        AddSuite(trackingSuite);
                        outFile.Close();
                    }
                    catch (Exception e) { }
                }
            }
        }
Пример #13
0
        void ProcessFrameFromSource(System.Drawing.Bitmap [] frames)
        {
            lock (mutex)
            {
                if (CMSLogger.CanCreateLogEvent(false, false, true, "CMSLogProcessesEvent"))
                {
                    CMSLogProcessesEvent pEvent = new CMSLogProcessesEvent();
                    pEvent.CaptureProcesses();
                    CMSLogger.SendLogEvent(pEvent);
                }

                if (!controllerState.Equals(CMSState.CameraNotFound))
                {
                    foreach (Bitmap frame in frames)
                    {
                        frame.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    }

                    CMSTrackingSuite currentTracker = model.SelectedSuite;

                    if (currentTracker != null && frames != null && frames.Length > 0)
                    {
                        if (!currentTracker.Initialized)
                        {
                            Size[] sizes = new Size[frames.Length];
                            for (int i = 0; i < frames.Length; i++)
                            {
                                sizes[i] = new Size(frames[i].Width, frames[i].Height);
                            }
                            currentTracker.Init(sizes);
                        }


                        bool control = controllerState.Equals(CMSState.ControlTracking);

                        /*
                         * CMSLogExperimentFrameEvent logExpFrameEvent = null;
                         *
                         * if (ExperimentFrameSaver.IsExperimentFrameEnabled())
                         * {
                         *  if (ExperimentFrameSaver.CanSaveLogEvent())
                         *  {
                         *      logExpFrameEvent = new CMSLogExperimentFrameEvent(frames[0], currentTracker.Name, 0, 0);
                         *  }
                         * }*/

                        currentTracker.ProcessFrame(frames, control);

                        /*
                         * if (logExpFrameEvent != null)
                         * {
                         *  if (currentTracker.TrackingModule != null)
                         *  {
                         *      PointF curPoint = currentTracker.TrackingModule.ImagePoint;
                         *      logExpFrameEvent.X = (int)curPoint.X;
                         *      logExpFrameEvent.Y = (int)curPoint.Y;
                         *      ExperimentFrameSaver.SaveLogEvent(logExpFrameEvent);
                         *  }
                         * }*/

                        if (CMSLogger.CanCreateLogEvent(true, true, false, "CMSLogFrameEvent"))
                        {
                            CMSLogFrameEvent frameEvent = new CMSLogFrameEvent();
                            if (frameEvent != null)
                            {
                                frameEvent.SetImages(frames);
                                CMSLogger.SendLogEvent(frameEvent);
                            }
                        }
                    }

                    videoDisplay.SetVideo(frames);
                }
            }
        }
 public void UpdateTrackingSuite(CMSTrackingSuite trackingSuite)
 {
     model.TrackingDirectory.GetTrackingSuite(trackingSuite.Name).Update(trackingSuite);
 }