Exemplo n.º 1
0
        public void Flush()
        {
            var us = new FixedStack <int>(12);

            us.Push(10);
            us.Push(10);
            us.Push(10);
            us.Push(10);
            Assert.True(us.HasItems);
            us.Clear();
            Assert.False(us.HasItems);
        }
Exemplo n.º 2
0
    public void Init(Texture2D inputTex, Texture2D outputTex, int N, PathOverlapAttributes attributes)
    {
        this.N          = N;
        this.attributes = attributes;

        // We use outsize to get the size of the bitmap image to prevent issues when accessing bitmap images across multiple threads
        insize = new Size()
        {
            width  = inputTex.width,
            height = inputTex.height
        };

        outsize = new Size()
        {
            width  = outputTex.width,
            height = outputTex.height
        };

        colors.Clear();
        // First 2 colors represent mask colors
        colors.Add(Color.clear);
        colors.Add(Color.clear);

        byte[] indices = TileUtils.IndexColours(inputTex.GetPixels32(), colors);
        output_idx = TileUtils.IndexColours(outputTex.GetPixels32(), colors);

        FillSpecialColorIndices();

        // Instantiate masks
        Pattern.layer1 = new Mask(true, path_idx);
        Pattern.layer2 = new Mask(true);
        bufferMask     = new Mask(true, path_idx, freespace_idx, obstacle_idx);
        masks          = new Mask(false, Pattern.mask_idx_l1, Pattern.mask_idx_l2);

        // Set boundaries
        ConfigureBoundaries();
        ConfigureObstacleBoundaries();

        int tilecount = outsize.width * outsize.height;

        // Try to optimize array initialization
        if (wave == null || wave.Length != tilecount)
        {
            wave       = new bool[tilecount][];
            compatible = new int[tilecount][][];
        }

        // We set T in this function!
        ExtractPattern(indices, this.attributes.GenerateMasksFromOutput);

        if (indexstack == null || indexstack.Size() != tilecount * T)
        {
            indexstack = new FixedStack <Tuple <int, int> >(tilecount * T);
        }
        else
        {
            indexstack.Clear();
        }

        // Initialize wave and compatible arrays
        for (int i = 0; i < wave.Length; ++i)
        {
            wave[i]       = new bool[T];
            compatible[i] = new int[T][];
            for (int t = 0; t < T; ++t)
            {
                compatible[i][t] = new int[4];
            }
        }

        // Initialize fixed arrays
        weightLogWeights      = new double[T];
        sumOfWeights          = 0;
        sumOfWeightLogWeights = 0;

        for (int t = 0; t < T; t++)
        {
            weightLogWeights[t]    = weights[t] * Math.Log(weights[t]);
            sumOfWeights          += weights[t];
            sumOfWeightLogWeights += weightLogWeights[t];
        }

        startingEntropy = Math.Log(sumOfWeights) - sumOfWeightLogWeights / sumOfWeights;

        // Intialize sum arrays
        sumsOfOnes             = new int[tilecount];
        sumsOfWeights          = new double[tilecount];
        sumsOfWeightLogWeights = new double[tilecount];
        entropies = new double[tilecount];

        distribution = new double[T];

        // Populate propagator
        for (int d = 0; d < 4; ++d)
        {
            propagator[d] = new int[T][];
            for (int t = 0; t < T; ++t)
            {
                patterns[t].Overlap(patterns, DX[d], DY[d], out propagator[d][t]);
            }
        }
    }
Exemplo n.º 3
0
 public void Clear()
 {
     m_mean        = default(T);
     m_isMeanDirty = false;
     m_values.Clear();
 }