mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
store_mask() with a range limit
This commit is contained in:
parent
ffabf6925c
commit
059c929b79
@ -467,6 +467,48 @@ store_mask(PNMImage &pnmimage) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PfmFile::store_mask
|
||||||
|
// Access: Published
|
||||||
|
// Description: Stores 1 or 0 values into the indicated PNMImage,
|
||||||
|
// according to has_point() for each pixel. Each valid
|
||||||
|
// point gets a 1 value; each nonexistent point gets a 0
|
||||||
|
// value.
|
||||||
|
//
|
||||||
|
// This flavor of store_mask also checks whether the
|
||||||
|
// valid points are within the specified min/max range.
|
||||||
|
// Any valid points without the condition min_point[c]
|
||||||
|
// <= value[c] <= max_point[c], for any c, are stored
|
||||||
|
// with a 0 in the mask.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool PfmFile::
|
||||||
|
store_mask(PNMImage &pnmimage, const LVecBase4f &min_point, const LVecBase4f &max_point) const {
|
||||||
|
if (!is_valid()) {
|
||||||
|
pnmimage.clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pnmimage.clear(get_x_size(), get_y_size(), 1, 255);
|
||||||
|
for (int yi = 0; yi < get_y_size(); ++yi) {
|
||||||
|
for (int xi = 0; xi < get_x_size(); ++xi) {
|
||||||
|
if (!has_point(xi, yi)) {
|
||||||
|
pnmimage.set_gray(xi, yi, 0);
|
||||||
|
} else {
|
||||||
|
const float *value = &_table[(yi * _x_size + xi) * _num_channels];
|
||||||
|
bool in_range = true;
|
||||||
|
for (int ci = 0; ci < _num_channels; ++ci) {
|
||||||
|
if (value[ci] < min_point[ci] || value[ci] > max_point[ci]) {
|
||||||
|
in_range = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pnmimage.set_gray(xi, yi, (float)in_range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PfmFile::fill
|
// Function: PfmFile::fill
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -50,6 +50,7 @@ PUBLISHED:
|
|||||||
BLOCKING bool load(const PNMImage &pnmimage);
|
BLOCKING bool load(const PNMImage &pnmimage);
|
||||||
BLOCKING bool store(PNMImage &pnmimage) const;
|
BLOCKING bool store(PNMImage &pnmimage) const;
|
||||||
BLOCKING bool store_mask(PNMImage &pnmimage) const;
|
BLOCKING bool store_mask(PNMImage &pnmimage) const;
|
||||||
|
BLOCKING bool store_mask(PNMImage &pnmimage, const LVecBase4f &min_point, const LVecBase4f &max_point) const;
|
||||||
|
|
||||||
INLINE bool is_valid() const;
|
INLINE bool is_valid() const;
|
||||||
MAKE_PROPERTY(valid, is_valid);
|
MAKE_PROPERTY(valid, is_valid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user