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