Esempio n. 1
0
 //monitor only, independent of button state; stops on cancel only
 public StylusAcquisition(PolhemusController controller, Monitor monitor)
 {
     if (controller == null) throw new ArgumentNullException("controller");
     if (monitor == null) throw new ArgumentNullException("monitor");
     _controller = controller;
     _monitor = monitor;
     _continuousMode = true;
     initialization();
     ProgressChanged += new ProgressChangedEventHandler(sa_StylusProgressChanged);
 }
Esempio n. 2
0
 public PolhemusException(byte errorNum, PolhemusController pc = null)
 {
     _errNum = errorNum;
     if (pc != null)
     {
         if (pc.CurrentFormat == PolhemusController.Format.ASCII)
         {
             _errMess = pc.TReader.ReadLine();
             pc.TReader.ReadLine(); //read line of asterisks
         }
         else
         {
             char[] mess = pc.BReader.ReadChars(pc.currentHeader.Length);
         }
         return;
     }
     else
     {
         if (!_errorDictionary.TryGetValue(_errNum, out _errMess))
             _errMess = "Polhemus error " + _errNum.ToString("X2");
     }
 }
Esempio n. 3
0
 public StylusAcquisition(PolhemusController controller, SingleShot singleShot, Monitor monitor = null)
 {
     if (controller == null) throw new ArgumentNullException("controller");
     if (singleShot == null) throw new ArgumentNullException("singleShot");
     _controller = controller;
     _singleShot = singleShot;
     _monitor = monitor;
     _continuousMode = false;
     initialization();
     if (monitor != null)
         ProgressChanged += new ProgressChangedEventHandler(sa_StylusProgressChanged);
 }
Esempio n. 4
0
        public MainWindow()
        {
            bool standAlone = Environment.GetCommandLineArgs().Length < 3;
            Window1 w;
            string templateFileName;
            string ETRFileName;
            bool useMonitor;
            if (standAlone)
            {
                w = new Window1();
                try
                {
                    foreach (string s in Directory.EnumerateFiles(networkFolder + System.IO.Path.DirectorySeparatorChar + templatesFolder))
                    {
                        string f = System.IO.Path.GetFileNameWithoutExtension(s);
                        w.Templates.Items.Add(f);
                    }
                }
                catch (Exception e)
                {
                    CCIUtilities.ErrorWindow ew = new CCIUtilities.ErrorWindow();
                    ew.Message = "Unable to access Templates folder; message = " + e.Message;
                    ew.ShowDialog();
                    Environment.Exit(0);
                }
                w.Templates.SelectedIndex = 0;
                w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                if (!(bool)w.ShowDialog()) Environment.Exit(0);
                mode = w._mode;
                if (mode == 0) samples = w._sampCount1;
                else if (mode == 1) samples = w._sampCount2;
                else if (mode == 3) threshold = w._SDThresh;
                voice = (bool)w.Voice.IsChecked;
                hemisphere = w.Hemisphere.SelectedIndex;
                templateFileName = (string)w.Templates.SelectedValue;
                ETRFileName = System.IO.Path.GetFileNameWithoutExtension(w._etrFileName);
                useMonitor = (bool)w.Monitor.IsChecked;
            }
            else
            {
                mode = 0; //always single click
                samples = 1; //single sample only
                voice = true;
                hemisphere = 0; //X+
                templateFileName = Environment.GetCommandLineArgs()[1];
                ETRFileName = networkFolder + System.IO.Path.DirectorySeparatorChar + Environment.GetCommandLineArgs()[2];
                useMonitor = true;
            }

            //Read in electrode array template
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.CloseInput = true;
            XmlReader templateReader = XmlReader.Create(networkFolder + System.IO.Path.DirectorySeparatorChar +
                templatesFolder + System.IO.Path.DirectorySeparatorChar + templateFileName + ".xml", settings); //templates are always on network drive
            templateReader.MoveToContent();
            templateReader.MoveToAttribute("N");
            numberOfElectrodes = templateReader.ReadContentAsInt(); //number of items
            templateList = new List<electrodeTemplateListElement>(numberOfElectrodes);
            templateReader.ReadStartElement("ElectrodeNames");
            for (int i = 0; i < numberOfElectrodes; i++)
            {
                templateReader.ReadStartElement("Electrode");
                electrodeTemplateListElement ele = new electrodeTemplateListElement();
                ele.Name = templateReader.ReadElementContentAsString("Print","");
                if (templateReader.Name == "Speak")
                {
                    ele.speakType = templateReader["Type"];
                    if (ele.speakType == "String")
                        ele.speakString = templateReader.ReadElementContentAsString("Speak", ""); //read string to speak
                    else
                    {
                        templateReader.ReadStartElement("Speak");
                        while (templateReader.Name != "Speak")
                            ele.speakString += templateReader.ReadOuterXml(); //read SSML string to speak
                        templateReader.ReadEndElement(/*Speak*/);
                    }
                }
                else
                {
                    ele.speakType = "None";
                    ele.speakString = null;
                }
                templateList.Add(ele);
                templateReader.ReadEndElement(/*Electrode*/);
            }
            templateReader.ReadEndElement(/*ElectrodeNames*/);
            templateReader.Close();

            //Open electrode position file
            efs = new ElectrodeOutputFileStream(
                new FileStream(ETRFileName + "." + numberOfElectrodes.ToString("000") + ".etr", FileMode.Create, FileAccess.Write),
                typeof(XYZRecord));
            electrodeLocations = new List<XYZRecord>(numberOfElectrodes); //set up temporary location list, so changes can be made

            projection = new Projection(eyeDistance);

            InitializeComponent();

            this.MinWidth = (double)SystemInformation.WorkingArea.Width * 96D / screenDPI;
            this.MinHeight = (double)SystemInformation.WorkingArea.Height * 96D / screenDPI;

            //Initialize Polhemus into standard state
            try
            {
                PolhemusStream ps = new PolhemusStream();
                p = new PolhemusController(ps);
                p.InitializeSystem();
                p.SetEchoMode(PolhemusController.EchoMode.On); //Echo on
                p.OutputFormat(PolhemusController.Format.Binary); //Binary output
                int v = hemisphere % 2 == 1 ? -1 : 1; //set correct hemisphere of operation
                if (hemisphere < 2)
                    p.HemisphereOfOperation(null, v, 0, 0);
                else if (hemisphere < 4)
                    p.HemisphereOfOperation(null, 0, v, 0);
                else
                    p.HemisphereOfOperation(null, 0, 0, v);
                p.SetUnits(PolhemusController.Units.Metric); //Metric measurements
                Type[] df1 = { typeof(CartesianCoordinates) }; //set up cartesian coordinate output only for stylus
                p.OutputDataList(1, df1);
                Type[] df2 = { typeof(CartesianCoordinates), typeof(DirectionCosineMatrix) }; //coordinates and direction cosines for reference sensor
                p.OutputDataList(2, df2);
                StylusAcquisition.Monitor c = null;
                if (useMonitor)
                    c = Monitor;
                w = null; //free resources, if any
                if (mode == 0)
                {
                    StylusAcquisition.SingleShot sm = SinglePoint;
                    sa = new StylusAcquisition(p, sm, c);
                }
                else
                {
                    StylusAcquisition.Continuous sm = ContinuousPoints;
                    sa = new StylusAcquisition(p, sm, c);
                }
                AcquisitionFinished += new PointAcquisitionFinishedEventHandler(AcquisitionLoop);
                electrodeNumber = -3; //Fiducial points are first
                if(!standAlone)
                {
                    Window2 w2 = new Window2();
                    w2.ElecTemplate.Text = Environment.GetCommandLineArgs()[1];
                    w2.Output.Text = Environment.GetCommandLineArgs()[2];
                    if (!(bool)w2.ShowDialog()) Environment.Exit(0);
                }
                AcquisitionLoop(sa, null); //Prime the pump!
            }
            catch (Exception e)
            {
                ErrorWindow ew = new ErrorWindow();
                ew.Message = "Error in Polhemus initialization: " + e.Message;
                ew.ShowDialog();
                Environment.Exit(1);
            }
        }