Пример #1
0
    // STEP I-3.
    double[] SolveHeat()
    {
        double init_heat = (double)System.Math.Sqrt(W * H) / 64.0;

        double[] b_heat_sparse = new double[area_cnt];
        double[] u_heat_sparse = new double[area_cnt];

        int voxid_init = GetVoxelIndex(i0, j0);
        int matid_init;

        if (Voxel2Matrix.TryGetValue(voxid_init, out matid_init))
        {
            b_heat_sparse[matid_init] = init_heat; // the point of initial seed
        }

        solver_heat.Solve(b_heat_sparse, u_heat_sparse);

        return(u_heat_sparse);
    }
Пример #2
0
    // STEP III-3.
    double[] SolveDistance(double[][] X_sparse)
    {
        ////////////////////////////////////////////////////////////
        // divergence of normalized gradient X
        // [CAUTION] NEGATED value to fit Cholesky decomposition
        ////////////////////////////////////////////////////////////
        double[] b_dist_sparse = new double[area_cnt];

        // change for loop based on sparse
        for (int matid_this = 0; matid_this < area_cnt; matid_this++)
        {
            List <int> matid_neighbor;
            if (!MatrixNeighbors.TryGetValue(matid_this, out matid_neighbor))
            {
                continue;
            }

            double div_x = 0.0;
            double div_y = 0.0;

            bool bound_x0 = false;
            bool bound_x2 = false;
            if (matid_neighbor[0] != -1)
            {
                div_x -= X_sparse[0][matid_neighbor[0]];
            }
            else
            {
                bound_x0 = true;
            }
            if (matid_neighbor[1] != -1)
            {
                div_x += X_sparse[0][matid_neighbor[1]];
            }
            else
            {
                bound_x2 = true;
            }
            if (bound_x0 || bound_x2)
            {
                div_x *= 2.0;
            }

            bool bound_y0 = false;
            bool bound_y2 = false;
            if (matid_neighbor[2] != -1)
            {
                div_y -= X_sparse[1][matid_neighbor[2]];
            }
            else
            {
                bound_y0 = true;
            }
            if (matid_neighbor[3] != -1)
            {
                div_y += X_sparse[1][matid_neighbor[3]];
            }
            else
            {
                bound_y2 = true;
            }
            if (bound_y0 || bound_y2)
            {
                div_y *= 2.0;
            }

            b_dist_sparse[matid_this] = -0.5 * (div_x + div_y); // NEGATED!
        }

        ////////////////////////////////////////////////////////////
        // solve distance field
        ////////////////////////////////////////////////////////////
        double[] phi_sparse = new double[area_cnt];
        solver_dist.Solve(b_dist_sparse, phi_sparse);

        double phi_max = phi_sparse.Max();
        double phi_min = phi_sparse.Min();

        double[] phi_dense = new double[W * H];

        for (int matid_this = 0; matid_this < area_cnt; matid_this++)
        {
            int voxid_this;
            Matrix2Voxel.TryGetValue(matid_this, out voxid_this);

            phi_dense[voxid_this] = phi_sparse[matid_this] - phi_min;
        }
        return(phi_dense);
    }