From 30884b9e814d7baaa2299803e8cb76cf203ca084 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 4 Aug 2010 05:45:58 +0200 Subject: Wholesale cruft removal part 1 (bzr r9508.1.44) --- src/display/nr-3dutils.cpp | 125 ++------------------------------------------- 1 file changed, 3 insertions(+), 122 deletions(-) (limited to 'src/display/nr-3dutils.cpp') diff --git a/src/display/nr-3dutils.cpp b/src/display/nr-3dutils.cpp index 89c21940a..1d92d3ec9 100644 --- a/src/display/nr-3dutils.cpp +++ b/src/display/nr-3dutils.cpp @@ -11,134 +11,15 @@ #include -#include "libnr/nr-pixblock.h" #include "display/nr-3dutils.h" #include +#include <2geom/point.h> +#include <2geom/matrix.h> namespace NR { -#define BEGIN 0 // TOP or LEFT -#define MIDDLE 1 -#define END 2 // BOTTOM or RIGHT - -#define START(v) ((v)==BEGIN? 1 : 0) -#define FINISH(v) ((v)==END? 1 : 2) - -signed char K_X[3][3][3][3] = { - //K_X[TOP] - { - //K_X[TOP][LEFT] - { - { 0, 0, 0}, - { 0, -2, 2}, - { 0, -1, 1} - }, - { - { 0, 0, 0}, - {-2, 0, 2}, - {-1, 0, 1} - }, - { - { 0, 0, 0}, - {-2, 2, 0}, - {-1, 1, 0} - } - }, - //K_X[MIDDLE] - { - //K_X[MIDDLE][LEFT] - { - { 0, -1, 1}, - { 0, -2, 2}, - { 0, -1, 1} - }, - { - {-1, 0, 1}, - {-2, 0, 2}, - {-1, 0, 1} - }, - { - {-1, 1, 0}, - {-2, 2, 0}, - {-1, 1, 0} - } - }, - //K_X[BOTTOM] - { - //K_X[BOTTOM][LEFT] - { - { 0, -1, 1}, - { 0, -2, 2}, - { 0, 0, 0} - }, - { - {-1, 0, 1}, - {-2, 0, 2}, - { 0, 0, 0} - }, - { - {-1, 1, 0}, - {-2, 2, 0}, - { 0, 0, 0} - } - } -}; - -//K_Y is obtained by transposing K_X globally and each of its components - -gdouble FACTOR_X[3][3] = { - {2./3, 1./3, 2./3}, - {1./2, 1./4, 1./2}, - {2./3, 1./3, 2./3} -}; - -//FACTOR_Y is obtained by transposing FACTOR_X - -inline -int get_carac(int i, int len, int delta) { - if (i < delta) - return BEGIN; - else if (i > len - 1 - delta) - return END; - else - return MIDDLE; -} - -//assumes in is RGBA -//should be made more resistant -void compute_surface_normal(Fvector &N, gdouble ss, NRPixBlock *in, int i, int j, int dx, int dy) { - 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; - accu_y += K_X[x_carac][y_carac][l][k] * alpha; - } - } - ss /= 255.0; // Correction for scale of pixel values - N[X_3D] = -ss * FACTOR_X[y_carac][x_carac] * accu_x / dx; - N[Y_3D] = -ss * FACTOR_X[x_carac][y_carac] * accu_y / dy; - N[Z_3D] = 1.0; - normalize_vector(N); - //std::cout << "(" << N[X_3D] << ", " << N[Y_3D] << ", " << N[Z_3D] << ")" << std::endl; -} - void convert_coord(gdouble &x, gdouble &y, gdouble &z, Geom::Matrix const &trans) { - Point p = Point(x, y); + Geom::Point p = Geom::Point(x, y); p *= trans; x = p[Geom::X]; y = p[Geom::Y]; -- cgit v1.2.3