Working with B-Reps

Alexander Fokin

July 05, 2018

In Teigha you can work with solids and shells using boundary representations, or B-Reps. In different Teigha products, Teigha Drawings (for working with both .dwg and .dgn files), Teigha PRC, and Teigha BIM, there are separate implementations of B-Rep interfaces, but you can work with them using the common class OdBrBrep.

A B-Rep can be created with the help of the appropriate BrepBuilder. Builders are wrapped by the common class OdBrepBuilder just like a B-Rep.

You can fill the builder manually by calling add* functions (addFace, addEdge, etc.). Or you can get an existing B-Rep using OdBrepBuilderFillerModule.

The OdBrepBuilderFillerModule is the core extension module. It traverses a B-Rep and collects topology and material information. Then the module puts data into the builder.

To use B-Reps:

  1. Add the include header:
    #include "BrepBuilderFillerModule.h"
    
  2. For static builds, add a declaration of the module:
    #ifndef _TOOLKIT_IN_DLL_
    
    ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdBrepBuilderFillerModule);
    
    ODRX_BEGIN_STATIC_MODULE_MAP()
    ODRX_DEFINE_STATIC_APPMODULE(OdBrepBuilderFillerModuleName, OdBrepBuilderFillerModule)
    ODRX_END_STATIC_MODULE_MAP()
    
    #endif
    
  3. Set up the implementation of OdBrepBuilder using the method brepBuilder of the host app service instance. For example:
    OdDbHostAppServices* pHostApp;
    …
    OdBrepBuilder builder;
    OdResult err = pHostApp->brepBuilder(builder, kOpenShell);
    if (eOk != err)
    {
      throw err;
    }
    
  4. Load the module:
    OdBrepBuilderFillerModulePtr pFillerModule = ::odrxDynamicLinker()->loadModule(OdBrepBuilderFillerModuleName, false);
    
  5. To handle materials, use a helper structure (its fields are optional):
    OdMaterialHelper materialHelper;
    materialHelper.pDefaultMaterial = ...;
    materialHelper.pMaterialResolver = ...;
    materialHelper.pGiContext = ...;
    
  6. Because the builder does not own geometry data, you have to store this data while you use the builder:
    OdGeCurve3dPtrArray arrEdges;
    OdGeCurve2dPtrArray arrCoedges;
    OdGeSurfacePtrArray arrSurfaces;
    
  7. To initialize the builder, use the method initFrom:
    OdResult err = pFillerModule->initFrom(builder, brep, arrEdges, arrCoedges, arrSurfaces, materialHelper));
    if (eOk != err)
    {
      throw err;
    }