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

            Split Shape by Plane in OpenCASCADE

            Posted on 2017-07-01 12:21 eryar 閱讀(3997) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            Split Shape by Plane in OpenCASCADE

            eryar@163.com

            Abstract. Sometimes you want to split a shape by plane or even split a shape by a B Spline surface, OpenCASCADE provide a feature class BRepFeat_SplitShape to implement the function. The paper give a sample code to split a cylinder by plane.

            Key Words. Split Shape, BRep Feature Algorithms.

            1. Introduction

            OpenCASCADE提供了Boolean Operation實(shí)現(xiàn)了任意兩個(gè)形狀的交、并、差的布爾操作。但是如何實(shí)現(xiàn)用一個(gè)面將一個(gè)形狀切割成兩半呢?其實(shí)Boolean Operation中已經(jīng)有求交分割的算法,但是沒有直接提供一個(gè)分割的功能類,而是在BRepFeat_SplitShape提供了分割功能。

            wps69BE.tmp

            Figure 1. Split Cylinder by Plane

            2. Code Demo

            使用類BRepAlgoAPI_Section和類BRepFeat_SplitShape相結(jié)合來實(shí)現(xiàn)分割Split形狀的功能。完整代碼示例如下:

            /*
            Copyright(C) 2017 Shing Liu(eryar@163.com)

            Permission is hereby granted, free of charge, to any person obtaining a copy
            of this software and associated documentation files(the "Software"), to deal
            in the Software without restriction, including without limitation the rights
            to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
            copies of the Software, and to permit persons to whom the Software is
            furnished to do so, subject to the following conditions :

            The above copyright notice and this permission notice shall be included in all
            copies or substantial portions of the Software.

            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
            SOFTWARE.
            */

            // Visual Studio 2013 & OpenCASCADE7.1.0

            #include <gp_Pln.hxx>

            #include <TopoDS.hxx>

            #include <TopExp.hxx>
            #include <TopExp_Explorer.hxx>

            #include <BRepTools.hxx>

            #include <BRepPrimAPI_MakeCylinder.hxx>

            #include <BRepAlgoAPI_Section.hxx>

            #include <BRepFeat_SplitShape.hxx>

            #pragma comment(lib, "TKernel.lib")
            #pragma comment(lib, "TKMath.lib")

            #pragma comment(lib, "TKG2d.lib")
            #pragma comment(lib, "TKG3d.lib")
            #pragma comment(lib, "TKGeomBase.lib")
            #pragma comment(lib, "TKGeomAlgo.lib")

            #pragma comment(lib, "TKBRep.lib")
            #pragma comment(lib, "TKTopAlgo.lib")

            #pragma comment(lib, "TKBO.lib")
            #pragma comment(lib, "TKPrim.lib")
            #pragma comment(lib, "TKFeat.lib")

            //! Test split a cylinder by plane.
            //! You can use the algorithm to split other shapes.
            void testSplit()
            {
                BRepPrimAPI_MakeCylinder aCylinderMaker(10.0, 20.0);
                TopoDS_Shape aCylinder = aCylinderMaker.Shape();

                // Build section by the split plane for the cylinder.
                BRepAlgoAPI_Section aSection(aCylinder, gp_Pln(gp_Pnt(0.0, 0.0, 15.0), gp::DZ()), Standard_False);
                aSection.ComputePCurveOn1(Standard_True);
                aSection.Approximation(Standard_True);
                aSection.Build();

                // Split the cylinder shape.
                BRepFeat_SplitShape aShapeSpliter(aCylinder);

                for (TopExp_Explorer i(aSection.Shape(), TopAbs_EDGE); i.More(); i.Next())
                {
                    TopoDS_Shape anEdge = i.Current();
                    TopoDS_Shape aFace;

                    if (aSection.HasAncestorFaceOn1(anEdge, aFace))
                    {
                        TopoDS_Edge E = TopoDS::Edge(anEdge);
                        TopoDS_Face F = TopoDS::Face(aFace);

                        aShapeSpliter.Add(E, F);
                    }
                }

                aShapeSpliter.Build();

                // Rebuild left and right shape.
                BRep_Builder aBuilder;
                TopoDS_Compound aLeftCompound;
                TopoDS_Compound aRightCompound;

                aBuilder.MakeCompound(aLeftCompound);
                aBuilder.MakeCompound(aRightCompound);

                // Left shape.
                TopTools_MapOfShape aLeftShapeMap;
                const TopTools_ListOfShape& aLeftShapes = aShapeSpliter.Left();
                for (auto i = aLeftShapes.cbegin(); i != aLeftShapes.cend(); i++)
                {
                    aLeftShapeMap.Add(*i);

                    aBuilder.Add(aLeftCompound, *i);
                }

                // Right shape.
                TopTools_IndexedMapOfShape aShapeMap;
                TopExp::MapShapes(aShapeSpliter.Shape(), TopAbs_FACE, aShapeMap);

                for (auto i = aShapeMap.cbegin(); i != aShapeMap.cend(); i++)
                {
                    if (!aLeftShapeMap.Contains(*i))
                    {
                        aBuilder.Add(aRightCompound, *i);
                    }
                }

                // Output left and right shape.
                BRepTools::Write(aLeftCompound, "d:/left.brep");
                BRepTools::Write(aRightCompound, "d:/right.brep");
            }

            int main(int argc, char* argv[])
            {
                testSplit();

                return 0;
            }

            先創(chuàng)建一個(gè)圓柱體,再使用類BRepAlgoAPI_Section將圓柱體用平面進(jìn)行分割,最后使用類BRepFeat_SplitShape進(jìn)行分類,得到切割后的形狀及Left()形狀,把切割后形狀中的Left過濾后剩下就是切割另一半的形狀;最后導(dǎo)出被平面切割后得到的兩半形狀。結(jié)果用動(dòng)畫演示如下:

            split shape

            Figure 2. Split Shape animation demo

            3. Conclusion

            OpenCASCADE提供類BRepFeat_SplitShape來實(shí)現(xiàn)對(duì)一個(gè)形狀進(jìn)行切割的功能,但是要配合BRepAlgoAPI_Section使用。因?yàn)锽oolean Operation中已經(jīng)實(shí)現(xiàn)了求交、分類的功能,所以在最新版本的源碼7.2.0中已經(jīng)將分割功能集成到了Boolean Operation中。分割后如果沒有被改變的面還是原來的面。

            久久亚洲精品国产亚洲老地址| 一本一道久久a久久精品综合| 国产成人精品综合久久久| 思思久久99热只有频精品66| 久久久久亚洲AV无码麻豆| 久久精品国产第一区二区三区| 94久久国产乱子伦精品免费 | 人人狠狠综合久久亚洲高清| 久久久噜噜噜久久中文字幕色伊伊| 亚洲伊人久久精品影院| 精品综合久久久久久97超人| 国产精品美女久久福利网站| 99久久精品费精品国产一区二区| 91精品国产综合久久香蕉| 伊人久久大香线蕉AV一区二区 | 99久久国产热无码精品免费| 精品99久久aaa一级毛片| 久久久久免费看成人影片| 国内精品伊人久久久久网站| 久久久久99精品成人片欧美| 久久久久久国产a免费观看黄色大片 | 精品久久久一二三区| 91久久精品无码一区二区毛片| 亚洲精品无码久久久久| 亚洲v国产v天堂a无码久久| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 久久国产成人| 99热都是精品久久久久久| 精品国产VA久久久久久久冰 | 国产精品嫩草影院久久| 99久久人妻无码精品系列蜜桃 | 99热都是精品久久久久久| 免费国产99久久久香蕉| 日韩人妻无码精品久久免费一 | 久久91这里精品国产2020| 大美女久久久久久j久久| 久久99精品国产一区二区三区| 久久精品国产亚洲av日韩| 久久精品九九亚洲精品| 999久久久无码国产精品| 狠狠色丁香婷婷综合久久来|