Fraxinus  16.5.0-fx-rc4
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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;
77  mShadingCheckBox = NULL;
78  mMainLayout = NULL;
79 }
80 
82 {
83  int renderingInterval = settings()->value("renderingInterval").toInt();
84 
85  QLabel* renderingIntervalLabel = new QLabel(tr("Rendering interval"));
86 
87  mRenderingIntervalSpinBox = new QSpinBox;
88  mRenderingIntervalSpinBox->setSuffix("ms");
89  mRenderingIntervalSpinBox->setMinimum(4);
90  mRenderingIntervalSpinBox->setMaximum(1000);
91  mRenderingIntervalSpinBox->setValue(renderingInterval);
92  connect(mRenderingIntervalSpinBox, SIGNAL(valueChanged(int)), this, SLOT(renderingIntervalSlot(int)));
93 
94  mRenderingRateLabel = new QLabel("");
95  this->renderingIntervalSlot(renderingInterval);
96 
97  double Mb = pow(10.0,6);
98  bool ok = true;
99  double maxRenderSize = settings()->value("View3D/maxRenderSize").toDouble(&ok);
100  if (!ok)
101  maxRenderSize = 10 * Mb;
102  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());
103  mMaxRenderSize->setInternal2Display(1.0/Mb);
104 
105  double stillUpdateRate = settings()->value("stillUpdateRate").value<double>();
106  mStillUpdateRate = DoubleProperty::initialize("StillUpdateRate", "Still Update Rate",
107  "<p>Still Update Rate in vtkRenderWindow. "
108  "Increasing the value may improve rendering speed "
109  "at the cost of render quality.</p> "
110  "Generally raycast rendering requires this to be low (0.001), "
111  "while texture based rendering requires it to be high (5-10)."
112  "<p>Restart needed.</p>",
113  stillUpdateRate, DoubleRange(0.0001, 20, 0.0001), 4, QDomNode());
114 
115  mSmartRenderCheckBox = new QCheckBox("Smart Render");
116  mSmartRenderCheckBox->setChecked(settings()->value("smartRender", true).toBool());
117  mSmartRenderCheckBox->setToolTip("Render only when scene has changed, plus once per second.");
118 
119  m3DVisualizer = StringProperty::initialize("ImageRender3DVisualizer",
120  "3D Renderer",
121  "Select 3D visualization method for images",
122  settings()->value("View3D/ImageRender3DVisualizer").toString(),
123  this->getAvailableVisualizers(),
124  QDomNode());
125  m3DVisualizer->setDisplayNames(this->getAvailableVisualizerDisplayNames());
126 
127  bool useGPU2DRender = settings()->value("useGPU2DRendering").toBool();
128  mGPU2DRenderCheckBox = new QCheckBox("2D Overlay");
129  mGPU2DRenderCheckBox->setChecked(useGPU2DRender);
130  mGPU2DRenderCheckBox->setToolTip("<p>Use a GPU-based 2D renderer instead of "
131  "the software-based one, if available.</p>"
132  "<p>This enables multiple volume rendering in 2D.<p>");
133 
134  bool optimizedViews = settings()->value("optimizedViews").toBool();
135  mOptimizedViewsCheckBox = new QCheckBox("Optimized Views");
136  mOptimizedViewsCheckBox->setChecked(optimizedViews);
137  mOptimizedViewsCheckBox->setToolTip("<p>Merge all non-3D views into a single vtkRenderWindow</p>"
138  "<p>This speeds up render on some platforms, still experimental.<p>");
139 
140  bool useGPU3DDepthPeeling = settings()->value("View3D/depthPeeling").toBool();
141  mGPU3DDepthPeelingCheckBox = new QCheckBox("Use GPU 3D depth peeling");
142  mGPU3DDepthPeelingCheckBox->setChecked(useGPU3DDepthPeeling);
143  mGPU3DDepthPeelingCheckBox->setToolTip("Use a GPU-based 3D depth peeling to correctly visualize translucent surfaces.");
144 
145  //Layout
146  mMainLayout = new QGridLayout;
147  mMainLayout->addWidget(renderingIntervalLabel, 0, 0);
149  mMainLayout->addWidget(mRenderingIntervalSpinBox, 0, 1);
150  mMainLayout->addWidget(mRenderingRateLabel, 0, 2);
151  mMainLayout->addWidget(mSmartRenderCheckBox, 2, 0);
152  mMainLayout->addWidget(mGPU2DRenderCheckBox, 5, 0);
153  mMainLayout->addWidget(mOptimizedViewsCheckBox, 6, 0);
154  mMainLayout->addWidget(mGPU3DDepthPeelingCheckBox, 7, 0);
155  new SpinBoxGroupWidget(this, mStillUpdateRate, mMainLayout, 8);
156  mMainLayout->addWidget(sscCreateDataWidget(this, m3DVisualizer), 9, 0, 1, 2);
157 
158  mMainLayout->setColumnStretch(0, 2);
159  mMainLayout->setColumnStretch(1, 2);
160  mMainLayout->setColumnStretch(2, 1);
161 
162  mTopLayout->addLayout(mMainLayout);
163 }
164 
165 static QStringList getAvailableVisualizers();
166 static std::map<QString, QString> getAvailableVisualizerDisplayNames();
167 
168 void PerformanceTab::renderingIntervalSlot(int interval)
169 {
170  mRenderingRateLabel->setText(QString("%1 fps").arg(1000.0/interval, 0, 'f', 1));
171 }
172 
173 QStringList PerformanceTab::getAvailableVisualizers()
174 {
175  QStringList retval;
176  retval << "vtkVolumeTextureMapper3D";
177  retval << "vtkGPUVolumeRayCastMapper";
178 #ifdef CX_BUILD_MEHDI_VTKMULTIVOLUME
179  retval << "vtkOpenGLGPUMultiVolumeRayCastMapper";
180 #endif //CX_BUILD_MEHDI_VTKMULTIVOLUME
181 
182  return retval;
183 }
184 
185 std::map<QString, QString> PerformanceTab::getAvailableVisualizerDisplayNames()
186 {
187  std::map<QString, QString> names;
188  names["vtkVolumeTextureMapper3D"] = "Texture (single volume)";
189  names["vtkGPUVolumeRayCastMapper"] = "Raycast GPU (single volume)";
190  names["vtkOpenGLGPUMultiVolumeRayCastMapper"] = "Mehdi Raycast GPU (multi volume)";
191  return names;
192 }
193 
195 {
196  settings()->setValue("renderingInterval", mRenderingIntervalSpinBox->value());
197  settings()->setValue("useGPU2DRendering", mGPU2DRenderCheckBox->isChecked());
198  settings()->setValue("optimizedViews", mOptimizedViewsCheckBox->isChecked());
199 
200  settings()->setValue("View3D/maxRenderSize", mMaxRenderSize->getValue());
201  settings()->setValue("smartRender", mSmartRenderCheckBox->isChecked());
202  settings()->setValue("stillUpdateRate", mStillUpdateRate->getValue());
203  settings()->setValue("View3D/depthPeeling", mGPU3DDepthPeelingCheckBox->isChecked());
204  settings()->setValue("View3D/ImageRender3DVisualizer", m3DVisualizer->getValue());
205 }
206 
207 } /* namespace cx */
QCheckBox * mSmartRenderCheckBox
PreferenceTab(QWidget *parent=0)
QCheckBox * mOptimizedViewsCheckBox
DoublePropertyPtr mStillUpdateRate
QSpinBox * mRenderingIntervalSpinBox
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
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.