• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            BRep Builder

            Posted on 2020-06-16 11:04 eryar 閱讀(2852) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            BRep Builder

            eryar@163.com

             

            1 Introduction

            BRep_Builder提供了創(chuàng)建、修改BRep模型的方法。使用這個(gè)類,你可以從底層自己構(gòu)建BRep體,前提條件是你要對(duì)BRep模型的數(shù)據(jù)結(jié)構(gòu)有一定理解。邊界表示法BRep的重點(diǎn)在邊界的定義,打開BRep_Builder的類圖:

             

            可以看到其中重載了很多UpdateEdge函數(shù),每個(gè)UpdateEdge函數(shù)都修改了Edge中的幾何數(shù)據(jù),包括邊界的定義數(shù)據(jù)。若能理解每個(gè)UpdateEdge函數(shù),則對(duì)OpenCASCADEBREP數(shù)據(jù)結(jié)構(gòu)就能理解了。本文主要介紹其中兩個(gè)函數(shù)的用法:AddRemove。

             2 Add Shape

            BRep_BuilderAdd函數(shù)的字面意思是將一個(gè)Shape添加到另外一個(gè)Shape中。因這個(gè)函數(shù)的實(shí)現(xiàn)比較簡單,把源碼列出如下:

             

            void TopoDS_Builder::Add (TopoDS_Shape& aShape, 
                                      const TopoDS_Shape& aComponent) const
            {
              // From now the Component cannot be edited
              aComponent.TShape()->Free(Standard_False);
              // Note that freezing aComponent before testing if aShape is free
              // prevents from self-insertion
              // but aShape will be frozen when the Exception is raised
              if (aShape.Free())
              {
                static const unsigned int aTb[9]=
                {
                  //COMPOUND to:
                  (1<<((unsigned int)TopAbs_COMPOUND)),
                  //COMPSOLID to:
                  (1<<((unsigned int)TopAbs_COMPOUND)),
                  //SOLID to:
                  (1<<((unsigned int)TopAbs_COMPOUND)) |
                  (1<<((unsigned int)TopAbs_COMPSOLID)),
                  //SHELL to:
                  (1<<((unsigned int)TopAbs_COMPOUND)) |
                  (1<<((unsigned int)TopAbs_SOLID)),
                  //FACE to:
                  (1<<((unsigned int)TopAbs_COMPOUND)) |
                  (1<<((unsigned int)TopAbs_SHELL)),
                  //WIRE to:
                  (1<<((unsigned int)TopAbs_COMPOUND)) |
                  (1<<((unsigned int)TopAbs_FACE)),
                  //EDGE to:
                  (1<<((unsigned int)TopAbs_COMPOUND)) |
                  (1<<((unsigned int)TopAbs_SOLID)) |
                  (1<<((unsigned int)TopAbs_WIRE)),
                  //VERTEX to:
                  (1<<((unsigned int)TopAbs_COMPOUND)) |
                  (1<<((unsigned int)TopAbs_SOLID)) |
                  (1<<((unsigned int)TopAbs_FACE)) |
                  (1<<((unsigned int)TopAbs_EDGE)),
                  //SHAPE to:
                  0
                };
                //
                const unsigned int iC=(unsigned int)aComponent.ShapeType();
                const unsigned int iS=(unsigned int)aShape.ShapeType();
                //
                if ((aTb[iC] & (1<<iS)) != 0) {
                  TopoDS_ListOfShape& L = aShape.TShape()->myShapes;
                  L.Append(aComponent);
                  TopoDS_Shape& S = L.Last();
                  //
                  // compute the relative Orientation
                  if (aShape.Orientation() == TopAbs_REVERSED)
                    S.Reverse();
                  //
                  // and the Relative Location
                  const TopLoc_Location& aLoc=aShape.Location();
                  if (!aLoc.IsIdentity())
                    S.Move(aLoc.Inverted());
                  //
                  // Set the TShape as modified.
                  aShape.TShape()->Modified(Standard_True);
                }
                else {
                  throw TopoDS_UnCompatibleShapes("TopoDS_Builder::Add");
                }
              }
              else {
                throw TopoDS_FrozenShape("TopoDS_Buider::Add");
              }
            }

             

            Add函數(shù)通過一個(gè)靜態(tài)的檢查列表,來檢查添加的Shape是不是合法的,即FACE只能添加到SHELLCOMPOUND中,EDGE只能添加到WIRESOLIDCOMPOUND中等。添加之后還檢查了ShapeORIENTATION及位置信息并作相應(yīng)調(diào)整。不滿足條件的情況都會(huì)拋出異常,所以對(duì)于Add函數(shù)需要增加異常處理邏輯。

            使用這個(gè)函數(shù)需要注意的是這個(gè)Add只是簡單的將Shape添加到TShapeShape表中,并沒有維護(hù)BREP的邊界信息。

            3 Remove Shape

            Add對(duì)應(yīng)的有Remove函數(shù),可以從一個(gè)Shape中刪除一個(gè)子Shape。還是打開源碼,有源碼有真相:

            //=======================================================================
            //function : Remove
            //purpose  : Remove a Shape from an other one
            //=======================================================================
            void TopoDS_Builder::Remove (TopoDS_Shape& aShape, 
                                         const TopoDS_Shape& aComponent) const
            {
              // check  if aShape  is  not Frozen
              TopoDS_FrozenShape_Raise_if (!aShape.Free(),"TopoDS_Builder::Remove");
              // compute the relative Orientation and Location of aComponent
              TopoDS_Shape S = aComponent;
              if (aShape.Orientation() == TopAbs_REVERSED)
                S.Reverse();
              S.Location(S.Location().Predivided(aShape.Location()));
              TopoDS_ListOfShape& L = aShape.TShape()->myShapes;
              TopoDS_ListIteratorOfListOfShape It(L);
              while (It.More()) {
                if (It.Value() == S) {
                  L.Remove(It);
                  aShape.TShape()->Modified(Standard_True);
                  break;
                }
                It.Next();
              }
            }

             

            從源碼中可知,Remove實(shí)現(xiàn)的邏輯也是很簡單的:

            檢查Shape是不是Free的,若不是則拋出異常;

            計(jì)算要?jiǎng)h除ComponentORIENTATIONLOCATION

            Shape列中查找Component,若找到將其從列表中刪除;

             

            刪除操作比添加操作要簡單,一個(gè)是把已有的數(shù)據(jù)刪除,一個(gè)是從無到有的構(gòu)建數(shù)據(jù)。從函數(shù)實(shí)現(xiàn)代碼來看,刪除操作也是簡單的從Shape列表中刪除指定的Shape。刪除之后多余的邊界信息還會(huì)存在原來的Shape中,要確保刪除的Shape之后沒有多余信息,還需要?jiǎng)h除沒有使用的PCurves

             

            上圖所示為刪除一個(gè)底面的圓柱體。

             4 Conclusion

            BRep_Builder的操作需要以充分理解OpenCASCADEBREP數(shù)據(jù)結(jié)構(gòu)為前提,因?yàn)槠?/span>AddRemove函數(shù)并沒有提供維護(hù)邊界的功能,只是將指定的Shape添加到列表中或從列表中刪除。


            為了方便大家在移動(dòng)端也能看到我的博文和討論交流,現(xiàn)已注冊(cè)微信公眾號(hào),歡迎大家掃描下方二維碼關(guān)注。
            Shing Liu(eryar@163.com)
            亚洲国产成人精品无码久久久久久综合 | 亚洲午夜无码久久久久小说| 久久精品国产一区二区三区不卡| 久久99精品国产麻豆宅宅 | 久久露脸国产精品| 久久精品国产乱子伦| 久久精品国产亚洲AV无码娇色| 久久国产香蕉一区精品| 无码任你躁久久久久久老妇App| …久久精品99久久香蕉国产| 青青草国产精品久久| 久久99这里只有精品国产| 精品蜜臀久久久久99网站| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久亚洲中文字幕精品一区| 国产精品对白刺激久久久| 一本大道久久香蕉成人网| 97久久天天综合色天天综合色hd| 中文无码久久精品| 99热成人精品免费久久| 久久精品人成免费| 久久久久久国产精品美女| 精品久久久久中文字| 热99re久久国超精品首页| 久久久精品人妻一区二区三区四| 久久久噜噜噜久久熟女AA片| 综合久久给合久久狠狠狠97色 | 国产激情久久久久久熟女老人| 久久人妻少妇嫩草AV无码蜜桃| 国产国产成人精品久久| 伊人久久大香线蕉综合影院首页| 性做久久久久久久久| 91麻豆精品国产91久久久久久| 草草久久久无码国产专区| 国产精品久久久久天天影视| 久久久久久国产精品无码超碰| 久久久久se色偷偷亚洲精品av| 精品国产乱码久久久久软件| 日日狠狠久久偷偷色综合0| 久久这里只精品国产99热| 四虎国产精品免费久久5151 |