예제 #1
0
        public void InitFromConfig(string filename)
        {
            configFilename = filename;

            if (!File.Exists(configFilename))
            {
                return;
            }

            configData = JsonConvert.DeserializeObject <FilterConfigData>(File.ReadAllText(configFilename), new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            foreach (List <FilterBase> filterList in filters)
            {
                if (filterList != null)
                {
                    filterList.Clear();
                }
            }

            for (int i = 0; i < filters.Length; ++i)
            {
                filters[i] = null;
            }

            for (int i = 0; i < configData.keys.Count; ++i)
            {
                if (configData.keys[i] == null)
                {
                    continue;
                }

                FilterDataKey key = configData.keys[i];

                List <FilterBase> filterList = filters[(int)key.key] = new List <FilterBase>();

                foreach (FilterData filterData in key.filters)
                {
                    if (filterData is SmoothFilterData)
                    {
                        SmoothFilterData   smoothFilterData = (SmoothFilterData)filterData;
                        NestedSmoothFilter newFilter        = new NestedSmoothFilter();
                        newFilter.SetParameters(smoothFilterData.nestCount, smoothFilterData.sampleCount, smoothFilterData.maxDelta);

                        filterList.Add(newFilter);
                    }
                    else
                    if (filterData is KalmanFilterData)
                    {
                        KalmanFilterData  kalmanFilterData = (KalmanFilterData)filterData;
                        KalmanNoiseFilter newFilter        = new KalmanNoiseFilter();
                        newFilter.SetParameters(kalmanFilterData.a, kalmanFilterData.h, kalmanFilterData.q, kalmanFilterData.r, kalmanFilterData.p, kalmanFilterData.x);

                        filterList.Add(newFilter);
                    }
                }
            }
        }
예제 #2
0
        public void SaveConfig()
        {
            configData = new FilterConfigData();

            for (int i = 0; i < (int)GenericProviderData.DataKey.Max; ++i)
            {
                List <FilterBase> filterList = filters[i];
                if (filterList == null)
                {
                    continue;
                }
                else
                {
                    FilterDataKey newConfig = new FilterDataKey(i);
                    configData.keys.Add(newConfig);

                    foreach (FilterBase filter in filterList)
                    {
                        if (filter is NestedSmoothFilter)
                        {
                            SmoothFilterData   newFilterData    = new SmoothFilterData();
                            NestedSmoothFilter nestSmoothFilter = (NestedSmoothFilter)filter;
                            newFilterData.nestCount   = nestSmoothFilter.GetNestCount();
                            newFilterData.sampleCount = nestSmoothFilter.GetSampleCount();
                            newFilterData.maxDelta    = nestSmoothFilter.GetMaxDelta();

                            newConfig.filters.Add(newFilterData);
                        }
                        else
                        if (filter is KalmanNoiseFilter)
                        {
                            KalmanFilterData  newFilterData     = new KalmanFilterData();
                            KalmanNoiseFilter kalmanNoiseFilter = (KalmanNoiseFilter)filter;
                            newFilterData.a = kalmanNoiseFilter.GetA();
                            newFilterData.h = kalmanNoiseFilter.GetH();
                            newFilterData.q = kalmanNoiseFilter.GetQ();
                            newFilterData.r = kalmanNoiseFilter.GetR();
                            newFilterData.p = kalmanNoiseFilter.GetP();
                            newFilterData.x = kalmanNoiseFilter.GetX();

                            newConfig.filters.Add(newFilterData);
                        }
                    }
                }
            }


            string outputString = JsonConvert.SerializeObject(configData, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });


            File.WriteAllText(configFilename, outputString);
        }