1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 #include "View3DSettings.h"
18
19 #include <QCloseEvent>
20
View3DSettings()21 View3DSettings::View3DSettings() :
22 // Display
23 spaceScale_(0.001),
24 timeScale_(0.011),
25 isTimeHorizontal_(true),
26 freezeSpaceRect_(false),
27 cameraFollowActiveTime_(false),
28
29 drawGrid_(false),
30 drawTimePlane_(true),
31 drawCurrentFrame_(true),
32 drawAllFrames_(false),
33 drawFramesAsTopology_(true),
34 drawCurrentFrameAsTopology_(false),
35 drawTopologyFaces_(true),
36 drawKeyCells_(true),
37 drawInbetweenCells_(true),
38 drawKeyVerticesAsDots_(false),
39 clipToSpaceTimeWindow_(false),
40
41 vertexTopologySize_(5),
42 edgeTopologyWidth_(3),
43
44 opacity_(0.08),
45 drawAsMesh_(true),
46 k1_(1),
47 k2_(1)
48 {
49 }
50
~View3DSettings()51 View3DSettings::~View3DSettings()
52 {
53 }
54
spaceScale() const55 double View3DSettings::spaceScale() const
56 {
57 return spaceScale_;
58 }
setSpaceScale(double newValue)59 void View3DSettings::setSpaceScale(double newValue)
60 {
61 spaceScale_ = newValue;
62 }
63
timeScale() const64 double View3DSettings::timeScale() const
65 {
66 return timeScale_;
67 }
setTimeScale(double newValue)68 void View3DSettings::setTimeScale(double newValue)
69 {
70 timeScale_ = newValue;
71 }
72
isTimeHorizontal() const73 bool View3DSettings::isTimeHorizontal() const
74 {
75 return isTimeHorizontal_;
76 }
setIsTimeHorizontal(bool newValue)77 void View3DSettings::setIsTimeHorizontal(bool newValue)
78 {
79 isTimeHorizontal_ = newValue;
80 }
81
freezeSpaceRect() const82 bool View3DSettings::freezeSpaceRect() const
83 {
84 return freezeSpaceRect_;
85 }
setFreezeSpaceRect(bool newValue)86 void View3DSettings::setFreezeSpaceRect(bool newValue)
87 {
88 freezeSpaceRect_ = newValue;
89 }
90
cameraFollowActiveTime() const91 bool View3DSettings::cameraFollowActiveTime() const
92 {
93 return cameraFollowActiveTime_;
94 }
setCameraFollowActiveTime(bool newValue)95 void View3DSettings::setCameraFollowActiveTime(bool newValue)
96 {
97 cameraFollowActiveTime_ = newValue;
98 }
99
100
101
102
103
104
105
drawGrid() const106 bool View3DSettings::drawGrid() const
107 {
108 return drawGrid_;
109 }
setDrawGrid(bool newValue)110 void View3DSettings::setDrawGrid(bool newValue)
111 {
112 drawGrid_ = newValue;
113 }
114
drawTimePlane() const115 bool View3DSettings::drawTimePlane() const
116 {
117 return drawTimePlane_;
118 }
setDrawTimePlane(bool newValue)119 void View3DSettings::setDrawTimePlane(bool newValue)
120 {
121 drawTimePlane_ = newValue;
122 }
123
drawCurrentFrame() const124 bool View3DSettings::drawCurrentFrame() const
125 {
126 return drawCurrentFrame_;
127 }
setDrawCurrentFrame(bool newValue)128 void View3DSettings::setDrawCurrentFrame(bool newValue)
129 {
130 drawCurrentFrame_ = newValue;
131 }
132
drawAllFrames() const133 bool View3DSettings::drawAllFrames() const
134 {
135 return drawAllFrames_;
136 }
setDrawAllFrames(bool newValue)137 void View3DSettings::setDrawAllFrames(bool newValue)
138 {
139 drawAllFrames_ = newValue;
140 }
141
drawCurrentFrameAsTopology() const142 bool View3DSettings::drawCurrentFrameAsTopology() const
143 {
144 return drawCurrentFrameAsTopology_;
145 }
setDrawCurrentFrameAsTopology(bool newValue)146 void View3DSettings::setDrawCurrentFrameAsTopology(bool newValue)
147 {
148 drawCurrentFrameAsTopology_ = newValue;
149 }
drawFramesAsTopology() const150 bool View3DSettings::drawFramesAsTopology() const
151 {
152 return drawFramesAsTopology_;
153 }
setDrawFramesAsTopology(bool newValue)154 void View3DSettings::setDrawFramesAsTopology(bool newValue)
155 {
156 drawFramesAsTopology_ = newValue;
157 }
158
drawTopologyFaces() const159 bool View3DSettings::drawTopologyFaces() const
160 {
161 return drawTopologyFaces_;
162 }
setDrawTopologyFaces(bool newValue)163 void View3DSettings::setDrawTopologyFaces(bool newValue)
164 {
165 drawTopologyFaces_ = newValue;
166 }
167
drawKeyCells() const168 bool View3DSettings::drawKeyCells() const
169 {
170 return drawKeyCells_;
171 }
setDrawKeyCells(bool newValue)172 void View3DSettings::setDrawKeyCells(bool newValue)
173 {
174 drawKeyCells_ = newValue;
175 }
176
drawInbetweenCells() const177 bool View3DSettings::drawInbetweenCells() const
178 {
179 return drawInbetweenCells_;
180 }
setDrawInbetweenCells(bool newValue)181 void View3DSettings::setDrawInbetweenCells(bool newValue)
182 {
183 drawInbetweenCells_ = newValue;
184 }
185
drawKeyVerticesAsDots() const186 bool View3DSettings::drawKeyVerticesAsDots() const
187 {
188 return drawKeyVerticesAsDots_;
189 }
setDrawKeyVerticesAsDots(bool newValue)190 void View3DSettings::setDrawKeyVerticesAsDots(bool newValue)
191 {
192 drawKeyVerticesAsDots_ = newValue;
193 }
194
clipToSpaceTimeWindow() const195 bool View3DSettings::clipToSpaceTimeWindow() const
196 {
197 return clipToSpaceTimeWindow_;
198 }
setClipToSpaceTimeWindow(bool newValue)199 void View3DSettings::setClipToSpaceTimeWindow(bool newValue)
200 {
201 clipToSpaceTimeWindow_ = newValue;
202 }
203
vertexTopologySize() const204 int View3DSettings::vertexTopologySize() const
205 {
206 return vertexTopologySize_;
207 }
setVertexTopologySize(int newValue)208 void View3DSettings::setVertexTopologySize(int newValue)
209 {
210 vertexTopologySize_ = newValue;
211 }
212
edgeTopologyWidth() const213 int View3DSettings::edgeTopologyWidth() const
214 {
215 return edgeTopologyWidth_;
216 }
setEdgeTopologyWidth(int newValue)217 void View3DSettings::setEdgeTopologyWidth(int newValue)
218 {
219 edgeTopologyWidth_ = newValue;
220 }
221
222
opacity() const223 double View3DSettings::opacity() const
224 {
225 return opacity_;
226 }
setOpacity(double newValue)227 void View3DSettings::setOpacity(double newValue)
228 {
229 opacity_ = newValue;
230 }
drawAsMesh() const231 bool View3DSettings::drawAsMesh() const
232 {
233 return drawAsMesh_;
234 }
setDrawAsMesh(bool newValue)235 void View3DSettings::setDrawAsMesh(bool newValue)
236 {
237 drawAsMesh_ = newValue;
238 }
k1() const239 int View3DSettings::k1() const
240 {
241 return k1_;
242 }
setK1(int newValue)243 void View3DSettings::setK1(int newValue)
244 {
245 k1_ = newValue;
246 }
k2() const247 int View3DSettings::k2() const
248 {
249 return k2_;
250 }
setK2(int newValue)251 void View3DSettings::setK2(int newValue)
252 {
253 k2_ = newValue;
254 }
255
256
xFromX2D(double xScene) const257 double View3DSettings::xFromX2D(double xScene) const
258 {
259 return xScene;
260 }
yFromY2D(double yScene) const261 double View3DSettings::yFromY2D(double yScene) const
262 {
263 return -yScene;
264 }
265
zFromT(double time) const266 double View3DSettings::zFromT(double time) const
267 {
268 double res = - time * timeScale() / spaceScale();
269 return res;
270 }
271
zFromT(int time) const272 double View3DSettings::zFromT(int time) const
273 {
274 return zFromT( (double) time );
275 }
276
zFromT(Time time) const277 double View3DSettings::zFromT(Time time) const
278 {
279 return zFromT(time.floatTime());
280 }
281
xSceneMin() const282 double View3DSettings::xSceneMin() const { return xSceneMin_; }
xSceneMax() const283 double View3DSettings::xSceneMax() const { return xSceneMax_; }
ySceneMin() const284 double View3DSettings::ySceneMin() const { return ySceneMin_; }
ySceneMax() const285 double View3DSettings::ySceneMax() const { return ySceneMax_; }
286
setXSceneMin(double value)287 void View3DSettings::setXSceneMin(double value)
288 {
289 xSceneMin_ = value;
290 }
291
setXSceneMax(double value)292 void View3DSettings::setXSceneMax(double value)
293 {
294 xSceneMax_ = value;
295 }
296
setYSceneMin(double value)297 void View3DSettings::setYSceneMin(double value)
298 {
299 ySceneMin_ = value;
300 }
301
setYSceneMax(double value)302 void View3DSettings::setYSceneMax(double value)
303 {
304 ySceneMax_ = value;
305 }
306
307
308
View3DSettingsWidget()309 View3DSettingsWidget::View3DSettingsWidget() :
310 QWidget(0),
311 viewSettings_(nullptr),
312 isUpdatingWidgetFromSettings_(false)
313 {
314 setWindowTitle("3D View Settings [Beta]");
315
316 spaceScale_ = new QDoubleSpinBox();
317 spaceScale_->setRange(-100,100);
318 spaceScale_->setDecimals(5);
319 spaceScale_->setSingleStep(0.0001);
320
321 timeScale_ = new QDoubleSpinBox();
322 timeScale_->setRange(-100,100);
323 timeScale_->setDecimals(5);
324 timeScale_->setSingleStep(0.001);
325
326 isTimeHorizontal_ = new QCheckBox();
327 freezeSpaceRect_ = new QCheckBox();
328 cameraFollowActiveTime_ = new QCheckBox();
329
330 drawGrid_ = new QCheckBox();
331 drawTimePlane_ = new QCheckBox();
332 drawCurrentFrame_ = new QCheckBox();
333 drawAllFrames_ = new QCheckBox();
334 drawFramesAsTopology_ = new QCheckBox();
335 drawCurrentFrameAsTopology_ = new QCheckBox();
336 drawTopologyFaces_ = new QCheckBox();
337 drawKeyCells_ = new QCheckBox();
338 drawInbetweenCells_ = new QCheckBox();
339 drawKeyVerticesAsDots_ = new QCheckBox();
340 clipToSpaceTimeWindow_ = new QCheckBox();
341
342 vertexTopologySize_ = new QSpinBox();
343 vertexTopologySize_->setRange(1,100);
344
345 edgeTopologyWidth_ = new QSpinBox();
346 edgeTopologyWidth_->setRange(1,100);
347
348
349 opacity_ = new QDoubleSpinBox();
350 opacity_->setRange(0,1);
351 opacity_->setDecimals(3);
352 opacity_->setSingleStep(0.05);
353 drawAsMesh_ = new QCheckBox();
354 k1_ = new QSpinBox();
355 k1_->setRange(1,100);
356 k2_ = new QSpinBox();
357 k2_->setRange(1,100);
358
359 QFormLayout * layout = new QFormLayout();
360 layout->addRow("Space scale:", spaceScale_);
361 layout->addRow("Time scale:", timeScale_);
362 //layout->addRow("Is time horizontal:", isTimeHorizontal_);
363 layout->addRow("Freeze space rect:", freezeSpaceRect_);
364 layout->addRow("Camera follow active time:", cameraFollowActiveTime_);
365 layout->addRow("Draw grid:", drawGrid_);
366 layout->addRow("Draw canvas:", drawTimePlane_);
367 layout->addRow("Draw current frame:", drawCurrentFrame_);
368 layout->addRow("Draw current frame as topology:", drawCurrentFrameAsTopology_);
369 layout->addRow("Draw faces:", drawTopologyFaces_);
370 layout->addRow("Draw all frames:", drawAllFrames_);
371 layout->addRow("Draw frames as topology:", drawFramesAsTopology_);
372 layout->addRow("Draw key cells:", drawKeyCells_);
373 layout->addRow("Draw inbetween cells:", drawInbetweenCells_);
374 //layout->addRow("Draw vertices as dots:", drawKeyVerticesAsDots_);
375 //layout->addRow("clip to space-time window:", clipToSpaceTimeWindow_);
376 layout->addRow("Vertex topology size:", vertexTopologySize_);
377 layout->addRow("Edge topology width:", edgeTopologyWidth_);
378 layout->addRow("Opacity:", opacity_);
379 layout->addRow("Draw inbetween faces as mesh:", drawAsMesh_);
380 layout->addRow("Mesh temporal res:", k1_);
381 layout->addRow("Mesh inverse spatial res:", k2_);
382 setLayout(layout);
383
384 connect(spaceScale_, SIGNAL(valueChanged(double)), this, SLOT(updateSettingsFromWidget()));
385 connect(timeScale_, SIGNAL(valueChanged(double)), this, SLOT(updateSettingsFromWidget()));
386 connect(isTimeHorizontal_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
387 connect(freezeSpaceRect_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
388 connect(cameraFollowActiveTime_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
389 connect(drawGrid_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
390 connect(drawTimePlane_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
391 connect(drawCurrentFrame_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
392 connect(drawCurrentFrameAsTopology_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
393 connect(drawTopologyFaces_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
394 connect(drawAllFrames_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
395 connect(drawFramesAsTopology_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
396 connect(drawKeyCells_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
397 connect(drawInbetweenCells_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
398 connect(drawKeyVerticesAsDots_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
399 connect(clipToSpaceTimeWindow_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
400 connect(vertexTopologySize_, SIGNAL(valueChanged(int)), this, SLOT(updateSettingsFromWidget()));
401 connect(edgeTopologyWidth_, SIGNAL(valueChanged(int)), this, SLOT(updateSettingsFromWidget()));
402 connect(opacity_, SIGNAL(valueChanged(double)), this, SLOT(updateSettingsFromWidget()));
403 connect(drawAsMesh_, SIGNAL(stateChanged(int)), this, SLOT(updateSettingsFromWidget()));
404 connect(k1_, SIGNAL(valueChanged(int)), this, SLOT(updateSettingsFromWidget()));
405 connect(k2_, SIGNAL(valueChanged(int)), this, SLOT(updateSettingsFromWidget()));
406 }
407
~View3DSettingsWidget()408 View3DSettingsWidget::~View3DSettingsWidget()
409 {
410
411 }
412
setViewSettings(View3DSettings * viewSettings)413 void View3DSettingsWidget::setViewSettings(View3DSettings * viewSettings)
414 {
415 viewSettings_ = viewSettings;
416
417 updateWidgetFromSettings(); // Might not be an exact match due to widget min/max values
418 updateSettingsFromWidget(); // Make sure its an exact match
419 }
420
closeEvent(QCloseEvent * event)421 void View3DSettingsWidget::closeEvent(QCloseEvent * event)
422 {
423 emit closed();
424 event->accept();
425 }
426
updateWidgetFromSettings()427 void View3DSettingsWidget::updateWidgetFromSettings()
428 {
429 isUpdatingWidgetFromSettings_ = true;
430
431 if (viewSettings_)
432 {
433 spaceScale_->setValue(viewSettings_->spaceScale());
434 timeScale_->setValue(viewSettings_->timeScale());
435 isTimeHorizontal_->setChecked(viewSettings_->isTimeHorizontal());
436 freezeSpaceRect_->setChecked(viewSettings_->freezeSpaceRect());
437 cameraFollowActiveTime_->setChecked(viewSettings_->cameraFollowActiveTime());
438 drawGrid_->setChecked(viewSettings_->drawGrid());
439 drawTimePlane_->setChecked(viewSettings_->drawTimePlane());
440 drawCurrentFrame_->setChecked(viewSettings_->drawCurrentFrame());
441 drawAllFrames_->setChecked(viewSettings_->drawAllFrames());
442 drawFramesAsTopology_->setChecked(viewSettings_->drawFramesAsTopology());
443 drawCurrentFrameAsTopology_->setChecked(viewSettings_->drawCurrentFrameAsTopology());
444 drawTopologyFaces_->setChecked(viewSettings_->drawTopologyFaces());
445 drawKeyCells_->setChecked(viewSettings_->drawKeyCells());
446 drawInbetweenCells_->setChecked(viewSettings_->drawInbetweenCells());
447 drawKeyVerticesAsDots_->setChecked(viewSettings_->drawKeyVerticesAsDots());
448 clipToSpaceTimeWindow_->setChecked(viewSettings_->clipToSpaceTimeWindow());
449 vertexTopologySize_->setValue(viewSettings_->vertexTopologySize());
450 edgeTopologyWidth_->setValue(viewSettings_->edgeTopologyWidth());
451 opacity_->setValue(viewSettings_->opacity());
452 drawAsMesh_->setChecked(viewSettings_->drawAsMesh());
453 k1_->setValue(viewSettings_->k1());
454 k2_->setValue(viewSettings_->k2());
455 }
456
457 isUpdatingWidgetFromSettings_ = false;
458 }
459
updateSettingsFromWidget()460 void View3DSettingsWidget::updateSettingsFromWidget()
461 {
462 if (!isUpdatingWidgetFromSettings_ && viewSettings_)
463 {
464 viewSettings_->setSpaceScale(spaceScale_->value());
465 viewSettings_->setTimeScale(timeScale_->value());
466 viewSettings_->setIsTimeHorizontal(isTimeHorizontal_->isChecked());
467 viewSettings_->setFreezeSpaceRect(freezeSpaceRect_->isChecked());
468 viewSettings_->setCameraFollowActiveTime(cameraFollowActiveTime_->isChecked());
469 viewSettings_->setDrawGrid(drawGrid_->isChecked());
470 viewSettings_->setDrawTimePlane(drawTimePlane_->isChecked());
471 viewSettings_->setDrawCurrentFrame(drawCurrentFrame_->isChecked());
472 viewSettings_->setDrawAllFrames(drawAllFrames_->isChecked());
473 viewSettings_->setDrawFramesAsTopology(drawFramesAsTopology_->isChecked());
474 viewSettings_->setDrawCurrentFrameAsTopology(drawCurrentFrameAsTopology_->isChecked());
475 viewSettings_->setDrawTopologyFaces(drawTopologyFaces_->isChecked());
476 viewSettings_->setDrawKeyCells(drawKeyCells_->isChecked());
477 viewSettings_->setDrawInbetweenCells(drawInbetweenCells_->isChecked());
478 viewSettings_->setDrawKeyVerticesAsDots(drawKeyVerticesAsDots_->isChecked());
479 viewSettings_->setClipToSpaceTimeWindow(clipToSpaceTimeWindow_->isChecked());
480 viewSettings_->setVertexTopologySize(vertexTopologySize_->value());
481 viewSettings_->setEdgeTopologyWidth(edgeTopologyWidth_->value());
482 viewSettings_->setOpacity(opacity_->value());
483 viewSettings_->setDrawAsMesh(drawAsMesh_->isChecked());
484 viewSettings_->setK1(k1_->value());
485 viewSettings_->setK2(k2_->value());
486
487 emit changed();
488 }
489 }
490