Panda3D
pfmVizzer.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pfmVizzer.h
10  * @author drose
11  * @date 2012-09-30
12  */
13 
14 #ifndef PFMVIZZER_H
15 #define PFMVIZZER_H
16 
17 #include "pandabase.h"
18 #include "nodePath.h"
19 #include "internalName.h"
20 #include "lens.h"
21 #include "pfmFile.h"
22 
23 class GeomNode;
24 class Lens;
25 class GeomVertexWriter;
26 
27 /**
28  * This class aids in the visualization and manipulation of PfmFile objects.
29  */
30 class EXPCL_PANDA_GRUTIL PfmVizzer {
31 PUBLISHED:
32  explicit PfmVizzer(PfmFile &pfm);
33  INLINE ~PfmVizzer();
34  INLINE PfmFile &get_pfm();
35  INLINE const PfmFile &get_pfm() const;
36 
37  BLOCKING void project(const Lens *lens, const PfmFile *undist_lut = nullptr);
38  BLOCKING void extrude(const Lens *lens);
39 
40  INLINE void set_vis_inverse(bool vis_inverse);
41  INLINE bool get_vis_inverse() const;
42  INLINE void set_flat_texcoord_name(InternalName *flat_texcoord_name);
43  INLINE void clear_flat_texcoord_name();
44  INLINE InternalName *get_flat_texcoord_name() const;
45  INLINE void set_vis_2d(bool vis_2d);
46  INLINE bool get_vis_2d() const;
47  INLINE void set_keep_beyond_lens(bool keep_beyond_lens);
48  INLINE bool get_keep_beyond_lens() const;
49 
50  INLINE void set_vis_blend(const PNMImage *vis_blend);
51  INLINE void clear_vis_blend();
52  INLINE const PNMImage *get_vis_blend() const;
53 
54  INLINE void set_aux_pfm(const PfmFile *pfm);
55  INLINE void clear_aux_pfm();
56  INLINE const PfmFile *get_aux_pfm() const;
57 
58  enum ColumnType {
59  CT_texcoord2,
60  CT_texcoord3,
61  CT_vertex1,
62  CT_vertex2,
63  CT_vertex3,
64  CT_normal3,
65  CT_blend1,
66  CT_aux_vertex1,
67  CT_aux_vertex2,
68  CT_aux_vertex3,
69  };
70  void clear_vis_columns();
71  void add_vis_column(ColumnType source, ColumnType target,
72  InternalName *name,
73  const TransformState *transform = nullptr, const Lens *lens = nullptr,
74  const PfmFile *undist_lut = nullptr);
75 
76  BLOCKING NodePath generate_vis_points() const;
77 
78  enum MeshFace {
79  MF_front = 0x01,
80  MF_back = 0x02,
81  MF_both = 0x03,
82  };
83  BLOCKING NodePath generate_vis_mesh(MeshFace face = MF_front) const;
84 
85  BLOCKING double calc_max_u_displacement() const;
86  BLOCKING double calc_max_v_displacement() const;
87  BLOCKING void make_displacement(PNMImage &result, double max_u, double max_v, bool for_32bit) const;
88  BLOCKING void make_displacement(PfmFile &result, double max_u, double max_v, bool for_32bit) const;
89 
90 private:
91  bool uses_aux_pfm() const;
92  void r_fill_displacement(PNMImage &result, int xi, int yi,
93  double nxi, double nyi, double u_scale, double v_scale,
94  int distance) const;
95  void r_fill_displacement(PfmFile &result, int xi, int yi,
96  double nxi, double nyi, double u_scale, double v_scale,
97  int distance) const;
98 
99  void make_vis_mesh_geom(GeomNode *gnode, bool inverted) const;
100 
101 
102  class VisColumn {
103  public:
104  INLINE VisColumn();
105  bool add_data(const PfmVizzer &vizzer, GeomVertexWriter &vwriter, int xi, int yi, bool reverse_normals) const;
106  bool transform_point(LPoint2f &point) const;
107  bool transform_point(LPoint3f &point) const;
108  bool transform_vector(LVector3f &vec) const;
109 
110  public:
111  ColumnType _source;
112  ColumnType _target;
113  PT(InternalName) _name;
114  CPT(TransformState) _transform;
115  CPT(Lens) _lens;
116  const PfmFile *_undist_lut;
117  };
119 
120  static void add_vis_column(VisColumns &vis_columns,
121  ColumnType source, ColumnType target,
122  InternalName *name,
123  const TransformState *transform = nullptr,
124  const Lens *lens = nullptr, const PfmFile *undist_lut = nullptr);
125  void build_auto_vis_columns(VisColumns &vis_columns, bool for_points) const;
126  CPT(GeomVertexFormat) make_array_format(const VisColumns &vis_columns) const;
127 
128 private:
129  PfmFile &_pfm;
130  const PfmFile *_aux_pfm;
131 
132  bool _vis_inverse;
133  PT(InternalName) _flat_texcoord_name;
134  bool _vis_2d;
135  bool _keep_beyond_lens;
136  const PNMImage *_vis_blend;
137 
138  VisColumns _vis_columns;
139 
140  friend class VisColumn;
141 };
142 
143 #include "pfmVizzer.I"
144 
145 #endif
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
This class defines the physical layout of the vertex data stored within a Geom.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:41
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
Definition: pfmFile.h:31
This class aids in the visualization and manipulation of PfmFile objects.
Definition: pfmVizzer.h:30
Indicates a coordinate-system transform on vertices.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.