Procházet zdrojové kódy

PfmVizzer::set_keep_beyond_lens(), and some bugfixes

David Rose před 12 roky
rodič
revize
1885ccdb97

+ 1 - 1
panda/src/gobj/geomPrimitive.h

@@ -98,7 +98,7 @@ PUBLISHED:
   INLINE int get_first_vertex() const;
   INLINE int get_num_vertices() const;
   INLINE int get_vertex(int i) const;
-  MAKE_SEQ(get_vertices, get_num_vertices, get_vertex);
+  MAKE_SEQ(get_vertex_list, get_num_vertices, get_vertex);
   void add_vertex(int vertex);
   INLINE void add_vertices(int v1, int v2);
   INLINE void add_vertices(int v1, int v2, int v3);

+ 25 - 0
panda/src/grutil/pfmVizzer.I

@@ -138,6 +138,31 @@ get_vis_2d() const {
   return _vis_2d;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmVizzer::set_keep_beyond_lens
+//       Access: Published
+//  Description: Sets the keep_beyond_lens flag.  When this flag is
+//               true, points that fall outside of the normal lens
+//               range in project() or in add_vis_column() will be
+//               retained anyway; when it is false, these points will
+//               be discarded.
+////////////////////////////////////////////////////////////////////
+INLINE void PfmVizzer::
+set_keep_beyond_lens(bool keep_beyond_lens) {
+  _keep_beyond_lens = keep_beyond_lens;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PfmVizzer::get_keep_beyond_lens
+//       Access: Published
+//  Description: Returns the keep_beyond_lens flag.  See
+//               set_keep_beyond_lens().
+////////////////////////////////////////////////////////////////////
+INLINE bool PfmVizzer::
+get_keep_beyond_lens() const {
+  return _keep_beyond_lens;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmVizzer::set_vis_blend
 //       Access: Published

+ 18 - 6
panda/src/grutil/pfmVizzer.cxx

@@ -36,6 +36,7 @@ PfmVizzer::
 PfmVizzer(PfmFile &pfm) : _pfm(pfm) {
   _vis_inverse = false;
   _vis_2d = false;
+  _keep_beyond_lens = false;
   _vis_blend = NULL;
 }
 
@@ -67,7 +68,7 @@ project(const Lens *lens) {
       LPoint3f &p = _pfm.modify_point(xi, yi);
 
       LPoint3 film;
-      if (!lens->project(LCAST(PN_stdfloat, p), film)) {
+      if (!lens->project(LCAST(PN_stdfloat, p), film) && !_keep_beyond_lens) {
         if (_pfm.has_no_data_value()) {
           _pfm.set_point4(xi, yi, _pfm.get_no_data_value());
         } else {
@@ -561,6 +562,7 @@ r_fill_displacement(PNMImage &result, int xi, int yi,
 ////////////////////////////////////////////////////////////////////
 void PfmVizzer::
 make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
+  static const bool keep_beyond_lens = true;
   int num_x_cells = 1;
   int num_y_cells = 1;
 
@@ -682,10 +684,11 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
             continue;
           }
 
-          if (skip_points[(yi - y_begin) * x_size + (xi - x_begin)] ||
-              skip_points[(yi - y_begin + 1) * x_size + (xi - x_begin)] ||
-              skip_points[(yi - y_begin) * x_size + (xi - x_begin + 1)] ||
-              skip_points[(yi - y_begin + 1) * x_size + (xi - x_begin + 1)]) {
+          if (!keep_beyond_lens &&
+              (skip_points[(yi - y_begin) * x_size + (xi - x_begin)] ||
+               skip_points[(yi - y_begin + 1) * x_size + (xi - x_begin)] ||
+               skip_points[(yi - y_begin) * x_size + (xi - x_begin + 1)] ||
+               skip_points[(yi - y_begin + 1) * x_size + (xi - x_begin + 1)])) {
             continue;
           }
 
@@ -964,7 +967,16 @@ add_data(const PfmVizzer &vizzer, GeomVertexWriter &vwriter, int xi, int yi, boo
         n[2] += v0[0] * v1[1] - v0[1] * v1[0];
       }
       n.normalize();
-      nassertr(!n.is_nan(), false);
+      if (n.is_nan()) {
+        /*
+        cerr << "\nnan!\n"
+             << "  v[0] = " << v[0] << "\n"
+             << "  v[1] = " << v[1] << "\n"
+             << "  v[2] = " << v[2] << "\n";
+        */
+        n.set(0, 0, 0);
+        success = false;
+      }
       if (flip) {
         n = -n;
       }

+ 3 - 0
panda/src/grutil/pfmVizzer.h

@@ -46,6 +46,8 @@ PUBLISHED:
   INLINE InternalName *get_flat_texcoord_name() const;
   INLINE void set_vis_2d(bool vis_2d);
   INLINE bool get_vis_2d() const;
+  INLINE void set_keep_beyond_lens(bool keep_beyond_lens);
+  INLINE bool get_keep_beyond_lens() const;
 
   INLINE void set_vis_blend(const PNMImage *vis_blend);
   INLINE void clear_vis_blend();
@@ -119,6 +121,7 @@ private:
   bool _vis_inverse;
   PT(InternalName) _flat_texcoord_name;
   bool _vis_2d;
+  bool _keep_beyond_lens;
   const PNMImage *_vis_blend;
 
   VisColumns _vis_columns;

+ 5 - 5
panda/src/pnmimage/pfmFile.cxx

@@ -262,7 +262,7 @@ write(ostream &out, const Filename &fullpath) {
     return false;
   }
 
-  PNMWriter *writer = make_writer(fullpath);
+  PNMWriter *writer = make_writer(&out, false, fullpath);
   if (writer == (PNMWriter *)NULL) {
     return false;
   }
@@ -1381,11 +1381,11 @@ calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point) const {
         found_any = true;
       } else {
         min_point.set(min(min_point[0], point[0]),
-                      min(min_point[0], point[0]),
-                      min(min_point[0], point[0]));
+                      min(min_point[1], point[1]),
+                      min(min_point[2], point[2]));
         max_point.set(max(max_point[0], point[0]),
-                      max(max_point[0], point[0]),
-                      max(max_point[0], point[0]));
+                      max(max_point[1], point[1]),
+                      max(max_point[2], point[2]));
       }
     }
   }