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