Teigha BIM 中的许多元素在 GElement 中包含 B-Rep 几何体,GElement 是元素的几何缓存。然而,B-Rep 并非通用格式。每个产品都有其特定的 B-Rep 表示。
有关 B-Rep 和 BIM 特性的概述可在文档中找到(需要登录)。
使用 OdaBimApp 输出 B-Rep 数据
\Examples\TB_DevGuideCommands 文件夹中的 _BrBrepDump_func 是文档中的一个示例,可用于输出 B-Rep 数据。
- 运行 OdaBimApp
- 加载 DevGuideCommands.tx
- 运行 BrBrepDump 命令(编辑->已注册命令->TBDevGuideCommands->BrBrepDump)
B-Rep 数据在控制台中输出。
这是解析 BIM B-Rep 数据的好方法,但必须考虑 BIM 数据结构。
使用 BrBrep 类
BrBrep 类为不同的 B-Rep 表示提供了一个通用接口。
此接口用于 Teigha BIM、.dgn 文件 (Siemens Parasolid®) 和 .dwg 文件 (Spatial ACIS®)。它是一个面向客户的通用接口,但每个产品都有一个与其产品特定数据一起工作的实现。该接口将内部数据转换为所需的接口,但您可以对不同 Teigha 产品中的不同 B-Rep 数据使用相同的代码。
\Examples\TB_DevGuideCommands 文件夹中的 _BmBrepDump_func 是使用 BrBrep 类的一个示例。
void _BmBrepDump_func(OdEdCommandContext* pCmdCtx)
{
OdBmCommandContextPtr pDbCmdCtx(pCmdCtx);
OdBmDatabasePtr pDb = pDbCmdCtx->database();
OdSmartPtr<OdEdBaseUserIO> pIO = pDbCmdCtx->userIO();
OdInt32 iHandle = pIO->getInt("Enter id of an element for dumping:", OdEd::kInpDefault, -1);
if (iHandle > -1)
{
// Get object
OdBmElementPtr pElem = pDb->getObjectId(OdDbHandle(OdUInt64(iHandle))).safeOpenObject();
// Get object's geometry
OdBmObjectPtr pGeom = pElem->getGeometry();
if (pGeom->isA() == OdBmGElement::desc())
{
OdBmGElement* pGElem = dynamic_cast<OdBmGElement*>(pGeom.get());
//Get nodes
OdBmGNodePtrArray nodes;
pGElem->getAllSubNodes(nodes);
//Test all nodes until OdBmGeometry found or all nodes verified
for (OdUInt32 iIdx = 0; iIdx < nodes.size(); ++iIdx)
{
if (nodes[iIdx]->isA() == OdBmGeometry::desc())
{
const OdBmGeometry* pGeometry = dynamic_cast<const OdBmGeometry*>(nodes[iIdx].get());
OdString message;
// Get faces
OdBmFacePtrArray faceNodes;
pGeometry->getFaces(faceNodes);
message.format(L"Number of faces is %x", faceNodes.size());
pIO->putString(message);
// Use Face Iterator to iterate all faces of the object
int faceNum = 0;
for (OdBmFacePtrArray::iterator faceIt = faceNodes.begin(); faceIt != faceNodes.end(); ++faceIt)
{
message.format(L"Face %x", faceNum);
pIO->putString(message);
faceNum++;
// Get first EdgeLoop of a face
OdBmFacePtr pFace = *faceIt;
OdBmGEdgeLoopPtr pFirstEdgeLoop = pFace->getFirstLoop();
if (pFirstEdgeLoop.isNull()) //it is possible
continue;
int loopNum = 0;
OdBmGEdgeLoopPtr pNextEdgeLoop = pFirstEdgeLoop;
while (!pNextEdgeLoop.isNull())
{
message.format(L" Loop %x", loopNum);
pIO->putString(message);
// Get first edge in loop
OdBmGEdgeBase* pNext = pNextEdgeLoop->getNext();
int edgeNum = 0;
while (!pNext->isLoop())
{
OdBmGEdge* pGEdge = dynamic_cast<OdBmGEdge*>(pNext);
bool bForvardDir = true;
int iEdgeForFace = 0;
{
OdBmFace* pFaceInt = pGEdge->getFacesItem(iEdgeForFace);
if (pFaceInt != pFace.get())
{
pFaceInt = pGEdge->getFacesItem(1);
if (pFaceInt == pFace.get())
{
bForvardDir = false;
iEdgeForFace = 1;
}
}
}
if (pGEdge->isFlipped())
bForvardDir = !bForvardDir;
// Get start and end points of the Edge
OdGePoint3dArray egepnts;
pGEdge->getFirstAndLastEdgeGePnts(egepnts);
if (bForvardDir)
message.format(L" Edge %i points: [%f , %f , %f], [%f , %f , %f]", edgeNum++, egepnts[0].x, egepnts[0].y, egepnts[0].z, egepnts[1].x, egepnts[1].y, egepnts[1].z);
else
message.format(L" Edge %i points: [%f , %f , %f], [%f , %f , %f]", edgeNum++, egepnts[1].x, egepnts[1].y, egepnts[1].z, egepnts[0].x, egepnts[0].y, egepnts[0].z);
pIO->putString(message);
// Go to next edge in loop
try
{
pNext = pGEdge->getNextItem(iEdgeForFace);
}
catch (const OdError& err)
{
message.format(L"%ls", err.description().c_str());
pIO->putString(message);
break;
}
}//while (!pNext->isLoop())
loopNum++;
pNextEdgeLoop = pNextEdgeLoop->getNextLoop();
}//while (!pNextEdgeLoop.isNull())
}//for (OdBmFacePtrArray::iterator faceIt = faceNodes.begin(); faceIt != faceNodes.end(); ++faceIt)
}//if (nodes[0]->isA() == OdBmGeometry::desc())
}//for (OdBmGNodePtrArray::const_iterator it = nodes.begin(); it != nodes.end(); ++it)
}//if (pGeom->isA() == OdBmGElement::desc())
}//if (iHandle > -1)
}