Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/vtkpost/colorbar.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI colorbar *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#include <QtGui>
42
#include <iostream>
43
#include "vtkpost.h"
44
#include "colorbar.h"
45
46
#include <vtkActor.h>
47
#include <vtkMapper.h>
48
#include <vtkScalarBarActor.h>
49
#include <vtkTextMapper.h>
50
#include <vtkTextProperty.h>
51
#include <vtkActor.h>
52
53
using namespace std;
54
55
ColorBar::ColorBar(QWidget *parent)
56
: QDialog(parent)
57
{
58
ui.setupUi(this);
59
60
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
61
connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
62
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
63
connect(ui.colorCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(colorSelectionChanged(int)));
64
65
setWindowTitle("Colorbar");
66
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
67
68
ui.cancelButton->setIcon(QIcon::fromTheme("dialog-error-round"));
69
ui.applyButton->setIcon(QIcon::fromTheme("view-refresh"));
70
ui.okButton->setIcon(QIcon::fromTheme("dialog-accept"));
71
}
72
73
ColorBar::~ColorBar()
74
{
75
}
76
77
void ColorBar::cancelButtonClicked()
78
{
79
emit(hideColorBarSignal());
80
close();
81
}
82
83
void ColorBar::okButtonClicked()
84
{
85
applyButtonClicked();
86
close();
87
}
88
89
void ColorBar::applyButtonClicked()
90
{
91
emit(drawColorBarSignal());
92
}
93
94
void ColorBar::colorSelectionChanged(int newIndex)
95
{
96
}
97
98
void ColorBar::populateWidgets(VtkPost* vtkPost)
99
{
100
ui.colorCombo->clear();
101
ui.colorCombo->addItem("Surface");
102
ui.colorCombo->addItem("Vector");
103
ui.colorCombo->addItem("Isocontour");
104
ui.colorCombo->addItem("Isosurface");
105
ui.colorCombo->addItem("Streamline");
106
}
107
108
void ColorBar::draw(VtkPost* vtkPost)
109
{
110
vtkScalarBarActor* colorBarActor = vtkPost->GetColorBarActor();
111
/*
112
vtkTextMapper* tMapper = vtkTextMapper::New();
113
colorBarActor->SetMapper(tMapper);
114
tMapper->Delete();
115
*/
116
117
QString actorName = ui.colorCombo->currentText().trimmed();
118
119
if(actorName.isEmpty()) return;
120
121
QString fieldName = "";
122
123
vtkScalarsToColors* lut = NULL;
124
125
if(actorName == "Surface") {
126
fieldName = vtkPost->GetCurrentSurfaceName();
127
if(fieldName.isEmpty()) return;
128
lut = vtkPost->GetSurfaceActor()->GetMapper()->GetLookupTable();
129
}
130
131
if(actorName == "Vector") {
132
fieldName = vtkPost->GetCurrentVectorName();
133
if(fieldName.isEmpty()) return;
134
lut = vtkPost->GetVectorActor()->GetMapper()->GetLookupTable();
135
}
136
137
if(actorName == "Isocontour") {
138
fieldName = vtkPost->GetCurrentIsoContourName();
139
if(fieldName.isEmpty()) return;
140
lut = vtkPost->GetIsoContourActor()->GetMapper()->GetLookupTable();
141
}
142
143
if(actorName == "Isosurface") {
144
fieldName = vtkPost->GetCurrentIsoSurfaceName();
145
if(fieldName.isEmpty()) return;
146
lut = vtkPost->GetIsoSurfaceActor()->GetMapper()->GetLookupTable();
147
}
148
149
if(actorName == "Streamline") {
150
fieldName = vtkPost->GetCurrentStreamLineName();
151
if(fieldName.isEmpty()) return;
152
lut = vtkPost->GetStreamLineActor()->GetMapper()->GetLookupTable();
153
}
154
155
if(!lut) return;
156
157
//colorBarActor->SetLookupTable(lut);
158
colorBarActor->SetLookupTable((vtkScalarsToColors*)vtkPost->GetLut(actorName));
159
160
bool horizontal = ui.horizontalRButton->isChecked();
161
bool annotate = ui.annotateBox->isChecked();
162
int labels = ui.labelsSpin->value();
163
double width = ui.widthEdit->text().toDouble();
164
double height = ui.heightEdit->text().toDouble();
165
166
if(width < 0.01) width = 0.01;
167
if(width > 1.00) width = 1.00;
168
if(height < 0.01) height = 0.01;
169
if(height > 1.00) height = 1.00;
170
171
colorBarActor->SetPosition(0.05, 0.05);
172
173
if(horizontal) {
174
colorBarActor->SetOrientationToHorizontal();
175
colorBarActor->SetWidth(height);
176
colorBarActor->SetHeight(width);
177
} else {
178
colorBarActor->SetOrientationToVertical();
179
colorBarActor->SetWidth(width);
180
colorBarActor->SetHeight(height);
181
}
182
183
colorBarActor->SetNumberOfLabels(labels);
184
185
colorBarActor->GetLabelTextProperty()->SetFontSize(16);
186
colorBarActor->GetLabelTextProperty()->SetFontFamilyToArial();
187
colorBarActor->GetLabelTextProperty()->BoldOn();
188
colorBarActor->GetLabelTextProperty()->ItalicOn();
189
colorBarActor->GetLabelTextProperty()->SetColor(0, 0, 1);
190
191
colorBarActor->GetTitleTextProperty()->SetFontSize(16);
192
colorBarActor->GetTitleTextProperty()->SetFontFamilyToArial();
193
colorBarActor->GetTitleTextProperty()->BoldOn();
194
colorBarActor->GetTitleTextProperty()->ItalicOn();
195
colorBarActor->GetTitleTextProperty()->SetColor(0, 0, 1);
196
197
if(annotate) {
198
#if WITH_QT5 || WITH_QT6
199
colorBarActor->SetTitle(fieldName.toLatin1().data());
200
#else
201
colorBarActor->SetTitle(fieldName.toAscii().data());
202
#endif
203
} else {
204
colorBarActor->SetTitle("");
205
}
206
}
207
208
// Public slots:
209
//---------------
210
bool ColorBar::SetFieldName(QString name)
211
{
212
for(int i = 0; i < ui.colorCombo->count(); i++) {
213
if(ui.colorCombo->itemText(i) == name) {
214
ui.colorCombo->setCurrentIndex(i);
215
return true;
216
}
217
}
218
return false;
219
}
220
221
void ColorBar::UseHorizontalLayout(bool b)
222
{
223
ui.horizontalRButton->setChecked(b);
224
}
225
226
void ColorBar::UseVerticalLayout(bool b)
227
{
228
ui.verticalRButton->setChecked(b);
229
}
230
231
void ColorBar::AnnotateFieldName(bool b)
232
{
233
ui.annotateBox->setChecked(b);
234
}
235
236
void ColorBar::SetLabels(int n)
237
{
238
ui.labelsSpin->setValue(n);
239
}
240
241
void ColorBar::SetLineWidth(double f)
242
{
243
ui.widthEdit->setText(QString::number(f));
244
}
245
246
void ColorBar::SetLength(double f)
247
{
248
ui.heightEdit->setText(QString::number(f));
249
}
250
251