Exemplo n.º 1
0
    /*
     * public int this[int i, int j, int k]
     * {
     *  get
     *  {
     *      // indexer
     *      return data[i, j, k];
     *  }
     *  set
     *  {
     *      data[i, j, k] = value;
     *  }
     *
     * }
     *
     * public int this[Vector3 idx]
     * {
     *  get
     *  {
     *      // indexer
     *      Triple i = imageToGrid(idx);
     *      return data[i.x, i.y, i.z];
     *  }
     *  set
     *  {
     *      Triple i = imageToGrid(idx);
     *      data[i.x, i.y, i.z] = value;
     *  }
     *
     * }
     */

    /**
     * WARNING: This copies only the reference, not the data array!
     **/
    public Grid3D2 getSubgrid(Vector3 p, int extend)
    {
        Triple  p_grid    = imageToGrid(p);
        Grid3D2 subgrid   = new Grid3D2(new Triple(extend, extend, extend), _cellSize);
        int     centerIdx = (extend - 1) / 2 + 1;

        for (int i = 0; i < extend; i++)
        {
            for (int j = 0; j < extend; j++)
            {
                for (int k = 0; k < extend; k++)
                {
                    int x = (int)p_grid.x + i - (extend - 1) / 2;
                    int y = (int)p_grid.y + j - (extend - 1) / 2;
                    int z = (int)p_grid.z + k - (extend - 1) / 2;
                    if (x >= 0 && x < data.GetLength(0) && y >= 0 && y < data.GetLength(1) && z >= 0 && z < data.GetLength(2))
                    {
                        subgrid.data[i, j, k] = data[x, y, z];
                    }
                    else
                    {
                        subgrid.data[i, j, k] = invalid;
                    }
                }
            }
        }

        return(subgrid);
    }
Exemplo n.º 2
0
    public PoissonDiskSampling2(float width, float height, float depth, float minDist, int k = 30, int maxPointCount = 10000)
        : base(new Vector3(0, 0, 0), new Vector3(width, height, depth))
    {
        _minDist       = minDist;
        _k             = k;
        _maxPointCount = maxPointCount;

        float cellSize = _minDist / Mathf.Sqrt(3.0f);      // sqrt of dimension, in this case 3D

        _grid = new Grid3D2(new Triple(
                                Mathf.CeilToInt(_size.x / cellSize),             // grid width
                                Mathf.CeilToInt(_size.y / cellSize),             // grid height
                                Mathf.CeilToInt(_size.z / cellSize)), cellSize); // grid depth

        //RandomQueue works like a queue, except that it
        //pops a random element from the queue instead of
        //the element at the head of the queue
        _activeList = new RandomQueue <int>();
    }
Exemplo n.º 3
0
    bool inNeighbourhood(Vector3 point)
    {
        float sqrDist = _minDist * _minDist;
        //get the neighbourhood if the point in the grid
        // check between minDist and 2 * mindist implies 2 cells to each side.
        // Thus we need a subgrid of size 2*2+1 (2 to both sides + 1 for the center)
        int     neighbourhoodSize = 5;
        Grid3D2 cubeAroundPoint   = _grid.getSubgrid(point, neighbourhoodSize);

        // check the distance
        foreach (int c in cubeAroundPoint)
        {
            if (c != Grid3D2.invalid)
            {
                if ((_grid.samples[c] - point).sqrMagnitude < sqrDist)
                {
                    return(true);
                }
            }
        }
        return(false);
    }