• <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 閱讀(5431) 評論(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

            久久国产精品久久| 亚洲熟妇无码另类久久久| 国产精品久久国产精麻豆99网站| 伊人久久久AV老熟妇色| 国产精品美女久久久久| 久久国产V一级毛多内射| 久久久久人妻一区二区三区| 亚洲中文久久精品无码| 精品乱码久久久久久夜夜嗨| 2021最新久久久视精品爱| 天天综合久久久网| 久久99久久99精品免视看动漫| 久久不射电影网| 99久久精品国产一区二区 | 91久久精品视频| 一本色道久久88精品综合| 久久性生大片免费观看性| 97久久综合精品久久久综合| 中文字幕无码av激情不卡久久| 久久线看观看精品香蕉国产| 亚洲va久久久噜噜噜久久 | 99热精品久久只有精品| 一本色综合网久久| 久久精品国产99国产精品| 精品国际久久久久999波多野| 性做久久久久久久久浪潮| 精品视频久久久久| 国产精品久久久久久久| 亚洲第一极品精品无码久久| 婷婷国产天堂久久综合五月| 亚洲日韩欧美一区久久久久我 | 中文无码久久精品| 久久久久久久波多野结衣高潮 | 亚洲国产另类久久久精品黑人 | 久久精品国产亚洲AV久| 一本久久综合亚洲鲁鲁五月天| 久久精品亚洲精品国产欧美| 91精品观看91久久久久久| 精品综合久久久久久88小说| 久久婷婷五月综合成人D啪| 中文字幕精品无码久久久久久3D日动漫 |