Geometry manipulation in C++


I am working on a C++ shape optimization project with a HDG solver which interfaces Netgen. I am exclusively working with spline geometries from the SplineGeometry2D class.

For this project, I would like to modify the coordinates of the geometry points (one at a time) in the normal direction. To do that, I have access to a shared pointer , from which I access the Netgen geometry through:

shared_ptr<MeshAccess> ma;
shared_ptr<netgen::Mesh> ngmesh = ma->GetNetgenMesh();
shared_ptr<netgen::NetgenGeometry> nggeom = ngmesh->GetGeometry();

Up to that, everything works fine. But I would like to use the routines of SplineGeometry2d (such as GetSpline()) so I tried to cast my NetgenGeometry shared_ptr to a SplineGeometry2d shared_ptr (knowing SplineGeometry2d is a derived class of NetgenGeometry) with:

shared_ptr<netgen::SplineGeometry2d> splinegeom = dynamic_pointer_cast<netgen::SplineGeometry2d>(nggeom);

but I get that : [quote]error: ‘SplineGeometry2d’ is not a member of ‘netgen’[/quote]
and [quote] error: ‘template argument 1 is invalid’[/quote]

SplineGeometry2d is well-defined inside the netgen namespace so I am not sure what I forget here. Could you hint me on what I am missing?

I attach the function which causes this error.

Thank you very much,


Attachment: deformgeometry.h

Hi Joachim,

you have to include the appropriate header files. In your case “#include <geometry2d.hpp>” should do the job.

Another hint: Changing the points of the splines won’t change your mesh directly. You would have to generate a new mesh after changing the points.


Hello Christoph,

Thank you very much for your reply! I followed your advice but whenever I add #include <geometry2d.hpp> (even if the rest of the function is empty), I have new error messages:

In file included from /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/geometry2d.hpp:1:0, from ShapeOptimization/deformgeometry.h:1, from main.cpp:406: /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/../geom2d/geometry2d.hpp:21:40: error: expected template-name before ‘<’ token class SplineSegExt : public SplineSeg<2> ^ /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/../geom2d/geometry2d.hpp:21:40: error: expected ‘{’ before ‘<’ token /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/../geom2d/geometry2d.hpp:21:40: error: expected unqualified-id before ‘<’ token /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/../geom2d/geometry2d.hpp:131:49: error: expected template-name before ‘<’ token class SplineGeometry2d : public SplineGeometry<2>, public NetgenGeometry ^ /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/../geom2d/geometry2d.hpp:131:49: error: expected ‘{’ before ‘<’ token /home/joachim/Documents/ResearchProject/ngsuite/ngsolve-install/bin/../include/include/../geom2d/geometry2d.hpp:131:49: error: expected unqualified-id before ‘<’ token

I tried to sort out the issue, and I thought that it could come from the fact that the compiler does not know SplineSeg and SplineGeometry at the time geometry2d.hpp is defined. So I tried to include these with:

#include "../gprim/spline.hpp" #include "../gprim/splinegeometry.hpp"

before the #include “geometry2d.hpp” but that does not change anything to the errors.

I am a bit out of ideas because #include <gprim.hpp> and #include <meshing.hpp> do not trigger any errors, it is only the #include <geometry2d.hpp> which causes my troubles.

[EDIT: problem solved]

I put #include <geometry2d.hpp> at the top of my main file and everything runs smoothly now.

Thank you again for your kind help,