From c277d802a00c5f49e8286fa3b384f619e0a30392 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 6 Jun 2013 02:05:35 +0000 Subject: [PATCH] pull_spot() --- panda/src/pnmimage/pfmFile.cxx | 37 ++++++++++++++++++++++++++++++++++ panda/src/pnmimage/pfmFile.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/panda/src/pnmimage/pfmFile.cxx b/panda/src/pnmimage/pfmFile.cxx index 8475e29c3e..3591b72795 100644 --- a/panda/src/pnmimage/pfmFile.cxx +++ b/panda/src/pnmimage/pfmFile.cxx @@ -1529,6 +1529,43 @@ clear_to_texcoords(int x_size, int y_size) { } } +//////////////////////////////////////////////////////////////////// +// Function: PfmFile::pull_spot +// Access: Published +// Description: Applies delta * t to the point values within radius +// distance of (xc, yc). The t value is scaled from 1.0 +// at the center to 0.0 at radius, and this scale +// follows the specified exponent. Returns the number +// of points affected. +//////////////////////////////////////////////////////////////////// +int PfmFile:: +pull_spot(const LPoint4f &delta, double xc, double yc, + double radius, double exponent) { + int minx = max((int)cceil(xc - radius), 0); + int maxx = min((int)cfloor(xc + radius), _x_size - 1); + int miny = max((int)cceil(yc - radius), 0); + int maxy = min((int)cfloor(yc + radius), _y_size - 1); + + int count = 0; + for (int yi = miny; yi <= maxy; ++yi) { + for (int xi = minx; xi <= maxx; ++xi) { + double r2 = (xi - xc) * (xi - xc) + (yi - yc) * (yi - yc); + if (r2 >= 1.0) { + continue; + } + PN_float32 t = (PN_float32)pow(1.0 - sqrt(r2), exponent); + + PN_float32 *f = &_table[(yi * _x_size + xi) * _num_channels]; + for (int ci = 0; ci < _num_channels; ++ci) { + f[ci] += delta[ci] * t; + } + ++count; + } + } + + return count; +} + //////////////////////////////////////////////////////////////////// // Function: PfmFile::calc_tight_bounds // Access: Published diff --git a/panda/src/pnmimage/pfmFile.h b/panda/src/pnmimage/pfmFile.h index b1697481ec..608cac0c56 100644 --- a/panda/src/pnmimage/pfmFile.h +++ b/panda/src/pnmimage/pfmFile.h @@ -124,6 +124,9 @@ PUBLISHED: BLOCKING void apply_crop(int x_begin, int x_end, int y_begin, int y_end); BLOCKING void clear_to_texcoords(int x_size, int y_size); + BLOCKING int pull_spot(const LPoint4f &delta, double xc, double yc, + double radius, double exponent); + bool calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point) const; BLOCKING PT(BoundingHexahedron) compute_planar_bounds(const LPoint2f ¢er, PN_float32 point_dist, PN_float32 sample_radius, bool points_only) const; INLINE BLOCKING PT(BoundingHexahedron) compute_planar_bounds(const LPoint2d ¢er, PN_float32 point_dist, PN_float32 sample_radius, bool points_only) const;