• <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 閱讀(5414) 評論(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與計算機圖形軟件開發(fā)人員提供一個在不同的軟件間精確轉(zhuǎn)換 3D 幾何的工具。OpenNURBS 所提供的功能包括:

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

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

            v 品質(zhì)保證與版本控制。

            v 技術(shù)支持。

            與其他開源產(chǎn)品的開發(fā)平臺不同之處:

            v 鼓勵使用在商業(yè)用途。

            v 提供免費的開發(fā)工具與技術(shù)支持。

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

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

            NURBS是當(dāng)前流行幾何造型系統(tǒng)中通用的曲線曲面表達形式,OpenNURBS開源庫提供了NURBS曲線曲面的數(shù)據(jù)表達,但缺少一些造型算法,而OpenCASCADE中提供了大量的造型算法。通過將OpenNURBS中的曲線曲面轉(zhuǎn)換到OpenCASCADE中,就可以將OpenNURBS和OpenCASCADE結(jié)合起來使用了。

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

            2.Convert OpenNURBS Curve 

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

             

            /**
            * @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());
            }

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

            wps_clip_image-11344

            Figure 2.1 OpenNURBS nurbs circle in OpenCASCADE Draw Test Harness

            3.Convert OpenNURBS Surface

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

             

            /**
            * @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());
            }

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

            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中的曲線曲面,不過有最高次數(shù)為25次的限制。

            4.Conclusion

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

            將OpenNURBS的曲線曲面轉(zhuǎn)換成OpenCASCADE的曲線曲面后,下一步準備將OpenNURBS中的BRep體也轉(zhuǎn)換到OpenCASCADE中,從而對BRep表示形式做進一步的學(xué)習(xí)。

            5. References

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

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

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

             

            PDF Version and Code: OpenNURBS to OpenCASCADE

            少妇人妻综合久久中文字幕| 伊人久久亚洲综合影院| 国产L精品国产亚洲区久久| 久久婷婷五月综合国产尤物app | 久久99热这里只有精品国产| 国产精品伊人久久伊人电影 | 久久99精品久久久久久水蜜桃| 久久精品一区二区三区中文字幕| 久久久久亚洲AV无码专区桃色| 久久亚洲高清综合| 久久久久一级精品亚洲国产成人综合AV区 | 久久亚洲精品国产精品| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久久久亚洲av无码专区喷水| 婷婷久久综合九色综合98| 欧美性猛交xxxx免费看久久久| 久久99久久99精品免视看动漫| 欧美亚洲国产精品久久高清| 亚洲精品乱码久久久久久蜜桃图片| 国产精品一区二区久久精品无码| 久久久久99精品成人片牛牛影视| 午夜精品久久久久久影视riav | 久久综合九色综合网站| 2021精品国产综合久久| 欧美粉嫩小泬久久久久久久| 久久久久亚洲AV无码专区首JN| 久久亚洲国产成人精品性色| 久久精品国产99国产精品澳门| 国产成人无码精品久久久性色 | 亚洲AⅤ优女AV综合久久久| 亚洲色大成网站WWW久久九九| 一本久久久久久久| 久久久久高潮综合影院| 亚洲欧美精品伊人久久| 噜噜噜色噜噜噜久久| 7777久久亚洲中文字幕| 久久综合视频网| 国产一区二区精品久久岳| 久久精品aⅴ无码中文字字幕重口| 9999国产精品欧美久久久久久 | 91精品久久久久久无码|