Example #1
0
        public ProcessorProject LoadFromCsv(String radiants, String layers, String signals, String sphere, String resultSet, String common)
        {
            var radiantsCsv = CsvHelper.FromCsv(radiants);
            var layersCsv   = CsvHelper.FromCsv(layers);
            var signalsCsv  = CsvHelper.FromCsv(signals);
            var sphereCsv   = CsvHelper.FromCsv(sphere);
            var commonCsv   = CsvHelper.FromCsv(common);

            var project = new ProcessorProject();

            project.SphereCutRadius = Double.Parse(sphereCsv["SphereCutRadius", 0], CultureInfo.InvariantCulture);
            project.SphereRadius    = Double.Parse(sphereCsv["SphereRadius", 0], CultureInfo.InvariantCulture);

            for (int i = 0; i < signalsCsv.Count; i++)
            {
                var signal = new ProcessorSignal
                {
                    Amplitude = Double.Parse(signalsCsv["Amplitude", i], CultureInfo.InvariantCulture),
                    Phase     = Double.Parse(signalsCsv["Phase", i], CultureInfo.InvariantCulture),
                    Frequency = Double.Parse(signalsCsv["Frequency", i], CultureInfo.InvariantCulture),
                };
                project.Signals.Add(signal);
            }
            for (int i = 0; i < layersCsv.Count; i++)
            {
                var item = new ProcessorLayer
                {
                    Name = layersCsv["Name", i],
                    AttenuationConstant = Double.Parse(layersCsv["AttenuationConstant", i], CultureInfo.InvariantCulture),
                    AttenuationFreq     = Double.Parse(layersCsv["AttenuationFreq", i], CultureInfo.InvariantCulture),
                    Density             = Double.Parse(layersCsv["Density", i], CultureInfo.InvariantCulture),
                    IsSquareAttenuation = Double.Parse(layersCsv["IsSquareAttenuation", i], CultureInfo.InvariantCulture) > 0,
                    Thickness           = Double.Parse(layersCsv["Thickness", i], CultureInfo.InvariantCulture),
                    WaveSpeed           = Double.Parse(layersCsv["WaveSpeed", i], CultureInfo.InvariantCulture)
                };
                project.Layers.Add(item);
            }

            for (int i = 0; i < radiantsCsv.Count; i++)
            {
                var item = new ProcessorRadiant
                {
                    Delay    = Double.Parse(radiantsCsv["Delay", i], CultureInfo.InvariantCulture),
                    Position = new Point3D(Double.Parse(radiantsCsv["Position.X", i], CultureInfo.InvariantCulture),
                                           Double.Parse(radiantsCsv["Position.Y", i], CultureInfo.InvariantCulture),
                                           Double.Parse(radiantsCsv["Position.Z", i], CultureInfo.InvariantCulture)),
                    Radius = Double.Parse(radiantsCsv["Radius", i], CultureInfo.InvariantCulture)
                };
                project.Radiants.Add(item);
            }
            project.ResearchSets = LoadResearchRects(resultSet).ToList();
            project.Reflections  = Int32.Parse(commonCsv["Reflections", 0], CultureInfo.InvariantCulture);
            project.RadinatDomainMinPeriodFactor = Double.Parse(commonCsv["DomainFactor", 0], CultureInfo.InvariantCulture);

            return(project);
        }
Example #2
0
 public void ReinitResearchParams(ProcessorProject info)
 {
     foreach (var radiant in info.Radiants)
     {
         var processorRadiant =
             _radiants.FirstOrDefault(it => radiant.Position == it.Position);
         if (processorRadiant == null)
         {
             continue;
         }
         processorRadiant.Delay = radiant.Delay;
     }
 }
Example #3
0
        public void Init(ProcessorProject info)
        {
            if (!_isStopped)
            {
                throw new InvalidOperationException("in progress");
            }
            _radiants.Clear();
            _signals.Clear();
            _layers.Clear();
            _signals.AddRange(
                info.Signals.Select(
                    it => new ProcessorSignal {
                Amplitude = it.Amplitude, Frequency = it.Frequency, Phase = it.Phase
            }));
            _sphereRadius    = info.SphereRadius;
            _reflectionDepth = info.Reflections;

            _waveSpeed0 = info.Layers.First().WaveSpeed;
            _layers.AddRange(
                info.Layers.Select(
                    it =>
                    new ProcessorLayerEx
            {
                AttenuationConstant = it.AttenuationConstant,
                AttenuationFreq     = it.AttenuationFreq,
                IsSquareAttenuation = it.IsSquareAttenuation,
                Density             = it.Density,
                WaveSpeed           = it.WaveSpeed,
                Impedance           = it.Density * it.WaveSpeed,
                RatioToLayer0       = it.WaveSpeed / _waveSpeed0,
                Thickness           = it.Thickness
            }));
            //pump cache for attenuation
            for (var i = 0; i < _layers.Count; i++)
            {
                var processorLayer = _layers[i];
                processorLayer.ThicknessBefore = _layers.Select(it => it.Thickness).Take(i).Sum();
                processorLayer.ThicknessAfter  = processorLayer.ThicknessBefore + processorLayer.Thickness;
                foreach (var signal in info.Signals)
                {
                    processorLayer.GetAttenuationFactor(signal.Frequency);
                }
            }
            _radiants.AddRange(info.Radiants.Select(it => new ProcessorRaidantEx
            {
                Delay     = it.Delay,
                Position  = it.Position,
                Radius    = it.Radius,
                Direction = new Point3D(_sphereRadius, 0, 0) - it.Position
            }));

            var highestFreq = info.Signals.Select(it => it.Frequency).OrderByDescending(it => it).First();



            var shortestWave = _waveSpeed0 / highestFreq;

            _domainFactor = info.RadinatDomainMinPeriodFactor;
            if (_domainFactor == 0)
            {
                _domainFactor = .25;
            }
            var radiusDict = _radiants.Select(it => it.Radius).Distinct().ToDictionary(it => it,
                                                                                       it =>
                                                                                       GetDomains(it, shortestWave * _domainFactor));

            foreach (var processorRadiant in _radiants)
            {
                processorRadiant.Domains =
                    radiusDict[processorRadiant.Radius].Select(
                        it => Point3D.Multiply(it, GetRotatesOnSphereMatrix(processorRadiant.Position, _sphereRadius))).ToList();
                processorRadiant.ValuePerDomain = 1.0 / processorRadiant.Domains.Count;
            }
        }
Example #4
0
 public String SaveToJson(ProcessorProject project)
 {
     return(JsonConvert.SerializeObject(project, Formatting.Indented));
 }