[Gmsh] Generating triangle mesh only from given point cloud and outline edges via the API

Takuya OSHIMA oshima at eng.niigata-u.ac.jp
Fri Aug 12 13:23:09 CEST 2011


I will stil have to do more testing but problem seems to have been
solved. In case anyone is interested the attached is the modification
I made to the 2.5.0 source. The useage is to set givenVerticesOnly
attribute to the GFace/GEdge instances where you want to create mesh
only from given (embedded) vertices.

  GFace *f0 = m->addPlanarFace(edges);
  f0->meshAttributes.givenVerticesOnly = 1;

Takuya

Takuya OSHIMA, Ph.D.
Faculty of Engineering, Niigata University
8050 Ikarashi-Ninocho, Nishi-ku, Niigata, 950-2181, JAPAN

From: Takuya OSHIMA <oshima at eng.niigata-u.ac.jp>
Subject: [Gmsh] Generating triangle mesh only from given point cloud and outline edges via the API
Date: Mon, 08 Aug 2011 22:56:53 +0900 (JST)

> Hi,
> 
> I want to attain something similar to an old post:
> http://www.geuz.org/pipermail/gmsh/2008/003655.html
> 
> which is in my case generating a triangle mesh from (and only from)
> existing nodes and outline edges via the Gmsh library API. Now that
> Gmsh 2.5.0 supports embedded vertices, I managed to write a small
> demonstration code as shown below.
> 
> I thought using a huge characteristic length would work to suppress
> addition of generated vertices, but in reality it didn't. Is there any
> way I can suppress the addition of generated vertices? If someone
> points me where to start, I wouldn't mind modifying the Gmsh source.
> 
> Thanks,
> Takuya
> 
> Takuya OSHIMA, Ph.D.
> Faculty of Engineering, Niigata University
> 8050 Ikarashi-Ninocho, Nishi-ku, Niigata, 950-2181, JAPAN
> 
> // Create square surface mesh with triangular elements
> 
> #include "Gmsh.h"
> #include "GModel.h"
> 
> #include <math.h>
> #include <iostream>
> 
> int main(int argc, char **argv)
> {
>   const double lc = MAXFLOAT;
>   const int nDivs = 10;
>   GmshInitialize(argc, argv);
> 
>   GModel *m = new GModel;
>   m->setFactory("Gmsh");
> 
>   // Add boundary vertices and edges of outline polygon
>   std::vector<std::vector<GEdge *> > edges(1);
>   GVertex *v, *v0;
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld;
>     if(i == 0)
>       {
>       vOld = v0 = m->addVertex(0., 0., 0., lc);
>       }
>     else
>       {
>       vOld = v;
>       }
>     v = m->addVertex((i + 1.0) / nDivs, 0., 0., lc);
>     edges[0].push_back(m->addLine(vOld, v));
>     }
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld = v;
>     v = m->addVertex(1.0, (i + 1.0) / nDivs, 0., lc);
>     edges[0].push_back(m->addLine(vOld, v));
>     }
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld = v;
>     v = m->addVertex(1.0 - (i + 1.0) / nDivs, 1.0, 0., lc);
>     edges[0].push_back(m->addLine(vOld, v));
>     }
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld = v;
>     v = ((i == nDivs - 1)
>         ? v0: m->addVertex(0., 1.0 - (i + 1.0) / nDivs, 0., lc));
>     edges[0].push_back(m->addLine(vOld, v));
>     }
> 
>   // Create surface
>   GFace *f0 = m->addPlanarFace(edges);
> 
>   // Add point cloud inside the polygon as embedded vertices
>   // -- I want to have only those given vertices inside the outline edges!
>   GVertex *v1 = m->addVertex(0.3, 0.3, 0., lc);
>   f0->addEmbeddedVertex(v1);
>   v1 = m->addVertex(0.8, 0.2, 0., lc);
>   f0->addEmbeddedVertex(v1);
>   v1 = m->addVertex(0.4, 0.7, 0., lc);
>   f0->addEmbeddedVertex(v1);
>   v1 = m->addVertex(0.7, 0.6, 0., lc);
>   f0->addEmbeddedVertex(v1);
> 
>   // Create mesh
>   m->mesh(2);
>   m->writeMSH("test.msh");
> 
>   delete m;
> 
>   GmshFinalize();
> }
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gmsh-2.5.0-meshFromGivenVertices.diff
Type: text/x-patch
Size: 3707 bytes
Desc: not available
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20110812/ce5b729a/attachment.diff>