From 29e5d746131b8989ad576be82a83e6c1b3510ffb Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 28 Mar 2012 00:12:56 +0000 Subject: [PATCH] LMatrix4::xform_point_general_in_place() --- panda/src/grutil/pfmFile.cxx | 3 +-- panda/src/linmath/lmatrix4_src.I | 27 +++++++++++++++++++++ panda/src/linmath/lmatrix4_src.h | 6 +++++ panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx | 5 +++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/panda/src/grutil/pfmFile.cxx b/panda/src/grutil/pfmFile.cxx index 63e13bc2b5..da7f49c188 100755 --- a/panda/src/grutil/pfmFile.cxx +++ b/panda/src/grutil/pfmFile.cxx @@ -534,8 +534,7 @@ xform(const LMatrix4 &transform) { if (_has_no_data_value && (*ti) == _no_data_value) { continue; } - - (*ti) = (*ti) * transform; + transform.xform_point_general_in_place(*ti); } } diff --git a/panda/src/linmath/lmatrix4_src.I b/panda/src/linmath/lmatrix4_src.I index d1d5422246..a2e27538b1 100644 --- a/panda/src/linmath/lmatrix4_src.I +++ b/panda/src/linmath/lmatrix4_src.I @@ -862,6 +862,21 @@ xform_point(const FLOATNAME(LVecBase3) &v) const { return v_res; } +//////////////////////////////////////////////////////////////////// +// Function: LMatrix4::xform_point_general +// Access: Public +// Description: The matrix transforms a 3-component point (including +// translation component) and returns the result, as a +// fully general operation. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: +xform_point_general(const FLOATNAME(LVecBase3) &v) const { + TAU_PROFILE("LVecBase3 LMatrix4::xform_point_general(const LVecBase3 &)", " ", TAU_USER); + FLOATNAME(LVecBase4) v4(v[0], v[1], v[2], 1.0); + v4 = xform(v4); + return FLOATNAME(LVecBase3)(v4[0] / v4[3], v4[1] / v4[3], v4[2] / v4[3]); +} + //////////////////////////////////////////////////////////////////// // Function: LMatrix4::xform_vec // Access: Public @@ -943,6 +958,18 @@ xform_point_in_place(FLOATNAME(LVecBase3) &v) const { #endif // HAVE_EIGEN } +//////////////////////////////////////////////////////////////////// +// Function: LMatrix4::xform_point_general_in_place +// Access: Public +// Description: The matrix transforms a 3-component point (including +// translation component), as a fully general operation. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH void FLOATNAME(LMatrix4):: +xform_point_general_in_place(FLOATNAME(LVecBase3) &v) const { + TAU_PROFILE("void LMatrix4::xform_point_general_in_place(LVecBase3 &)", " ", TAU_USER); + v = xform_point_general(v); +} + //////////////////////////////////////////////////////////////////// // Function: LMatrix4::xform_vec_in_place // Access: Public diff --git a/panda/src/linmath/lmatrix4_src.h b/panda/src/linmath/lmatrix4_src.h index afb8f07f84..d7a445ccde 100644 --- a/panda/src/linmath/lmatrix4_src.h +++ b/panda/src/linmath/lmatrix4_src.h @@ -137,6 +137,9 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVecBase3) xform_point(const FLOATNAME(LVecBase3) &v) const; + INLINE_LINMATH FLOATNAME(LVecBase3) + xform_point_general(const FLOATNAME(LVecBase3) &v) const; + INLINE_LINMATH FLOATNAME(LVecBase3) xform_vec(const FLOATNAME(LVecBase3) &v) const; @@ -149,6 +152,9 @@ PUBLISHED: INLINE_LINMATH void xform_point_in_place(FLOATNAME(LVecBase3) &v) const; + INLINE_LINMATH void + xform_point_general_in_place(FLOATNAME(LVecBase3) &v) const; + INLINE_LINMATH void xform_vec_in_place(FLOATNAME(LVecBase3) &v) const; diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx index 5e7655cb18..b7dc992c96 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx @@ -899,6 +899,7 @@ write_data(xel *array, xelval *alpha) { switch ( get_color_type() ) { case CT_color: + case CT_grayscale: // This call is a bit of fakery to convert our proper 2-d array of // xels to an indirect 2-d array of pixels. We make it look like a // single row of _x_size * _y_size pixels. @@ -907,7 +908,7 @@ write_data(xel *array, xelval *alpha) { // regardless of the number of colors we can read. chv = ppm_computecolorhist( (pixel **)&array, _x_size * _y_size, 1, 256, &colors ); - if ( chv == (colorhist_vector) 0 ) { + if ( chv == (colorhist_vector) 0 || true) { pnmimage_tiff_cat.debug() << colors << " colors found; too many for a palette.\n" << "Writing a 24-bit RGB file.\n"; @@ -936,10 +937,12 @@ write_data(xel *array, xelval *alpha) { grayscale = false; break; + /* case CT_grayscale: chv = (colorhist_vector) 0; grayscale = true; break; + */ default: break;