SeExpr
ExprDeepWater.cpp
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 ExprDeepWater.cpp
18 */
19 #include <iostream>
20 #include <algorithm>
21 
22 #include <QtGui/QDialog>
23 #include <QtGui/QHBoxLayout>
24 #include <QtGui/QLabel>
25 #include <QtGui/QVBoxLayout>
26 #include <QtGui/QResizeEvent>
27 #include <QtGui/QIntValidator>
28 
29 #include <SeExpr2/ExprBuiltins.h>
30 #include <cfloat>
31 
32 #include "ExprDeepWater.h"
33 
34 void DeepWaterGraphicsView::resizeEvent(QResizeEvent *event)
35 {
36  emit resizeSignal(event->size().width(), event->size().height());
37 }
38 
39 
40 DeepWaterScene::DeepWaterScene() : _curve(new T_CURVE),_width(320), _height(170), _curvePoly(0), _baseRect(0), _gridRect(0)
41 {
43 }
44 
46 {
47  delete _curve;
48 }
49 
50 void DeepWaterScene::resize(const int width, const int height)
51 {
52  // width and height already have the 8 px padding factored in
53  _width = width-16;
54  _height = height-16;
55  setSceneRect(-9, -7, width, height);
56  drawRect();
57  drawPoly();
58  drawGrid();
59 }
60 
62 {
63  params.resolution = val;
65 }
66 
68 {
69  params.tileSize = val;
71 }
72 
74 {
75  params.lengthCutoff = val;
77 }
78 
80 {
81  params.amplitude = val;
83 }
84 
86 {
87  params.windAngle = val;
89 }
90 
92 {
93  params.windSpeed = val;
95 }
96 
98 {
99  QString flowDirection = val.remove(0,1);
100  flowDirection = flowDirection.remove(flowDirection.size()-1,1);
101  QStringList components = flowDirection.split(",");
102  params.flowDirection = SeExpr2::Vec3d(components[0].toDouble(),components[1].toDouble(),components[2].toDouble());
103  setParams(params);
104 }
105 
107 {
109  setParams(params);
110 }
111 
113 {
115  setParams(params);
116 }
117 
119 {
120  params.sharpen = val;
121  setParams(params);
122 }
123 
125 {
126  params = paramsIn;
128  drawPoly();
129  drawGrid();
131 }
132 
134 {
135  delete _curve;
136  _curve=new T_CURVE;
139 }
140 
141 // return points in reverse order in order to use same parsing in editor
143 {
144  emit deepWaterChanged();
145 }
146 
147 // draws the base gray outline rectangle
149 {
150  if (_baseRect == 0) {
151  _baseRect = addRect(0, 0, _width, _height, QPen(Qt::black, 1.0), QBrush(Qt::gray));
152  }
153  _baseRect->setRect(0, 0, _width, _height);
154  _baseRect->setZValue(0);
155 }
156 
157 
158 // draws the poly curve representation
160 {
161  if (_curvePoly == 0) {
162  _curvePoly = addPolygon(QPolygonF(), QPen(Qt::black, 1.0), QBrush(Qt::darkGray));
163  }
164 
165  QPolygonF poly;
166  poly.append(QPointF(_width, 0));
167  poly.append(QPointF(0, 0));
168  for (int i = 0; i < 1000; i++) {
169  double x = i/1000.0;
170  poly.append(QPointF(_width*x, _height*_curve->getValue(x)));
171  }
172  poly.append(QPointF(_width, 0));
173  _curvePoly->setPolygon(poly);
174  _curvePoly->setZValue(1);
175 }
176 
177 // draws the base gray outline rectangle
179 {
180  if (_gridRect == 0) {
181  _gridRect = addRect(0, 0, _width, _height, QPen(Qt::black, 1.0), QBrush(Qt::gray));
182  }
184  _gridRect->setBrush(QBrush(_curve->inGrid()?Qt::green:Qt::cyan));
185  _gridRect->setZValue(2);
186  _gridRect->setOpacity(0.25);
187 }
188 
189 ExprDeepWater::ExprDeepWater(QWidget* parent) : QWidget(parent), _scene(0), _resolutionEdit(0), _tileSizeEdit(0), _lengthCutoffEdit(0), _amplitudeEdit(0), _windAngleEdit(0), _windSpeedEdit(0), _flowDirectionEdit(0), _directionalFactorExponentEdit(0), _directionalReflectionDampingEdit(0), _sharpenEdit(0)
190 {
191  QHBoxLayout *mainLayout = new QHBoxLayout();
192  mainLayout->setSpacing(2);
193  mainLayout->setMargin(4);
194 
195  QWidget *edits = new QWidget;
196  QVBoxLayout *editsLayout = new QVBoxLayout;
197  editsLayout->setAlignment(Qt::AlignTop);
198  editsLayout->setSpacing(0);
199  editsLayout->setMargin(0);
200  edits->setLayout(editsLayout);
201 
202  int editWidth = QFontMetrics(font()).width("[0,0,0]")+8;
203 
204  QWidget *resolution = new QWidget;
205  QHBoxLayout *resolutionLayout = new QHBoxLayout;
206  resolutionLayout->setSpacing(1);
207  resolutionLayout->setMargin(1);
208  resolution->setLayout(resolutionLayout);
210  _resolutionEdit->setFixedWidth(editWidth);
211  QIntValidator *resolutionValidator = new QIntValidator(_resolutionEdit);
212  resolutionValidator->setBottom(1);
213  _resolutionEdit->setValidator(resolutionValidator);
214  _resolutionEdit->setFixedHeight(20);
215  resolutionLayout->addStretch(50);
216  QLabel *resolutionLabel = new QLabel("R");
217  resolutionLabel->setToolTip("Resolution");
218  resolutionLayout->addWidget(resolutionLabel);
219  resolutionLayout->addWidget(_resolutionEdit);
220 
221  QWidget *tileSize = new QWidget;
222  QHBoxLayout *tileSizeLayout = new QHBoxLayout;
223  tileSizeLayout->setSpacing(1);
224  tileSizeLayout->setMargin(1);
225  tileSize->setLayout(tileSizeLayout);
227  _tileSizeEdit->setFixedWidth(editWidth);
228  _tileSizeEdit->setFixedHeight(20);
229  tileSizeLayout->addStretch(50);
230  QLabel *tileSizeLabel = new QLabel("TS");
231  tileSizeLabel->setToolTip("Tile Size");
232  tileSizeLayout->addWidget(tileSizeLabel);
233  tileSizeLayout->addWidget(_tileSizeEdit);
234 
235  QWidget *lengthCutoff = new QWidget;
236  QHBoxLayout *lengthCutoffLayout = new QHBoxLayout;
237  lengthCutoffLayout->setSpacing(1);
238  lengthCutoffLayout->setMargin(1);
239  lengthCutoff->setLayout(lengthCutoffLayout);
241  _lengthCutoffEdit->setFixedWidth(editWidth);
242  _lengthCutoffEdit->setFixedHeight(20);
243  lengthCutoffLayout->addStretch(50);
244  QLabel *lengthCutoffLabel = new QLabel("LC");
245  lengthCutoffLabel->setToolTip("Length Cutoff");
246  lengthCutoffLayout->addWidget(lengthCutoffLabel);
247  lengthCutoffLayout->addWidget(_lengthCutoffEdit);
248 
249  QWidget *amplitude = new QWidget;
250  QHBoxLayout *amplitudeLayout = new QHBoxLayout;
251  amplitudeLayout->setSpacing(1);
252  amplitudeLayout->setMargin(1);
253  amplitude->setLayout(amplitudeLayout);
255  _amplitudeEdit->setFixedWidth(editWidth);
256  _amplitudeEdit->setFixedHeight(20);
257  amplitudeLayout->addStretch(50);
258  QLabel *amplitudeLabel = new QLabel("A");
259  amplitudeLabel->setToolTip("Amplitude");
260  amplitudeLayout->addWidget(amplitudeLabel);
261  amplitudeLayout->addWidget(_amplitudeEdit);
262 
263  QWidget *windAngle = new QWidget;
264  QHBoxLayout *windAngleLayout = new QHBoxLayout;
265  windAngleLayout->setSpacing(1);
266  windAngleLayout->setMargin(1);
267  windAngle->setLayout(windAngleLayout);
269  _windAngleEdit->setFixedWidth(editWidth);
270  _windAngleEdit->setFixedHeight(20);
271  windAngleLayout->addStretch(50);
272  QLabel *windAngleLabel = new QLabel("WA");
273  windAngleLabel->setToolTip("Wind Angle");
274  windAngleLayout->addWidget(windAngleLabel);
275  windAngleLayout->addWidget(_windAngleEdit);
276 
277  QWidget *windSpeed = new QWidget;
278  QHBoxLayout *windSpeedLayout = new QHBoxLayout;
279  windSpeedLayout->setSpacing(1);
280  windSpeedLayout->setMargin(1);
281  windSpeed->setLayout(windSpeedLayout);
283  _windSpeedEdit->setFixedWidth(editWidth);
284  _windSpeedEdit->setFixedHeight(20);
285  windSpeedLayout->addStretch(50);
286  QLabel *windSpeedLabel = new QLabel("WS");
287  windSpeedLabel->setToolTip("Wind Speed");
288  windSpeedLayout->addWidget(windSpeedLabel);
289  windSpeedLayout->addWidget(_windSpeedEdit);
290 
291  QWidget *directionalFactorExponent = new QWidget;
292  QHBoxLayout *directionalFactorExponentLayout = new QHBoxLayout;
293  directionalFactorExponentLayout->setSpacing(1);
294  directionalFactorExponentLayout->setMargin(1);
295  directionalFactorExponent->setLayout(directionalFactorExponentLayout);
297  _directionalFactorExponentEdit->setFixedWidth(editWidth);
298  _directionalFactorExponentEdit->setFixedHeight(20);
299  directionalFactorExponentLayout->addStretch(50);
300  QLabel *directionalFactorExponentLabel = new QLabel("DFE");
301  directionalFactorExponentLabel->setToolTip("Directional Factor Exponent");
302  directionalFactorExponentLayout->addWidget(directionalFactorExponentLabel);
303  directionalFactorExponentLayout->addWidget(_directionalFactorExponentEdit);
304 
305  QWidget *directionalReflectionDamping = new QWidget;
306  QHBoxLayout *directionalReflectionDampingLayout = new QHBoxLayout;
307  directionalReflectionDampingLayout->setSpacing(1);
308  directionalReflectionDampingLayout->setMargin(1);
309  directionalReflectionDamping->setLayout(directionalReflectionDampingLayout);
311  _directionalReflectionDampingEdit->setFixedWidth(editWidth);
312  _directionalReflectionDampingEdit->setFixedHeight(20);
313  directionalReflectionDampingLayout->addStretch(50);
314  QLabel *directionalReflectionDampingLabel = new QLabel("DRD");
315  directionalReflectionDampingLabel->setToolTip("Directional Reflection Damping");
316  directionalReflectionDampingLayout->addWidget(directionalReflectionDampingLabel);
317  directionalReflectionDampingLayout->addWidget(_directionalReflectionDampingEdit);
318 
319  QWidget *flowDirection = new QWidget;
320  QHBoxLayout *flowDirectionLayout = new QHBoxLayout;
321  flowDirectionLayout->setSpacing(1);
322  flowDirectionLayout->setMargin(1);
323  flowDirection->setLayout(flowDirectionLayout);
325  _flowDirectionEdit->setFixedWidth(editWidth);
326  _flowDirectionEdit->setFixedHeight(20);
327  flowDirectionLayout->addStretch(50);
328  QLabel *flowDirectionLabel = new QLabel("FD");
329  flowDirectionLabel->setToolTip("Flow Direction");
330  flowDirectionLayout->addWidget(flowDirectionLabel);
331  flowDirectionLayout->addWidget(_flowDirectionEdit);
332 
333  QWidget *sharpen = new QWidget;
334  QHBoxLayout *sharpenLayout = new QHBoxLayout;
335  sharpenLayout->setSpacing(1);
336  sharpenLayout->setMargin(1);
337  sharpen->setLayout(sharpenLayout);
339  _sharpenEdit->setFixedWidth(editWidth);
340  _sharpenEdit->setFixedHeight(20);
341  sharpenLayout->addStretch(50);
342  QLabel *sharpenLabel = new QLabel("S");
343  sharpenLabel->setToolTip("Sharpen");
344  sharpenLayout->addWidget(sharpenLabel);
345  sharpenLayout->addWidget(_sharpenEdit);
346 
347  QFrame *curveFrame = new QFrame;
348  curveFrame->setFrameShape(QFrame::Panel);
349  curveFrame->setFrameShadow(QFrame::Sunken);
350  curveFrame->setLineWidth(1);
351  QHBoxLayout *curveFrameLayout = new QHBoxLayout;
352  curveFrameLayout->setMargin(0);
354  curveView->setFrameShape(QFrame::Panel);
355  curveView->setFrameShadow(QFrame::Sunken);
356  curveView->setLineWidth(1);
357  curveView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
358  curveView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
359  _scene = new DeepWaterScene;
360  curveView->setScene(_scene);
361  curveView->setTransform(QTransform().scale(1, -1));
362  curveView->setRenderHints(QPainter::Antialiasing);
363  curveFrameLayout->addWidget(curveView);
364  curveFrame->setLayout(curveFrameLayout);
365 
366  editsLayout->addWidget(resolution);
367  editsLayout->addWidget(tileSize);
368  editsLayout->addWidget(lengthCutoff);
369  editsLayout->addWidget(amplitude);
370  editsLayout->addWidget(windSpeed);
371  editsLayout->addWidget(directionalFactorExponent);
372  QFrame* line = new QFrame();
373  line->setToolTip("Parameters below this do not affect spectrum");
374  line->setFrameShape(QFrame::HLine);
375  line->setFrameShadow(QFrame::Sunken);
376  editsLayout->addWidget(line);
377  editsLayout->addWidget(windAngle);
378  editsLayout->addWidget(flowDirection);
379  editsLayout->addWidget(directionalReflectionDamping);
380  editsLayout->addWidget(sharpen);
381 
382  mainLayout->addWidget(edits);
383  mainLayout->addWidget(curveFrame);
384  mainLayout->setStretchFactor(curveFrame,100);
385  setLayout(mainLayout);
386 
387  // SIGNALS
388 
389  connect(_resolutionEdit, SIGNAL(returnPressed()), this, SLOT(resolutionChanged()));
390  connect(_resolutionEdit, SIGNAL(focusOut()), this, SLOT(resolutionChanged()));
391  connect(this, SIGNAL(resolutionChangedSignal(int)), _scene, SLOT(resolutionChanged(int)));
392  connect(_tileSizeEdit, SIGNAL(returnPressed()), this, SLOT(tileSizeChanged()));
393  connect(_tileSizeEdit, SIGNAL(focusOut()), this, SLOT(tileSizeChanged()));
394  connect(this, SIGNAL(tileSizeChangedSignal(double)), _scene, SLOT(tileSizeChanged(double)));
395  connect(_lengthCutoffEdit, SIGNAL(returnPressed()), this, SLOT(lengthCutoffChanged()));
396  connect(_lengthCutoffEdit, SIGNAL(focusOut()), this, SLOT(lengthCutoffChanged()));
397  connect(this, SIGNAL(lengthCutoffChangedSignal(double)), _scene, SLOT(lengthCutoffChanged(double)));
398  connect(_amplitudeEdit, SIGNAL(returnPressed()), this, SLOT(amplitudeChanged()));
399  connect(_amplitudeEdit, SIGNAL(focusOut()), this, SLOT(amplitudeChanged()));
400  connect(this, SIGNAL(amplitudeChangedSignal(double)), _scene, SLOT(amplitudeChanged(double)));
401  connect(_windAngleEdit, SIGNAL(returnPressed()), this, SLOT(windAngleChanged()));
402  connect(_windAngleEdit, SIGNAL(focusOut()), this, SLOT(windAngleChanged()));
403  connect(this, SIGNAL(windAngleChangedSignal(double)), _scene, SLOT(windAngleChanged(double)));
404  connect(_windSpeedEdit, SIGNAL(returnPressed()), this, SLOT(windSpeedChanged()));
405  connect(_windSpeedEdit, SIGNAL(focusOut()), this, SLOT(windSpeedChanged()));
406  connect(this, SIGNAL(windSpeedChangedSignal(double)), _scene, SLOT(windSpeedChanged(double)));
407  connect(_flowDirectionEdit, SIGNAL(returnPressed()), this, SLOT(flowDirectionChanged()));
408  connect(_flowDirectionEdit, SIGNAL(focusOut()), this, SLOT(flowDirectionChanged()));
409  connect(this, SIGNAL(flowDirectionChangedSignal(QString)), _scene, SLOT(flowDirectionChanged(QString)));
410  connect(_directionalFactorExponentEdit, SIGNAL(returnPressed()), this, SLOT(directionalFactorExponentChanged()));
411  connect(_directionalFactorExponentEdit, SIGNAL(focusOut()), this, SLOT(directionalFactorExponentChanged()));
412  connect(this, SIGNAL(directionalFactorExponentChangedSignal(double)), _scene, SLOT(directionalFactorExponentChanged(double)));
413  connect(_directionalReflectionDampingEdit, SIGNAL(returnPressed()), this, SLOT(directionalReflectionDampingChanged()));
414  connect(_directionalReflectionDampingEdit, SIGNAL(focusOut()), this, SLOT(directionalReflectionDampingChanged()));
415  connect(this, SIGNAL(directionalReflectionDampingChangedSignal(double)), _scene, SLOT(directionalReflectionDampingChanged(double)));
416  connect(_sharpenEdit, SIGNAL(returnPressed()), this, SLOT(sharpenChanged()));
417  connect(_sharpenEdit, SIGNAL(focusOut()), this, SLOT(sharpenChanged()));
418  connect(this, SIGNAL(sharpenChangedSignal(double)), _scene, SLOT(sharpenChanged(double)));
419 
420  // when the widget is resized, resize the curve widget
421  connect(curveView, SIGNAL(resizeSignal(int, int)), _scene, SLOT(resize(int, int)));
422 }
423 
425 {
426  int val = QString(_resolutionEdit->text()).toInt();
427  emit resolutionChangedSignal(val);
428 }
429 
431 {
432  double val = QString(_tileSizeEdit->text()).toDouble();
433  emit tileSizeChangedSignal(val);
434 }
435 
437 {
438  double val = QString(_lengthCutoffEdit->text()).toDouble();
439  emit lengthCutoffChangedSignal(val);
440 }
441 
443 {
444  double val = QString(_amplitudeEdit->text()).toDouble();
445  emit amplitudeChangedSignal(val);
446 }
447 
449 {
450  double val = QString(_windAngleEdit->text()).toDouble();
451  emit windAngleChangedSignal(val);
452 }
453 
455 {
456  double val = QString(_windSpeedEdit->text()).toDouble();
457  emit windSpeedChangedSignal(val);
458 }
459 
461 {
463 }
464 
466 {
467  double val = QString(_directionalFactorExponentEdit->text()).toDouble();
469 }
470 
472 {
473  double val = QString(_directionalReflectionDampingEdit->text()).toDouble();
475 }
476 
478 {
479  double val = QString(_sharpenEdit->text()).toDouble();
480  emit sharpenChangedSignal(val);
481 }
482 
484 {
485  _scene->setParams(params);
486  _resolutionEdit->setText(QString::number(params.resolution));
487  _tileSizeEdit->setText(QString::number(params.tileSize));
488  _lengthCutoffEdit->setText(QString::number(params.lengthCutoff));
489  _amplitudeEdit->setText(QString::number(params.amplitude));
490  _windAngleEdit->setText(QString::number(params.windAngle));
491  _windSpeedEdit->setText(QString::number(params.windSpeed));
492  QString flowDirection = "[";
493  flowDirection += QString::number(params.flowDirection[0]) + ","
494  + QString::number(params.flowDirection[1]) + ","
495  + QString::number(params.flowDirection[2]) + "]";
496  _flowDirectionEdit->setText(flowDirection);
497  _directionalFactorExponentEdit->setText(QString::number(params.directionalFactorExponent));
498  _directionalReflectionDampingEdit->setText(QString::number(params.directionalReflectionDamping));
499  _sharpenEdit->setText(QString::number(params.sharpen));
500 }
DeepWaterLineEdit * _amplitudeEdit
DeepWaterLineEdit * _sharpenEdit
void lengthCutoffChanged(double val)
void windAngleChangedSignal(double val)
DeepWaterLineEdit * _windSpeedEdit
void amplitudeChanged(double val)
virtual void resizeEvent(QResizeEvent *event)
SeDeepWaterParams params
QGraphicsRectItem * _baseRect
QGraphicsRectItem * _gridRect
DeepWaterLineEdit * _lengthCutoffEdit
void windSpeedChangedSignal(double val)
void flowDirectionChanged(QString val)
void windAngleChanged(double val)
void setParams(const SeDeepWaterParams &paramsIn)
Definition: ExprDeepWater.h:58
void deepWaterChanged()
void resolutionChangedSignal(int val)
void flowDirectionChanged()
void generateSpectrum()
DeepWaterLineEdit * _resolutionEdit
DeepWaterLineEdit * _flowDirectionEdit
void directionalFactorExponentChanged()
QGraphicsPolygonItem * _curvePoly
void directionalReflectionDampingChangedSignal(double val)
Vec< double, 3, false > Vec3d
Definition: Vec.h:368
void windSpeedChanged()
SeExpr2::Vec3d flowDirection
Definition: ExprDeepWater.h:46
void amplitudeChanged()
double directionalReflectionDamping
Definition: ExprDeepWater.h:45
DeepWaterLineEdit * _windAngleEdit
double directionalFactorExponent
Definition: ExprDeepWater.h:44
void directionalReflectionDampingChanged(double val)
void sharpenChanged(double val)
void windSpeedChanged(double val)
void sharpenChangedSignal(double val)
void tileSizeChanged()
void resize(const int width, const int height)
DeepWaterLineEdit * _directionalReflectionDampingEdit
</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
void resolutionChanged(int val)
ExprDeepWater(QWidget *parent=0)
SeDeepWater< double > T_CURVE
void tileSizeChangedSignal(double val)
T_CURVE * _curve
void setParams(const SeDeepWaterParams &params)
void flowDirectionChangedSignal(QString val)
T getValue(double param) const
Evaluates curve and returns full value.
DeepWaterLineEdit * _directionalFactorExponentEdit
void directionalFactorExponentChangedSignal(double val)
void resizeSignal(int width, int height)
DeepWaterScene * _scene
void windAngleChanged()
void lengthCutoffChanged()
DeepWaterLineEdit * _tileSizeEdit
If a scalar is used in a vector it is replicated into the three components(e.g.0.5 becomes[0.5, 0.5, 0.5]).&nbsp
void resolutionChanged()
void directionalReflectionDampingChanged()
void tileSizeChanged(double val)
void emitDeepWaterChanged()
void setParams(const SeDeepWaterParams &paramsIn)
void amplitudeChangedSignal(double val)
void lengthCutoffChangedSignal(double val)
void directionalFactorExponentChanged(double val)