예제 #1
0
        public static ICell <Vector3> GaussFilter(this ICell <Vector3> value, int samples,
                                                  float sampleInterval, Action <IDisposable> connectionSink)
        {
            Cell <Vector3>        newValue    = new Cell <Vector3>();
            CycleBuffer <Vector3> valueBuffer = new CycleBuffer <Vector3>(samples);

            connectionSink(UnityExecutor.instance.TickStream(sampleInterval).Subscribe(() => {
                valueBuffer.Push(value.value);
                float sigma       = samples * samples * 2;
                float weightAccum = 0;
                Vector3 valAccum  = Vector3.zero;
                valueBuffer.ForEach((i, v) =>
                {
                    var gauss    = Mathf.Exp(-i * i / sigma);
                    weightAccum += gauss;
                    valAccum    += gauss * v;
                });

//                Debug.Log("value accum: " + valAccum);
//                Debug.Log("weight accum: " + weightAccum);

                valAccum      /= weightAccum;
                newValue.value = valAccum;
            }));
            return(newValue);
        }
예제 #2
0
        public static ICell <float> GaussFilter(this ICell <float> value, int samples,
                                                float sampleInterval, Action <IDisposable> connectionSink, bool prefil = false)
        {
            Cell <float>        newValue    = new Cell <float>();
            CycleBuffer <float> valueBuffer = new CycleBuffer <float>(samples);

            if (prefil)
            {
                for (int i = 0; i < samples; i++)
                {
                    valueBuffer.Push(value.value);
                }
            }

            connectionSink(UnityExecutor.instance.TickStream(sampleInterval).Subscribe(() => {
                valueBuffer.Push(value.value);
                float sigma       = samples * samples * 2;
                float weightAccum = 0;
                float valAccum    = 0;
                valueBuffer.ForEach((i, v) =>
                {
                    var gauss    = Mathf.Exp(-i * i / sigma);
                    weightAccum += gauss;
                    valAccum    += gauss * v;
                });

//                Debug.Log("value accum: " + valAccum);
//                Debug.Log("weight accum: " + weightAccum);

                valAccum      /= weightAccum;
                newValue.value = valAccum;
            }));
            return(newValue);
        }
 public GaussFilterBufferBase(int samples, T prefillValue)
 {
     valueBuffer = new CycleBuffer <T>(samples, prefillValue);
 }
 public GaussFilterBufferBase(int samples)
 {
     valueBuffer = new CycleBuffer <T>(samples);
 }