12#include <vtkImageImport.h>
24using namespace netCDF;
30 _currentFile(fileName.c_str(), NcFile::read),
31 _currentMesh(nullptr),
32 _currentRaster(nullptr),
33 _currentPath(fileName)
39 comboBoxVariable->setCurrentIndex(
43 _currentFile.getVar(comboBoxVariable->itemText(idx).toStdString());
47 lineEditName->setText(
setName());
49 this->radioMesh->setChecked(
true);
57 QMessageBox valueErrorBox;
60 valueErrorBox.setText(
"Selected Variable has not enough dimensions.");
63 else if (doubleSpinBoxDim2Start->value() ==
64 doubleSpinBoxDim2Start->maximum())
66 valueErrorBox.setText(
"Lon has invalid extend.");
69 else if (doubleSpinBoxDim1Start->value() ==
70 doubleSpinBoxDim1Start->maximum())
72 valueErrorBox.setText(
"Lat has invalid extend.");
78 this->done(QDialog::Accepted);
85 this->done(QDialog::Rejected);
90 std::string
const var_name = comboBoxVariable->currentText().toStdString();
98 double firstValue = 0, lastValue = 0;
100 getDimEdges(comboBoxDim1->currentText().toStdString(), size, firstValue,
102 doubleSpinBoxDim1Start->setValue(firstValue);
103 doubleSpinBoxDim1End->setValue(lastValue);
112 double firstValue = 0, lastValue = 0;
114 getDimEdges(comboBoxDim2->currentText().toStdString(), size, firstValue,
116 doubleSpinBoxDim2Start->setValue(firstValue);
117 doubleSpinBoxDim2End->setValue(lastValue);
126 double firstValue = 0, lastValue = 0;
128 getDimEdges(comboBoxDim3->currentText().toStdString(), size, firstValue,
130 dateTimeEditDim3->setValue(
static_cast<int>(firstValue));
131 dateTimeEditDim3->setMinimum(
static_cast<int>(firstValue));
132 dateTimeEditDim3->setMaximum(
static_cast<int>(lastValue));
133 lineEditName->setText(
setName());
142 double firstValue = 0, lastValue = 0;
144 getDimEdges(comboBoxDim4->currentText().toStdString(), size, firstValue,
146 spinBoxDim4->setValue(
static_cast<int>(firstValue));
147 spinBoxDim4->setMinimum(
static_cast<int>(firstValue));
148 spinBoxDim4->setMaximum(
static_cast<int>(lastValue));
157 for (
auto [name, var] : names)
159 int const var_dim_count = var.getDimCount();
160 if (var_dim_count > 1)
162 comboBoxVariable->addItem(QString::fromStdString(name));
163 if (var_dim_count > max_dim)
165 max_dim = var_dim_count;
166 max_dim_idx = comboBoxVariable->count() - 1;
176 std::array<QComboBox*, 4> dim_box = {
177 {comboBoxDim1, comboBoxDim2, comboBoxDim3, comboBoxDim4}};
179 for (
int i = 0; i < 4; ++i)
182 dim_box[i]->setEnabled(i < dim_count);
186 for (
int i = 0; i < dim_count; ++i)
188 for (
int j = 0; j < dim_count; ++j)
191 QString::fromStdString(
_currentVar.getDim(i).getName()));
194 comboBoxDim1->setCurrentIndex(dim_count - 2);
196 comboBoxDim2->setCurrentIndex(dim_count - 1);
199 dateTimeEditDim3->setEnabled(dim_count > 2);
201 spinBoxDim4->setEnabled(dim_count > 3);
205 comboBoxDim3->setCurrentIndex(0);
209 dateTimeEditDim3->setSingleStep(0);
213 comboBoxDim4->setCurrentIndex(1);
217 spinBoxDim4->setValue(0);
221 double& firstValue,
double& lastValue)
230 if ((tmpVarOfDim.getDimCount()) == 1)
232 size = tmpVarOfDim.getDim(0).getSize();
233 tmpVarOfDim.getVar({0}, {1}, &firstValue);
234 tmpVarOfDim.getVar({size - 1}, {1}, &lastValue);
240 return dateTimeEditDim3->value();
245 NcVar
const& dim3Var =
246 _currentFile.getVar(comboBoxDim4->currentText().toStdString());
247 std::vector<std::size_t> start{
248 static_cast<std::size_t
>(spinBoxDim4->value())};
250 dim3Var.getVar(start, {1}, &value);
259 if (comboBoxDim1->currentIndex() > -1)
262 _currentFile.getVar(comboBoxDim1->currentText().toStdString());
263 double firstValue = 0, lastValue = 0;
265 getDimEdges(var.getName(), size, firstValue, lastValue);
271 double interval = fabs(lastValue - firstValue);
272 double resolution = (double)interval / (size - 1);
281 double originLon = 0, originLat = 0;
282 double lastLon = 0, lastLat = 0;
283 unsigned sizeLon = 0, sizeLat = 0;
284 std::string
const dim1_name = comboBoxDim1->currentText().toStdString();
285 getDimEdges(dim1_name, sizeLat, originLat, lastLat);
286 std::string
const dim2_name = comboBoxDim2->currentText().toStdString();
287 getDimEdges(dim2_name, sizeLon, originLon, lastLon);
290 std::vector<double> data_array(sizeLat * sizeLon, 0);
292 std::vector<std::size_t> data_origin;
293 std::vector<std::size_t> data_length;
299 data_length.push_back(1);
303 data_origin.push_back(
getDim4());
304 data_length.push_back(1);
308 data_origin.push_back(0);
309 data_origin.push_back(0);
310 data_length.push_back(sizeLat);
311 data_length.push_back(sizeLon);
312 _currentVar.getVar(data_origin, data_length, data_array.data());
315 data_array.begin(), data_array.end(),
316 [](
double const& x) { return x <= -9999; }, -9999);
318 double origin_x = (originLon < lastLon) ? originLon : lastLon;
319 double origin_y = (originLat < lastLat) ? originLat : lastLat;
321 double resolution = (doubleSpinBoxResolution->value());
329 origin, resolution, -9999};
330 if (this->radioMesh->isChecked())
335 if (comboBoxMeshElemType->currentIndex() == 1)
343 if ((comboBoxUseIntensity->currentIndex()) == 1)
352 data_array.data(), header, meshElemType, useIntensity,
357 vtkImageImport* image =
361 QString::fromStdString(this->
getName()));
369 name.erase(0, name.find_last_of(
"/") + 1);
370 name.erase(name.find_last_of(
"."));
371 return QString::fromStdString(name);
376 std::string name = (lineEditName->text()).toStdString();
377 QString
const date = QString::number(dateTimeEditDim3->value());
378 name.append(
" - ").append(date.toStdString());
385 auto* cp_array =
new double[width * height];
387 for (std::size_t i = 0; i < height; i++)
389 for (std::size_t j = 0; j < width; j++)
391 std::size_t old_index((width * height) - (width * (i + 1)));
392 std::size_t new_index(width * i);
393 cp_array[new_index + j] = data[old_index + j];
397 std::size_t length(height * width);
398 for (std::size_t i = 0; i < length; i++)
399 data[i] = cp_array[i];
408 this->label_2->setEnabled(
true);
409 this->label_3->setEnabled(
false);
410 this->comboBoxMeshElemType->setEnabled(
true);
411 this->comboBoxUseIntensity->setEnabled(
false);
415 this->label_2->setEnabled(
false);
416 this->label_3->setEnabled(
true);
417 this->comboBoxMeshElemType->setEnabled(
false);
418 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.
static std::unique_ptr< MeshLib::Mesh > convert(GeoLib::Raster const &raster, MeshElemType elem_type, UseIntensityAs intensity_type, std::string const &array_name="Colour")
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.