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

            OpenNURBS to OpenCASCADE

            Posted on 2014-11-01 10:17 eryar 閱讀(5409) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenNURBS to OpenCASCADE

            eryar@163.com

            Abstract. The OpenNURBS initiative provides CAD/CAM/CAE and computer graphics software developers the tools to accurately transfer 3D geometry between applications. The OpenNURBS C++ source code is clean and fairly simple. The OpenNURBS Toolkit is intended for use by C++ and .NET programmers. The toolkit includes complete source code to create a library that will read and write 3dm files. OpenCASCADE providing services for 3D surface and solid modeling, CAD data exchange, and visulization. Most of OCCT functionality is available in the form of C++ libraries. If can convert OpenNURBS curve/surface to OpenCASCADE, then it will fill the gap of data exchange between OpenNURBS and OpenCASCADE.

            Key Words. OpenCASCADE, OpenNURBS, NURBS, 3DM, DataExchange

            1. Introduction

            OpenNURBS 旨在為CAD、CAM、CAE與計算機圖形軟件開發人員提供一個在不同的軟件間精確轉換 3D 幾何的工具。OpenNURBS 所提供的功能包括:

            v 可以讀、寫3DM文件格式的C ++原代碼庫,支持目前的 Microsoft、Apple與 Gnu for Windows、Windows X64、Mac與Linux編繹器...

            v 可以讀、寫3DM文件格式的.NET 源代碼庫。

            v 品質保證與版本控制。

            v 技術支持。

            與其他開源產品的開發平臺不同之處:

            v 鼓勵使用在商業用途。

            v 提供免費的開發工具與技術支持。

            v 無任何約束,不受版權與公共版權(copyleft )條款約束。

            v 鼓勵但不強迫用戶分享自己的研發成果。

            NURBS是當前流行幾何造型系統中通用的曲線曲面表達形式,OpenNURBS開源庫提供了NURBS曲線曲面的數據表達,但缺少一些造型算法,而OpenCASCADE中提供了大量的造型算法。通過將OpenNURBS中的曲線曲面轉換到OpenCASCADE中,就可以將OpenNURBS和OpenCASCADE結合起來使用了。

            OpenNURBS中的代碼簡潔,易懂;OpenCASCADE的造型功能強大。所以先將OpenNURBS中的曲線曲面轉換到OpenCASCADE中,為OpenCASCADE的3DM格式的數據交換打下基礎。

            2.Convert OpenNURBS Curve 

            OpenNURBS中統一使用NURBS方式來表達曲線和曲面。OpenCASCADE中對應NURBS曲線的類為Geom_BSplineCurve。因此,可以將OpenNURBS的曲線轉換到OpenCASCADE中。轉換時需要注意節點矢量Knot Vector的方式有很大的不同。OpenNURBS中的節點矢量是所有的節點值,包括了重節點,而且在節點矢量的首尾還少了兩個節點。OpenCASCADE中的節點矢量由不包含重復節點的節點矢量及其重數來構造。其它數據基本相同,將轉換曲線的示例代碼列出如下:

             

            /**
            * @breif Convert OpenNURBS NURBS curve to OpenCASCADE Geom_BSplineCurve.
            * @param [in] theCurve opennurbs nurbs curve;
            * @param [in] theBRepFile the curve is in brep file of opencascade;
            * @note pay attention to the knots of opennurbs nurbs curve/surface.
            */
            void ConvertCurve(const ON_NurbsCurve& theCurve, const std::string& theBRepFile)
            {
                TColgp_Array1OfPnt aPoles(
            1, theCurve.CVCount());
                TColStd_Array1OfReal aWeights(
            1, theCurve.CVCount());

                TColStd_Array1OfReal aKnotSequence(
            1, theCurve.KnotCount() + 2);

                
            bool IsRational = theCurve.IsRational();
                
            bool IsPeriodic = (theCurve.IsPeriodic()) ? truefalse;

                
            // Control point and its weight.
                for (int i = 0; i < theCurve.CVCount(); ++i)
                {
                    
            if (IsRational)
                    {
                        ON_4dPoint aPole;

                        theCurve.GetCV(i, aPole);

                        aPoles.SetValue(i 
            + 1, gp_Pnt(aPole.x / aPole.w, aPole.y / aPole.w, aPole.z / aPole.w));
                        aWeights.SetValue(i 
            + 1, aPole.w);
                    }
                    
            else
                    {
                        ON_3dPoint aPole;

                        theCurve.GetCV(i, aPole);

                        aPoles.SetValue(i 
            + 1, gp_Pnt(aPole.x, aPole.y, aPole.z));
                    }
                }

                
            // Knot vector and its multiplicity.
                for (int i = 0; i < theCurve.KnotCount(); ++i)
                {
                    aKnotSequence.SetValue(i 
            + 2, theCurve.Knot(i));
                }

                aKnotSequence.SetValue(aKnotSequence.Lower(), theCurve.Knot(
            0));
                aKnotSequence.SetValue(aKnotSequence.Upper(), theCurve.Knot(theCurve.KnotCount() 
            - 1));

                TColStd_Array1OfReal aKnots(
            1, BSplCLib::KnotsLength(aKnotSequence, IsPeriodic));
                TColStd_Array1OfInteger aMultiplicities(
            1, aKnots.Upper());

                BSplCLib::Knots(aKnotSequence, aKnots, aMultiplicities);

                Handle_Geom_BSplineCurve aBSplineCurve 
            = new Geom_BSplineCurve(
                    aPoles, aWeights, aKnots, aMultiplicities,
                    theCurve.Degree(), theCurve.IsPeriodic());

                GeomTools_CurveSet::PrintCurve(aBSplineCurve, std::cout);

                TopoDS_Edge anEdge 
            = BRepBuilderAPI_MakeEdge(aBSplineCurve);
                
                BRepTools::Write(anEdge, theBRepFile.c_str());
            }

            程序先轉換控制頂點,若是有理曲線,還要設置控制頂點的權值w。在轉換節點矢量時,使用了BSplCLib::Knots()函數將OpenNURBS的節點矢量轉換為OpenCASCADE的形式,并補齊了缺少的端部的兩個節點。最后為了在OpenCASCADE中顯示轉換結果,將曲線生成TopoDS_Edge并保存為BRep格式,方便在Draw Test Harness中查看結果如下圖所示:

            wps_clip_image-11344

            Figure 2.1 OpenNURBS nurbs circle in OpenCASCADE Draw Test Harness

            3.Convert OpenNURBS Surface

            OpenNURBS曲面的轉換同樣也需要注意u, v方向上的節點矢量的問題,和曲線的轉換類似。除此之外就是把相同的屬性分別賦值即可,列出代碼如下所示:

             

            /**
            * @breif Convert OpenNURBS NURBS surface to OpenCASCADE Geom_BSplineSurface.
            * @param [in] theSurface opennurbs nurbs surface;
            * @param [in] theBRepFile the surface is in the brep file of opencascade;
            * @note pay attention to the knots of opennurbs nurbs curve/surface.
            */
            void ConvertSurface(const ON_NurbsSurface& theSurface, const std::string& theBRepFile)
            {
                TColgp_Array2OfPnt aPoles(
            1, theSurface.CVCount(0), 1, theSurface.CVCount(1));
                TColStd_Array2OfReal aWeights(
            1, theSurface.CVCount(0), 1, theSurface.CVCount(1));

                TColStd_Array1OfReal aUKnotSequence(
            1, theSurface.KnotCount(0+ 2);
                TColStd_Array1OfReal aVKnotSequence(
            1, theSurface.KnotCount(1+ 2);

                
            bool IsRational = theSurface.IsRational();
                
            bool IsUPeriodic = (theSurface.IsPeriodic(0)) ? truefalse;
                
            bool IsVPeriodic = (theSurface.IsPeriodic(1)) ? truefalse;

                
            // control point and its weight.
                for (int i = 0; i < theSurface.CVCount(0); ++i)
                {
                    
            for (int j = 0; j < theSurface.CVCount(1); ++j)
                    {
                        
            if (IsRational)
                        {
                            ON_4dPoint aPole;

                            theSurface.GetCV(i, j, aPole);

                            aPoles.SetValue(i 
            + 1, j + 1, gp_Pnt(aPole.x / aPole.w, aPole.y / aPole.w, aPole.z / aPole.w));
                            aWeights.SetValue(i 
            + 1, j + 1, aPole.w);
                        }
                        
            else
                        {
                            ON_3dPoint aPole;

                            theSurface.GetCV(i, j, aPole);

                            aPoles.SetValue(i 
            + 1, j + 1, gp_Pnt(aPole.x, aPole.y, aPole.z));
                        }
                        
                    }
                }

                
            // Knot vector and its multiplicity.
                for (int i = 0; i < theSurface.KnotCount(0); ++i)
                {
                    aUKnotSequence.SetValue(i 
            + 2, theSurface.Knot(0, i));
                }

                aUKnotSequence.SetValue(aUKnotSequence.Lower(), theSurface.Knot(
            00));
                aUKnotSequence.SetValue(aUKnotSequence.Upper(), theSurface.Knot(
            0, theSurface.KnotCount(0- 1));

                TColStd_Array1OfReal aUKnots(
            1, BSplCLib::KnotsLength(aUKnotSequence, IsUPeriodic));
                TColStd_Array1OfInteger aUMults(
            1, aUKnots.Upper());

                BSplCLib::Knots(aUKnotSequence, aUKnots, aUMults);

                
            for (int j = 0; j < theSurface.KnotCount(1); ++j)
                {
                    aVKnotSequence.SetValue(j 
            + 2, theSurface.Knot(1, j));
                }

                aVKnotSequence.SetValue(aVKnotSequence.Lower(), theSurface.Knot(
            10));
                aVKnotSequence.SetValue(aVKnotSequence.Upper(), theSurface.Knot(
            1, theSurface.KnotCount(1- 1));

                TColStd_Array1OfReal aVKnots(
            1, BSplCLib::KnotsLength(aVKnotSequence, IsVPeriodic));
                TColStd_Array1OfInteger aVMults(
            1, aVKnots.Upper());

                BSplCLib::Knots(aVKnotSequence, aVKnots, aVMults);

                Handle_Geom_BSplineSurface aBSplineSurface 
            = new Geom_BSplineSurface(aPoles,
                    aWeights, aUKnots, aVKnots, aUMults, aVMults,
                    theSurface.Degree(
            0), theSurface.Degree(1),
                    IsUPeriodic, IsVPeriodic);

                GeomTools_SurfaceSet::PrintSurface(aBSplineSurface, std::cout);

              TopoDS_Face aFace 
            = BRepBuilderAPI_MakeFace(aBSplineSurface, Precision::Confusion());
              
                BRepTools::Write(aFace, theBRepFile.c_str());
            }

            轉換過程與曲線的類似,只是多了v方向上的處理。以上兩個函數分別實現曲線曲面的轉換,完整程序可以在本文后面的鏈接中下載。以圓柱面和球面為例,測試了一下轉換效果,在Draw Test Harness中顯示結果如下圖所示:

            wps_clip_image-7205

            Figure 3.1 OpenNURBS nurbs sphere in OpenCASCADE Draw Test Harness

            wps_clip_image-6073

            Figure 3.2 OpenNURBS nurbs cylinder in OpenCASCADE Draw Test Harness

            由上圖可知,OpenCASCADE中的Geom_BSplineCurve/Geom_BSplineSurface可以完美表示OpenNURBS中的曲線曲面,不過有最高次數為25次的限制。

            4.Conclusion

            現可看出,OpenNURBS中的曲線曲面可以轉換成OpenCASCADE中。不過在轉換時需要注意OpenNURBS的節點矢量數據與教科書中及OpenCASCADE中不同,需要做些處理。還有需要注意的事項就是OpenNURBS中數組是從0開始的,而在OpenCASCADE中可以指定為從1開始。

            將OpenNURBS的曲線曲面轉換成OpenCASCADE的曲線曲面后,下一步準備將OpenNURBS中的BRep體也轉換到OpenCASCADE中,從而對BRep表示形式做進一步的學習。

            5. References

            1. OpenNURBS Web: http://www.rhino3d.com/opennurbs

            2. Les Piegl, Wayne Tiller. The NURBS Book. Springer-Verlag. 1997

            3. 趙罡,穆國旺,王拉柱譯. 非均勻有理B樣條. 清華大學出版社. 2010

             

            PDF Version and Code: OpenNURBS to OpenCASCADE

            a高清免费毛片久久| 尹人香蕉久久99天天拍| 精品午夜久久福利大片| 久久91精品久久91综合| 久久精品成人国产午夜| 青青热久久国产久精品| 婷婷久久久亚洲欧洲日产国码AV | 久久久久久亚洲精品不卡| 少妇久久久久久被弄到高潮| 伊人久久无码中文字幕| 亚洲成色999久久网站| 久久九九久精品国产免费直播| 99久久成人国产精品免费| 热RE99久久精品国产66热| 久久水蜜桃亚洲av无码精品麻豆| 激情五月综合综合久久69| 久久综合给合久久国产免费 | 狠狠色丁香婷综合久久| 一级A毛片免费观看久久精品| 久久久久无码精品国产| 色播久久人人爽人人爽人人片AV| 久久综合中文字幕| 久久精品人人做人人爽电影蜜月| 久久久精品国产亚洲成人满18免费网站 | 香蕉久久夜色精品国产尤物| 久久免费视频观看| 久久久一本精品99久久精品66| 久久人人爽人人爽AV片| 欧美亚洲国产精品久久蜜芽 | 日本高清无卡码一区二区久久| 国内精品人妻无码久久久影院| 亚洲人成无码网站久久99热国产| 久久综合九色综合精品| 久久精品人人做人人爽97| 亚洲国产另类久久久精品小说 | 性做久久久久久免费观看| 国产精品成人精品久久久| 久久99精品国产麻豆宅宅| 久久久久久无码Av成人影院| 97精品伊人久久久大香线蕉| 亚洲国产香蕉人人爽成AV片久久 |