bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double eps) { if (mesh.getDimension() != 2) { ERR ("Mesh to geometry conversion is only working for 2D meshes."); return false; } // nodes to points conversion std::string mesh_name(mesh.getName()); { auto points = std::make_unique<std::vector<GeoLib::Point*>>(); points->reserve(mesh.getNumberOfNodes()); for (auto node_ptr : mesh.getNodes()) points->push_back(new GeoLib::Point(*node_ptr, node_ptr->getID())); geo_objects.addPointVec(std::move(points), mesh_name, nullptr, eps); } const std::vector<std::size_t> id_map (geo_objects.getPointVecObj(mesh_name)->getIDMap()); // elements to surface triangles conversion std::string const mat_name ("MaterialIDs"); auto bounds (MeshInformation::getValueBounds<int>(mesh, mat_name)); const unsigned nMatGroups(bounds.second-bounds.first+1); auto sfcs = std::make_unique<std::vector<GeoLib::Surface*>>(); sfcs->reserve(nMatGroups); auto const& points = *geo_objects.getPointVec(mesh_name); for (unsigned i=0; i<nMatGroups; ++i) sfcs->push_back(new GeoLib::Surface(points)); const std::vector<MeshLib::Element*> &elements = mesh.getElements(); const std::size_t nElems (mesh.getNumberOfElements()); MeshLib::PropertyVector<int> const*const materialIds = mesh.getProperties().existsPropertyVector<int>("MaterialIDs") ? mesh.getProperties().getPropertyVector<int>("MaterialIDs") : nullptr; for (unsigned i=0; i<nElems; ++i) { auto surfaceId = !materialIds ? 0 : ((*materialIds)[i] - bounds.first); MeshLib::Element* e (elements[i]); if (e->getGeomType() == MeshElemType::TRIANGLE) (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]); if (e->getGeomType() == MeshElemType::QUAD) { (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]); (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(2)], id_map[e->getNodeIndex(3)]); } // all other element types are ignored (i.e. lines) } std::for_each(sfcs->begin(), sfcs->end(), [](GeoLib::Surface* sfc){ if (sfc->getNumberOfTriangles()==0) delete sfc; sfc = nullptr;}); auto sfcs_end = std::remove(sfcs->begin(), sfcs->end(), nullptr); sfcs->erase(sfcs_end, sfcs->end()); geo_objects.addSurfaceVec(std::move(sfcs), mesh_name); return true; }
void CondFromRasterDialog::accept() { std::string mesh_name (this->meshBox->currentText().toStdString()); std::string raster_name (this->rasterEdit->text().toStdString()); double scaling_factor = this->scalingEdit->text().toDouble(); std::vector< std::pair<size_t,double> > direct_values; if (mesh_name.empty()) { OGSError::box("No mesh selected."); return; } if (raster_name.empty()) { OGSError::box("No raster selected."); return; } MeshLib::Mesh* mesh (NULL); for (size_t i=0; i<_msh_vec.size(); i++) if (_msh_vec[i]->getName().compare(mesh_name) == 0) { mesh = _msh_vec[i]; break; } if (this->directButton->isChecked()) { DirectConditionGenerator dcg; direct_values = dcg.directToSurfaceNodes(*mesh, raster_name); //dcg.writeToFile(direct_node_name); } else { if (scaling_factor <= 0) { OGSError::box("No valid scaling factor given."); return; } MeshLib::Mesh* new_mesh = const_cast<MeshLib::Mesh*>(mesh); DirectConditionGenerator dcg; direct_values = dcg.directWithSurfaceIntegration(*new_mesh, raster_name, scaling_factor); //dcg.writeToFile(direct_node_name); } //emit directNodesWritten(direct_node_name); emit transmitDisValues(direct_values); this->done(QDialog::Accepted); }