找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1678|回复: 3

用BREP API去掉3DSOLID的洞(附代码)

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-1-10 21:05:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
void removeHoles()
{
    AcDb3dSolid* pSolid;
    AcDbObjectId solidId;
    AcBr::ErrorStatus bs;
    AcBrBrep brep;
    AcBrBrepFaceTraverser bft;
    AcBrFaceLoopTraverser flt;
    AcBrLoopEdgeTraverser let;
    AcBrEdgeLoopTraverser elt;

    AcBrFace face;
    AcBrLoop loop,loop2;
    AcBrEdge edge;
    AcBr::LoopType loopType;
    AcArray<AcDbSubentId*> faces;
    AcBrFace faceToRemove;


    if((pSolid = selectSolid("\nSelect a solid",solidId,AcDb::kForWrite)) == NULL)
    {
        acutPrintf("\nSelection failed");
        return;
    }

    // Initialize the Brep
    AcDbFullSubentPath path(solidId,AcDbSubentId());

    try
    {
        bs = brep.setSubentPath(path);
        if(bs != AcBr::eOk)
        {
            acutPrintf("\nsetSubentPath failed");
            throw bs;
        }

        // Initialize the BrepFace traverser
        bs = bft.setBrep(brep);
        if(bs != AcBr::eOk)
        {
            acutPrintf("\nsetBrep failed");
            throw bs;
        }


        // Traverse all faces
        for(;!bft.done();bft.next())
        {
            bs = bft.getFace(face);
            if(bs != Acad::eOk)
            {
                acutPrintf("\ngetFace failed");
                throw bs;
            }

            // Initialize the face-loop traverser
            bs = flt.setFace(face);
            if(bs != Acad::eOk)
            {
                acutPrintf("\nsetFace failed");
                throw bs;
            }

            // Traverse all loops of the actual face
            for(;!flt.done();flt.next())
            {
                bs = flt.getLoop(loop);
                if(bs != Acad::eOk)
                {
                    acutPrintf("\ngetLoop failed");
                    throw bs;
                }

                loop.getType(loopType);

                // If we got an outer loop continue with the face traversing
                if(loopType != AcBr::kLoopInterior)
                    break;

                // Traverse all edges of current interior loop
                bs = let.setLoop(flt);
                if(bs != AcBr::eOk)
                {
                    acutPrintf("\nsetLoop failed");
                    throw bs;
                }
            
                for(;!let.done();let.next())
                {
                    bs = let.getEdge(edge);
                    if(bs != Acad::eOk)
                    {
                        acutPrintf("\ngetEdge failed");
                        throw bs;
                    }

                    // Traverse all loops of current edge
                    bs = elt.setEdge(edge);
                    if(bs != AcBr::eOk)
                        acutPrintf("\nsetEdgeAndLoop failed");

                    for(;!elt.done();elt.next())
                    {
                        bs = elt.getLoop(loop2);
                        if(bs != AcBr::eOk)
                        {
                            acutPrintf("\ngetLoop failed");
                            throw bs;
                        }
                        // if it is the same loop as the loop processed by flt
                        // continue
                        if(loop.isEqualTo(&loop2))
                            continue;
                        loop2.getFace(faceToRemove);
                            faceToRemove.getSubentPath(path);

                        Adesk::Boolean isInList = Adesk::kFalse;
                        
                        for(int i=0;i<faces.length();i++)
                        {
                            if(path.subentId() == *(faces))
                                isInList = Adesk::kTrue;
                        }
                        if(!isInList)
                            faces.append(new AcDbSubentId(path.subentId()));
                    }
                }
            }
        }

        acutPrintf("\nGot %d faces ",faces.length());
        pSolid->removeFaces(faces);
    }
    catch(AcBr::ErrorStatus bs)
    {
        acutPrintf(" bs = %d",bs);
    }
    pSolid->close();
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2006-8-17 12:53:47 | 显示全部楼层
谢谢晓东!我要收藏!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-8-23 17:54:12 | 显示全部楼层
Brep是什么东东?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 9个

财富等级: 恭喜发财

发表于 2021-1-19 11:05:15 | 显示全部楼层
感谢分享。发帖日期竟然是2002年。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-23 17:16 , Processed in 0.364389 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表