2
0
Эх сурвалжийг харах

add optional undist_lut parameter to PfmVizzer::project()

David Rose 11 жил өмнө
parent
commit
255027b18d

+ 14 - 2
panda/src/grutil/pfmVizzer.cxx

@@ -54,7 +54,7 @@ PfmVizzer(PfmFile &pfm) : _pfm(pfm) {
 //               texture image.
 //               texture image.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void PfmVizzer::
 void PfmVizzer::
-project(const Lens *lens) {
+project(const Lens *lens, const PfmFile *undist_lut) {
   nassertv(_pfm.is_valid());
   nassertv(_pfm.is_valid());
 
 
   static LMatrix4f to_uv(0.5f, 0.0f, 0.0f, 0.0f,
   static LMatrix4f to_uv(0.5f, 0.0f, 0.0f, 0.0f,
@@ -77,7 +77,19 @@ project(const Lens *lens) {
           _pfm.set_point4(xi, yi, LVecBase4f(0, 0, 0, 0));
           _pfm.set_point4(xi, yi, LVecBase4f(0, 0, 0, 0));
         }
         }
       } else {
       } else {
-        p = to_uv.xform_point(LCAST(PN_float32, film));
+        // Now the lens gives us coordinates in the range [-1, 1].
+        // Rescale these to [0, 1].
+        LPoint3f uvw = film * to_uv;
+        
+        if (undist_lut != NULL) {
+          // Apply the undistortion map, if given.
+          LPoint3f p2;
+          undist_lut->calc_bilinear_point(p2, uvw[0], 1.0 - uvw[1]);
+          uvw = p2;
+          uvw[1] = 1.0 - uvw[1];
+        }
+        
+        p = uvw;
       }
       }
     }
     }
   }
   }

+ 1 - 1
panda/src/grutil/pfmVizzer.h

@@ -36,7 +36,7 @@ PUBLISHED:
   INLINE PfmFile &get_pfm();
   INLINE PfmFile &get_pfm();
   INLINE const PfmFile &get_pfm() const;
   INLINE const PfmFile &get_pfm() const;
 
 
-  BLOCKING void project(const Lens *lens);
+  BLOCKING void project(const Lens *lens, const PfmFile *undist_lut = NULL);
   BLOCKING void extrude(const Lens *lens);
   BLOCKING void extrude(const Lens *lens);
 
 
   INLINE void set_vis_inverse(bool vis_inverse);
   INLINE void set_vis_inverse(bool vis_inverse);