public SimpleVTSFileOutput(MultiChannelInput <IDataChannel> mci, string path, bool createFileSeries = false) : base(mci, path)
        {
            this.fileWriteThreshold = 0.0f;
            this.createFileSeries   = createFileSeries;

            PhysicalBoundaries boundaries = ChannelMapper.GetChannelInputBoundaries(mci);
            var filter = FilterManager.FindFilter <FFTWFilter>(mci.GetChannel(0));

            if (filter == null)
            {
                throw new Exception("SimpleVTSFileOutput supports FFTWFilter only.");
            }
            var filterSettings = filter.GetSettings();

            if (filterSettings.OutputFormat != FFTOutputFormat.Magnitude)
            {
                throw new InvalidDataException($"SimpleVTSFileOutput needs and FFT output format of 'Magnitude'. Your FFT filter has '{filterSettings.OutputFormat}'.");
            }

            this.fftSize = filterSettings.FFTSampleCount;
            zSize        = fftSize / 2;

            channelCount = mci.ChannelCount;

            header   = $"<VTKFile type=\"StructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"UInt64\">{Environment.NewLine}<StructuredGrid WholeExtent=\"0 {channelCount-1} 0 0 0 {zSize-1}\">{Environment.NewLine}<Piece Extent=\"0 {channelCount - 1} 0 0 0 {zSize - 1}\">{Environment.NewLine}";
            footer   = $"</Piece>{Environment.NewLine}</StructuredGrid>{Environment.NewLine}</VTKFile>{Environment.NewLine}";
            cellData = $"<CellData>{Environment.NewLine}</CellData>{Environment.NewLine}";

            sb = new StringBuilder();
            lock (sb)
            {
                sb.AppendLine("<Points>");
                sb.AppendLine("<DataArray type=\"Float32\" Name=\"Points\" NumberOfComponents=\"3\" format=\"ascii\">");
                for (int z = 0; z < zSize; z++)
                {
                    for (int chIndex = 0; chIndex < channelCount; chIndex++)
                    {
                        PhysicalPosition pp = ChannelMapper.GetChannelPosition(mci.GetChannel(chIndex));

                        sb.AppendLine(pp.X.ToString("0.0000000000") + " " + pp.Y.ToString("0.0000000000") + " " + (pp.Z + (z * filter.FrequencyStep)).ToString("0.0000000000"));
                    }
                }
                sb.AppendLine("</DataArray>");
                sb.AppendLine("</Points>");
                points = sb.ToString();
            }
        }
Exemple #2
0
        public VisualOutput(MultiChannelInput <IDataChannel> mci, int maxFramesPerSecond, VisualOutputMode mode)
        {
            this.mode = mode;
            if (mode == VisualOutputMode.Matrix)
            {
                channels   = ChannelMapper.Get2DChannelMatrix(mci);
                dimensions = new int[3] {
                    channels.GetLength(0), channels.GetLength(1), 1
                };
                values = new float[channels.GetLength(0), channels.GetLength(1), 1];
            }
            else if (mode == VisualOutputMode.Waveform)
            {
                channels = new IDataChannel[mci.ChannelCount, 1];
                for (int i = 0; i < mci.ChannelCount; i++)
                {
                    channels[i, 0] = mci.GetChannel(i);
                }
                dimensions = new int[3] {
                    mci.ChannelCount, mci.SamplesPerSecond, 1
                };
                values = new float[mci.ChannelCount, mci.SamplesPerSecond, 1];
            }
            else if (mode == VisualOutputMode.Spectrum)
            {
                channels = new IDataChannel[mci.ChannelCount, 1];
                int?blockSize = null;

                for (int i = 0; i < mci.ChannelCount; i++)
                {
                    channels[i, 0] = mci.GetChannel(i);

                    var filter = FilterManager.FindFilter <FFTWFilter>(channels[i, 0]);
                    if (filter == null)
                    {
                        throw new Exception("VisualOutput's Spectrum mode supports FFTWFilter only.");
                    }
                    var filterSettings = filter.GetSettings();
                    if (filterSettings.OutputFormat != FFTOutputFormat.Magnitude)
                    {
                        throw new InvalidDataException($"VisualOutput's Spectrum mode needs and FFT output format of 'Magnitude'. Your FFT filter has '{filterSettings.OutputFormat}'.");
                    }

                    if (!blockSize.HasValue)
                    {
                        blockSize = filter.OutputBlockSize;
                    }
                    if (blockSize != filter.OutputBlockSize)
                    {
                        throw new Exception("All of the OutputBlockSizes of the filters of the multichannel input must be the same.");
                    }
                }

                dimensions = new int[3] {
                    mci.ChannelCount, blockSize.Value, 1
                };
                values = new float[mci.ChannelCount, blockSize.Value, 1];
            }
            else if (mode == VisualOutputMode.DominanceMatrix)
            {
                channels = ChannelMapper.Get2DChannelMatrix(mci);

                var filter = FilterManager.FindFilter <FFTWFilter>(channels[0, 0]);
                if (filter == null)
                {
                    throw new Exception("VisualOutput's DominanceMatrix mode supports FFTWFilter only.");
                }
                var filterSettings = filter.GetSettings();
                if (filterSettings.OutputFormat != FFTOutputFormat.FrequencyMagnitudePair)
                {
                    throw new InvalidDataException($"VisualOutput's DominanceMatrix mode needs and FFT output format of 'FrequencyMagnitudePair'. Your FFT filter has '{filterSettings.OutputFormat}'.");
                }

                dimensions = new int[3] {
                    channels.GetLength(0), channels.GetLength(1), 5 * 2
                };                                                                                  // will containg the top 5 frequencies and their strength
                values = new float[channels.GetLength(0), channels.GetLength(1), 5 * 2];
            }

            mci.DataChanged += DataChanged;

            refreshVisualOutputTimer = new Timer(UpdateVisualOutput, this, 0, 1000 / maxFramesPerSecond);
        }