Hi Cesar,

for 1), I am by far not expert in OpenMesh, but in principle that way:

#define DIM2
struct MyTraits : public OpenMesh::DefaultTraits
{
#ifdef DIM2
  using Point = OpenMesh::Vec2d; // the default is Vec3d..
#endif //DIM2
};

using MyMesh = OpenMesh::PolyMesh_ArrayKernelT<MyTraits>;

Then you can use 2D points as you did in your example. However, I played with 2D meshes a bit but got the feeling that certain things do not work "out of the box".
For 2), as you said, exporting does not work. I think only 3d export is supported, see

OpenMesh/src/OpenMesh/Core/IO/exporter/BaseExporter.hh:
virtual Vec3f  point(VertexHandle _vh)    const = 0;
virtual Vec3d  pointd(VertexHandle _vh)   const = 0;
...

Likely, you will need to provide your own custom exporter classes. If your goal is to export to VTK a 2d mesh, then you could (as a hack) work in OpenMesh with 3D
points and modify the existing vtk exporter for 2D export by neglecting the z-component.

Anyway, I would also like to if some gained some experiences with 2D meshes.
Cheers, M

On Thu, Aug 27, 2020 at 5:20 PM <cesar.polindara-lopez@uni-due.de> wrote:
Hi to all.

Before asking my question I would like to state two important things:

1) My goal is to work with 2d triangular/polygonal meshes, from which i don't see any examples in the documentation. As a starting point I want to create and export (to a .vtk file) a simple 2d polygonal mesh, i.e. just a square.
2) I'm new to the library so this might be a rather broad/general question.

Now, here's what i have tried.

1) I've started with the tutorial "Building a cube". There i have managed to export the mesh to a .vtk file doing the following (variable names follow from the tutorial):

    //
    typedef OpenMesh::IO::ExporterT<MyMesh> BaseExporter;
    BaseExporter be = BaseExporter(mesh);
    OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
    OpenMesh::IO::_VTKWriter_ mywriter;
    mywriter.write("output.vtk",be,opt,sizeof(double));
    //

2) Now i want to modify this tutorial example to have a single square. To be clear, I want a 2d geometry, not a 3d geometry whose vertices have constant z=0 coordinate. This is how i define the mesh:

  //
  MyMesh::VertexHandle vhandle[4];
  vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1));
  vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, -1));
  vhandle[2] = mesh.add_vertex(MyMesh::Point( 1,  1));
  vhandle[3] = mesh.add_vertex(MyMesh::Point(-1,  1));

  std::vector<MyMesh::VertexHandle>  face_vhandles;
  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[3]);
  mesh.add_face(face_vhandles)
  //

  When i try to compile the code last code i get the following error, amongst many others:

  no matching function for call to ‘OpenMesh::VectorT<float, 3>::VectorT(int, int)’  vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1));


Now, these are my questions:

1) How can i create a 2d polygonal mesh? I guess i have to give the proper template parameter to type definition on

    typedef OpenMesh::PolyMesh_ArrayKernelT<>  MyMesh;

    but i don't know what to put in there exactly.

2) How is that going to affect the BaseExporter that i use to create the .vtk file? I am asking this because i already manage to create a 2d mesh following what i found in one of the unit tests, namely unittests_polymesh_vec2i.cc, but then i cannot export the mesh following the approach i had used for the cube. So, just in case anyone would suggest that piece of code as an answer to my question.


Any thoughts or suggestions will be greatly appreciated :)

Kind regards,
_______________________________________________
OpenMesh mailing list -- openmesh@lists.rwth-aachen.de
To unsubscribe send an email to openmesh-leave@lists.rwth-aachen.de
https://lists.rwth-aachen.de/postorius/lists/openmesh.lists.rwth-aachen.de