示例#1
0
    public YaoGraph(Grid3D grid, ConnectionType connectivity)
    {
        data             = grid;
        connectivityType = connectivity;
        edgeset          = getEdgeset();

        xdim = data.GetLength(0);
        ydim = data.GetLength(1);
        zdim = data.GetLength(2);

        graph      = new YaoNode[data.samples.Length];
        sample2Yao = new int[data.samples.Length];

        int insertionIdx = 0;

        for (int x = 0; x < xdim; x++)
        {
            for (int y = 0; y < ydim; y++)
            {
                for (int z = 0; z < zdim; z++)
                {
                    if (grid[x, y, z] != -1)
                    {
                        graph[insertionIdx]       = new YaoNode(grid[x, y, z], -1, float.MaxValue, int.MaxValue, new Vector3(0, 0, 0), edgeset.Count);
                        sample2Yao[grid[x, y, z]] = insertionIdx;
                        assignNeigbors(graph[insertionIdx], x, y, z);
                        insertionIdx++;
                    }
                }
            }
        }

        rootNodeId = grid[Mathf.FloorToInt(xdim / 2), 0, Mathf.FloorToInt(zdim / 2)];
    }
    /**
     * Generate samples at grid vertices
     **/
    private void populateGrid(Vector3 offset)
    {
        offset -= new Vector3((data.GetLength(0) - 1) * data.cellSize / 2, 0, (data.GetLength(2) - 1) * data.cellSize / 2);

        int sampleIdx = 0;

        for (int i = 0; i < data.GetLength(0); i++)
        {
            for (int j = 0; j < data.GetLength(1); j++)
            {
                for (int k = 0; k < data.GetLength(2); k++)
                {
                    // populate with grid vertices
                    data.samples[sampleIdx] = new Vector3(offset.x + i * data.cellSize, offset.y + j * data.cellSize, offset.z + k * data.cellSize);
                    data[i, j, k]           = sampleIdx;
                    sampleIdx++;
                }
            }
        }
    }
    /**
     * Generate samples at grid vertices
     **/
    private void populateGrid(Vector3 offset)
    {
        // To move above the stem
        //offset -= new Vector3((_data.GetLength(0) - 1) * _data.cellSize / 2, 0, (_data.GetLength(2) - 1) * _data.cellSize / 2);

        offset -= new Vector3((_data.GetLength(0) - 1) * _data.cellSize / 2, (_data.GetLength(1) - 1) * _data.cellSize / 2, (_data.GetLength(2) - 1) * _data.cellSize / 2);

        int sampleIdx = 0;

        for (int i = 0; i < _data.GetLength(0); i++)
        {
            for (int j = 0; j < _data.GetLength(1); j++)
            {
                for (int k = 0; k < _data.GetLength(2); k++)
                {
                    // populate with grid vertices
                    _data.samples[sampleIdx] = new Vector3(offset.x + i * _data.cellSize, offset.y + j * _data.cellSize, offset.z + k * _data.cellSize);
                    _data[i, j, k]           = sampleIdx;
                    sampleIdx++;
                }
            }
        }
    }