Cortex  10.0.0-a4
CurveLookup.h
1 //
3 // Copyright (c) 2007-2010, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IECORENUKE_CURVELOOKUP_H
36 #define IECORENUKE_CURVELOOKUP_H
37 
38 #include "DDImage/Description.h"
39 #if ( DD_IMAGE_VERSION_MAJOR >= 5 && DD_IMAGE_VERSION_MINOR > 0 ) || DD_IMAGE_VERSION_MAJOR >= 6
40 #define IECORENUKE_NO_ANIMATION
41 #endif
42 
43 #ifdef IECORENUKE_NO_ANIMATION
44 #include "DDImage/LookupCurves.h"
45 #else
46 #include "DDImage/Animation.h"
47 #endif
48 
49 #include "DDImage/Knobs.h"
50 
51 #include <vector>
52 
53 namespace IECoreNuke
54 {
55 
62 template<class T>
64 {
65 
66  public :
67 
68  typedef T BaseType;
69 
70  CurveLookup( const std::string &name, const std::string &label, const std::string &toolTip = "" );
71  ~CurveLookup();
76  int addCurve( const std::string &name, const std::string &defaultCurve = "y C 0 1" );
78  void knob( DD::Image::Knob_Callback f );
81  void validate( T xMin = 0, T xMax = 1, unsigned numSamples=100 );
83  void append( DD::Image::Hash &hash ) const;
85  void append( unsigned curveIndex, DD::Image::Hash &hash ) const;
89  void validate( unsigned curveIndex, T xMin = 0, T xMax = 1, unsigned numSamples=100 );
92  inline T evaluate( unsigned curveIndex, T x ) const;
93 
94  private :
95 
97  CurveLookup( const CurveLookup<T> &other );
98  const CurveLookup<T> &operator=( const CurveLookup &other );
99 
100  unsigned numCurves() const;
101 
102  std::string m_name;
103  std::string m_label;
104  std::string m_toolTip;
105 
106 #ifdef IECORENUKE_NO_ANIMATION
107  std::vector<std::string> *m_namesAndDefaultsStrings;
108  std::vector<DD::Image::CurveDescription> *m_curveDescriptions;
109  DD::Image::LookupCurves *m_curves;
110 #else
111  std::vector<std::string> m_namesAndDefaultsStrings;
112  std::vector<const char *> m_namesAndDefaultsPtrs;
113  std::vector<const DD::Image::Animation *> m_curves;
114 #endif
115 
116  struct Lookup
117  {
118  std::vector<T> values;
119  float xMin;
120  float xMax;
121  float xMult;
122  };
123 
124  std::vector<Lookup> m_lookups;
125 
126 };
127 
128 } // namespace IECoreNuke
129 
130 #include "IECoreNuke/CurveLookup.inl"
131 
132 #endif // IECORENUKE_CURVELOOKUP_H
void validate(T xMin=0, T xMax=1, unsigned numSamples=100)
int addCurve(const std::string &name, const std::string &defaultCurve="y C 0 1")
void knob(DD::Image::Knob_Callback f)
Call this in the knobs() method for a node, to build the interface for the curves.
Definition: CurveLookup.h:63
The IECoreNuke namespace holds all the functionality of libIECoreNuke.
Definition: BoolParameterHandler.h:40
T evaluate(unsigned curveIndex, T x) const
void append(DD::Image::Hash &hash) const
Append all the curves to the specified Hash.