Browse Source

pfm-trans -nan

David Rose 12 years ago
parent
commit
686b69fe84

+ 2 - 0
pandatool/src/objegg/objToEggConverter.cxx

@@ -188,6 +188,7 @@ process(const Filename &filename) {
   _vn_table.clear();
   _vn_table.clear();
   _rgb_table.clear();
   _rgb_table.clear();
   _vt_table.clear();
   _vt_table.clear();
+  _xvt_table.clear();
   _ref_plane_res.set(1.0, 1.0);
   _ref_plane_res.set(1.0, 1.0);
   _v4_given = false;
   _v4_given = false;
   _vt3_given = false;
   _vt3_given = false;
@@ -592,6 +593,7 @@ process_node(const Filename &filename) {
   _vn_table.clear();
   _vn_table.clear();
   _rgb_table.clear();
   _rgb_table.clear();
   _vt_table.clear();
   _vt_table.clear();
+  _xvt_table.clear();
   _ref_plane_res.set(1.0, 1.0);
   _ref_plane_res.set(1.0, 1.0);
   _v4_given = false;
   _v4_given = false;
   _vt3_given = false;
   _vt3_given = false;

+ 35 - 2
pandatool/src/pfmprogs/pfmTrans.cxx

@@ -30,6 +30,7 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PfmTrans::
 PfmTrans::
 PfmTrans() {
 PfmTrans() {
+  _no_data_nan_num_channels = 0;
   _got_transform = false;
   _got_transform = false;
   _transform = LMatrix4::ident_mat();
   _transform = LMatrix4::ident_mat();
   _rotate = 0;
   _rotate = 0;
@@ -46,6 +47,11 @@ PfmTrans() {
      "Treats (0,0,0) in the pfm file as a special don't-touch value.",
      "Treats (0,0,0) in the pfm file as a special don't-touch value.",
      &PfmTrans::dispatch_none, &_got_zero_special);
      &PfmTrans::dispatch_none, &_got_zero_special);
 
 
+  add_option
+    ("nan", "num_channels", 0,
+     "Treats a NaN in any of the first num_channels channels as a special don't-touch value.",
+     &PfmTrans::dispatch_int, &_got_no_data_nan, &_no_data_nan_num_channels);
+
   add_option
   add_option
     ("resize", "width,height", 0,
     ("resize", "width,height", 0,
      "Resamples the pfm file to scale it to the indicated grid size.  "
      "Resamples the pfm file to scale it to the indicated grid size.  "
@@ -62,7 +68,7 @@ PfmTrans() {
   add_option
   add_option
     ("autocrop", "", 0,
     ("autocrop", "", 0,
      "Automatically crops to the smallest possible rectangle that includes "
      "Automatically crops to the smallest possible rectangle that includes "
-     "all points.  Requires -z.",
+     "all points.  Requires -z or -nan.",
      &PfmTrans::dispatch_none, &_got_autocrop);
      &PfmTrans::dispatch_none, &_got_autocrop);
 
 
   add_option
   add_option
@@ -118,6 +124,11 @@ PfmTrans() {
     ("vistex", "texture.jpg", 60,
     ("vistex", "texture.jpg", 60,
      "Specifies the name of the texture to apply to the visualization.",
      "Specifies the name of the texture to apply to the visualization.",
      &PfmTrans::dispatch_filename, &_got_vistex_filename, &_vistex_filename);
      &PfmTrans::dispatch_filename, &_got_vistex_filename, &_vistex_filename);
+
+  add_option
+    ("ls", "filename.txt", 60,
+     "Lists the points in the file to the indicated text file.",
+     &PfmTrans::dispatch_filename, &_got_ls_filename, &_ls_filename);
 }
 }
 
 
 
 
@@ -162,7 +173,11 @@ run() {
 bool PfmTrans::
 bool PfmTrans::
 process_pfm(const Filename &input_filename, PfmFile &file) {
 process_pfm(const Filename &input_filename, PfmFile &file) {
   PfmVizzer vizzer(file);
   PfmVizzer vizzer(file);
-  file.set_zero_special(_got_zero_special);
+  if (_got_no_data_nan) {
+    file.set_no_data_nan(_no_data_nan_num_channels);
+  } else if (_got_zero_special) {
+    file.set_zero_special(true);
+  }
   vizzer.set_vis_inverse(_got_vis_inverse);
   vizzer.set_vis_inverse(_got_vis_inverse);
   vizzer.set_vis_2d(_got_vis_2d);
   vizzer.set_vis_2d(_got_vis_2d);
 
 
@@ -238,6 +253,24 @@ process_pfm(const Filename &input_filename, PfmFile &file) {
     mesh.reparent_to(_mesh_root);
     mesh.reparent_to(_mesh_root);
   }
   }
 
 
+  if (_got_ls_filename) {
+    pofstream out;
+    _ls_filename.set_text();
+    if (_ls_filename.open_write(out, true)) {
+      for (int yi = 0; yi < file.get_y_size(); ++yi) {
+        for (int xi = 0; xi < file.get_x_size(); ++xi) {
+          if (file.has_point(xi, yi)) {
+            out << "(" << xi << ", " << yi << "):";
+            for (int ci = 0; ci < file.get_num_channels(); ++ci) {
+              out << " " << file.get_channel(xi, yi, ci);
+            }
+            out << "\n";
+          }
+        }
+      }
+    }
+  }
+
   Filename output_filename;
   Filename output_filename;
   if (_got_output_filename) {
   if (_got_output_filename) {
     output_filename = _output_filename;
     output_filename = _output_filename;

+ 4 - 0
pandatool/src/pfmprogs/pfmTrans.h

@@ -52,6 +52,8 @@ private:
   Filenames _input_filenames;
   Filenames _input_filenames;
 
 
   bool _got_zero_special;
   bool _got_zero_special;
+  bool _got_no_data_nan;
+  int _no_data_nan_num_channels;
   bool _got_vis_inverse;
   bool _got_vis_inverse;
   bool _got_vis_2d;
   bool _got_vis_2d;
   bool _got_resize;
   bool _got_resize;
@@ -71,6 +73,8 @@ private:
   Filename _vis_filename;
   Filename _vis_filename;
   bool _got_vistex_filename;
   bool _got_vistex_filename;
   Filename _vistex_filename;
   Filename _vistex_filename;
+  bool _got_ls_filename;
+  Filename _ls_filename;
 
 
   bool _got_transform;
   bool _got_transform;
   LMatrix4 _transform;
   LMatrix4 _transform;