13#include <vtkImageImport.h>
25using namespace netCDF;
31 _currentFile(fileName.c_str(), NcFile::read),
32 _currentMesh(nullptr),
33 _currentRaster(nullptr),
34 _currentPath(fileName)
40 comboBoxVariable->setCurrentIndex(
44 _currentFile.getVar(comboBoxVariable->itemText(idx).toStdString());
48 lineEditName->setText(
setName());
50 this->radioMesh->setChecked(
true);
61 QMessageBox valueErrorBox;
64 valueErrorBox.setText(
"Selected Variable has not enough dimensions.");
67 else if (doubleSpinBoxDim2Start->value() ==
68 doubleSpinBoxDim2Start->maximum())
70 valueErrorBox.setText(
"Lon has invalid extend.");
73 else if (doubleSpinBoxDim1Start->value() ==
74 doubleSpinBoxDim1Start->maximum())
76 valueErrorBox.setText(
"Lat has invalid extend.");
82 this->done(QDialog::Accepted);
89 this->done(QDialog::Rejected);
94 std::string
const var_name = comboBoxVariable->currentText().toStdString();
102 double firstValue = 0, lastValue = 0;
104 getDimEdges(comboBoxDim1->currentText().toStdString(), size, firstValue,
106 doubleSpinBoxDim1Start->setValue(firstValue);
107 doubleSpinBoxDim1End->setValue(lastValue);
116 double firstValue = 0, lastValue = 0;
118 getDimEdges(comboBoxDim2->currentText().toStdString(), size, firstValue,
120 doubleSpinBoxDim2Start->setValue(firstValue);
121 doubleSpinBoxDim2End->setValue(lastValue);
130 double firstValue = 0, lastValue = 0;
132 getDimEdges(comboBoxDim3->currentText().toStdString(), size, firstValue,
134 dateTimeEditDim3->setValue(
static_cast<int>(firstValue));
135 dateTimeEditDim3->setMinimum(
static_cast<int>(firstValue));
136 dateTimeEditDim3->setMaximum(
static_cast<int>(lastValue));
137 lineEditName->setText(
setName());
146 double firstValue = 0, lastValue = 0;
148 getDimEdges(comboBoxDim4->currentText().toStdString(), size, firstValue,
150 spinBoxDim4->setValue(
static_cast<int>(firstValue));
151 spinBoxDim4->setMinimum(
static_cast<int>(firstValue));
152 spinBoxDim4->setMaximum(
static_cast<int>(lastValue));
161 for (
auto [name, var] : names)
163 int const var_dim_count = var.getDimCount();
164 if (var_dim_count > 1)
166 comboBoxVariable->addItem(QString::fromStdString(name));
167 if (var_dim_count > max_dim)
169 max_dim = var_dim_count;
170 max_dim_idx = comboBoxVariable->count() - 1;
180 std::array<QComboBox*, 4> dim_box = {
181 {comboBoxDim1, comboBoxDim2, comboBoxDim3, comboBoxDim4}};
183 for (
int i = 0; i < 4; ++i)
186 dim_box[i]->setEnabled(i < dim_count);
190 for (
int i = 0; i < dim_count; ++i)
192 for (
int j = 0; j < dim_count; ++j)
195 QString::fromStdString(
_currentVar.getDim(i).getName()));
198 comboBoxDim1->setCurrentIndex(dim_count - 2);
200 comboBoxDim2->setCurrentIndex(dim_count - 1);
203 dateTimeEditDim3->setEnabled(dim_count > 2);
205 spinBoxDim4->setEnabled(dim_count > 3);
209 comboBoxDim3->setCurrentIndex(0);
213 dateTimeEditDim3->setSingleStep(0);
217 comboBoxDim4->setCurrentIndex(1);
221 spinBoxDim4->setValue(0);
225 double& firstValue,
double& lastValue)
234 if ((tmpVarOfDim.getDimCount()) == 1)
236 size = tmpVarOfDim.getDim(0).getSize();
237 tmpVarOfDim.getVar({0}, {1}, &firstValue);
238 tmpVarOfDim.getVar({size - 1}, {1}, &lastValue);
244 return dateTimeEditDim3->value();
249 NcVar
const& dim3Var =
250 _currentFile.getVar(comboBoxDim4->currentText().toStdString());
251 std::vector<std::size_t> start{
252 static_cast<std::size_t
>(spinBoxDim4->value())};
254 dim3Var.getVar(start, {1}, &value);
263 if (comboBoxDim1->currentIndex() > -1)
266 _currentFile.getVar(comboBoxDim1->currentText().toStdString());
267 double firstValue = 0, lastValue = 0;
269 getDimEdges(var.getName(), size, firstValue, lastValue);
275 double interval = fabs(lastValue - firstValue);
276 double resolution = (double)interval / (size - 1);
285 double originLon = 0, originLat = 0;
286 double lastLon = 0, lastLat = 0;
287 unsigned sizeLon = 0, sizeLat = 0;
288 std::string
const dim1_name = comboBoxDim1->currentText().toStdString();
289 getDimEdges(dim1_name, sizeLat, originLat, lastLat);
290 std::string
const dim2_name = comboBoxDim2->currentText().toStdString();
291 getDimEdges(dim2_name, sizeLon, originLon, lastLon);
294 std::vector<double> data_array(sizeLat * sizeLon, 0);
296 std::vector<std::size_t> data_origin;
297 std::vector<std::size_t> data_length;
303 data_length.push_back(1);
307 data_origin.push_back(
getDim4());
308 data_length.push_back(1);
312 data_origin.push_back(0);
313 data_origin.push_back(0);
314 data_length.push_back(sizeLat);
315 data_length.push_back(sizeLon);
316 _currentVar.getVar(data_origin, data_length, data_array.data());
319 data_array.begin(), data_array.end(),
320 [](
double const& x) { return x <= -9999; }, -9999);
322 double origin_x = (originLon < lastLon) ? originLon : lastLon;
323 double origin_y = (originLat < lastLat) ? originLat : lastLat;
325 double resolution = (doubleSpinBoxResolution->value());
333 origin, resolution, -9999};
334 if (this->radioMesh->isChecked())
339 if (comboBoxMeshElemType->currentIndex() == 1)
347 if ((comboBoxUseIntensity->currentIndex()) == 1)
356 data_array.data(), header, meshElemType, useIntensity,
361 vtkImageImport* image =
365 QString::fromStdString(this->
getName()));
373 name.erase(0, name.find_last_of(
"/") + 1);
374 name.erase(name.find_last_of(
"."));
375 return QString::fromStdString(name);
380 std::string name = (lineEditName->text()).toStdString();
381 QString
const date = QString::number(dateTimeEditDim3->value());
382 name.append(
" - ").append(date.toStdString());
389 auto* cp_array =
new double[width * height];
391 for (std::size_t i = 0; i < height; i++)
393 for (std::size_t j = 0; j < width; j++)
395 std::size_t old_index((width * height) - (width * (i + 1)));
396 std::size_t new_index(width * i);
397 cp_array[new_index + j] = data[old_index + j];
401 std::size_t length(height * width);
402 for (std::size_t i = 0; i < length; i++)
403 data[i] = cp_array[i];
412 this->label_2->setEnabled(
true);
413 this->label_3->setEnabled(
false);
414 this->comboBoxMeshElemType->setEnabled(
true);
415 this->comboBoxUseIntensity->setEnabled(
false);
419 this->label_2->setEnabled(
false);
420 this->label_3->setEnabled(
true);
421 this->comboBoxMeshElemType->setEnabled(
false);
422 this->comboBoxUseIntensity->setEnabled(
true);
Definition of mesh-related Enumerations.
Definition of the Point3d class.
Definition of the GeoLib::Raster class.
Definition of the VtkGeoImageSource class.
Definition of the VtkRaster class.
void setImage(vtkImageAlgorithm *image, const QString &name)
Imports an existing image object.
static VtkGeoImageSource * New()
Create new objects with New() because of VTKs reference counting.
static vtkImageImport * loadImageFromArray(double const *const data_array, GeoLib::RasterHeader header)
Returns a VtkImageAlgorithm from an array of pixel values and some image meta data.
UseIntensityAs
Selection of possible interpretations for intensities.
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.