Cortex  10.0.0-a4
LensDistort.h
1 //
3 // Copyright (c) 2011, Weta Digital Limited. All rights reserved.
4 // Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // * Neither the name of Image Engine Design nor the names of any
18 // other contributors to this software may be used to endorse or
19 // promote products derived from this software without specific prior
20 // written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
35 
36 #ifndef IECORENUKE_LENSDISTORT_H
37 #define IECORENUKE_LENSDISTORT_H
38 
39 #include "DDImage/Knobs.h"
40 #include "DDImage/Row.h"
41 #include "DDImage/Thread.h"
42 #include "DDImage/Iop.h"
43 #include "DDImage/Filter.h"
44 #include "IECore/LensModel.h"
45 
46 namespace IECoreNuke
47 {
48 
59 class LensDistort : public DD::Image::Iop
60 {
63  struct PluginAttribute
64  {
65  public:
66 
67  PluginAttribute( std::string name, double defaultValue = 0. ) :
68  m_name( name ),
69  m_knob( NULL ),
70  m_value( defaultValue ),
71  m_low( 0. ),
72  m_high( 1. )
73  {};
74 
75  PluginAttribute() :
76  m_name( "Unused" ),
77  m_knob( NULL ),
78  m_value( 0. ),
79  m_low( 0. ),
80  m_high( 1. )
81  {};
82 
83  std::string m_name;
84  DD::Image::Knob *m_knob;
85  std::string m_script;
86  double m_value;
87  double m_low;
88  double m_high;
89  };
90 
91  typedef std::vector< PluginAttribute > PluginAttributeList;
92 
93  public:
94 
95  enum
96  {
97  Distort,
98  Undistort
99  };
100 
101  LensDistort( Node* node );
102 
103  inline int getLensModel() const { return (int)knob("model")->get_value(); };
104  inline PluginAttributeList &attributeList() { return m_pluginAttributes; };
105 
106  virtual void knobs( DD::Image::Knob_Callback f );
107  virtual int knob_changed( DD::Image::Knob* k );
108  virtual void append( DD::Image::Hash &hash );
109  virtual void _request( int x, int y, int r, int t, DD::Image::ChannelMask channels, int count );
110  virtual const char *Class() const;
111  virtual const char *node_help() const;
112  virtual void _validate( bool for_real );
113  virtual void engine( int y, int x, int r, DD::Image::ChannelMask channels, DD::Image::Row & outrow );
114 
115  static void buildDynamicKnobs( void*, DD::Image::Knob_Callback f );
116  static void addDynamicKnobs( void*, DD::Image::Knob_Callback f );
117  static const Iop::Description m_description;
118  static DD::Image::Op *build( Node *node );
119 
120  private:
121 
123  static const char ** modelNames();
124  static int indexFromModelName( const char *name );
125 
127  void setLensModel( IECore::ConstCompoundObjectPtr parameters );
128  void setLensModel( std::string modelName );
129 
134  void updateLensModel( bool updateKnobsFromParameters = false );
135 
137  bool getFileSequencePath( std::string& path );
138 
143  bool setLensFromFile( std::string &returnPath );
144 
146  void updatePluginAttributesFromKnobs();
147 
150  void updateUI();
151 
153  const int m_nThreads;
154 
156  std::vector< IECore::LensModelPtr > m_model;
157 
159  DD::Image::Lock* m_locks;
160 
162  PluginAttributeList m_pluginAttributes;
163 
165  int m_lensModel;
166 
168  int m_numNewKnobs;
169 
171  DD::Image::Filter m_filter;
172 
174  DD::Image::Knob *m_kModel;
175 
177  int m_mode;
178 
180  DD::Image::Knob* m_lastStaticKnob;
181 
183  const char *m_assetPath;
184 
186  bool m_hasValidFileSequence;
187  bool m_useFileSequence;
188 };
189 
190 };
191 
192 #endif
The IECoreNuke namespace holds all the functionality of libIECoreNuke.
Definition: BoolParameterHandler.h:40
Definition: LensDistort.h:59