PART I – How 3D Models are Stored in DWG. —- Tech Tips: Creating 3D models with Teigha Platform

PART I – How 3D Models are Stored in DWG. —- Tech Tips:  Creating 3D models with Teigha Platform

Guest post by Alexander Spivakov, mathematician and programmer at C3D Labs

The Terminology of B-reps

When we speak of 3D models in the mathematical sense, we usual refer to the “boundary representation” of solid bodies– their skin, as it were. Solids are so-called because their shape tends to be constant (cannot be easily modified), and their material is considered to be homogeneous throughout. By contrast, surface and mesh models are empty inside, but their skins can be modified in the extreme.In our industry, boundary representation is called “b-rep” for short.

I would like tobriefly discuss boundary representation in the style of Abraham begat Isaac, Isaac begat Jacob. I’ll introduce b-rep concepts (without giving strict definitions) by providing illustrations. Detailed descriptions can be found in specialist literature.

The primary description of bodies is the boundary: the described object is the body bound, or shell, which separates space in two parts. One part, called inner, contains material and lays inside the body, and the other lays outside.The properties of shell are very similar to that of a surface.In practice, the boundaries of bodies are represented as sets of flat and curved faces.


A face is a surface fragment that is oriented in a specific way and is linkedto other faces in a defined way. The linking method works as follows: the boundary of each face is split into edges, and the transition from one face to the next is performed by at least one of the edges. On each face, the edges are grouped into closed, oriented chains called “loops.”

Edges are arranged in loops in such a way as to ensure the correct direction when passing the face: the face must be on the left hand side for the outer loop and on the right hand side for the inner loop.

Each edge connects not only two faces, but also two vertices: the passage along the chain of oriented edges from one vertex to another also defines a loop: when we start from any vertex, we eventually return to it.


Shells, faces, loops, edges, and vertices (that is, the objects that describe the relative positions of geometry elements) are called “topological objects.”

Defining Geometry

You are unlikely to find a designer who manually describes the geometry of items, especially not the many relationships between faces and vertices.  In fact, designers don’t even have to know anything about the functionsthat store models in CAD files, such asthoseused by the Open Design Alliance’sTeigha API to store three-dimensional data in theModelSpace section of DWG/DXF files. As it turns out, 3D solids are stored as descriptions of b-rep Db3dSolid bodies in SAT format (short for “Save As Text”).This format was designed to facilitate exchange of data between the CAD system and the ACIS geometric kernel from Dassault SystemesSpatial.

Modern CAD systems provide designers with a rich set of tools based on a relatively small number of modeling operations. The correct combination of these operations allows designers to create items with complex shapes. Whether using a command-line interface or a graphical user interface, the UI transparently calls functions from the geometric kernel (also known simply as the “modeler”).

Using Boolean Operations to Create 3D Models with Teigha

One of the Teigha APIs (short for “application programming interface”) that undertakes 3D modeling is the OdDb3dSolid interface. The modeling methods provided by the interface can be divided into two groups. One group involves operations on bodies as they are: creation bodies and Boolean operations on them. The other group includes modification of solids based on topological elements.

Boolean Operations

Using Boolean operations on bodies is a powerful tool as it is visual, intuitive, and applicable to many modeling tasks. At the same time, the corresponding section of the Teigha platform’s API is most concise, with only one method:

OdResult OdDb3dSolid::booleanOper(OdDb::BoolOperType operation, OdDb3dSolid* solid);

The first argument defines the type of the operation: Unite, Intersect, or Subtract.

namespace OdDb




kBoolUnite     = 0,

kBoolIntersect = 1,

kBoolSubtract  = 2



Fig 3

Fig 3

If the problem of what can be arguments for Boolean operations is somehow solved, then the tree of Boolean operations is sufficient to describe entire body shapes. This principle underlies a large section of modeling called Constructive Solid Geometry (or “CSG” for short). The essence of this approach is that the leaves of the construction graph are elementary bodies, such as parallelepipeds, cylinders, and spheres.

Fig 4

Fig 4


Defining Elementary Bodies

Teigha provides a comprehensive set of methods for creating elementary bodies, such as these:

void createBox( doublexLen, double yLen, double zLen );

void createFrustum( double height, double xRadius, double yRadius, double topXRadius );

void createSphere( double radius );

void createWedge( doublexLen, double yLen, double zLen );

void createTorus( double majorRadius, double minorRadius );

All elementary bodies are created in the global coordinate system. Parallel movement, rotation around axes, and scaling are used to position bodies in space. Operational parameters are presented as a matrix in the form of a 3-by-3 square rotation matrix. This is effectively expanded to a 4-by-4 matrix by an additional column and row that store the offset vector and the scaling coefficients along the coordinate axes.

locMatr=OdGeMatrix3d::rotation( OdaPI2, OdGeVector3d::kXAxis ) *OdGeMatrix3d::translation( OdGeVector3d::kXAxis* 100.0 );



Broadly defined, the CSG approach is sometimes considered to be the modeling of solids using Boolean operations over a class of bodies which is wider than the class of elementary bodies.


Continue reading PART II

About Guest/blogger

Guest/blogger posts belongs to respective authors. The articles/tips are summarized here, if interested in reading the complete blog post, please follow the links given under each post.
Download Now