Browse Source

resolve some float-double confusion

David Rose 13 years ago
parent
commit
7fd2a81412
3 changed files with 94 additions and 15 deletions
  1. 87 1
      panda/src/grutil/pfmFile.I
  2. 0 12
      panda/src/grutil/pfmFile.cxx
  3. 7 2
      panda/src/grutil/pfmFile.h

+ 87 - 1
panda/src/grutil/pfmFile.I

@@ -120,6 +120,18 @@ set_point(int x, int y, const LVecBase3f &point) {
   } 
   } 
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::set_point
+//       Access: Published
+//  Description: Replaces the 3-component point value at the indicated
+//               point.  In a 1-channel image, the channel value is in
+//               the x component.
+////////////////////////////////////////////////////////////////////
+INLINE void PfmFile::
+set_point(int x, int y, const LVecBase3d &point) {
+  set_point(x, y, LCAST(PN_float32, point));
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::modify_point
 //     Function: PfmFile::modify_point
 //       Access: Published
 //       Access: Published
@@ -178,6 +190,18 @@ set_point4(int x, int y, const LVecBase4f &point) {
   } 
   } 
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::set_point4
+//       Access: Published
+//  Description: Replaces the 4-component point value at the indicated
+//               point.  In a 1-channel image, the channel value is in
+//               the x component.
+////////////////////////////////////////////////////////////////////
+INLINE void PfmFile::
+set_point4(int x, int y, const LVecBase4d &point) {
+  set_point4(x, y, LCAST(PN_float32, point));
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::modify_point4
 //     Function: PfmFile::modify_point4
 //       Access: Published
 //       Access: Published
@@ -205,7 +229,24 @@ modify_point4(int x, int y) {
 //               0, get_y_size()).
 //               0, get_y_size()).
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool PfmFile::
 INLINE bool PfmFile::
-calc_autocrop(LVecBase4 &range) const {
+calc_autocrop(LVecBase4f &range) const {
+  int x_begin, x_end, y_begin, y_end;
+  bool result = calc_autocrop(x_begin, x_end, y_begin, y_end);
+  range.set(x_begin, x_end, y_begin, y_end);
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::calc_autocrop
+//       Access: Published
+//  Description: Computes the minimum range of x and y across the PFM
+//               file that include all points.  If there are no points
+//               with no_data_value in the grid--that is, all points
+//               are included--then this will return (0, get_x_size(),
+//               0, get_y_size()).
+////////////////////////////////////////////////////////////////////
+INLINE bool PfmFile::
+calc_autocrop(LVecBase4d &range) const {
   int x_begin, x_end, y_begin, y_end;
   int x_begin, x_end, y_begin, y_end;
   bool result = calc_autocrop(x_begin, x_end, y_begin, y_end);
   bool result = calc_autocrop(x_begin, x_end, y_begin, y_end);
   range.set(x_begin, x_end, y_begin, y_end);
   range.set(x_begin, x_end, y_begin, y_end);
@@ -252,6 +293,17 @@ set_no_data_chan4(bool chan4) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::set_no_data_value
+//       Access: Published
+//  Description: Sets the special value that means "no data" when it
+//               appears in the pfm file.
+////////////////////////////////////////////////////////////////////
+INLINE void PfmFile::
+set_no_data_value(const LPoint4d &no_data_value) {
+  set_no_data_value(LCAST(PN_float32, no_data_value));
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::set_no_data_value
 //     Function: PfmFile::set_no_data_value
 //       Access: Published
 //       Access: Published
@@ -289,6 +341,40 @@ get_no_data_value() const {
   return _no_data_value;
   return _no_data_value;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::xform
+//       Access: Published
+//  Description: Applies the indicated transform matrix to all points
+//               in-place.
+////////////////////////////////////////////////////////////////////
+INLINE void PfmFile::
+xform(const LMatrix4d &transform) {
+  xform(LCAST(PN_float32, transform));
+}
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::compute_planar_bounds
+//       Access: Published
+//  Description: Computes the minmax bounding volume of the points in
+//               3-D space, assuming the points represent a
+//               mostly-planar surface.
+//
+//               This algorithm works by sampling the (square)
+//               sample_radius pixels at the four point_dist corners
+//               around the center (cx - pd, cx + pd) and so on, to
+//               approximate the plane of the surface.  Then all of
+//               the points are projected into that plane and the
+//               bounding volume of the entire mesh within that plane
+//               is determined.  If points_only is true, the bounding
+//               volume of only those four points is determined.
+//
+//               center, point_dist and sample_radius are in UV space,
+//               i.e. in the range 0..1.
+////////////////////////////////////////////////////////////////////
+INLINE PT(BoundingHexahedron) PfmFile::
+compute_planar_bounds(const LPoint2d &center, PN_float32 point_dist, PN_float32 sample_radius, bool points_only) const {
+  return compute_planar_bounds(LCAST(PN_float32, center), point_dist, sample_radius, points_only);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::set_vis_inverse
 //     Function: PfmFile::set_vis_inverse
 //       Access: Published
 //       Access: Published

+ 0 - 12
panda/src/grutil/pfmFile.cxx

@@ -1001,18 +1001,6 @@ apply_crop(int x_begin, int x_end, int y_begin, int y_end) {
   _y_size = new_y_size;
   _y_size = new_y_size;
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: PfmFile::compute_planar_bounds
-//       Access: Published
-//  Description: This version of this method exists for temporary
-//               backward compatibility only.
-////////////////////////////////////////////////////////////////////
-PT(BoundingHexahedron) PfmFile::
-compute_planar_bounds(PN_float32 point_dist, PN_float32 sample_radius) const {
-  return compute_planar_bounds(LPoint2f(0.5, 0.5), point_dist, sample_radius, false);
-}
-
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::compute_planar_bounds
 //     Function: PfmFile::compute_planar_bounds
 //       Access: Published
 //       Access: Published

+ 7 - 2
panda/src/grutil/pfmFile.h

@@ -59,15 +59,18 @@ PUBLISHED:
   INLINE bool has_point(int x, int y) const;
   INLINE bool has_point(int x, int y) const;
   INLINE const LPoint3f &get_point(int x, int y) const;
   INLINE const LPoint3f &get_point(int x, int y) const;
   INLINE void set_point(int x, int y, const LVecBase3f &point);
   INLINE void set_point(int x, int y, const LVecBase3f &point);
+  INLINE void set_point(int x, int y, const LVecBase3d &point);
   INLINE LPoint3f &modify_point(int x, int y);
   INLINE LPoint3f &modify_point(int x, int y);
   INLINE const LPoint4f &get_point4(int x, int y) const;
   INLINE const LPoint4f &get_point4(int x, int y) const;
   INLINE void set_point4(int x, int y, const LVecBase4f &point);
   INLINE void set_point4(int x, int y, const LVecBase4f &point);
+  INLINE void set_point4(int x, int y, const LVecBase4d &point);
   INLINE LPoint4f &modify_point4(int x, int y);
   INLINE LPoint4f &modify_point4(int x, int y);
 
 
   BLOCKING bool calc_average_point(LPoint3f &result, PN_float32 x, PN_float32 y, PN_float32 radius) const;
   BLOCKING bool calc_average_point(LPoint3f &result, PN_float32 x, PN_float32 y, PN_float32 radius) const;
   BLOCKING bool calc_min_max(LVecBase3f &min_points, LVecBase3f &max_points) const;
   BLOCKING bool calc_min_max(LVecBase3f &min_points, LVecBase3f &max_points) const;
   BLOCKING bool calc_autocrop(int &x_begin, int &x_end, int &y_begin, int &y_end) const;
   BLOCKING bool calc_autocrop(int &x_begin, int &x_end, int &y_begin, int &y_end) const;
-  BLOCKING INLINE bool calc_autocrop(LVecBase4 &range) const;
+  BLOCKING INLINE bool calc_autocrop(LVecBase4f &range) const;
+  BLOCKING INLINE bool calc_autocrop(LVecBase4d &range) const;
  
  
   bool is_row_empty(int y, int x_begin, int x_end) const;
   bool is_row_empty(int y, int x_begin, int x_end) const;
   bool is_column_empty(int x, int y_begin, int y_end) const;
   bool is_column_empty(int x, int y_begin, int y_end) const;
@@ -75,6 +78,7 @@ PUBLISHED:
   INLINE void set_zero_special(bool zero_special);
   INLINE void set_zero_special(bool zero_special);
   INLINE void set_no_data_chan4(bool chan4);
   INLINE void set_no_data_chan4(bool chan4);
   void set_no_data_value(const LPoint4f &no_data_value);
   void set_no_data_value(const LPoint4f &no_data_value);
+  INLINE void set_no_data_value(const LPoint4d &no_data_value);
   INLINE void clear_no_data_value();
   INLINE void clear_no_data_value();
   INLINE bool has_no_data_value() const;
   INLINE bool has_no_data_value() const;
   INLINE const LPoint4f &get_no_data_value() const;
   INLINE const LPoint4f &get_no_data_value() const;
@@ -83,12 +87,13 @@ PUBLISHED:
   BLOCKING void reverse_rows();
   BLOCKING void reverse_rows();
   BLOCKING void flip(bool flip_x, bool flip_y, bool transpose);
   BLOCKING void flip(bool flip_x, bool flip_y, bool transpose);
   BLOCKING void xform(const LMatrix4f &transform);
   BLOCKING void xform(const LMatrix4f &transform);
+  INLINE BLOCKING void xform(const LMatrix4d &transform);
   BLOCKING void project(const Lens *lens);
   BLOCKING void project(const Lens *lens);
   BLOCKING void merge(const PfmFile &other);
   BLOCKING void merge(const PfmFile &other);
   BLOCKING void apply_crop(int x_begin, int x_end, int y_begin, int y_end);
   BLOCKING void apply_crop(int x_begin, int x_end, int y_begin, int y_end);
 
 
-  BLOCKING PT(BoundingHexahedron) compute_planar_bounds(PN_float32 point_dist, PN_float32 sample_radius) const;
   BLOCKING PT(BoundingHexahedron) compute_planar_bounds(const LPoint2f &center, PN_float32 point_dist, PN_float32 sample_radius, bool points_only) const;
   BLOCKING PT(BoundingHexahedron) compute_planar_bounds(const LPoint2f &center, PN_float32 point_dist, PN_float32 sample_radius, bool points_only) const;
+  INLINE BLOCKING PT(BoundingHexahedron) compute_planar_bounds(const LPoint2d &center, PN_float32 point_dist, PN_float32 sample_radius, bool points_only) const;
   void compute_sample_point(LPoint3f &result,
   void compute_sample_point(LPoint3f &result,
                             PN_float32 x, PN_float32 y, PN_float32 sample_radius) const;
                             PN_float32 x, PN_float32 y, PN_float32 sample_radius) const;