CustusX  15.8
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 
141  //Layout
142  mMainLayout = new QGridLayout;
143  mMainLayout->addWidget(renderingIntervalLabel, 0, 0);
145  mMainLayout->addWidget(mRenderingIntervalSpinBox, 0, 1);
146  mMainLayout->addWidget(mRenderingRateLabel, 0, 2);
147  mMainLayout->addWidget(mSmartRenderCheckBox, 2, 0);
148  mMainLayout->addWidget(mGPU2DRenderCheckBox, 5, 0);
149  mMainLayout->addWidget(mOptimizedViewsCheckBox, 6, 0);
150  new SpinBoxGroupWidget(this, mStillUpdateRate, mMainLayout, 7);
151  mMainLayout->addWidget(sscCreateDataWidget(this, m3DVisualizer), 8, 0, 1, 2);
152 
153  mMainLayout->setColumnStretch(0, 2);
154  mMainLayout->setColumnStretch(1, 2);
155  mMainLayout->setColumnStretch(2, 1);
156 
157  mTopLayout->addLayout(mMainLayout);
158 }
159 
160 static QStringList getAvailableVisualizers();
161 static std::map<QString, QString> getAvailableVisualizerDisplayNames();
162 
163 void PerformanceTab::renderingIntervalSlot(int interval)
164 {
165  mRenderingRateLabel->setText(QString("%1 fps").arg(1000.0/interval, 0, 'f', 1));
166 }
167 
168 QStringList PerformanceTab::getAvailableVisualizers()
169 {
170  QStringList retval;
171  retval << "vtkVolumeTextureMapper3D";
172  retval << "vtkGPUVolumeRayCastMapper";
173 #ifdef CX_BUILD_MEHDI_VTKMULTIVOLUME
174  retval << "vtkOpenGLGPUMultiVolumeRayCastMapper";
175 #endif //CX_BUILD_MEHDI_VTKMULTIVOLUME
176 
177  return retval;
178 }
179 
180 std::map<QString, QString> PerformanceTab::getAvailableVisualizerDisplayNames()
181 {
182  std::map<QString, QString> names;
183  names["vtkVolumeTextureMapper3D"] = "Texture (single volume)";
184  names["vtkGPUVolumeRayCastMapper"] = "Raycast GPU (single volume)";
185  names["vtkOpenGLGPUMultiVolumeRayCastMapper"] = "Mehdi Raycast GPU (multi volume)";
186  return names;
187 }
188 
190 {
191  settings()->setValue("renderingInterval", mRenderingIntervalSpinBox->value());
192  settings()->setValue("useGPU2DRendering", mGPU2DRenderCheckBox->isChecked());
193  settings()->setValue("optimizedViews", mOptimizedViewsCheckBox->isChecked());
194 
195  settings()->setValue("View3D/maxRenderSize", mMaxRenderSize->getValue());
196  settings()->setValue("smartRender", mSmartRenderCheckBox->isChecked());
197  settings()->setValue("stillUpdateRate", mStillUpdateRate->getValue());
198 // settings()->setValue("View3D/depthPeeling", mGPU3DDepthPeelingCheckBox->isChecked());
199  settings()->setValue("View3D/ImageRender3DVisualizer", m3DVisualizer->getValue());
200 }
201 
202 } /* 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
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.