MeshLib::Mesh* MshEditor::getMeshSurface(const MeshLib::Mesh &mesh, const double* dir) { INFO ("Extracting mesh surface..."); const std::vector<MeshLib::Element*> all_elements (mesh.getElements()); const std::vector<MeshLib::Node*> all_nodes (mesh.getNodes()); std::vector<MeshLib::Element*> sfc_elements; get2DSurfaceElements(all_elements, sfc_elements, dir, mesh.getDimension()); std::vector<MeshLib::Node*> sfc_nodes; std::vector<unsigned> node_id_map(mesh.getNNodes()); get2DSurfaceNodes(all_nodes, sfc_nodes, sfc_elements, node_id_map); // create new elements vector with newly created nodes const size_t nNewElements (sfc_elements.size()); std::vector<MeshLib::Element*> new_elements(sfc_elements.size()); for (unsigned i=0; i<nNewElements; ++i) { MeshLib::Element* elem (sfc_elements[i]); if (elem->getType() == MshElemType::TRIANGLE) { MeshLib::Node** tri_nodes = new MeshLib::Node*[3]; for (unsigned k(0); k<3; k++) tri_nodes[k] = sfc_nodes[node_id_map[elem->getNode(k)->getID()]]; new_elements[i] = new MeshLib::Tri(tri_nodes); } else { MeshLib::Node** quad_nodes = new MeshLib::Node*[4]; for (unsigned k(0); k<3; k++) quad_nodes[k] = sfc_nodes[node_id_map[elem->getNode(k)->getID()]]; new_elements[i] = new MeshLib::Quad(quad_nodes); } delete sfc_elements[i]; } return new Mesh("SurfaceMesh", sfc_nodes, new_elements); }
std::vector<GeoLib::PointWithID*> MshEditor::getSurfaceNodes(const MeshLib::Mesh &mesh, const double *dir) { INFO ("Extracting surface nodes..."); const std::vector<MeshLib::Element*> all_elements (mesh.getElements()); const std::vector<MeshLib::Node*> all_nodes (mesh.getNodes()); std::vector<MeshLib::Element*> sfc_elements; get2DSurfaceElements(all_elements, sfc_elements, dir, mesh.getDimension()); std::vector<MeshLib::Node*> sfc_nodes; std::vector<unsigned> node_id_map(mesh.getNNodes()); get2DSurfaceNodes(all_nodes, sfc_nodes, sfc_elements, node_id_map); const unsigned nElements (sfc_elements.size()); for (unsigned i=0; i<nElements; ++i) delete sfc_elements[i]; const size_t nNodes (sfc_nodes.size()); std::vector<GeoLib::PointWithID*> surface_pnts(nNodes); for (unsigned i=0; i<nNodes; ++i) { surface_pnts[i] = new GeoLib::PointWithID(sfc_nodes[i]->getCoords(), sfc_nodes[i]->getID()); delete sfc_nodes[i]; } return surface_pnts; }
MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface( const MeshLib::Mesh& mesh, const MathLib::Vector3& dir, double angle, std::string const& subsfc_node_id_backup_prop_name) { if (angle < 0 || angle > 90) { ERR ("Supported angle between 0 and 90 degrees only."); return nullptr; } INFO ("Extracting mesh surface..."); std::vector<MeshLib::Element*> sfc_elements; get2DSurfaceElements(mesh.getElements(), sfc_elements, dir, angle, mesh.getDimension()); if (sfc_elements.empty()) return nullptr; std::vector<MeshLib::Node*> sfc_nodes; std::vector<std::size_t> node_id_map(mesh.getNNodes()); get2DSurfaceNodes(sfc_nodes, mesh.getNNodes(), sfc_elements, node_id_map); // create new elements vector with newly created nodes std::vector<MeshLib::Element*> new_elements; new_elements.reserve(sfc_elements.size()); for (auto elem = sfc_elements.cbegin(); elem != sfc_elements.cend(); ++elem) { unsigned const n_elem_nodes ((*elem)->getNBaseNodes()); MeshLib::Node** new_nodes = new MeshLib::Node*[n_elem_nodes]; for (unsigned k(0); k<n_elem_nodes; k++) new_nodes[k] = sfc_nodes[node_id_map[(*elem)->getNode(k)->getID()]]; if ((*elem)->getGeomType() == MeshElemType::TRIANGLE) new_elements.push_back(new MeshLib::Tri(new_nodes)); else { assert((*elem)->getGeomType() == MeshElemType::QUAD); new_elements.push_back(new MeshLib::Quad(new_nodes)); } delete *elem; } std::vector<std::size_t> id_map; if (!subsfc_node_id_backup_prop_name.empty()) { id_map.reserve(sfc_nodes.size()); for (auto node = sfc_nodes.cbegin(); node != sfc_nodes.cend(); ++node) id_map.push_back((*node)->getID()); } MeshLib::Mesh* result (new Mesh(mesh.getName()+"-Surface", sfc_nodes, new_elements)); // transmit the original node ids of the subsurface mesh as a property if (!subsfc_node_id_backup_prop_name.empty()) { boost::optional<MeshLib::PropertyVector<std::size_t>&> orig_node_ids( result->getProperties().createNewPropertyVector<std::size_t>( subsfc_node_id_backup_prop_name , MeshLib::MeshItemType::Node, 1)); if (orig_node_ids) { orig_node_ids->resize(id_map.size()); std::copy(id_map.cbegin(), id_map.cend(), orig_node_ids->begin()); } } return result; }
MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface(const MeshLib::Mesh &mesh, const MathLib::Vector3 &dir, bool keepOriginalNodeIds) { INFO ("Extracting mesh surface..."); const std::vector<MeshLib::Element*> all_elements (mesh.getElements()); const std::vector<MeshLib::Node*> all_nodes (mesh.getNodes()); std::vector<MeshLib::Element*> sfc_elements; get2DSurfaceElements(all_elements, sfc_elements, dir, mesh.getDimension()); if (sfc_elements.empty()) return nullptr; std::vector<MeshLib::Node*> sfc_nodes; std::vector<unsigned> node_id_map(mesh.getNNodes()); get2DSurfaceNodes(all_nodes, sfc_nodes, sfc_elements, node_id_map); // create new elements vector with newly created nodes std::vector<MeshLib::Element*> new_elements; new_elements.reserve(sfc_elements.size()); for (auto elem = sfc_elements.begin(); elem != sfc_elements.end(); ++elem) { if ((*elem)->getGeomType() == MeshElemType::TRIANGLE) { MeshLib::Node** tri_nodes = new MeshLib::Node*[3]; for (unsigned k(0); k<3; k++) tri_nodes[k] = sfc_nodes[node_id_map[(*elem)->getNode(k)->getID()]]; new_elements.push_back(new MeshLib::Tri(tri_nodes)); } else { assert((*elem)->getGeomType() == MeshElemType::QUAD); MeshLib::Node** quad_nodes = new MeshLib::Node*[4]; for (unsigned k(0); k<4; k++) quad_nodes[k] = sfc_nodes[node_id_map[(*elem)->getNode(k)->getID()]]; new_elements.push_back(new MeshLib::Quad(quad_nodes)); } delete *elem; } std::vector<std::size_t> id_map; if (keepOriginalNodeIds) { id_map.reserve(sfc_nodes.size()); for (auto node = sfc_nodes.cbegin(); node != sfc_nodes.cend(); ++node) id_map.push_back((*node)->getID()); } MeshLib::Mesh* result (new Mesh(mesh.getName()+"-Surface", sfc_nodes, new_elements)); if (keepOriginalNodeIds) for (auto node = sfc_nodes.begin(); node != sfc_nodes.end(); ++node) (*node)->setID(id_map[(*node)->getID()]); return result; }
std::vector<GeoLib::Point*> MeshSurfaceExtraction::getSurfaceNodes(const MeshLib::Mesh &mesh, const MathLib::Vector3 &dir, double angle) { INFO ("Extracting surface nodes..."); std::vector<MeshLib::Element*> sfc_elements; get2DSurfaceElements(mesh.getElements(), sfc_elements, dir, angle, mesh.getDimension()); std::vector<MeshLib::Node*> sfc_nodes; std::vector<std::size_t> node_id_map(mesh.getNNodes()); get2DSurfaceNodes(sfc_nodes, mesh.getNNodes(), sfc_elements, node_id_map); for (auto e : sfc_elements) delete e; const std::size_t nNodes (sfc_nodes.size()); std::vector<GeoLib::Point*> surface_pnts(nNodes); for (std::size_t i=0; i<nNodes; ++i) { surface_pnts[i] = new GeoLib::Point(*(sfc_nodes[i]), sfc_nodes[i]->getID()); delete sfc_nodes[i]; } return surface_pnts; }