From 5cbc4180732eb0ef586d87b49dd387a35a173a61 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 2 Nov 2011 22:50:39 +0000 Subject: [PATCH] add project() --- panda/src/grutil/pfmFile.cxx | 34 ++++++++++++++++++++++++++++++++++ panda/src/grutil/pfmFile.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/panda/src/grutil/pfmFile.cxx b/panda/src/grutil/pfmFile.cxx index cff7c4c98a..5965064981 100755 --- a/panda/src/grutil/pfmFile.cxx +++ b/panda/src/grutil/pfmFile.cxx @@ -26,6 +26,7 @@ #include "geomPoints.h" #include "geomTriangles.h" #include "geomVertexWriter.h" +#include "lens.h" #include "look_at.h" //////////////////////////////////////////////////////////////////// @@ -524,6 +525,39 @@ xform(const LMatrix4 &transform) { } } +//////////////////////////////////////////////////////////////////// +// Function: PfmFile::project +// Access: Published +// Description: Adjusts each (x, y, z) point of the Pfm file by +// projecting it through the indicated lens, converting +// each point to a (u, v, 0) texture coordinate. The +// resulting file can be generated to a mesh (with +// set_vis_inverse(true) and generate_vis_mesh(true)) +// that will apply the lens distortion to an arbitrary +// texture image. +//////////////////////////////////////////////////////////////////// +void PfmFile:: +project(const Lens *lens) { + nassertv(is_valid()); + + static LMatrix4 to_uv(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, + 0.5, 0.5, 0.0, 1.0); + + Table::iterator ti; + for (ti = _table.begin(); ti != _table.end(); ++ti) { + if (_zero_special && (*ti) == LPoint3::zero()) { + continue; + } + + LPoint3 &p = (*ti); + LPoint3 film; + lens->project(p, film); + p = to_uv.xform_point(film); + } +} + //////////////////////////////////////////////////////////////////// // Function: PfmFile::compute_planar_bounds // Access: Published diff --git a/panda/src/grutil/pfmFile.h b/panda/src/grutil/pfmFile.h index 1c97f316b9..2f438b31eb 100755 --- a/panda/src/grutil/pfmFile.h +++ b/panda/src/grutil/pfmFile.h @@ -21,6 +21,7 @@ #include "boundingHexahedron.h" class GeomNode; +class Lens; //////////////////////////////////////////////////////////////////// // Class : PfmFile @@ -62,6 +63,7 @@ PUBLISHED: void resize(int new_x_size, int new_y_size); void reverse_rows(); void xform(const LMatrix4 &transform); + void project(const Lens *lens); PT(BoundingHexahedron) compute_planar_bounds(double point_dist, double sample_radius) const;