Panda3D
 All Classes Functions Variables Enumerations
pfmFile.h
00001 // Filename: pfmFile.h
00002 // Created by:  drose (23Dec10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PFMFILE_H
00016 #define PFMFILE_H
00017 
00018 #include "pandabase.h"
00019 #include "luse.h"
00020 #include "nodePath.h"
00021 #include "boundingHexahedron.h"
00022 #include "internalName.h"
00023 
00024 class GeomNode;
00025 class Lens;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : PfmFile
00029 // Description : Defines a pfm file, a 2-d table of floating-point
00030 //               numbers, either 3-component or 1-component.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDA_GRUTIL PfmFile {
00033 PUBLISHED:
00034   PfmFile();
00035   PfmFile(const PfmFile &copy);
00036   void operator = (const PfmFile &copy);
00037 
00038   void clear();
00039   void clear(int x_size, int y_size, int num_channels);
00040 
00041   BLOCKING bool read(const Filename &fullpath);
00042   BLOCKING bool read(istream &in);
00043   BLOCKING bool write(const Filename &fullpath);
00044   BLOCKING bool write(ostream &out);
00045 
00046   INLINE bool is_valid() const;
00047 
00048   INLINE int get_x_size() const;
00049   INLINE int get_y_size() const;
00050   INLINE PN_stdfloat get_scale() const;
00051   INLINE int get_num_channels() const;
00052 
00053   INLINE bool has_point(int x, int y) const;
00054   INLINE const LPoint3 &get_point(int x, int y) const;
00055   INLINE void set_point(int x, int y, const LVecBase3 &point);
00056   INLINE LPoint3 &modify_point(int x, int y);
00057 
00058   BLOCKING bool calc_average_point(LPoint3 &result, PN_stdfloat x, PN_stdfloat y, PN_stdfloat radius) const;
00059   BLOCKING bool calc_min_max(LVecBase3 &min_points, LVecBase3 &max_points) const;
00060 
00061   INLINE void set_zero_special(bool zero_special);
00062   INLINE bool get_zero_special() const;
00063 
00064   BLOCKING void resize(int new_x_size, int new_y_size);
00065   BLOCKING void reverse_rows();
00066   BLOCKING void xform(const LMatrix4 &transform);
00067   BLOCKING void project(const Lens *lens);
00068   BLOCKING void merge(const PfmFile &other);
00069 
00070   BLOCKING PT(BoundingHexahedron) compute_planar_bounds(PN_stdfloat point_dist, PN_stdfloat sample_radius) const;
00071   BLOCKING PT(BoundingHexahedron) compute_planar_bounds(const LPoint2 &center, PN_stdfloat point_dist, PN_stdfloat sample_radius, bool points_only) const;
00072   void compute_sample_point(LPoint3 &result,
00073                             PN_stdfloat x, PN_stdfloat y, PN_stdfloat sample_radius) const;
00074 
00075   INLINE void set_vis_inverse(bool vis_inverse);
00076   INLINE bool get_vis_inverse() const;
00077   INLINE void set_flat_texcoord_name(InternalName *flat_texcoord_name);
00078   INLINE void clear_flat_texcoord_name();
00079   INLINE InternalName *get_flat_texcoord_name() const;
00080   INLINE void set_vis_2d(bool vis_2d);
00081   INLINE bool get_vis_2d() const;
00082 
00083   BLOCKING NodePath generate_vis_points() const;
00084 
00085   enum MeshFace {
00086     MF_front = 0x01,
00087     MF_back  = 0x02,
00088     MF_both  = 0x03,
00089   };
00090   BLOCKING NodePath generate_vis_mesh(MeshFace face = MF_front) const;
00091 
00092 private:
00093   void make_vis_mesh_geom(GeomNode *gnode, bool inverted) const;
00094 
00095   void box_filter_region(LPoint3 &result,
00096                          PN_stdfloat x0, PN_stdfloat y0, PN_stdfloat x1, PN_stdfloat y1) const;
00097   void box_filter_line(LPoint3 &result, PN_stdfloat &coverage,
00098                        PN_stdfloat x0, int y, PN_stdfloat x1, PN_stdfloat y_contrib) const;
00099   void box_filter_point(LPoint3 &result, PN_stdfloat &coverage,
00100                         int x, int y, PN_stdfloat x_contrib, PN_stdfloat y_contrib) const;
00101 
00102   class MiniGridCell {
00103   public:
00104     MiniGridCell() : _ti(-1), _dist(-1) { }
00105     int _ti;
00106     int _dist;
00107   };
00108 
00109   void fill_mini_grid(MiniGridCell *mini_grid, int x_size, int y_size, 
00110                       int xi, int yi, int dist, int ti) const;
00111 
00112 private:
00113   typedef pvector<LPoint3> Table;
00114   Table _table;
00115 
00116   int _x_size;
00117   int _y_size;
00118   PN_stdfloat _scale;
00119   int _num_channels;
00120 
00121   bool _zero_special;
00122   bool _vis_inverse;
00123   PT(InternalName) _flat_texcoord_name;
00124   bool _vis_2d;
00125 };
00126 
00127 #include "pfmFile.I"
00128 
00129 #endif
 All Classes Functions Variables Enumerations