Пример #1
0
 //this should be incremented at the time of successful acquistion and not if unsuccessful or cancelled
 private void AcquisitionLoop(object sa, PointAcqusitionFinishedEventArgs e)
 {
     #if TRACE
     if (e != null)
         Console.WriteLine("AcquisitionLoop " + electrodeNumber.ToString("0") + " " +
             (e.result == null) + " " + (e.Retry).ToString());
     else
         Console.WriteLine("AcquisitionLoop " + electrodeNumber.ToString("0"));
     #endif
     if (!executeSkip)
     {
         SystemSounds.Beep.Play();
         if (electrodeNumber >= 0)
         {
             if (!e.Retry)
             {
                 Triple t = DoCoordinateTransform(e.result);
                 string name = templateList[electrodeNumber].Name;
                 output1.Text = name + ": " + t.ToString();
                 XYZRecord xyz = new XYZRecord(name, t.v1, t.v2, t.v3);
                 if (electrodeLocations.Where(l => l.Name == name).Count() == 0) //assure unique electrode name
                 {
                     electrodeLocations.Add(xyz);
                     addPointToView(xyz);
                     Delete.IsEnabled = true;
                 }
                 else //this is a replacement
                 {
                     XYZRecord oldXYZ = electrodeLocations.Where(l => l.Name == name).First(); //get item to be replaced
                     int n = electrodeLocations.IndexOf(oldXYZ); //and replace old
                     electrodeLocations.Remove(oldXYZ); //remove
                     electrodeLocations.Insert(n, xyz); //replace with new
                     updateView(); //and redraw
                 }
                 electrodeNumber++; //on to next electrode location
             }
         }
         else if (electrodeNumber == -3) //first entry
         {
             if (e != null && !e.Retry)
             {
                 PN = e.result; //save Nasion
                 electrodeNumber++;
                 Redo.IsEnabled = true;
             }
             DoPrompting((e != null) && e.Retry);
             ((StylusAcquisition)sa).Start();
             return;
         }
         else if (electrodeNumber == -2)
         {
             //save previous result
             if (!e.Retry) //save Right preauricular
             {
                 PR = e.result;
                 electrodeNumber++;
             }
         }
         else //electrodeNumber == -1
         {
             //save previous result
             if (!e.Retry) //save Left preauricular
             {
                 PL = e.result;
                 CreateCoordinateTransform(); //calculate coordinate transformtion
                 electrodeNumber++;
                 drawAxes();
             }
         }
     }
     else //executing skip
     {
         electrodeNumber++;
         executeSkip = false;
     }
     if (electrodeNumber >= numberOfElectrodes)
     {
         if (voice)
         {
             int n = electrodeLocations.Count;
             prompt.ClearContent();
             prompt.StartSentence();
             prompt.AppendText("Completed acquisition of " + n.ToString("0") + " electrodes.");
             prompt.EndSentence();
             speak.Speak(prompt);
         }
         ElectrodeName.Text = "";
         writeElectrodeFile();
         return; //done
     }
     DoPrompting(e.Retry);
     ((StylusAcquisition)sa).Start();
     return;
 }
Пример #2
0
 /// <summary>
 /// Constructor for stream to read Electrode Position file, based on another stream;
 /// reads in entire file, creating dictionary of eletrode positions by name and then
 /// closing the stream
 /// </summary>
 /// <param name="str">Stream on which this stream is based</param>
 public ElectrodeInputFileStream(Stream str)
 {
     if (str == null || !str.CanRead) return; //return empty Dictionary
     XmlReaderSettings settings = new XmlReaderSettings();
     settings.IgnoreWhitespace = true;
     settings.IgnoreComments = true;
     settings.IgnoreProcessingInstructions = true;
     XmlReader xr;
     string nameSpace;
     string type;
     try
     {
         xr = XmlReader.Create(str, settings);
         if (xr.MoveToContent() != XmlNodeType.Element) throw new XmlException("Not a valid electrode file");
         nameSpace = xr.NamespaceURI;
         type = xr["Type", nameSpace];
         xr.ReadStartElement("Electrodes");
     }
     catch (Exception x)
     {
         throw new Exception("ElectrodeFileStream: " + x.Message);
     }
     ElectrodeRecord etrRecord;
     while (xr.Name == "Electrode")
     {
         try
         {
             if (type == "PhiTheta") etrRecord = new PhiThetaRecord();
             else if (type == "XY") etrRecord = new XYRecord();
             else if (type == "XYZ") etrRecord = new XYZRecord();
             else throw new Exception("Invalid electrode type");
             etrRecord.read(xr, nameSpace);
         }
         catch (XmlException e)
         {
             throw new Exception("ElectrodeFileStream: " + e.Message);
         }
         etrPositions.Add(etrRecord.Name, etrRecord);
     }
     xr.Close();
 }
Пример #3
0
 internal void addPointToView(XYZRecord xyz)
 {
     Triple t = new Triple(xyz.X, xyz.Y, xyz.Z);
     t = projection.PerspectiveProject(t);
     if (t.v3 <= 0) return;
     Ellipse circle = new Ellipse();
     circle.Stroke = System.Windows.Media.Brushes.Transparent;
     int pink = Math.Min((int)(10 * Math.Pow(t.v3,0.75)), 180);
     circle.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, (byte)pink, (byte)pink));
     double r = Math.Max(100D / t.v3, 2.5D);
     circle.Height = circle.Width = r * 2D;
     Canvas.SetTop(circle, Draw.ActualHeight / 2 - viewScale * t.v2 - r);
     Canvas.SetLeft(circle, Draw.ActualWidth / 2 + viewScale * t.v1 - r);
     Canvas.SetZIndex(circle, (int)(-t.v3 * 100));
     circle.ToolTip = new TextBlock(new Run(xyz.Name));
     circle.MouseDown+=new MouseButtonEventHandler(circle_MouseDown);
     Draw.Children.Add(circle);
 }