SeExpr
Editable.h
Go to the documentation of this file.
1/*
2* Copyright Disney Enterprises, Inc. All rights reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License
6* and the following modification to it: Section 6 Trademarks.
7* deleted and replaced with:
8*
9* 6. Trademarks. This License does not grant permission to use the
10* trade names, trademarks, service marks, or product names of the
11* Licensor and its affiliates, except as required for reproducing
12* the content of the NOTICE file.
13*
14* You may obtain a copy of the License at
15* http://www.apache.org/licenses/LICENSE-2.0
16*
17* @file Editable.h
18* @author Andrew Selle
19*/
20#ifndef __Editable__
21#define __Editable__
22#include <sstream>
23#include <SeExpr2/Vec.h>
24#include <SeExpr2/Curve.h>
25#include <cstdio>
26#include <cstring>
27#ifdef SEEXPR_USE_ANIMLIB
28#include <animlib/AnimCurve.h>
29#include <animlib/AnimKeyframe.h>
30#endif
31#include <ExprDeepWater.h>
32
33inline void printVal(std::stringstream& stream, double v) { stream << v; }
34inline void printVal(std::stringstream& stream, const SeExpr2::Vec3d& v) {
35 stream << "[" << v[0] << "," << v[1] << "," << v[2] << "]";
36}
37
38#define UNUSED(x) (void)(x)
39
40struct Editable {
41 std::string name;
43
44 Editable(const std::string& name, int startPos, int endPos) : name(name), startPos(startPos), endPos(endPos) {}
45
46 void updatePositions(const Editable& other) {
47 startPos = other.startPos;
48 endPos = other.endPos;
49 }
50
51 virtual ~Editable() {} // must have this to ensure destruction
52
54 virtual bool parseComment(const std::string& comment) = 0;
55 virtual std::string str() const { return std::string("<unknown>"); }
56 virtual void appendString(std::stringstream& stream) const = 0;
57 virtual bool controlsMatch(const Editable&) const = 0;
58};
59
60struct NumberEditable : public Editable {
61 double v;
62 double min, max;
63 bool isInt;
64 NumberEditable(const std::string& name, int startPos, int endPos, double val)
65 : Editable(name, startPos, endPos), v(val), min(0), max(1), isInt(false) {}
66
67 bool parseComment(const std::string& comment) {
68 if (comment.find('.') != std::string::npos || comment.find('e') != std::string::npos) {
69 float fmin, fmax;
70 if (sscanf(comment.c_str(), "#%f,%f", &fmin, &fmax) == 2) {
71 min = fmin;
72 max = fmax;
73 isInt = false;
74 return true;
75 }
76 }
77 int imin, imax;
78 if (sscanf(comment.c_str(), "#%d,%d", &imin, &imax) == 2) {
79 min = imin;
80 max = imax;
81 isInt = true;
82 return true;
83 }
84 return true;
85 }
86 std::string str() const {
87 std::stringstream s;
88 s << name << " " << v << " in [" << min << "," << max << "] subset " << (isInt ? "Integers" : "Reals");
89 return s.str();
90 }
91 void appendString(std::stringstream& stream) const { stream << v; }
92
93 virtual bool controlsMatch(const Editable& other) const {
94 if (const NumberEditable* o = dynamic_cast<const NumberEditable*>(&other)) {
95 return min == o->min && max == o->max && v == o->v && isInt == o->isInt && name == o->name;
96 } else
97 return false;
98 }
99};
100
101struct VectorEditable : public Editable {
103 double min, max;
105 VectorEditable(const std::string& name, int startPos, int endPos, const SeExpr2::Vec3d& val)
106 : Editable(name, startPos, endPos), v(val), min(0), max(1), isColor(true) {}
107
108 bool parseComment(const std::string& comment) {
109 float fmin, fmax;
110 int numParsed = sscanf(comment.c_str(), "#%f,%f", &fmin, &fmax);
111 if (numParsed == 2) {
112 isColor = false;
113 min = fmin;
114 max = fmax;
115 }
116 return true;
117 }
118 std::string str() const {
119 std::stringstream s;
120 s << name << " " << v << " in [" << min << "," << max << "]";
121 return s.str();
122 }
123
124 void appendString(std::stringstream& stream) const { printVal(stream, v); }
125
126 virtual bool controlsMatch(const Editable& other) const {
127 if (const VectorEditable* o = dynamic_cast<const VectorEditable*>(&other)) {
128 return min == o->min && max == o->max && v == o->v && name == o->name;
129 } else
130 return false;
131 }
132};
133
134struct StringEditable : public Editable {
135 std::string v;
136 std::string type;
137 StringEditable(int startPos, int endPos, const std::string& val) : Editable("unknown", startPos, endPos), v(val) {}
138
139 bool parseComment(const std::string& comment) {
140 char namebuf[1024], typebuf[1024];
141 int parsed = sscanf(comment.c_str(), "#%s %s", typebuf, namebuf);
142 if (parsed == 2) {
143 name = namebuf;
144 type = typebuf;
145 return true;
146 } else {
147 return false;
148 }
149 }
150
151 void appendString(std::stringstream& stream) const {
152 // TODO: escape strs
153 stream << "\"" << v << "\"";
154 }
155 std::string str() const {
156 std::stringstream s;
157 s << name << " " << type << " = " << v;
158 return s.str();
159 }
160
161 virtual bool controlsMatch(const Editable& other) const {
162 if (const StringEditable* o = dynamic_cast<const StringEditable*>(&other)) {
163 return v == o->v && type == o->type && name == o->name;
164 } else
165 return false;
166 }
167};
168
169template <class TVAL>
171 typedef typename SeExpr2::Curve<TVAL> Curve;
172 typedef typename SeExpr2::Curve<TVAL>::CV CV;
174
175 std::vector<CV> cvs;
176 GenericCurveEditable(const std::string& name, int startPos, int endPos) : Editable(name, startPos, endPos) {}
177
178 void add(double x, const TVAL& y, int interp) { cvs.push_back(CV(x, y, InterpType(interp))); }
179
180 bool parseComment(const std::string& /*comment*/) { return true; }
181 std::string str() const {
182 std::stringstream s;
183 s << name << " ccurve";
184 return s.str();
185 }
186
187 private:
188 public:
189 void appendString(std::stringstream& stream) const {
190 for (size_t i = 0, sz = cvs.size(); i < sz; i++) {
191 const CV& cv = cvs[i];
192 stream << "," << cv._pos << ",";
193 printVal(stream, cv._val);
194 stream << "," << cv._interp;
195 }
196 }
197
198 virtual bool controlsMatch(const Editable& other) const {
199 if (const GenericCurveEditable* o = dynamic_cast<const GenericCurveEditable*>(&other)) {
200 // TODO: fix this
201 // return cvs==o->cvs && name==o->name;
202 UNUSED(o);
203 return false;
204 } else
205 return false;
206 }
207};
210
212 std::string name;
214#ifdef SEEXPR_USE_ANIMLIB
215 animlib::AnimCurve curve;
216#endif
217 std::string link;
219 std::string newText;
220
221 AnimCurveEditable(const std::string& name, int startPos, int endPos)
223#ifdef SEEXPR_USE_ANIMLIB
224 ,
225 curve(animlib::AnimAttrID())
226#endif
227 {
228 }
229
230 ~AnimCurveEditable() {} // must have this to ensure destruction
231
232 bool parseComment(const std::string& comment) {
233 animationSystemCurve = comment;
234 return true;
235 }
236 std::string str() const {
237 std::stringstream s;
238 s << name << " ccurve";
239 return s.str();
240 }
241 void appendString(std::stringstream& stream) const {
242#ifdef SEEXPR_USE_ANIMLIB
243 if (newText.length() > 0)
244 stream << newText;
245 else {
246 stream << ",\"" << animlib::AnimCurve::infinityTypeToString(curve.getPreInfinity()) << "\"";
247 stream << ",\"" << animlib::AnimCurve::infinityTypeToString(curve.getPostInfinity()) << "\"";
248 stream << "," << curve.isWeighted();
249 stream << ",\"" << link << "\"";
250 for (auto it = curve.getFirstKey(), itend = curve.getEndKey(); it != itend; ++it) {
251 const animlib::AnimKeyframe& key = *it;
252 stream << "," << key.getTime() << "," << key.getValue() << "," << key.getInWeight() << ","
253 << key.getOutWeight() << "," << key.getInAngle() << "," << key.getOutAngle() << ",\""
254 << animlib::AnimKeyframe::tangentTypeToString(key.getInTangentType()) << "\",\""
255 << animlib::AnimKeyframe::tangentTypeToString(key.getOutTangentType()) << "\","
256 << key.isWeightsLocked();
257 }
258 }
259#else
260 UNUSED(stream);
261#endif
262 }
263 virtual bool controlsMatch(const Editable& other) const {
264 if (const AnimCurveEditable* o = dynamic_cast<const AnimCurveEditable*>(&other)) {
265 // TODO: fix this
266 // return cvs==o->cvs && name==o->name;
267 UNUSED(o);
268 return false;
269 } else
270 return false;
271 }
272};
273
275 std::vector<SeExpr2::Vec3d> colors;
276 std::string labelType;
277
278 ColorSwatchEditable(const std::string& name, int startPos, int endPos) : Editable(name, startPos, endPos) {}
279
280 bool parseComment(const std::string& comment) {
281 char labelbuf[1024];
282 int parsed = sscanf(comment.c_str(), "#%s", labelbuf);
283 if (parsed == 1) {
284 labelType = labelbuf;
285 return true;
286 }
287 return true;
288 }
289
290 std::string str() const {
291 std::stringstream s;
292 s << name << " swatch";
293 return s.str();
294 }
295
296 void appendString(std::stringstream& stream) const {
297 for (size_t i = 0, sz = colors.size(); i < sz; i++) {
298 const SeExpr2::Vec3d& color = colors[i];
299 stream << ",";
300 printVal(stream, color);
301 }
302 }
303
304 virtual bool controlsMatch(const Editable& other) const {
305 if (const ColorSwatchEditable* o = dynamic_cast<const ColorSwatchEditable*>(&other)) {
306 // TODO: determine when controls match
307 UNUSED(o);
308 return false;
309 } else
310 return false;
311 }
312
313 void add(const SeExpr2::Vec3d& value) { colors.push_back(value); }
314
316
317 void remove(int index) { colors.erase(colors.begin() + index); }
318
319 void print() {
320 std::cerr << "\nColorSwatchEditable:\n";
321 for (unsigned int i = 0; i < colors.size(); i++) {
322 std::cerr << colors[i][0] << ", " << colors[i][1] << ", " << colors[i][2] << std::endl;
323 }
324 }
325};
326
329
330 DeepWaterEditable(const std::string& name, int startPos, int endPos) : Editable(name, startPos, endPos) {}
331
332 void setParams(const SeDeepWaterParams& paramsIn) { params = paramsIn; }
333
334 bool parseComment(const std::string& /*comment*/) { return true; }
335
336 std::string str() const {
337 std::stringstream s;
338 s << name << " deepWater";
339 return s.str();
340 }
341
342 void appendString(std::stringstream& stream) const {
343 stream << "," << params.resolution;
344 stream << "," << params.tileSize;
345 stream << "," << params.lengthCutoff;
346 stream << "," << params.amplitude;
347 stream << "," << params.windAngle;
348 stream << "," << params.windSpeed;
349 stream << "," << params.directionalFactorExponent;
350 stream << "," << params.directionalReflectionDamping << ",";
352 stream << "," << params.sharpen;
353 stream << "," << params.time;
354 stream << "," << params.filterWidth;
355 }
356
357 virtual bool controlsMatch(const Editable& other) const {
358 if (const DeepWaterEditable* o = dynamic_cast<const DeepWaterEditable*>(&other)) {
359 // TODO: determine when controls match
360 UNUSED(o);
361 return false;
362 } else
363 return false;
364 }
365};
366
367#endif
void printVal(std::stringstream &stream, double v)
Definition: Editable.h:33
GenericCurveEditable< SeExpr2::Vec3d > ColorCurveEditable
Definition: Editable.h:208
GenericCurveEditable< double > CurveEditable
Definition: Editable.h:209
#define UNUSED(x)
Definition: Editable.h:38
endif() set(ANIMLIB_SRCS "") if(DEFINED ANIMLIB_DIR) set(CE_MOC_HDRS CE/CECurveListUI.h CE/CEDragHandlers.h CE/CEGraphCurve.h CE/CEGraphKey.h CE/CEGraphSeg.h CE/CEGraphUI.h CE/CEMainUI.h CE/CESegEditUI.h CE/CETool.h) set(CE_CPPS CE/CECurveListUI.cpp CE/CEDragHandlers.cpp CE/CEGraphCurve.cpp CE/CEGraphKey.cpp CE/CEGraphSeg.cpp CE/CEGraphUI.cpp CE/CEMainUI.cpp CE/CESegEditUI.cpp CE/CETool.cpp) if(ENABLE_QT5) qt5_wrap_cpp(CE_MOC_SRCS $
Definition: CMakeLists.txt:47
Interpolation curve class for double->double and double->Vec3D.
Definition: Curve.h:38
InterpType
Supported interpolation types.
Definition: Curve.h:43
you may not use this file except in compliance with the License and the following modification to it
Definition: license.txt:10
SeExpr2::CurveFuncX curve
void appendString(std::stringstream &stream) const
Definition: Editable.h:241
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:263
std::string link
Definition: Editable.h:217
std::string animationSystemCurve
Definition: Editable.h:218
AnimCurveEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:221
std::string newText
Definition: Editable.h:219
std::string str() const
Definition: Editable.h:236
std::string name
Definition: Editable.h:212
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:232
std::vector< SeExpr2::Vec3d > colors
Definition: Editable.h:275
void remove(int index)
Definition: Editable.h:317
void appendString(std::stringstream &stream) const
Definition: Editable.h:296
std::string labelType
Definition: Editable.h:276
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:280
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:304
ColorSwatchEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:278
std::string str() const
Definition: Editable.h:290
void add(const SeExpr2::Vec3d &value)
Definition: Editable.h:313
void change(int index, const SeExpr2::Vec3d &value)
Definition: Editable.h:315
void setParams(const SeDeepWaterParams &paramsIn)
Definition: Editable.h:332
SeDeepWaterParams params
Definition: Editable.h:328
void appendString(std::stringstream &stream) const
Definition: Editable.h:342
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:357
bool parseComment(const std::string &)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:334
DeepWaterEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:330
std::string str() const
Definition: Editable.h:336
void updatePositions(const Editable &other)
Definition: Editable.h:46
virtual void appendString(std::stringstream &stream) const =0
int endPos
Definition: Editable.h:42
virtual std::string str() const
Definition: Editable.h:55
Editable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:44
virtual ~Editable()
Definition: Editable.h:51
int startPos
Definition: Editable.h:42
virtual bool parseComment(const std::string &comment)=0
parses a comment. if false is returned then delete the control from the editable
std::string name
Definition: Editable.h:41
virtual bool controlsMatch(const Editable &) const =0
Curve::InterpType InterpType
Definition: Editable.h:173
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:198
bool parseComment(const std::string &)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:180
std::string str() const
Definition: Editable.h:181
void appendString(std::stringstream &stream) const
Definition: Editable.h:189
SeExpr2::Curve< TVAL >::CV CV
Definition: Editable.h:172
void add(double x, const TVAL &y, int interp)
Definition: Editable.h:178
SeExpr2::Curve< TVAL > Curve
Definition: Editable.h:171
GenericCurveEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:176
std::vector< CV > cvs
Definition: Editable.h:175
std::string str() const
Definition: Editable.h:86
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:93
void appendString(std::stringstream &stream) const
Definition: Editable.h:91
double min
Definition: Editable.h:62
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:67
double max
Definition: Editable.h:62
double v
Definition: Editable.h:61
NumberEditable(const std::string &name, int startPos, int endPos, double val)
Definition: Editable.h:64
SeExpr2::Vec3d flowDirection
Definition: ExprDeepWater.h:60
double directionalFactorExponent
Definition: ExprDeepWater.h:58
double directionalReflectionDamping
Definition: ExprDeepWater.h:59
double _pos
Definition: Curve.h:53
InterpType _interp
Definition: Curve.h:55
std::string v
Definition: Editable.h:135
std::string type
Definition: Editable.h:136
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:161
StringEditable(int startPos, int endPos, const std::string &val)
Definition: Editable.h:137
std::string str() const
Definition: Editable.h:155
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:139
void appendString(std::stringstream &stream) const
Definition: Editable.h:151
double min
Definition: Editable.h:103
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:108
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:126
void appendString(std::stringstream &stream) const
Definition: Editable.h:124
SeExpr2::Vec3d v
Definition: Editable.h:102
double max
Definition: Editable.h:103
std::string str() const
Definition: Editable.h:118
VectorEditable(const std::string &name, int startPos, int endPos, const SeExpr2::Vec3d &val)
Definition: Editable.h:105
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need x
Definition: tutorial.txt:108
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y
Definition: userdoc.txt:218
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed). &nbsp
For any rgb or hsl value(except for negative s values)