• <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

            布爾數(shù)據(jù) BOPDS_Iterator

            Posted on 2023-09-18 21:13 eryar 閱讀(993) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            布爾數(shù)據(jù) BOPDS_Iterator

            eryar@163.com

            1 Introduction

            OpenCASCADE中新的布爾工具TKBO相對已經(jīng)廢棄的TKBool代碼更規(guī)范,更易于理解。與ModelingData和ModelingAlgorithms大的模塊組織一樣,主要也是數(shù)據(jù)結構Data Structure+算法Algorithm的組織形式。

            其中BOPDS為布爾中的數(shù)據(jù)結構部分,BOPAlgo為布爾中的算法部分。理解算法的前提是先理解數(shù)據(jù)結構DS(Data Structure),所以先從數(shù)據(jù)結構入手,來深入理解布爾操作。本文先從簡單的數(shù)據(jù)結構BOPDS_Iterator開始對源碼進行分析。

             

            2 BOPDS_Iterator

            從類的注釋可以看出,迭代器BOPDS_Iterator有以下兩個功能:

            - 找出包圍盒相交的Shape;

            - 遍歷相交的一對Shape;

            //! The class BOPDS_Iterator is
            //! 1.to compute intersections between BRep sub-shapes
            //! of arguments of an operation (see the class BOPDS_DS)
            //! in terms of theirs bounding boxes
            //! 2.provides interface to iterate the pairs of
            //! intersected sub-shapes of given type
            class BOPDS_Iterator 
            {
            public:

            其中核心的算法在函數(shù)Intersect()中,代碼如下所示:

            //=======================================================================
            // function: Intersect
            // purpose: 
            //=======================================================================
            void BOPDS_Iterator::Intersect(const Handle(IntTools_Context)& theCtx,
                                           const Standard_Boolean theCheckOBB,
                                           const Standard_Real theFuzzyValue)
            {
              const Standard_Integer aNb = myDS->NbSourceShapes();
              // Prepare BVH
              BOPTools_BoxTree aBoxTree;
              aBoxTree.SetSize (aNb);
              for (Standard_Integer i = 0; i < aNb; ++i)
              {
                const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
                if (!aSI.HasBRep())
                  continue;
                const Bnd_Box& aBox = aSI.Box();
                aBoxTree.Add (i, Bnd_Tools::Bnd2BVH (aBox));
              }
              // Build BVH
              aBoxTree.Build();
              // Select pairs of shapes with interfering bounding boxes
              BOPTools_BoxPairSelector aPairSelector;
              aPairSelector.SetBVHSets (&aBoxTree, &aBoxTree);
              aPairSelector.SetSame (Standard_True);
              aPairSelector.Select();
              aPairSelector.Sort();
              // Treat the selected pairs
              const std::vector<BOPTools_BoxPairSelector::PairIDs>& aPairs = aPairSelector.Pairs();
              const Standard_Integer aNbPairs = static_cast<Standard_Integer> (aPairs.size());
              Standard_Integer iPair = 0;
              const Standard_Integer aNbR = myDS->NbRanges();
              for (Standard_Integer iR = 0; iR < aNbR; ++iR)
              {
                const BOPDS_IndexRange& aRange = myDS->Range(iR);
                for (; iPair < aNbPairs; ++iPair)
                {
                  const BOPTools_BoxPairSelector::PairIDs& aPair = aPairs[iPair];
                  if (!aRange.Contains (aPair.ID1))
                    // Go to the next range
                    break;
                  if (aRange.Contains (aPair.ID2))
                    // Go to the next pair
                    continue;
                  const BOPDS_ShapeInfo& aSI1 = myDS->ShapeInfo (aPair.ID1);
                  const BOPDS_ShapeInfo& aSI2 = myDS->ShapeInfo (aPair.ID2);
                  const TopAbs_ShapeEnum aType1 = aSI1.ShapeType();
                  const TopAbs_ShapeEnum aType2 = aSI2.ShapeType();
                  Standard_Integer iType1 = BOPDS_Tools::TypeToInteger (aType1);
                  Standard_Integer iType2 = BOPDS_Tools::TypeToInteger (aType2);
                  // avoid interfering of the shape with its sub-shapes
                  if (((iType1 < iType2) && aSI1.HasSubShape (aPair.ID2)) ||
                      ((iType1 > iType2) && aSI2.HasSubShape (aPair.ID1)))
                    continue;
                  if (theCheckOBB)
                  {
                    // Check intersection of Oriented bounding boxes of the shapes
                    const Bnd_OBB& anOBB1 = theCtx->OBB (aSI1.Shape(), theFuzzyValue);
                    const Bnd_OBB& anOBB2 = theCtx->OBB (aSI2.Shape(), theFuzzyValue);
                    if (anOBB1.IsOut (anOBB2))
                      continue;
                  }
                  Standard_Integer iX = BOPDS_Tools::TypeToInteger (aType1, aType2);
                  myLists(iX).Append (BOPDS_Pair (Min (aPair.ID1, aPair.ID2),
                                                  Max (aPair.ID1, aPair.ID2)));
                }
              }
            }

            在求交函數(shù)Intersect中使用BVH快速找出包圍盒有相交的每對Shape,并以索引的形式記錄下來。從這個函數(shù)中可以看出布爾操作是否使用OBB的選項的作用:當不使用OBB時,只以AABB包圍盒來檢測相交的Shape;當使用OBB時,在AABB的基礎上進一步使用包圍更緊密的OBB來檢測相交,可以排除部分。當相交的模型中以AABB檢測就能檢測出來的,再打開OBB選項,不會提高性能,反而會有所降低。為了減少這個影響,在IntTools_Context中緩存Caching這些OBB,避免構造OBB帶來的性能損失。

            3 Conclusion

            布爾迭代器BOPDS_Iterator通過BVH找出求交的模型中每對包圍盒有相交的模型并提供遍歷每對包圍盒相交的模型的功能,為后面求交作準備。從其代碼實現(xiàn)可以看出布爾選項使用OBB對性能提高是有限的,當使用AABB能檢測出來的,再使用OBB會降低性能。當使用AABB檢測出來相交,但OBB不相交的場景對性能提升明顯。

            今日是“九一八事變”92周年,落后就要挨打,吾輩仍需努力。

            精品熟女少妇a∨免费久久| A级毛片无码久久精品免费| 久久亚洲精品国产亚洲老地址| 天天综合久久一二三区| 国产精品久久婷婷六月丁香| 浪潮AV色综合久久天堂| 久久93精品国产91久久综合| 伊人色综合久久天天人手人婷| 国产一级做a爰片久久毛片| 亚洲国产成人久久综合区| 99久久精品费精品国产一区二区 | 中文字幕无码久久精品青草 | 久久久一本精品99久久精品88| 久久精品亚洲精品国产色婷| 欧美与黑人午夜性猛交久久久 | 久久久久久久国产免费看| 久久精品国产亚洲av麻豆蜜芽| 久久综合狠狠综合久久激情 | 亚洲国产精品无码久久久不卡| 欧美激情精品久久久久久久九九九| 日产精品99久久久久久| 亚洲欧洲久久久精品| 久久久久无码中| 久久久久这里只有精品| 精品久久久久久| 1000部精品久久久久久久久| 久久久久高潮综合影院| 伊人久久大香线蕉无码麻豆| 国内精品久久久久久久涩爱| 国产欧美久久一区二区| 日本久久久久亚洲中字幕| 亚洲精品乱码久久久久久蜜桃图片 | 国内精品伊人久久久久网站| 久久久久无码精品国产| 久久天堂AV综合合色蜜桃网 | 久久99热这里只频精品6| 久久亚洲国产精品123区| 日本久久中文字幕| 久久人妻少妇嫩草AV蜜桃| 伊人久久综合成人网| 无遮挡粉嫩小泬久久久久久久|