Skip to content
Snippets Groups Projects
Commit e5190055 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[App/DE] Update for ptr version of getPropertyVec.

Two cleanups: reserve and fill is equal to resize,
Wrote out ternary condition operator into if-else.
parent 065d256b
No related branches found
No related tags found
No related merge requests found
......@@ -256,10 +256,10 @@ void CreateStructuredGridDialog::accept()
return;
}
boost::optional<MeshLib::PropertyVector<int>&> mat_ids (
mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell));
mat_ids->reserve(mesh->getNumberOfElements());
std::fill_n(std::back_inserter(*mat_ids), mesh->getNumberOfElements(), 0);
auto* const mat_ids = mesh->getProperties().createNewPropertyVector<int>(
"MaterialIDs", MeshLib::MeshItemType::Cell);
assert(mat_ids != nullptr);
mat_ids->resize(mesh->getNumberOfElements());
emit meshAdded(mesh);
this->done(QDialog::Accepted);
}
......
......@@ -97,9 +97,10 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di
const std::size_t nNodes(surface_mesh->getNumberOfNodes());
const double no_data(raster->getHeader().no_data);
boost::optional<MeshLib::PropertyVector<int>&> const opt_node_id_pv(
surface_mesh->getProperties().getPropertyVector<int>(prop_name));
if (!opt_node_id_pv) {
auto const* const node_id_pv =
surface_mesh->getProperties().getPropertyVector<int>(prop_name);
if (!node_id_pv)
{
ERR(
"Need subsurface node ids, but the property \"%s\" is not "
"available.",
......@@ -107,13 +108,13 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di
return _direct_values;
}
MeshLib::PropertyVector<int> const& node_id_pv(*opt_node_id_pv);
_direct_values.reserve(nNodes);
for (std::size_t i=0; i<nNodes; ++i)
{
double val(raster->getValueAtPoint(*surface_nodes[i]));
val = (val == no_data) ? 0 : ((val*node_area_vec[i])/scaling);
_direct_values.push_back(std::pair<std::size_t, double>(node_id_pv[i], val));
_direct_values.push_back(
std::pair<std::size_t, double>((*node_id_pv)[i], val));
}
return _direct_values;
......
......@@ -171,20 +171,25 @@ void MeshElementRemovalDialog::on_materialIDCheckBox_toggled(bool is_checked)
materialListWidget->clear();
_matIDIndex = _currentIndex;
auto mesh = _project.getMesh(meshNameComboBox->currentText().toStdString());
auto const opt_mat_ids = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
if (!opt_mat_ids) {
auto const* const mat_ids =
mesh->getProperties().getPropertyVector<int>("MaterialIDs");
if (!mat_ids)
{
INFO("Properties \"MaterialIDs\" not found in the mesh \"%s\".",
mesh->getName().c_str());
return;
}
auto const& mat_ids = opt_mat_ids.get();
if (mat_ids.size() != mesh->getNumberOfElements()) {
INFO("Size mismatch: Properties \"MaterialIDs\" contains %u values,"
" the mesh \"%s\" contains %u elements.", mat_ids.size(),
mesh->getName().c_str(), mesh->getNumberOfElements());
if (mat_ids->size() != mesh->getNumberOfElements())
{
INFO(
"Size mismatch: Properties \"MaterialIDs\" contains %u values,"
" the mesh \"%s\" contains %u elements.",
mat_ids->size(), mesh->getName().c_str(),
mesh->getNumberOfElements());
return;
}
auto max_material = std::max_element(mat_ids.cbegin(), mat_ids.cend());
auto max_material =
std::max_element(mat_ids->cbegin(), mat_ids->cend());
for (unsigned i=0; i <= static_cast<unsigned>(*max_material); ++i)
materialListWidget->addItem(QString::number(i));
......@@ -200,7 +205,8 @@ void MeshElementRemovalDialog::on_meshNameComboBox_currentIndexChanged(int idx)
this->materialListWidget->clearSelection();
if (this->boundingBoxCheckBox->isChecked()) this->on_boundingBoxCheckBox_toggled(true);
auto mesh = _project.getMesh(meshNameComboBox->currentText().toStdString());
auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
auto const* const materialIds =
mesh->getProperties().getPropertyVector<int>("MaterialIDs");
if (materialIds)
{
if (materialIds->size() != mesh->getNumberOfElements())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment