HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Options.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP_Options.h (C++, Utility Library)
7  *
8  * COMMENTS: Subclass of UT_Options to provide some special functionality
9  * used by the SIM library.
10  *
11  */
12 
13 #ifndef _OP_OPTIONS_H_
14 #define _OP_OPTIONS_H_
15 
16 #include "OP_API.h"
17 #include <UT/UT_Matrix4.h>
18 #include <UT/UT_Options.h>
19 #include <SYS/SYS_Types.h>
20 
21 class OP_Node;
22 class PRM_Template;
23 class PRM_Parm;
24 class DEP_MicroNode;
25 class CH_Channel;
26 
27 /// This class stores a set of name/value pairs. Each value can be one of
28 /// several different data types. No automatic conversion between data types
29 /// is provided, so accessing existing data requires knowledge of both the
30 /// data name and the data type.
32 {
33 public:
34  explicit OP_Options();
35  ~OP_Options() override;
36 
37  // Delete the copy-ctor, but we still require the = operator
38  OP_Options(const OP_Options &) = delete;
39 
40  /// Set the data in this OP_Options to be an interpolation of the data
41  /// in two other OP_Options. The actual interpolation of each piece of
42  /// data is performed by the OP_OptionInterpolator, which allows
43  /// the interpolation behavior to be customized.
44  void interpolate(const OP_Options &source1,
45  const OP_Options &source2,
46  fpreal interp);
47 
48 
49  /// Utility function for setting an option based on a parm template.
50  /// This is useful for gathering information from operator parameters
51  /// to be passed on to OP_Data::setParameters().
52  /// This will harden op references to full paths, add parameter
53  /// tuples as vector2/vector3/etc options, and also build ramp
54  /// and multiparms. Ramps become strings and multiparms are
55  /// recursed and all their implied parms added.
56  /// Additionally, a dependency sink can be provided for all the
57  /// evaluated parameters to be added to.
58  /// Recursed multiparms may be added as option arrays rather
59  /// than as a list of parameters
60  /// If channels map is non-null, any parameter with channels will
61  /// instead add its default value and add itself to the channel map.
62  void setOptionFromTemplate(const OP_Node *node,
63  const PRM_Template &tplate,
64  int pi, fpreal time,
65  bool usetemplatetoken = false,
66  DEP_MicroNode *depnode = 0,
68  void setOptionFromTemplate(const OP_Node *node,
69  const PRM_Parm &parm,
70  const PRM_Template &tplate,
71  fpreal time,
72  bool usetemplatetoken = false,
73  DEP_MicroNode *depnode = 0,
75  const UT_StringRef *option_name=0,
76  bool expand_strings = true);
77 
78  /// Utility function for setting options based on channel names of a
79  /// parameter. This splits up a single parameter tuple into multiple
80  /// scalar options.
81  void setOptionFromParm(const OP_Node *node, int pi, int vi,
82  fpreal time);
83 
84  /// Utility function for setting an options based on the default value
85  /// stored in a parm template. This is used to gather default values
86  /// for initializing a OP_Data type. The parameter defaults are
87  /// gethered into a OP_Options data structure which is passed to
88  /// OP_Data::setParameters().
89  void setOptionFromTemplateDefault(const PRM_Template &tp);
90 
91  /// Returns how to interepret this template as an option type.
92  /// UT_OPTION_INVALID if unsupported.
93  static UT_OptionType getOptionTypeFromTemplate(const PRM_Template &tp);
94 
95  /// Sets an option based on strings coming from a command. This is
96  /// used by the dopsolvesetoption command. This funtion returns true
97  /// if the parameters make sense together and result in setting an
98  /// option. Otherwise false is returned.
99  bool setOptionFromCommand(const char *optionname,
100  const char *optionvalue,
101  fpreal optionvaluefloat,
102  UT_OptionType optiontype);
103 
104  /// Calculates a transform matrix based on standard transform options
105  /// like t, r, s, etc.
106  UT_DMatrix4 getTransformFromOptions() const;
107 
108  /// Set one OP_Options equal to another.
109  const OP_Options &operator=(const UT_Options &src);
110 
111 protected:
112  /// This function is called whenever data is added, removed, or changed.
113  /// If the name parameter is null, then multiple pieces of data were
114  /// changed simultaneously (probably through a load or assignment
115  /// operation). This function just calls OP_OptionsUser::optionChanged()
116  /// on each user of this data.
117  void optionChanged(const char *name) override;
118 
119  /// These functions perform the actual interpolation of each data type.
120  void getInterpolatedInt(int64 &value,
121  int64 source1,
122  int64 source2,
123  fpreal interp) const;
124  void getInterpolatedBool(bool &value,
125  bool source1,
126  bool source2,
127  fpreal interp) const;
128  void getInterpolatedFpreal(fpreal64 &value,
129  fpreal source1,
130  fpreal source2,
131  fpreal interp) const;
132  void getInterpolatedString(UT_StringHolder &value,
133  const UT_StringHolder &source1,
134  const UT_StringHolder &source2,
135  fpreal interp) const;
136  void getInterpolatedDict(UT_OptionsHolder &value,
137  const UT_OptionsHolder &source1,
138  const UT_OptionsHolder &source2,
139  fpreal interp) const;
140  void getInterpolatedVector2(UT_Vector2D &value,
141  const UT_Vector2D &source1,
142  const UT_Vector2D &source2,
143  fpreal interp) const;
144  void getInterpolatedVector3(UT_Vector3D &value,
145  const UT_Vector3D &source1,
146  const UT_Vector3D &source2,
147  fpreal interp) const;
148  void getInterpolatedVector4(UT_Vector4D &value,
149  const UT_Vector4D &source1,
150  const UT_Vector4D &source2,
151  fpreal interp) const;
152  void getInterpolatedQuaternion(UT_QuaternionD &value,
153  const UT_QuaternionD &source1,
154  const UT_QuaternionD &source2,
155  fpreal interp) const;
156  void getInterpolatedMatrix2(UT_Matrix2D &value,
157  const UT_Matrix2D &source1,
158  const UT_Matrix2D &source2,
159  fpreal interp) const;
160  void getInterpolatedMatrix3(UT_Matrix3D &value,
161  const UT_Matrix3D &source1,
162  const UT_Matrix3D &source2,
163  fpreal interp) const;
164  void getInterpolatedMatrix4(UT_Matrix4D &value,
165  const UT_Matrix4D &source1,
166  const UT_Matrix4D &source2,
167  fpreal interp) const;
168  void getInterpolatedIntArray(UT_Int64Array &value,
169  const UT_Int64Array &source1,
170  const UT_Int64Array &source2,
171  fpreal interp);
172  void getInterpolatedFprealArray(UT_Fpreal64Array &value,
173  const UT_Fpreal64Array &source1,
174  const UT_Fpreal64Array &source2,
175  fpreal interp);
176  void getInterpolatedStringArray(UT_StringArray &value,
177  const UT_StringArray &source1,
178  const UT_StringArray &source2,
179  fpreal interp);
180  void getInterpolatedDictArray(UT_Array<UT_OptionsHolder> &value,
181  const UT_Array<UT_OptionsHolder> &source1,
182  const UT_Array<UT_OptionsHolder> &source2,
183  fpreal interp);
184 };
185 
186 #endif
const UT_Options & operator=(const UT_Options &src)
Assignment operator.
GT_API const UT_StringHolder time
GLsizei const GLfloat * value
Definition: glcorearb.h:824
UT_OptionType
Definition: UT_Options.h:44
double fpreal64
Definition: SYS_Types.h:201
virtual void optionChanged(const char *name)
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
A map of string to various well defined value types.
Definition: UT_Options.h:87
__hostdev__ constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: NanoVDB.h:976
fpreal64 fpreal
Definition: SYS_Types.h:283
#define OP_API
Definition: OP_API.h:10
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
GLenum src
Definition: glcorearb.h:1793