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 
33 inline void printVal(std::stringstream& stream, double v) { stream << v; }
34 inline 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 
40 struct 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 
60 struct 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 
101 struct VectorEditable : public Editable {
103  double min, max;
104  bool isColor;
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 
134 struct 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 
169 template <class TVAL>
171  typedef typename SeExpr2::Curve<TVAL> Curve;
172  typedef typename SeExpr2::Curve<TVAL>::CV CV;
173  typedef typename Curve::InterpType InterpType;
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 
211 struct AnimCurveEditable : public Editable {
212  std::string name;
214 #ifdef SEEXPR_USE_ANIMLIB
215  animlib::AnimCurve curve;
216 #endif
217  std::string link;
218  std::string animationSystemCurve;
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 
274 struct ColorSwatchEditable : public Editable {
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 
315  void change(int index, const SeExpr2::Vec3d& value) { colors[index] = value; }
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 
327 struct DeepWaterEditable : public Editable {
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 << ",";
351  printVal(stream, params.flowDirection);
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
ColorSwatchEditable::labelType
std::string labelType
Definition: Editable.h:276
animlib
Definition: ExprControl.h:49
NumberEditable::str
std::string str() const
Definition: Editable.h:86
NumberEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:93
index
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
SeExpr2::Curve::CV::_val
T _val
Definition: Curve.h:54
SeDeepWaterParams::lengthCutoff
double lengthCutoff
Definition: ExprDeepWater.h:54
ColorSwatchEditable::colors
std::vector< SeExpr2::Vec3d > colors
Definition: Editable.h:275
AnimCurveEditable
Definition: Editable.h:211
ColorSwatchEditable::ColorSwatchEditable
ColorSwatchEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:278
VectorEditable
Definition: Editable.h:101
VectorEditable::v
SeExpr2::Vec3d v
Definition: Editable.h:102
Editable
Definition: Editable.h:40
AnimCurveEditable::parseComment
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:232
DeepWaterEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:342
GenericCurveEditable::GenericCurveEditable
GenericCurveEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:176
NumberEditable::max
double max
Definition: Editable.h:62
ColorSwatchEditable
Definition: Editable.h:274
VectorEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:126
SeExpr2::Vec< double, 3, false >
DeepWaterEditable::str
std::string str() const
Definition: Editable.h:336
SeExpr2::curve
SeExpr2::CurveFuncX curve
AnimCurveEditable::link
std::string link
Definition: Editable.h:217
StringEditable::type
std::string type
Definition: Editable.h:136
GenericCurveEditable::CV
SeExpr2::Curve< TVAL >::CV CV
Definition: Editable.h:172
SeDeepWaterParams::tileSize
double tileSize
Definition: ExprDeepWater.h:53
ColorSwatchEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:304
Editable::name
std::string name
Definition: Editable.h:41
DeepWaterEditable::parseComment
bool parseComment(const std::string &)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:334
AnimCurveEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:241
AnimCurveEditable::name
std::string name
Definition: Editable.h:212
VectorEditable::VectorEditable
VectorEditable(const std::string &name, int startPos, int endPos, const SeExpr2::Vec3d &val)
Definition: Editable.h:105
ColorSwatchEditable::parseComment
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:280
SeDeepWaterParams::resolution
int resolution
Definition: ExprDeepWater.h:52
GenericCurveEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:189
endif
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
VectorEditable::isColor
bool isColor
Definition: Editable.h:104
SeExpr2::Curve::CV::_pos
double _pos
Definition: Curve.h:53
SeExpr2::Curve::CV::_interp
InterpType _interp
Definition: Curve.h:55
Editable::str
virtual std::string str() const
Definition: Editable.h:55
y
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
SeDeepWaterParams::flowDirection
SeExpr2::Vec3d flowDirection
Definition: ExprDeepWater.h:60
ExprDeepWater.h
VectorEditable::parseComment
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:108
UNUSED
#define UNUSED(x)
Definition: Editable.h:38
GenericCurveEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:198
ColorCurveEditable
GenericCurveEditable< SeExpr2::Vec3d > ColorCurveEditable
Definition: Editable.h:208
AnimCurveEditable::animationSystemCurve
std::string animationSystemCurve
Definition: Editable.h:218
ColorSwatchEditable::str
std::string str() const
Definition: Editable.h:290
SeDeepWaterParams::windSpeed
double windSpeed
Definition: ExprDeepWater.h:57
Vec.h
VectorEditable::min
double min
Definition: Editable.h:103
AnimCurveEditable::startPos
int startPos
Definition: Editable.h:213
SeExpr2::Curve
Interpolation curve class for double->double and double->Vec3D.
Definition: Curve.h:38
SeDeepWaterParams::amplitude
double amplitude
Definition: ExprDeepWater.h:55
VectorEditable::max
double max
Definition: Editable.h:103
AnimCurveEditable::endPos
int endPos
Definition: Editable.h:213
ColorSwatchEditable::change
void change(int index, const SeExpr2::Vec3d &value)
Definition: Editable.h:315
NumberEditable
Definition: Editable.h:60
ColorSwatchEditable::remove
void remove(int index)
Definition: Editable.h:317
it
you may not use this file except in compliance with the License and the following modification to it
Definition: license.txt:10
Editable::updatePositions
void updatePositions(const Editable &other)
Definition: Editable.h:46
NumberEditable::min
double min
Definition: Editable.h:62
NumberEditable::NumberEditable
NumberEditable(const std::string &name, int startPos, int endPos, double val)
Definition: Editable.h:64
StringEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:161
SeDeepWaterParams::filterWidth
double filterWidth
Definition: ExprDeepWater.h:63
AnimCurveEditable::AnimCurveEditable
AnimCurveEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:221
ColorSwatchEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:296
DeepWaterEditable::params
SeDeepWaterParams params
Definition: Editable.h:328
value
For any rgb or hsl value(except for negative s values)
NumberEditable::isInt
bool isInt
Definition: Editable.h:63
SeDeepWaterParams::windAngle
double windAngle
Definition: ExprDeepWater.h:56
VectorEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:124
NumberEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:91
SeDeepWaterParams::sharpen
double sharpen
Definition: ExprDeepWater.h:61
ColorSwatchEditable::add
void add(const SeExpr2::Vec3d &value)
Definition: Editable.h:313
Editable::controlsMatch
virtual bool controlsMatch(const Editable &) const =0
printVal
void printVal(std::stringstream &stream, double v)
Definition: Editable.h:33
DeepWaterEditable
Definition: Editable.h:327
GenericCurveEditable::str
std::string str() const
Definition: Editable.h:181
DeepWaterEditable::setParams
void setParams(const SeDeepWaterParams &paramsIn)
Definition: Editable.h:332
Editable::endPos
int endPos
Definition: Editable.h:42
ColorSwatchEditable::print
void print()
Definition: Editable.h:319
SeDeepWaterParams::directionalFactorExponent
double directionalFactorExponent
Definition: ExprDeepWater.h:58
SeDeepWaterParams
Definition: ExprDeepWater.h:33
Editable::Editable
Editable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:44
AnimCurveEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:263
GenericCurveEditable::Curve
SeExpr2::Curve< TVAL > Curve
Definition: Editable.h:171
GenericCurveEditable::cvs
std::vector< CV > cvs
Definition: Editable.h:175
GenericCurveEditable::InterpType
Curve::InterpType InterpType
Definition: Editable.h:173
StringEditable::appendString
void appendString(std::stringstream &stream) const
Definition: Editable.h:151
Curve.h
Editable::appendString
virtual void appendString(std::stringstream &stream) const =0
Editable::parseComment
virtual bool parseComment(const std::string &comment)=0
parses a comment. if false is returned then delete the control from the editable
GenericCurveEditable::add
void add(double x, const TVAL &y, int interp)
Definition: Editable.h:178
AnimCurveEditable::newText
std::string newText
Definition: Editable.h:219
CurveEditable
GenericCurveEditable< double > CurveEditable
Definition: Editable.h:209
StringEditable::StringEditable
StringEditable(int startPos, int endPos, const std::string &val)
Definition: Editable.h:137
SeDeepWaterParams::directionalReflectionDamping
double directionalReflectionDamping
Definition: ExprDeepWater.h:59
NumberEditable::parseComment
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:67
StringEditable::str
std::string str() const
Definition: Editable.h:155
NumberEditable::v
double v
Definition: Editable.h:61
VectorEditable::str
std::string str() const
Definition: Editable.h:118
StringEditable
Definition: Editable.h:134
Editable::startPos
int startPos
Definition: Editable.h:42
GenericCurveEditable
Definition: Editable.h:170
DeepWaterEditable::DeepWaterEditable
DeepWaterEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:330
SeExpr2::Curve::InterpType
InterpType
Supported interpolation types.
Definition: Curve.h:43
DeepWaterEditable::controlsMatch
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:357
Editable::~Editable
virtual ~Editable()
Definition: Editable.h:51
SeDeepWaterParams::time
double time
Definition: ExprDeepWater.h:62
StringEditable::parseComment
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:139
x
</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
GenericCurveEditable::parseComment
bool parseComment(const std::string &)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:180
StringEditable::v
std::string v
Definition: Editable.h:135
SeExpr2::Curve::CV
Definition: Curve.h:50
AnimCurveEditable::~AnimCurveEditable
~AnimCurveEditable()
Definition: Editable.h:230
AnimCurveEditable::str
std::string str() const
Definition: Editable.h:236