• <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) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            BRep Builder

            eryar@163.com

             

            1 Introduction

            BRep_Builder提供了創建、修改BRep模型的方法。使用這個類,你可以從底層自己構建BRep體,前提條件是你要對BRep模型的數據結構有一定理解。邊界表示法BRep的重點在邊界的定義,打開BRep_Builder的類圖:

             

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

             2 Add Shape

            BRep_BuilderAdd函數的字面意思是將一個Shape添加到另外一個Shape中。因這個函數的實現比較簡單,把源碼列出如下:

             

            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函數通過一個靜態的檢查列表,來檢查添加的Shape是不是合法的,即FACE只能添加到SHELLCOMPOUND中,EDGE只能添加到WIRESOLIDCOMPOUND中等。添加之后還檢查了ShapeORIENTATION及位置信息并作相應調整。不滿足條件的情況都會拋出異常,所以對于Add函數需要增加異常處理邏輯。

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

            3 Remove Shape

            Add對應的有Remove函數,可以從一個Shape中刪除一個子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實現的邏輯也是很簡單的:

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

            計算要刪除ComponentORIENTATIONLOCATION

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

             

            刪除操作比添加操作要簡單,一個是把已有的數據刪除,一個是從無到有的構建數據。從函數實現代碼來看,刪除操作也是簡單的從Shape列表中刪除指定的Shape。刪除之后多余的邊界信息還會存在原來的Shape中,要確保刪除的Shape之后沒有多余信息,還需要刪除沒有使用的PCurves

             

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

             4 Conclusion

            BRep_Builder的操作需要以充分理解OpenCASCADEBREP數據結構為前提,因為其AddRemove函數并沒有提供維護邊界的功能,只是將指定的Shape添加到列表中或從列表中刪除。


            為了方便大家在移動端也能看到我的博文和討論交流,現已注冊微信公眾號,歡迎大家掃描下方二維碼關注。
            Shing Liu(eryar@163.com)
            精品久久久久久国产牛牛app| 久久久久久精品久久久久| 国产精品无码久久久久久| 99999久久久久久亚洲| 九九久久精品国产| 欧美日韩精品久久久久| 久久久久成人精品无码中文字幕| 久久精品天天中文字幕人妻| 成人精品一区二区久久久| 久久人人爽人人人人爽AV| 久久精品免费一区二区三区| 久久久久亚洲精品无码网址| 无码人妻久久一区二区三区| 久久久久黑人强伦姧人妻| 久久精品中文騷妇女内射| 青青草原综合久久大伊人导航| 人妻精品久久无码区| 国产精品伊人久久伊人电影| 久久综合88熟人妻| 日韩亚洲国产综合久久久| 一本久久久久久久| 久久国产亚洲高清观看| 久久久久av无码免费网| 久久久久一本毛久久久| 久久国产一区二区| 三上悠亚久久精品| 久久人人爽人人爽人人爽| 久久亚洲高清综合| 久久久亚洲精品蜜桃臀| 99久久免费只有精品国产| aaa级精品久久久国产片| 欧美喷潮久久久XXXXx| 大香伊人久久精品一区二区 | 国产精品久久久99| 久久久久亚洲AV成人片| 亚洲综合日韩久久成人AV| 欧美与黑人午夜性猛交久久久| 久久se精品一区精品二区国产| 中文字幕亚洲综合久久| 色综合久久综精品| 国产精品嫩草影院久久|