add set_no_data_value()

This commit is contained in:
David Rose 2012-03-13 16:18:33 +00:00
parent 252b7bc656
commit c8c7ea5dfb
3 changed files with 78 additions and 29 deletions

View File

@ -73,15 +73,15 @@ get_num_channels() const {
// Function: PfmFile::has_point
// Access: Published
// Description: Returns true if there is a valid point at x, y. This
// always returns true unless the zero_special flag is
// enabled, in which case it returns false if the point
// at x, y is zero.
// always returns true unless a "no data" value has been
// set, in which case it returns false if the point at
// x, y is the "no data" value.
////////////////////////////////////////////////////////////////////
INLINE bool PfmFile::
has_point(int x, int y) const {
if ((x >= 0 && x < _x_size) &&
(y >= 0 && y < _y_size)) {
return (!_zero_special || _table[y * _x_size + x] != LPoint3::zero());
return (!_has_no_data_value || _table[y * _x_size + x] != _no_data_value);
}
return false;
}
@ -138,22 +138,64 @@ modify_point(int x, int y) {
// Description: Sets the zero_special flag. When this flag is true,
// values of (0, 0, 0) in the pfm file are treated as a
// special case, and are not processed.
//
// This is a special case of set_no_data_value().
////////////////////////////////////////////////////////////////////
INLINE void PfmFile::
set_zero_special(bool zero_special) {
_zero_special = zero_special;
if (zero_special) {
set_no_data_value(LPoint3::zero());
} else {
clear_no_data_value();
}
}
////////////////////////////////////////////////////////////////////
// Function: PfmFile::get_zero_special
// Function: PfmFile::set_no_data_value
// Access: Published
// Description: Returns the zero_special flag. When this flag is true,
// values of (0, 0, 0) in the pfm file are treated as a
// special case, and are not processed.
// Description: Sets the special value that means "no data" when it
// appears in the pfm file.
////////////////////////////////////////////////////////////////////
INLINE void PfmFile::
set_no_data_value(const LPoint3 &no_data_value) {
_has_no_data_value = true;
_no_data_value = no_data_value;
}
////////////////////////////////////////////////////////////////////
// Function: PfmFile::set_no_data_value
// Access: Published
// Description: Removes the special value that means "no data" when it
// appears in the pfm file. All points will thus be
// considered valid.
////////////////////////////////////////////////////////////////////
INLINE void PfmFile::
clear_no_data_value() {
_has_no_data_value = false;
_no_data_value = LPoint3::zero();
}
////////////////////////////////////////////////////////////////////
// Function: PfmFile::has_no_data_value
// Access: Published
// Description: Returns whether a "no data" value has been
// established by set_no_data_value().
////////////////////////////////////////////////////////////////////
INLINE bool PfmFile::
get_zero_special() const {
return _zero_special;
has_no_data_value() const {
return _has_no_data_value;
}
////////////////////////////////////////////////////////////////////
// Function: PfmFile::get_no_data_value
// Access: Published
// Description: If has_no_data_value() returns true, this returns the
// particular "no data" value.
////////////////////////////////////////////////////////////////////
INLINE const LPoint3 &PfmFile::
get_no_data_value() const {
nassertr(_has_no_data_value, LPoint3::zero());
return _no_data_value;
}
////////////////////////////////////////////////////////////////////

View File

@ -36,7 +36,8 @@
////////////////////////////////////////////////////////////////////
PfmFile::
PfmFile() {
_zero_special = false;
_has_no_data_value = false;
_no_data_value = LPoint3::zero();
_vis_inverse = false;
_vis_2d = false;
clear();
@ -54,7 +55,8 @@ PfmFile(const PfmFile &copy) :
_y_size(copy._y_size),
_scale(copy._scale),
_num_channels(copy._num_channels),
_zero_special(copy._zero_special),
_has_no_data_value(copy._has_no_data_value),
_no_data_value(copy._no_data_value),
_vis_inverse(copy._vis_inverse),
_vis_2d(copy._vis_2d)
{
@ -72,7 +74,8 @@ operator = (const PfmFile &copy) {
_y_size = copy._y_size;
_scale = copy._scale;
_num_channels = copy._num_channels;
_zero_special = copy._zero_special;
_has_no_data_value = copy._has_no_data_value;
_no_data_value = copy._no_data_value;
_vis_inverse = copy._vis_inverse;
_vis_2d = copy._vis_2d;
}
@ -352,7 +355,7 @@ calc_average_point(LPoint3 &result, PN_stdfloat x, PN_stdfloat y, PN_stdfloat ra
for (yi = min_y; yi <= max_y; ++yi) {
for (xi = min_x; xi <= max_x; ++xi) {
const LPoint3 &p = _table[yi * _x_size + xi];
if (_zero_special && p == LPoint3::zero()) {
if (_has_no_data_value && p == _no_data_value) {
continue;
}
@ -413,7 +416,7 @@ calc_min_max(LVecBase3 &min_depth, LVecBase3 &max_depth) const {
Table::const_iterator ti;
for (ti = _table.begin(); ti != _table.end(); ++ti) {
const LPoint3 &p = (*ti);
if (_zero_special && p == LPoint3::zero()) {
if (_has_no_data_value && p == _no_data_value) {
continue;
}
@ -528,7 +531,7 @@ xform(const LMatrix4 &transform) {
Table::iterator ti;
for (ti = _table.begin(); ti != _table.end(); ++ti) {
if (_zero_special && (*ti) == LPoint3::zero()) {
if (_has_no_data_value && (*ti) == _no_data_value) {
continue;
}
@ -558,7 +561,7 @@ project(const Lens *lens) {
Table::iterator ti;
for (ti = _table.begin(); ti != _table.end(); ++ti) {
if (_zero_special && (*ti) == LPoint3::zero()) {
if (_has_no_data_value && (*ti) == _no_data_value) {
continue;
}
@ -582,13 +585,13 @@ merge(const PfmFile &other) {
nassertv(is_valid() && other.is_valid());
nassertv(other._x_size == _x_size && other._y_size == _y_size);
if (!_zero_special) {
if (!_has_no_data_value) {
// Trivial no-op.
return;
}
for (size_t i = 0; i < _table.size(); ++i) {
if (_table[i] == LPoint3::zero()) {
if (_table[i] == _no_data_value) {
_table[i] = other._table[i];
}
}
@ -701,7 +704,7 @@ compute_planar_bounds(const LPoint2 &center, PN_stdfloat point_dist, PN_stdfloat
} else {
Table::const_iterator ti;
for (ti = _table.begin(); ti != _table.end(); ++ti) {
if (_zero_special && (*ti) == LPoint3::zero()) {
if (_has_no_data_value && (*ti) == _no_data_value) {
continue;
}
LPoint3 point = (*ti) * rinv;
@ -1042,11 +1045,11 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
for (int yi = y_begin; yi < y_end - 1; ++yi) {
for (int xi = x_begin; xi < x_end - 1; ++xi) {
if (_zero_special) {
if (get_point(xi, yi) == LPoint3::zero() ||
get_point(xi, yi + 1) == LPoint3::zero() ||
get_point(xi + 1, yi + 1) == LPoint3::zero() ||
get_point(xi + 1, yi) == LPoint3::zero()) {
if (_has_no_data_value) {
if (get_point(xi, yi) == _no_data_value ||
get_point(xi, yi + 1) == _no_data_value ||
get_point(xi + 1, yi + 1) == _no_data_value ||
get_point(xi + 1, yi) == _no_data_value) {
continue;
}
}
@ -1164,7 +1167,7 @@ void PfmFile::
box_filter_point(LPoint3 &result, PN_stdfloat &coverage,
int x, int y, PN_stdfloat x_contrib, PN_stdfloat y_contrib) const {
const LPoint3 &point = get_point(x, y);
if (_zero_special && point == LPoint3::zero()) {
if (_has_no_data_value && point == _no_data_value) {
return;
}

View File

@ -59,7 +59,10 @@ PUBLISHED:
BLOCKING bool calc_min_max(LVecBase3 &min_points, LVecBase3 &max_points) const;
INLINE void set_zero_special(bool zero_special);
INLINE bool get_zero_special() const;
INLINE void set_no_data_value(const LPoint3 &no_data_value);
INLINE void clear_no_data_value();
INLINE bool has_no_data_value() const;
INLINE const LPoint3 &get_no_data_value() const;
BLOCKING void resize(int new_x_size, int new_y_size);
BLOCKING void reverse_rows();
@ -118,7 +121,8 @@ private:
PN_stdfloat _scale;
int _num_channels;
bool _zero_special;
bool _has_no_data_value;
LPoint3 _no_data_value;
bool _vis_inverse;
PT(InternalName) _flat_texcoord_name;
bool _vis_2d;