Skip to main content
Solved

Count number of vertex and triangle of a 3D geometry that will be export to OBJ


lavairye
Contributor
Forum|alt.badge.img

Hello,

I have CityGML files for buildings and I want to know and expose the number of vertex and triangles that will be exported by the OBJ writer.

I use the aggregator transformer to merge all the geometries and count the number of vertex, then remove all duplicated vertex (not immediate, but feasible), but I don't know how to find the number of triangles.

Is somebody having an idea ?

Maybe using the pythocaller, but I'm not a specialist !

Best answer by daveatsafe

Hi @lavairye

The CityGML surfaces will be converted to triangular meshes by the OBJ writer, but in order to count the resulting vertices, we can do the mesh conversion before writing, with the Triangulator transformer.

After the Triangulator, add a PythonCaller with the following code:

import fme
import fmeobjects
def meshStats(feature):
    # extract geometry from feature
    geom = feature.getGeometry()
    # get number of vertices in Mesh
    numVerts = geom.numVertices()
    # set number of vertices on feature as attribute
    feature.setAttribute("_numVertices", numVerts)
    # convert Mesh to MultiSurface
    msurf = geom.getAsMultiSurface()
    # get number of parts in MultiSurface
    numTriangles = msurf.numParts()
    # set number of parts on feature as attribute
    feature.setAttribute("_numTriangles", numTriangles)

This will create two new attributes on the feature:

  • _numVertices will contain the number of vertices in the Mesh
  • _numTriangles will contain the number of triangles in the Mesh

Although the geometry in the Python is converted from a Mesh to a MultiSurface to get the number of triangles, that geometry is not written back to the feature, so the feature geometry will be unchanged.

View original
Did this help you find an answer to your question?

3 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • Best Answer
  • June 30, 2017

Hi @lavairye

The CityGML surfaces will be converted to triangular meshes by the OBJ writer, but in order to count the resulting vertices, we can do the mesh conversion before writing, with the Triangulator transformer.

After the Triangulator, add a PythonCaller with the following code:

import fme
import fmeobjects
def meshStats(feature):
    # extract geometry from feature
    geom = feature.getGeometry()
    # get number of vertices in Mesh
    numVerts = geom.numVertices()
    # set number of vertices on feature as attribute
    feature.setAttribute("_numVertices", numVerts)
    # convert Mesh to MultiSurface
    msurf = geom.getAsMultiSurface()
    # get number of parts in MultiSurface
    numTriangles = msurf.numParts()
    # set number of parts on feature as attribute
    feature.setAttribute("_numTriangles", numTriangles)

This will create two new attributes on the feature:

  • _numVertices will contain the number of vertices in the Mesh
  • _numTriangles will contain the number of triangles in the Mesh

Although the geometry in the Python is converted from a Mesh to a MultiSurface to get the number of triangles, that geometry is not written back to the feature, so the feature geometry will be unchanged.


takashi
Influencer
  • July 1, 2017
daveatsafe wrote:

Hi @lavairye

The CityGML surfaces will be converted to triangular meshes by the OBJ writer, but in order to count the resulting vertices, we can do the mesh conversion before writing, with the Triangulator transformer.

After the Triangulator, add a PythonCaller with the following code:

import fme
import fmeobjects
def meshStats(feature):
    # extract geometry from feature
    geom = feature.getGeometry()
    # get number of vertices in Mesh
    numVerts = geom.numVertices()
    # set number of vertices on feature as attribute
    feature.setAttribute("_numVertices", numVerts)
    # convert Mesh to MultiSurface
    msurf = geom.getAsMultiSurface()
    # get number of parts in MultiSurface
    numTriangles = msurf.numParts()
    # set number of parts on feature as attribute
    feature.setAttribute("_numTriangles", numTriangles)

This will create two new attributes on the feature:

  • _numVertices will contain the number of vertices in the Mesh
  • _numTriangles will contain the number of triangles in the Mesh

Although the geometry in the Python is converted from a Mesh to a MultiSurface to get the number of triangles, that geometry is not written back to the feature, so the feature geometry will be unchanged.

It seems that the FMEMesh.numParts method (inherited from FMESimpleSurface class) can also be used here.

 

def meshStats(feature):
    # extract geometry from feature
    geom = feature.getGeometry()
    
    # get number of vertices and parts in Mesh
    numVerts = geom.numVertices()
    numTriangles = geom.numParts()
    
    # set number of vertices and parts on feature as attributes
    feature.setAttribute("_numVertices", numVerts)
    feature.setAttribute("_numTriangles", numTriangles) 

lavairye
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • July 2, 2017

Thanks a lot. All my workflow works fine now. I shall use more python in the future!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings