示例#1
0
        public void LoadMontages(string xmlFilePath)
        {
            Montages = new Dictionary <string, SignalMontage>();

            using (var reader = new StreamReader(xmlFilePath))
            {
                var doc = XDocument.Load(reader);

                var montages = doc.Element("brainHatSignalMontages")?.Element("Montages")?.Elements("Montage");
                if (montages == null)
                {
                    throw new Exception("Document does not hae a <Montages> element or any montages.");
                }

                foreach (var nextMontage in montages)
                {
                    var montageName = nextMontage.Element("Name")?.Value;
                    if (montageName == null || Montages.ContainsKey(montageName))
                    {
                        throw new Exception("Filter does not have a name or name is duplicated.");
                    }

                    var montage = new SignalMontage(montageName);

                    var derivations = nextMontage.Elements("Derivation");
                    if (derivations == null)
                    {
                        throw new Exception($"Filter {montageName} does not have any derivations.");
                    }

                    try
                    {
                        foreach (var nextDerivation in derivations)
                        {
                            var derivation = new SignalDerivation(nextDerivation.Element("Label")?.Value, nextDerivation.Element("Color")?.Value);

                            var channels = nextDerivation.Elements("Channel");
                            foreach (var nextChannel in channels)
                            {
                                var rawChannel = int.Parse(nextChannel.Element("Number").Value);
                                var factor     = double.Parse(nextChannel.Element("Factor").Value);

                                derivation.AddDerivationChannel(new SignalDerivationChannel(rawChannel, factor));
                            }

                            montage.AddDerivation(derivation);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"Filter {montageName} does not have any derivations.", e);
                    }


                    Montages.Add(montage.Name, montage);
                }
            }
        }
示例#2
0
        public static ISignalMontage MakeDefaultMontage(int channels)
        {
            var signalMontage = new SignalMontage($"Default{channels}");

            for (int i = 0; i < channels; i++)
            {
                var derivation = new SignalDerivation($"EXG {i}", null);
                derivation.AddDerivationChannel(new SignalDerivationChannel(i, 1.0));
                signalMontage.AddDerivation(derivation);
            }

            return(signalMontage);
        }
示例#3
0
 public void AddDerivation(SignalDerivation derivation)
 {
     Derivations.Add(derivation);
 }