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

            OpenCASCADE曲面求交之網格離散法1

            Posted on 2023-05-14 21:05 eryar 閱讀(896) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenCASCADE曲面求交之網格離散法1

            eryar@163.com

             

            1 Introduction

            由朱心雄等著《自由曲線曲面造型技術》書中對曲面求交之網格離散法描述如下:該法的基本思想是先將曲面離散為由小平面片組成的網格,當網格足夠密時,可以認為已經非常接近真實曲面,對分別表示不同曲面的兩張網格,利用平面片求交法求得的交線,并以此交線近似代表曲面間的交線。這種方法原理簡明,便于實現,適用范圍廣,任意參數曲面均可利用該法求交。但為獲取精確地交線,則必須生成非常細密的網格,這將導致占用內存多,計算花費大。因此,實際工作中很少單一使用離散網格法,而常將其與其他方法結合使用。

            OpenCASCADE中對于曲面求交也提供離散網格法,其中曲面的離散網格由類IntPatch_Polyhedron表示,兩個網格面求交使用類IntPatch_InterferencePolyhedron。本文主要介紹曲面的網格表示類IntPatch_Polyhedron。

            2 Polyhedron

            OpenCASCADE用于曲面求交的網格離散算法相對BRepMesh中的算法要簡單很多,主要思路是根據參數U,V方向上的采樣點數量來計算曲面上的點,再根據固定公式將采樣點連成三角形。其中生成采樣點代碼如下所示:

            成員變量CMyPnts是采樣點數組,CMyU和CMyV是采樣點在曲面上的參數。將采樣點連成三角形函數如下圖所示:

            根據上述生成采樣點及三角形函數,對于平面生成的三角形如下圖所示:

            其中Triangle()函數中變量line表示參數u方向上第幾條線,代入具體的索引Index來看規律:

            當參數索引 Index為1時,line為1,得到的三角形為1-4-5;

            當參數索引Index為2時,line為1,得到的三角形為1-5-2;

            當參數索引Index為3時,line為1,得到的三角形為2-5-6;

            當參數索引Index為4時,line為1,得到的三角形為2-6-3;

            當參數索引Index為5時,line為2,得到的三角形為4-7-8;

            當參數索引Index為6時,line為2,得到的三角形為4-8-5;

             

            從上可以得到生成三角形的規律,即根據索引Index計算正在處理的三角形是參數u方向上第幾條線line,生成這條線上在參數v方向上的所有的三角形。生成的三角形都是逆時針的。

            下面我們看看對于一些基本曲面,這種離散網格算法生成的網格效果:

            球面的離散網格

            圓柱面的離散網格

            圓環面的離散網格

            B樣條曲面

            3 Conclusion

            綜上所述,類IntPatch_Polyhedron中生成網格的算法主要依賴曲面在參數U,V上的采樣點數量。默認采樣點數量是根據函數NbSamplesV()和NbSamplesU()生成。

            也可以指定采樣點數量,當采樣點數量越多,則生成的三角形越多,網格越密。當然這種方式也可用來生成曲面的顯示數據,生成速度很快,唯一的缺陷是生成顯示用網格的精度只能通過采樣點數量來控制,對于曲率變化大的曲面,若指定多的采樣點,則會生成大量三角形,占用大量內存空間。

            附上測試代碼:

            
            #include <TColgp_Array2OfPnt.hxx>
            #include <Geom_Plane.hxx>
            #include <Geom_CylindricalSurface.hxx>
            #include <Geom_ConicalSurface.hxx>
            #include <Geom_SphericalSurface.hxx>
            #include <Geom_ToroidalSurface.hxx>
            #include <Geom_BSplineSurface.hxx>
            #include <GeomAdaptor_Surface.hxx>
            #include <GeomAPI_PointsToBSplineSurface.hxx>
            #include <IntPatch_Polyhedron.hxx>
            #include <IntPatch_InterferencePolyhedron.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")
            void makeSurface(Handle(Geom_BSplineSurface)& theSurface)
            {
                TColgp_Array2OfPnt aPoints(1, 5, 1, 5);
                aPoints.SetValue(1, 1, gp_Pnt(-4, -4, 5));
                aPoints.SetValue(1, 2, gp_Pnt(-4, -2, 5));
                aPoints.SetValue(1, 3, gp_Pnt(-4, 0, 4));
                aPoints.SetValue(1, 4, gp_Pnt(-4, 2, 5));
                aPoints.SetValue(1, 5, gp_Pnt(-4, 4, 5));
                aPoints.SetValue(2, 1, gp_Pnt(-2, -4, 4));
                aPoints.SetValue(2, 2, gp_Pnt(-2, -2, 4));
                aPoints.SetValue(2, 3, gp_Pnt(-2, 0, 4));
                aPoints.SetValue(2, 4, gp_Pnt(-2, 2, 4));
                aPoints.SetValue(2, 5, gp_Pnt(-2, 5, 4));
                aPoints.SetValue(3, 1, gp_Pnt(0, -4, 3.5));
                aPoints.SetValue(3, 2, gp_Pnt(0, -2, 3.5));
                aPoints.SetValue(3, 3, gp_Pnt(0, 0, 3.5));
                aPoints.SetValue(3, 4, gp_Pnt(0, 2, 3.5));
                aPoints.SetValue(3, 5, gp_Pnt(0, 5, 3.5));
                aPoints.SetValue(4, 1, gp_Pnt(2, -4, 4));
                aPoints.SetValue(4, 2, gp_Pnt(2, -2, 4));
                aPoints.SetValue(4, 3, gp_Pnt(2, 0, 3.5));
                aPoints.SetValue(4, 4, gp_Pnt(2, 2, 5));
                aPoints.SetValue(4, 5, gp_Pnt(2, 5, 4));
                aPoints.SetValue(5, 1, gp_Pnt(4, -4, 5));
                aPoints.SetValue(5, 2, gp_Pnt(4, -2, 5));
                aPoints.SetValue(5, 3, gp_Pnt(4, 0, 5));
                aPoints.SetValue(5, 4, gp_Pnt(4, 2, 6));
                aPoints.SetValue(5, 5, gp_Pnt(4, 5, 5));
                theSurface = GeomAPI_PointsToBSplineSurface(aPoints).Surface();
            }
            void writeStl(const IntPatch_Polyhedron& thePolyhedron, const std::string& theFileName)
            {
                // Dump surface polyhedron to STL file.
                std::ofstream aStlFile(theFileName);
                aStlFile << "solid polyhedron" << std::endl;
                // Dump triangles.
                for (Standard_Integer t = 1; t <= thePolyhedron.NbTriangles(); ++t)
                {
                    Standard_Integer aPi1 = 0;
                    Standard_Integer aPi2 = 0;
                    Standard_Integer aPi3 = 0;
                    thePolyhedron.Triangle(t, aPi1, aPi2, aPi3);
                    const gp_Pnt& aP1 = thePolyhedron.Point(aPi1);
                    const gp_Pnt& aP2 = thePolyhedron.Point(aPi2);
                    const gp_Pnt& aP3 = thePolyhedron.Point(aPi3);
                    aStlFile << "facet" << std::endl;
                    aStlFile << "outer loop" << std::endl;
                    aStlFile << "vertex " << aP1.X() << " " << aP1.Y() << " " << aP1.Z() << std::endl;
                    aStlFile << "vertex " << aP2.X() << " " << aP2.Y() << " " << aP2.Z() << std::endl;
                    aStlFile << "vertex " << aP3.X() << " " << aP3.Y() << " " << aP3.Z() << std::endl;
                    aStlFile << "endloop" << std::endl;
                    aStlFile << "endfacet" << std::endl;
                }
                aStlFile << "endsolid polyhedron" << std::endl;
                aStlFile.close();
            }
            void testPolyhedron()
            {
                // Plane surface polyhedron.
                Handle(Geom_Plane) aPlane = new Geom_Plane(gp::XOY());
                Handle(GeomAdaptor_Surface) aSurfaceAdaptor = new GeomAdaptor_Surface(aPlane, 0.0, 10.0, 0.0, 20.0);
                IntPatch_Polyhedron aPlanePolyhedron(aSurfaceAdaptor);
                writeStl(aPlanePolyhedron, "d:/plane.stl");
                // Spherical surface polyhedron.
                Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(gp::XOY(), 3.0);
                aSurfaceAdaptor = new GeomAdaptor_Surface(aSphericalSurface);
                IntPatch_Polyhedron aSphericalPolyhedron(aSurfaceAdaptor);
                writeStl(aSphericalPolyhedron, "d:/spherical.stl");
                // Cylindrical surface polyhedron.
                Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(gp::XOY(), 5.0);
                aSurfaceAdaptor = new GeomAdaptor_Surface(aCylindricalSurface, 0.0, M_PI, 0.0, 8.0);
                IntPatch_Polyhedron aCylindricalPolyhedron(aSurfaceAdaptor);
                writeStl(aCylindricalPolyhedron, "d:/cylindrical.stl");
                // Toroidal Surface polyhedron.
                Handle(Geom_ToroidalSurface) aToroidalSurface = new Geom_ToroidalSurface(gp::XOY(), 10.0, 3.0);
                aSurfaceAdaptor = new GeomAdaptor_Surface(aToroidalSurface);
                IntPatch_Polyhedron aToroidalPolyhedron(aSurfaceAdaptor);
                writeStl(aToroidalPolyhedron, "d:/toroidal.stl");
                // BSpline surface polyhedron.
                Handle(Geom_BSplineSurface) aBSplineSurface;
                makeSurface(aBSplineSurface);
                aSurfaceAdaptor = new GeomAdaptor_Surface(aBSplineSurface);
                IntPatch_Polyhedron aPolyhedron(aSurfaceAdaptor);
                writeStl(aPolyhedron, "d:/bspline.stl");
            }
            int main(int argc, char* argv[])
            {
                testPolyhedron();
                return 0;
            }

             

            香蕉99久久国产综合精品宅男自 | 久久久久无码专区亚洲av| 国产精品久久久久天天影视| 18岁日韩内射颜射午夜久久成人 | 久久久久免费精品国产| 久久成人精品| 久久夜色精品国产噜噜麻豆 | 久久久久久精品无码人妻| 久久国产精品久久久| 欧美成a人片免费看久久| 久久99久久99精品免视看动漫| 精品久久久久中文字幕一区| 亚洲AV日韩AV永久无码久久| 很黄很污的网站久久mimi色| 欧美噜噜久久久XXX| 亚洲国产精品狼友中文久久久| 久久精品国产亚洲AV电影| 日本精品一区二区久久久| 久久青草国产手机看片福利盒子| 久久人人爽人人爽人人爽| 国产伊人久久| 国产69精品久久久久99尤物| 亚洲国产精品久久电影欧美| 最新久久免费视频| 久久久久无码中| 久久精品三级视频| 国产成人香蕉久久久久| 久久精品成人免费网站| 日本久久久久亚洲中字幕 | 久久精品国产亚洲7777| 曰曰摸天天摸人人看久久久| 久久被窝电影亚洲爽爽爽| 久久久久久久人妻无码中文字幕爆| 久久婷婷国产剧情内射白浆| 尹人香蕉久久99天天拍| 亚洲国产精品综合久久网络| 久久性精品| 国产69精品久久久久久人妻精品| 国产成人精品久久| 国产精品天天影视久久综合网| AV无码久久久久不卡网站下载|