Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Polygon Meshes > Working with Vertices of Polygon Meshes
Working with Vertices of Polygon Meshes

A polygon mesh is an entity representing a surface defined by a set of 3D vertices forming an M*N array. Vertices define the track along which surfaces are drawn.

The polygon mesh object provides methods for getting the coordinates of vertices, adding a new vertex, and relocating an existing vertex. In the following examples, the pPolyMesh variable stores a pointer to the polygon mesh object.

A polygon mesh is a container that stores its own vertices which are structurally independent from the polygon mesh entity, but the polygon mesh is the owner of the vertices. Each vertex is an instance of a vertex entity implemented as an individual class. Properties of vertices are accessed through the interface of the three-dimensional vertex entity. Polygon mesh objects provide getting of an iterator for self-containers through which vertices are accessed. Using this iterator, the program can calculate the number of vertices.

Number of vertices

A simple polygon mesh entity has M*N vertices. A fitted polygon mesh entity has M*N control vertices and MDensity*NDensity fit vertices. To find the number of simple or control vertices, use the mSize() and nSize() methods, and multiply the values that were returned via these methods. To find the number of fit vertices, use the mSurfaceDensity() and nSurfaceDensity() methods, and multiply the values that were returned via these methods.

Adding a vertex

You can add vertices only to the end of the polygon mesh. To keep the polygon mesh valid, the whole row must be added; the number of added vertices should be the number of columns.

To add a vertex to a polygon mesh, use the appendVertex() method which requires a pointer to an existing vertex entity as an argument of the OdDbPolygonMeshVertex type and returns an object ID associated with this vertex when it is added to the database. To create an instance of the polygon mesh vertex entity, use the createObject() method of it (pseudo-constructor). This vertex entity requires three-dimensional coordinates of a point for specifying the three-dimensional position.

For example:


OdDbPolygonMeshVertexPtr p3dVertex;

p3dVertex = OdDbPolygonMeshVertex::createObject();
p3dVertex->setPosition( OdGePoint3d(10.0, 5.0, 1.0) );
OdDbObjectId id3dVertex1 = pPolyMesh->appendVertex(p3dVertex);

Getting a vertex and its coordinates

A polygon mesh has two mechanisms for getting a vertex — the first is using an iterator and the second is using an object ID.

To get an iterator, use the vertexIterator() method which returns the iterator object. Next, use the start() method to set the iterator on the first vertex, the step() method to move the iterator to the following vertex in the container, and the done() method to check whether the iterator is finished the traversing. To get a vertex, use the entity() method of the iterator, which returns a smart pointer to the current vertex that the iterator indicates or NULL if the iterator is done. To get the properties of a vertex, the returned pointer must be converted to the OdDbPolygonMeshVertexPtr type. Next, use the methods of the vertex entity for working with its properties.

For example:


OdGePoint3d wcs;
OdUint16 i = 0;
OdDbPolygonMeshVertexPtr p3dVertex;

OdDbObjectIteratorPtr itVertex = pPolyMesh->vertexIterator();

for(itVertex->start() ; !itVertex->done() ; itVertex->step())
{
  p3dVertex = (OdDbPolygonMeshVertexPtr)itVertex->entity();  
  wcs = p3dVertex->position();

  odPrintConsoleString(L"\nVertex (%i) places in WCS(%g,%g,%g)", i, wcs.x, wcs.y, wcs.z);
  i++;
}

A polygon mesh stores its own vertices as independent entities in the container. Each entity gets an object ID when it is added in the database or is appended to the polygon mesh container. Using an ID, the polygon mesh can get a smart pointer to the vertex entity from the own container instead of traversing, but the ID must be associated with a vertex first, that is, the vertex entity must be appended to the polygon mesh entity. To get a vertex by ID, use the openVertex() method, which requires an instance of the OdDbObjectId type associated with a vertex as the first argument, requires an instance of the OdDb::OpenMode type as the second argument, requires an erase status of a boolean type as the third optional argument, and returns a smart pointer to the vertex entity stored in the polygon mesh container associated with the specified object ID.

For example:


OdDbObjectId id3dVertex = pPolyMesh->appendVertex(OdDbPolygonMeshVertex::createObject());

OdDbPolygonMeshVertexPtr p3dCorner = pPolyMesh->openVertex(id3dVertex, OdDb::kForWrite);

OdGePoint3d wcs = p3dCorner->position();

odPrintConsoleString(L"\nVertex places in WCS(%g,%g,%g)", wcs.x, wcs.y, wcs.z);

Relocating a vertex

The location of vertices can be changed using the smart pointers to the corresponding vertex entities stored in the container of the polygon mesh.

To relocate a vertex of a polygon mesh, get the three-dimensional vertex entity using an iterator or object ID and use the setPosition() method of this vertex which requires new WCS coordinates for this vertex as an argument of the OdGePoint3d type. For example:


OdGePoint3d point3d;
OdDbPolygonMeshVertexPtr p3dVertex;
OdDbObjectIteratorPtr itVertex = pPolyMesh->vertexIterator();

for(itVertex->start() ; !itVertex->done() ; itVertex->step())
{
  p3dVertex = pPolyMesh->openVertex(itVertex->objectId(), OdDb::kForWrite);

  point3d = p3dVertex->position();
  point3d.x += 10;   point3d.y -= 10;   point3d.z *= 2;
  p3dVertex->setPosition(point3d);
}

See Also

Working with Polygon Meshes

Overview of Polygon Meshes

Types of Polygon Meshes and Vertices

Specific Properties of Polygon Meshes

Example of Working with Polygon Meshes

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.