ldpk
nuke_ld_3de4_base.h
1 #pragma once
2 
3 #include <DDImage/Iop.h>
4 #include <DDImage/Box.h>
5 #include <DDImage/Filter.h>
6 #include <DDImage/Knobs.h>
7 #include <DDImage/Pixel.h>
8 #include <DDImage/Row.h>
9 #include <DDImage/Tile.h>
10 #include <DDImage/NukeWrapper.h>
11 #include <ldpk/ldpk_ldp_builtin.h>
12 #include <ldpk/ldpk_line_cache.h>
13 
14 using namespace std;
15 
17  {
18  double _x,_y;
19  bool _status;
20 
21  nuke_ld_lut_entry():_x(HUGE_VAL),_y(HUGE_VAL),_status(false)
22  { }
23  nuke_ld_lut_entry(double x,double y,bool status):_x(x),_y(y),_status(status)
24  { }
25  double x() const
26  { return _x; }
27  double y() const
28  { return _y; }
29  bool status() const
30  { return _status; }
31  bool defd() const
32  { return (_x != HUGE_VAL) && (_y != HUGE_VAL); }
33  };
34 
37 class nuke_ld_3de4_base:public DD::Image::Iop
38  {
39 private:
40  DD::Image::Filter _filter;
41 // Anzahl der modellabhaengigen Parameter, wird im Konstruktor ermittelt.
42  int _num_par;
43 // Der Wert des Richtungsknobs
44  int _knob_direction;
45 // Current output mode (extension by RSP, see .C-file)
46  int _knob_output_mode;
47 // With LUT-Caching
48  int _knob_lut_cache;
49 // Bbox-Mode
50  int _knob_bbox_mode;
51 // Boundary for bbox-mode 2: l,b,r,t
52  float _knob_bbox_margin[2];
53 // Field-of-View
54  double _xa_fov_unit,_ya_fov_unit;
55  double _xb_fov_unit,_yb_fov_unit;
56  double _xd_fov_unit,_yd_fov_unit;
57  double _inv_xd_fov_unit,_inv_yd_fov_unit;
58 // Find out number of parameters per type and store here:
59  int _num_par_adjustable_double;
60  int _num_par_double;
61  int _num_par_int;
62  int _num_par_string;
63  int _num_par_file;
64  int _num_par_toggle;
65 // Wir verwenden hier absichtlich nicht std::vector, weil wir uns darauf verlassen
66 // muessen, dass die Werte nicht im Speicher verschoben werden. Es gibt einen Beispiel-Node,
67 // bei Nuke, der lustigerweise KnobParade heisst, da sehen wir, wie das geht.
68  double* _values_adjustable_double;
69  double* _values_double;
70  int* _values_int;
71  const char** _values_string;
72  const char** _values_file;
73  bool* _values_toggle;
74 // Default values for string- and file-knobs.
75  char** _defaults_string;
76  char** _defaults_file;
77 // The ld model instance.
78  typedef tde4_ld_plugin ldm_type;
79  ldm_type* _ldm;
80 // LUT-Caching
81  DD::Image::Hash _lut_hash;
83 // In _request we compute a bounding box from our ldm, intersect it with
84 // input0 and request that box from input0. Nuke's Devguide says, we should
85 // never lock tiles larger than this request-box, so we keep it here and
86 // take it into account in engine().
87  DD::Image::Box _box_requested;
88 
89 // Map x-coordinate from unit cordinates to fov coordinates.
90  double map_in_fov_x(double x_unit) const
91  { return (x_unit - _xa_fov_unit) * _inv_xd_fov_unit; }
92 // Map y-coordinate from unit cordinates to fov coordinates.
93  double map_in_fov_y(double y_unit) const
94  { return (y_unit - _ya_fov_unit) * _inv_yd_fov_unit; }
95 // Map x-coordinate from fov cordinates to unit coordinates.
96  double map_out_fov_x(double x_fov) const
97  { return x_fov * _xd_fov_unit + _xa_fov_unit; }
98 // Map y-coordinate from fov cordinates to unit coordinates.
99  double map_out_fov_y(double y_fov) const
100  { return y_fov * _yd_fov_unit + _ya_fov_unit; }
101 
102 // Model and parameter names in 3DE4 are human-readable, with characters
103 // like ",", "-" and space in it. This method eliminates maximum substrings containing
104 // other than [a-zA-Z0-9] and replaces them by a single underscore. The empty string is
105 // mapped to "_". A leading [0-9] is supplemented by a leading underscore.
106 // The result has the form of an identifier in C and Python.
107  std::string nukify_name(const std::string& name);
108 // Anscheinend von keiner Basisklasse gefordert.
109  enum direction_enum { distort = 0,undistort = 1 };
110  DD::Image::Box bounds(direction_enum,int x,int y,int r,int t);
111 // LDM-Parameter auf default
112  void set_default_values();
113 // Check for implementation errors
114  void check_indices(int i_par_adjustable_double,int i_par_double,int i_par_int,int i_par_string,int i_par_file,int i_par_toggle,int i_debug) const;
115 
116 protected:
117 /***** begin debugging ****************************************/
118 // Define the environment variable and get charming messages in stdout.
119 // Environment variable NUKE_DEBUG_REQUEST_SDV
120  bool _verbose_request;
121 // Environment variable NUKE_DEBUG_VALIDATE_SDV
122  bool _verbose_validate;
123 // Environment variable NUKE_DEBUG_CONSTRUCTOR_SDV
124  bool _verbose_constructor;
125 // Environment variable NUKE_DEBUG_DESTRUCTOR_SDV
126  bool _verbose_destructor;
127 /***** end debugging ******************************************/
128 
129 public:
130  nuke_ld_3de4_base(Node* node,ldm_type* ldm);
131  virtual ~nuke_ld_3de4_base();
132 
133  void knobs(DD::Image::Knob_Callback f);
134  void _validate(bool);
135  void _request(int x,int y,int r,int t,DD::Image::ChannelMask channels,int count);
136  void _open();
137  void engine(int y,int x,int r,DD::Image::ChannelMask channels,DD::Image::Row& out);
138 
139  static const DD::Image::Iop::Description description;
140  };
Definition: nuke_ld_3de4_base.h:16
Lens Distortion Plugin Base Class.
Definition: tde4_ld_plugin.h:29
The baseclass for Nuke plugins around LDPK-based lens distortion models. In order to implement a Nuke...
Definition: nuke_ld_3de4_base.h:37