Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxPreferenceTab.h"
34 
35 #include <cmath>
36 #include <QVBoxLayout>
37 #include <QLabel>
38 #include <QSpinBox>
39 #include <QCheckBox>
40 #include "cxDoubleWidgets.h"
41 #include "cxHelperWidgets.h"
42 #include "cxSettings.h"
43 #include "sscConfig.h"
44 #include "cxImage.h"
45 
46 namespace cx
47 {
48 //==============================================================================
49 // PreferencesTab
50 //------------------------------------------------------------------------------
51 
52 PreferenceTab::PreferenceTab(QWidget *parent) :
53  QWidget(parent)
54 {
55  this->setFocusPolicy(Qt::StrongFocus); // needed for help system: focus is used to display help text
56  mTopLayout = new QVBoxLayout;
57 
58  QVBoxLayout* vtopLayout = new QVBoxLayout;
59  vtopLayout->addLayout(mTopLayout);
60  vtopLayout->setMargin(0);
61  vtopLayout->addStretch();
62  this->setLayout(vtopLayout);
63 }
64 
65 //==============================================================================
66 // PerformanceTab
67 //------------------------------------------------------------------------------
69  PreferenceTab(parent)
70 {
71  this->setObjectName("preferences_performance_widget");
73  mRenderingRateLabel = NULL;
74  mSmartRenderCheckBox = NULL;
75  mGPU2DRenderCheckBox = NULL;
78  mShadingCheckBox = NULL;
79  mMainLayout = NULL;
80 }
81 
83 {
84  int renderingInterval = settings()->value("renderingInterval").toInt();
85 
86  QLabel* renderingIntervalLabel = new QLabel(tr("Rendering interval"));
87 
88  mRenderingIntervalSpinBox = new QSpinBox;
89  mRenderingIntervalSpinBox->setSuffix("ms");
90  mRenderingIntervalSpinBox->setMinimum(4);
91  mRenderingIntervalSpinBox->setMaximum(1000);
92  mRenderingIntervalSpinBox->setValue(renderingInterval);
93  connect(mRenderingIntervalSpinBox, SIGNAL(valueChanged(int)), this, SLOT(renderingIntervalSlot(int)));
94 
95  mRenderingRateLabel = new QLabel("");
96  this->renderingIntervalSlot(renderingInterval);
97 
98  double Mb = pow(10.0,6);
99  bool ok = true;
100  double maxRenderSize = settings()->value("View3D/maxRenderSize").toDouble(&ok);
101  if (!ok)
102  maxRenderSize = 10 * Mb;
103  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());
104  mMaxRenderSize->setInternal2Display(1.0/Mb);
105 
106  double stillUpdateRate = settings()->value("stillUpdateRate").value<double>();
107  mStillUpdateRate = DoubleProperty::initialize("StillUpdateRate", "Still Update Rate",
108  "<p>Still Update Rate in vtkRenderWindow. "
109  "Increasing the value may improve rendering speed "
110  "at the cost of render quality.</p> "
111  "Generally raycast rendering requires this to be low (0.001), "
112  "while texture based rendering requires it to be high (5-10)."
113  "<p>Restart needed.</p>",
114  stillUpdateRate, DoubleRange(0.0001, 20, 0.0001), 4, QDomNode());
115 
116  mSmartRenderCheckBox = new QCheckBox("Smart Render");
117  mSmartRenderCheckBox->setChecked(settings()->value("smartRender", true).toBool());
118  mSmartRenderCheckBox->setToolTip("Render only when scene has changed, plus once per second.");
119 
120  m3DVisualizer = StringProperty::initialize("ImageRender3DVisualizer",
121  "3D Renderer",
122  "Select 3D visualization method for images",
123  settings()->value("View3D/ImageRender3DVisualizer").toString(),
124  this->getAvailableVisualizers(),
125  QDomNode());
126  m3DVisualizer->setDisplayNames(this->getAvailableVisualizerDisplayNames());
127 
128  bool useGPU2DRender = settings()->value("View2D/useGPU2DRendering").toBool();
129  mGPU2DRenderCheckBox = new QCheckBox("2D Overlay");
130  mGPU2DRenderCheckBox->setChecked(useGPU2DRender);
131  mGPU2DRenderCheckBox->setToolTip("<p>Use a GPU-based 2D renderer instead of "
132  "the software-based one, if available.</p>"
133  "<p>This enables multiple volume rendering in 2D.<p>");
134 
135  bool linearInterpolationIn2D = settings()->value("View2D/useLinearInterpolationIn2DRendering").toBool();
136  mLinearInterpolationIn2DCheckBox = new QCheckBox("Linear interpolation in 2D (Requires restart)");
137  mLinearInterpolationIn2DCheckBox->setChecked(linearInterpolationIn2D);
138  mLinearInterpolationIn2DCheckBox->setToolTip("<p>Use linear interpolation in GPU 2D rendering "
139  "instead of nearest.</p>"
140  "<p>Requires restart.<p>");
141 
142  bool optimizedViews = settings()->value("optimizedViews").toBool();
143  mOptimizedViewsCheckBox = new QCheckBox("Optimized Views");
144  mOptimizedViewsCheckBox->setChecked(optimizedViews);
145  mOptimizedViewsCheckBox->setToolTip("<p>Merge all non-3D views into a single vtkRenderWindow</p>"
146  "<p>This speeds up render on some platforms, still experimental.<p>");
147 
148  bool useGPU3DDepthPeeling = settings()->value("View3D/depthPeeling").toBool();
149  mGPU3DDepthPeelingCheckBox = new QCheckBox("Use GPU 3D depth peeling");
150  mGPU3DDepthPeelingCheckBox->setChecked(useGPU3DDepthPeeling);
151  mGPU3DDepthPeelingCheckBox->setToolTip("Use a GPU-based 3D depth peeling to correctly visualize translucent surfaces.");
152 
153  //Layout
154  mMainLayout = new QGridLayout;
155  mMainLayout->addWidget(renderingIntervalLabel, 0, 0);
157  mMainLayout->addWidget(mRenderingIntervalSpinBox, 0, 1);
158  mMainLayout->addWidget(mRenderingRateLabel, 0, 2);
159  mMainLayout->addWidget(mSmartRenderCheckBox, 2, 0);
160  mMainLayout->addWidget(mGPU2DRenderCheckBox, 5, 0);
162  mMainLayout->addWidget(mOptimizedViewsCheckBox, 7, 0);
163  mMainLayout->addWidget(mGPU3DDepthPeelingCheckBox, 8, 0);
164  new SpinBoxGroupWidget(this, mStillUpdateRate, mMainLayout, 9);
165  mMainLayout->addWidget(sscCreateDataWidget(this, m3DVisualizer), 10, 0, 1, 2);
166 
167  mMainLayout->setColumnStretch(0, 2);
168  mMainLayout->setColumnStretch(1, 2);
169  mMainLayout->setColumnStretch(2, 1);
170 
171  mTopLayout->addLayout(mMainLayout);
172 }
173 
174 static QStringList getAvailableVisualizers();
175 static std::map<QString, QString> getAvailableVisualizerDisplayNames();
176 
177 void PerformanceTab::renderingIntervalSlot(int interval)
178 {
179  mRenderingRateLabel->setText(QString("%1 fps").arg(1000.0/interval, 0, 'f', 1));
180 }
181 
182 QStringList PerformanceTab::getAvailableVisualizers()
183 {
184  QStringList retval;
185  retval << "vtkVolumeTextureMapper3D";
186  retval << "vtkGPUVolumeRayCastMapper";
187 #ifdef CX_BUILD_MEHDI_VTKMULTIVOLUME
188  retval << "vtkOpenGLGPUMultiVolumeRayCastMapper";
189 #endif //CX_BUILD_MEHDI_VTKMULTIVOLUME
190 
191  return retval;
192 }
193 
194 std::map<QString, QString> PerformanceTab::getAvailableVisualizerDisplayNames()
195 {
196  std::map<QString, QString> names;
197  names["vtkVolumeTextureMapper3D"] = "Texture (single volume)";
198  names["vtkGPUVolumeRayCastMapper"] = "Raycast GPU (single volume)";
199  names["vtkOpenGLGPUMultiVolumeRayCastMapper"] = "Mehdi Raycast GPU (multi volume)";
200  return names;
201 }
202 
204 {
205  settings()->setValue("renderingInterval", mRenderingIntervalSpinBox->value());
206  settings()->setValue("View2D/useGPU2DRendering", mGPU2DRenderCheckBox->isChecked());
207  settings()->setValue("View2D/useLinearInterpolationIn2DRendering", mLinearInterpolationIn2DCheckBox->isChecked());
208  settings()->setValue("optimizedViews", mOptimizedViewsCheckBox->isChecked());
209 
210  settings()->setValue("View3D/maxRenderSize", mMaxRenderSize->getValue());
211  settings()->setValue("smartRender", mSmartRenderCheckBox->isChecked());
212  settings()->setValue("stillUpdateRate", mStillUpdateRate->getValue());
213  settings()->setValue("View3D/depthPeeling", mGPU3DDepthPeelingCheckBox->isChecked());
214  settings()->setValue("View3D/ImageRender3DVisualizer", m3DVisualizer->getValue());
215 }
216 
217 } /* 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:53
QGridLayout * mMainLayout
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:87
QCheckBox * mLinearInterpolationIn2DCheckBox
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
DoublePropertyPtr mMaxRenderSize
QCheckBox * mGPU3DDepthPeelingCheckBox
QLabel * mRenderingRateLabel
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
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.