Menu

get coordinates of a mesh vertex

cyril
2017-10-15
2017-10-15
  • cyril

    cyril - 2017-10-15

    Hello, what is an elegant way to get coordinates of a mesh vertex by its id? For the time being, I've implemented it like this:

    typedef viennagrid::triangular_2d_mesh                            MeshType;
    typedef  viennagrid::result_of::vertex<MeshType>::type            VertexType;
    typedef viennagrid::result_of::point<MeshType>::type              PointType;
    typedef viennagrid::result_of::id<VertexType>::type               VertexIDType;
    
    unsigned int cell_point_ID = 5;
    
    PointType p = viennagrid::find(mesh, VertexIDType(cell_point_ID))[0].appendix();
    

    which looks awkward. Maybe I should use something else (vertex handle for a example) to get coordinates of a mesh vertex in a simple way, shoudn't I?

    Thanks,
    Cyril

     
  • Karl Rupp

    Karl Rupp - 2017-10-17

    Hi Cyril,

    if you only have the vertex ID, but nothing else, then viennagrid::find() is all that is left. The reason is that vertex IDs do not have to be contiguous, so a direct array access is not always possible.

    You last code line can be simplified to

    PointType p = viennagrid::default_point_accessor(*viennagrid::find(mesh, VertexIDType(cell_point_ID));
    

    Best regards,
    Karli

     
  • cyril

    cyril - 2017-10-18

    Hello, Karli. Thanks for the answer, it seems this is what I was looking for.

    Best regards,
    Cyril

     
  • cyril

    cyril - 2017-11-13

    Actually, code

    PointType p = viennagrid::default_point_accessor(*viennagrid::find(mesh, VertexIDType(cell_point_ID));
    

    doesn't work.

    It should be

    PointType p = viennagrid::default_point_accessor(mesh)(*viennagrid::find(mesh, VertexIDType(cell_point_ID)));
    
     

Log in to post a comment.