GMSH C++ API is missing a variant of `getNodes` that would return node coordinates based on a vector of tags
If a user has a list of node tags, and wants to retrieve their coordinates, I think there is no straightforward way of doing it. For now, it seems a for loop
querying getNode
on the user side is needed. Moreover, getNodes
does "unnecessary" stuff in this case (such as returning the entity it belongs to, returning both parametric and normal coordinates, and so on).
Here is a code snippet.
/**
* Return the (parametric) coordinates of nodes.
*/
GMSH_API void gmsh::model::mesh::getNodesCoordinates(const std::vector<std::size_t>& nodeTags,
std::vector<double> &coords,
const bool parametric = false)
{
if(!_checkInit()) return;
const short ss = parametric ? 2 : 3;
coords.resize(ss * nodeTags.size());
for(size_t inode = 0; inode < nodeTags.size(); ++inode) {
const MVertex *v = GModel::current()->getMeshVertexByTag(nodeTags.at(inode));
if(!v) {
Msg::Error("Unknown node %d", nodeTag);
return;
}
if(!parametric) {
coord[inode * 3 + 0] = v->x();
coord[inode * 3 + 1] = v->y();
coord[inode * 3 + 2] = v->z();
} else {
double u;
if(v->getParameter(0, u)) parametricCoord.push_back(u);
if(v->getParameter(1, u)) parametricCoord.push_back(u);
}
}
}