[Gmsh] Change coordinate of a vertex in a GModel using API

Agnese, Marco m.agnese13 at imperial.ac.uk
Tue May 27 18:24:45 CEST 2014


If you use the vertex iterator, it is true that the iterator is not-const but the methods to get the coordinates are const:

// from GVertex
virtual double x() const = 0;
virtual double y() const = 0;
virtual double z() const = 0;

If you try to compile

typename GModel::viter it(myGModelPtr->firstVertex());
(*it)->x()=0.1;

you obtain the error

error: lvalue required as left operand of assignment

I do not like very much the solution of modify the header on my personal installation. I would prefer to request a modification upstream. But I would first understand why it is implemented in such a way. Maybe gmsh need to have const coordinates because these quantities are cached in some part of the code or for some other reasons (I do not know how gmsh is coded).

Best regards,
Marco.

________________________________________
From: Mikhail Artemyev [artemiev.mikhail at gmail.com]
Sent: Tuesday, May 27, 2014 4:31 PM
To: Agnese, Marco; gmsh at geuz.org
Subject: Re: Change coordinate of a vertex in a GModel using API

All right.

Then use these functions to get non-const iterators pointing to vertices:

// from GModel class
typedef std::set<GVertex*, GEntityLessThan>::iterator viter;
viter firstVertex() { return vertices.begin(); }
viter lastVertex() { return vertices.end(); }

or, I guess you can redefine getVertexByTag function in such a way that
it wouldn't be const and give you a non-const vertex iterator (in this
case you'll clearly need to recompile the Gmsh library).

Best regards,
Mikhail


On 05/27/2014 10:14 AM, Agnese, Marco wrote:
> Hi Mikhail,
> the problem of adding and deleting a vertex is that I have to redefine also the topology (I think, am I right ?).
> For example let's say that my GModel defining a rectangle: 4 vertices (from 1 to 4), 4 edges (from 1 to 4), 1 lines loops, 1 plane surface.
> Let's say that I want now move thew first vertex and keep everything the same (and obtain a quadrilateral). If I delete the first vertex, the two edges which contain the vertex number 1 need to be deleted and recreated with the new vertex which I want to add.
> In case the geometry is more complicated, maybe I have also to create again the lines loops.
> This procedure is quite inefficient and could become complicated (especially in 3D).
> If I can delete a vertex and add with the new coordinates without recreating my edges this could be a good solution to my problem. For know I recreate from scratch the GModel with the right coordinates, but of course this requires a certain amount of code and more operations to be performed by the code.
> Chhers, Marco.
> ________________________________________
> From: Mikhail Artemyev [artemiev.mikhail at gmail.com]
> Sent: Tuesday, May 27, 2014 3:51 PM
> To: gmsh at geuz.org; Agnese, Marco
> Subject: Re: Change coordinate of a vertex in a GModel using API
>
> Hi Marco,
>
> I would suggest to remove a wrong vertex from a model using:
>
> void remove(GVertex *v); // from GModel class
>
> and then to add a new (corrected) one:
>
> void add(GVertex *v) { vertices.insert(v); } // from GModel class
>
> However I didn't try that for myself.
>
> Best regards,
> Mikhail
>
>> Hello GMSH users,
>> I have a GModel and I want to change the coordinates of a point inside it: just the coordinates of a point , everything in the GModel need to remains exactly the same.
>> Is there a way without creating from scratch a new GModel?
>> Because if I extract the pointer to a GVertex with the method getVertexByTag I have a const pointer therefore I cannot modify the value but only read it.
>> Is there a method to have a non const pointer? Or is there  a method to simply change the coordinates?
>>
>> Thank you,
>> cheers,
>> Marco Agnese.
>>
>>
>>