Logo Search packages:      
Sourcecode: inkscape version File versions

void NR::compute_surface_normal ( Fvector &  N,
gdouble  ss,
NRPixBlock in,
int  i,
int  j,
int  dx,
int  dy 
)

Computes the unit suface normal vector of surface given by "in" at (i, j) and store it into N. "in" is a (NRPixBlock *) in mode RGBA but only the alpha channel is considered as a bump map. ss is the altitude when for the alpha value 255. dx and dy are the deltas used to compute in our discrete setting

Parameters:
N a reference to a Fvector in which we store the unit surface normal
ss the surface scale
in a NRPixBlock * whose alpha channel codes the surface
i the x coordinate of the point at which we compute the normal
j the y coordinate of the point at which we compute the normal
dx the delta used in the x coordinate
dy the delta used in the y coordinate

Definition at line 110 of file nr-3dutils.cpp.

References NRPixBlock::area, and normalize_vector().

                                                                                                  {
    int w = in->area.x1 - in->area.x0;
    int h = in->area.y1 - in->area.y0;
    int k, l, alpha_idx, alpha_idx_y;
    int x_carac, y_carac;
    gdouble alpha;
    gdouble accu_x;
    gdouble accu_y;
    unsigned char *data = NR_PIXBLOCK_PX (in);
    g_assert(NR_PIXBLOCK_BPP(in) == 4);
    x_carac = get_carac(j, w, dx); //LEFT, MIDDLE or RIGHT
    y_carac = get_carac(i, h, dy); //TOP, MIDDLE or BOTTOM
    alpha_idx = 4*(i*w + j);
    accu_x = 0;
    accu_y = 0;
    for (k = START(y_carac); k <= FINISH(y_carac); k++) {
        alpha_idx_y = alpha_idx + 4*(k-1)*dy*w;
        for (l = START(x_carac); l <= FINISH(x_carac); l++) {
            alpha = (data + alpha_idx_y + 4*dx*(l-1))[3];
            accu_x += K_X[y_carac][x_carac][k][l] * alpha / 255;
            accu_y += K_X[x_carac][y_carac][l][k] * alpha / 255;
        }
    }
    N[X_3D] = -1 * ss * FACTOR_X[y_carac][x_carac] * accu_x / dx;
    N[Y_3D] = -1 * ss * FACTOR_X[x_carac][y_carac] * accu_y / dy;
    N[Z_3D] = 1;
    normalize_vector(N);
    //std::cout << "(" << N[X_3D] << ", " << N[Y_3D] << ", " << N[Z_3D] << ")" << std::endl;
}


Generated by  Doxygen 1.6.0   Back to index