CustusX  22.04-rc5
An IGT application
cxPreferenceTab.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxPreferenceTab.h"
13 
14 #include <cmath>
15 #include <QVBoxLayout>
16 #include <QLabel>
17 #include <QSpinBox>
18 #include <QCheckBox>
19 #include "cxDoubleWidgets.h"
20 #include "cxHelperWidgets.h"
21 #include "cxSettings.h"
22 #include "sscConfig.h"
23 #include "cxImage.h"
24 
25 namespace cx
26 {
27 //==============================================================================
28 // PreferencesTab
29 //------------------------------------------------------------------------------
30 
31 PreferenceTab::PreferenceTab(QWidget *parent) :
32  QWidget(parent)
33 {
34  this->setFocusPolicy(Qt::StrongFocus); // needed for help system: focus is used to display help text
35  mTopLayout = new QVBoxLayout;
36 
37  QVBoxLayout* vtopLayout = new QVBoxLayout;
38  vtopLayout->addLayout(mTopLayout);
39  vtopLayout->setMargin(0);
40  vtopLayout->addStretch();
41  this->setLayout(vtopLayout);
42 }
43 
44 //==============================================================================
45 // PerformanceTab
46 //------------------------------------------------------------------------------
48  PreferenceTab(parent)
49 {
50  this->setObjectName("preferences_performance_widget");
52  mRenderingRateLabel = NULL;
53  mSmartRenderCheckBox = NULL;
54  mGPU2DRenderCheckBox = NULL;
57  mShadingCheckBox = NULL;
58  mMainLayout = NULL;
59 }
60 
62 {
63  int renderingInterval = settings()->value("renderingInterval").toInt();
64 
65  QLabel* renderingIntervalLabel = new QLabel(tr("Rendering interval"));
66 
67  mRenderingIntervalSpinBox = new QSpinBox;
68  mRenderingIntervalSpinBox->setSuffix("ms");
69  mRenderingIntervalSpinBox->setMinimum(4);
70  mRenderingIntervalSpinBox->setMaximum(1000);
71  mRenderingIntervalSpinBox->setValue(renderingInterval);
72  connect(mRenderingIntervalSpinBox, SIGNAL(valueChanged(int)), this, SLOT(renderingIntervalSlot(int)));
73 
74  mRenderingRateLabel = new QLabel("");
75  this->renderingIntervalSlot(renderingInterval);
76 
77  double Mb = pow(10.0,6);
78  bool ok = true;
79  double maxRenderSize = settings()->value("View3D/maxRenderSize").toDouble(&ok);
80  if (!ok)
81  maxRenderSize = 10 * Mb;
82  mMaxRenderSize = DoubleProperty::initialize("MaxRenderSize", "Max Render Size (Mb)", "Maximum size of volumes used in volume rendering. Applies to new volumes.", maxRenderSize, DoubleRange(1*Mb,300*Mb,1*Mb), 0, QDomNode());
83  mMaxRenderSize->setInternal2Display(1.0/Mb);
84 
85  double stillUpdateRate = settings()->value("stillUpdateRate").value<double>();
86  mStillUpdateRate = DoubleProperty::initialize("StillUpdateRate", "Still Update Rate",
87  "<p>Still Update Rate in vtkRenderWindow. "
88  "Increasing the value may improve rendering speed "
89  "at the cost of render quality.</p> "
90  "Generally raycast rendering requires this to be low (0.001), "
91  "while texture based rendering requires it to be high (5-10)."
92  "<p>Restart needed.</p>",
93  stillUpdateRate, DoubleRange(0.0001, 20, 0.0001), 4, QDomNode());
94 
95  mSmartRenderCheckBox = new QCheckBox("Smart Render");
96  mSmartRenderCheckBox->setChecked(settings()->value("smartRender", true).toBool());
97  mSmartRenderCheckBox->setToolTip("Render only when scene has changed, plus once per second.");
98 
99  m3DVisualizer = StringProperty::initialize("ImageRender3DVisualizer",
100  "3D Renderer",
101  "Select 3D visualization method for images",
102  settings()->value("View3D/ImageRender3DVisualizer").toString(),
103  this->getAvailableVisualizers(),
104  QDomNode());
105  m3DVisualizer->setDisplayNames(this->getAvailableVisualizerDisplayNames());
106 
107  bool useGPU2DRender = settings()->value("View2D/useGPU2DRendering").toBool();
108  mGPU2DRenderCheckBox = new QCheckBox("2D Overlay");
109  mGPU2DRenderCheckBox->setChecked(useGPU2DRender);
110  mGPU2DRenderCheckBox->setToolTip("<p>Use a GPU-based 2D renderer instead of "
111  "the software-based one, if available.</p>"
112  "<p>This enables multiple volume rendering in 2D.<p>");
113 
114  bool linearInterpolationIn2D = settings()->value("View2D/useLinearInterpolationIn2DRendering").toBool();
115  mLinearInterpolationIn2DCheckBox = new QCheckBox("Linear interpolation in 2D (Requires restart)");
116  mLinearInterpolationIn2DCheckBox->setChecked(linearInterpolationIn2D);
117  mLinearInterpolationIn2DCheckBox->setToolTip("<p>Use linear interpolation in GPU 2D rendering "
118  "instead of nearest.</p>"
119  "<p>Requires restart.<p>");
120 
121  bool optimizedViews = settings()->value("optimizedViews").toBool();
122  mOptimizedViewsCheckBox = new QCheckBox("Optimized Views");
123  mOptimizedViewsCheckBox->setChecked(optimizedViews);
124  mOptimizedViewsCheckBox->setToolTip("<p>Merge all non-3D views into a single vtkRenderWindow</p>"
125  "<p>This speeds up render on some platforms, still experimental.<p>");
126 
127  bool useGPU3DDepthPeeling = settings()->value("View3D/depthPeeling").toBool();
128  mGPU3DDepthPeelingCheckBox = new QCheckBox("Use GPU 3D depth peeling");
129  mGPU3DDepthPeelingCheckBox->setChecked(useGPU3DDepthPeeling);
130  mGPU3DDepthPeelingCheckBox->setToolTip("Use a GPU-based 3D depth peeling to correctly visualize translucent surfaces.");
131 
132  //Layout
133  mMainLayout = new QGridLayout;
134  mMainLayout->addWidget(renderingIntervalLabel, 0, 0);
136  mMainLayout->addWidget(mRenderingIntervalSpinBox, 0, 1);
137  mMainLayout->addWidget(mRenderingRateLabel, 0, 2);
138  mMainLayout->addWidget(mSmartRenderCheckBox, 2, 0);
139  mMainLayout->addWidget(mGPU2DRenderCheckBox, 5, 0);
141  mMainLayout->addWidget(mOptimizedViewsCheckBox, 7, 0);
142  mMainLayout->addWidget(mGPU3DDepthPeelingCheckBox, 8, 0);
143  new SpinBoxGroupWidget(this, mStillUpdateRate, mMainLayout, 9);
144  mMainLayout->addWidget(sscCreateDataWidget(this, m3DVisualizer), 10, 0, 1, 2);
145 
146  mMainLayout->setColumnStretch(0, 2);
147  mMainLayout->setColumnStretch(1, 2);
148  mMainLayout->setColumnStretch(2, 1);
149 
150  mTopLayout->addLayout(mMainLayout);
151 }
152 
153 static QStringList getAvailableVisualizers();
154 static std::map<QString, QString> getAvailableVisualizerDisplayNames();
155 
156 void PerformanceTab::renderingIntervalSlot(int interval)
157 {
158  mRenderingRateLabel->setText(QString("%1 fps").arg(1000.0/interval, 0, 'f', 1));
159 }
160 
161 QStringList PerformanceTab::getAvailableVisualizers()
162 {
163  QStringList retval;
164  retval << "vtkVolumeTextureMapper3D";
165  retval << "vtkGPUVolumeRayCastMapper";
166 #ifdef CX_BUILD_MEHDI_VTKMULTIVOLUME
167  retval << "vtkOpenGLGPUMultiVolumeRayCastMapper";
168 #endif //CX_BUILD_MEHDI_VTKMULTIVOLUME
169 
170  return retval;
171 }
172 
173 std::map<QString, QString> PerformanceTab::getAvailableVisualizerDisplayNames()
174 {
175  std::map<QString, QString> names;
176  names["vtkVolumeTextureMapper3D"] = "Texture (single volume)";
177  names["vtkGPUVolumeRayCastMapper"] = "Raycast GPU (single volume)";
178  names["vtkOpenGLGPUMultiVolumeRayCastMapper"] = "Mehdi Raycast GPU (multi volume)";
179  return names;
180 }
181 
183 {
184  settings()->setValue("renderingInterval", mRenderingIntervalSpinBox->value());
185  settings()->setValue("View2D/useGPU2DRendering", mGPU2DRenderCheckBox->isChecked());
186  settings()->setValue("View2D/useLinearInterpolationIn2DRendering", mLinearInterpolationIn2DCheckBox->isChecked());
187  settings()->setValue("optimizedViews", mOptimizedViewsCheckBox->isChecked());
188 
189  settings()->setValue("View3D/maxRenderSize", mMaxRenderSize->getValue());
190  settings()->setValue("smartRender", mSmartRenderCheckBox->isChecked());
191  settings()->setValue("stillUpdateRate", mStillUpdateRate->getValue());
192  settings()->setValue("View3D/depthPeeling", mGPU3DDepthPeelingCheckBox->isChecked());
193  settings()->setValue("View3D/ImageRender3DVisualizer", m3DVisualizer->getValue());
194 }
195 
196 } /* namespace cx */
QCheckBox * mSmartRenderCheckBox
PreferenceTab(QWidget *parent=0)
QCheckBox * mOptimizedViewsCheckBox
DoublePropertyPtr mStillUpdateRate
QSpinBox * mRenderingIntervalSpinBox
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:755
StringPropertyPtr m3DVisualizer
QVBoxLayout * mTopLayout
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
QGridLayout * mMainLayout
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
QCheckBox * mLinearInterpolationIn2DCheckBox
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
DoublePropertyPtr mMaxRenderSize
QCheckBox * mGPU3DDepthPeelingCheckBox
QLabel * mRenderingRateLabel
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
QCheckBox * mShadingCheckBox
PerformanceTab(QWidget *parent=0)
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
Composite widget for scalar data manipulation.
QCheckBox * mGPU2DRenderCheckBox
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Namespace for all CustusX production code.