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

            在OpenSceneGraph中繪制OpenCascade的曲線

            Posted on 2013-08-09 23:29 eryar 閱讀(9074) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            在OpenSceneGraph中繪制OpenCascade的曲線

            Draw OpenCascade Geometry Curves in OpenSceneGraph

            eryar@163.com

            摘要Abstract:本文簡要說明OpenCascade中幾何曲線的數據,并將這些幾何曲線在OpenSceneGraph中繪制出來。

            關鍵字KeyWords:OpenCascade、Geometry Curve、OpenSceneGraph、B-Spline、NURBS

            一、引言 Introduction

            結合《BRep Format Description White Paper》對OpenCascade中的幾何數據結構有詳細的介紹。OpenCascade中BRep格式中的曲線總共分為九種,不過有二維三維之分:

            1.直線 Line

            2.圓 Circle

            3.橢圓 Ellipse

            4.拋物線 Parabola

            5.雙曲線 Hyperbola

            6.Bezier曲線 Bezier Curve

            7.B-Spline曲線 B-Spline Curve

            8.裁剪曲線 Trimmed Curve

            9.偏移曲線 Offset Curve

            曲線的幾何數據都有一個抽象基類Geom_Curve,類圖如下所示:

            wps_clip_image-32738

            Figure 1.1 Geometry curve class diagram

            抽象基類Geom_Curve有幾個純虛函數FirstParameter()、LastParameter()、Value(),根據這幾個虛函數,就可以計算曲線上對應參數U的值。類圖如下圖所示:

            wps_clip_image-32037

            Figure 1.2 Geom_Curve Inherited class diagram

            每種曲線都對那些純虛函數進行實現,使計算曲線上點的方式統一。

            二、程序示例 Code Example

            根據抽象基類Geom_Curve的幾個純虛函數:

            1.FirstParameter();

            2.LastParameter();

            3.Value(u);

            利用多態可將曲線上點都以統一的方式計算出來,并使用GL_LINE_STRIP繪制出來。示例程序如下所示:

              1 /*
              2 *    Copyright (c) 2013 eryar All Rights Reserved.
              3 *
              4 *        File    : Main.cpp
              5 *        Author  : eryar@163.com
              6 *        Date    : 2013-08-09 18:09
              7 *        Version : 1.0v
              8 *
              9 *    Description : Draw OpenCascade Geometry Curves in OpenSceneGraph.
             10 *                  
             11 */
             12 
             13 // OpenSceneGraph library.
             14 #include <osgDB/ReadFile>
             15 #include <osgViewer/Viewer>
             16 #include <osgViewer/ViewerEventHandlers>
             17 #include <osgGA/StateSetManipulator>
             18 
             19 #pragma comment(lib, "osgd.lib")
             20 #pragma comment(lib, "osgDbd.lib")
             21 #pragma comment(lib, "osgGAd.lib")
             22 #pragma comment(lib, "osgViewerd.lib")
             23 
             24 // OpenCascade library.
             25 #include <TColgp_Array1OfPnt.hxx>
             26 #include <TColStd_Array1OfReal.hxx>
             27 #include <TColStd_Array1OfInteger.hxx>
             28 
             29 #include <Geom_Circle.hxx>
             30 #include <Geom_Ellipse.hxx>
             31 #include <Geom_Hyperbola.hxx>
             32 #include <Geom_Parabola.hxx>
             33 #include <Geom_BezierCurve.hxx>
             34 #include <Geom_BSplineCurve.hxx>
             35 
             36 #pragma comment(lib, "TKernel.lib")
             37 #pragma comment(lib, "TKMath.lib")
             38 #pragma comment(lib, "TKG3d.lib")
             39 
             40 // Curve Segment Delta.
             41 const double CURVE_SEGMENT_DELTA = 0.01;
             42 
             43 /*
             44 * @brief Build geometry curve of OpenCascade.
             45 */
             46 osg::Node* buildCurve(const Geom_Curve& curve)
             47 {
             48     osg::ref_ptr<osg::Geode> geode = new osg::Geode();
             49     osg::ref_ptr<osg::Geometry> linesGeom = new osg::Geometry();
             50     osg::ref_ptr<osg::Vec3Array> pointsVec = new osg::Vec3Array();
             51 
             52     gp_Pnt point;
             53     double dFirst = curve.FirstParameter();
             54     double dLast = curve.LastParameter();
             55 
             56     Precision::IsNegativeInfinite(dFirst) ? dFirst = -1.0 : dFirst;
             57     Precision::IsInfinite(dLast) ? dLast = 1.0 : dLast;
             58     
             59     for (double u = dFirst; u <= dLast; u += CURVE_SEGMENT_DELTA)
             60     {
             61         point = curve.Value(u);
             62 
             63         pointsVec->push_back(osg::Vec3(point.X(), point.Y(), point.Z()));
             64     }
             65 
             66     // Set the colors.
             67     osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
             68     colors->push_back(osg::Vec4(1.0f1.0f0.0f0.0f));
             69     linesGeom->setColorArray(colors.get());
             70     linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
             71 
             72     // Set the normal in the same way of color.
             73     osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
             74     normals->push_back(osg::Vec3(0.0f-1.0f0.0f));
             75     linesGeom->setNormalArray(normals.get());
             76     linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
             77 
             78     // Set vertex array.
             79     linesGeom->setVertexArray(pointsVec);
             80     linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, pointsVec->size()));
             81     
             82     geode->addDrawable(linesGeom.get());
             83 
             84     return geode.release();
             85 }
             86 
             87 /**
             88 * @breif Build geometry curve of OpenCascade.
             89 */
             90 osg::Node* buildScene()
             91 {
             92     osg::ref_ptr<osg::Group> root = new osg::Group();
             93 
             94     // 1. Build circle curve.
             95     Geom_Circle circle(gp::YOZ(), 1.0);
             96 
             97     root->addChild(buildCurve(circle));
             98 
             99     // 2. Build ellipse curve.
            100     Geom_Ellipse ellipse(gp::ZOX(), 1.00.3);
            101 
            102     root->addChild(buildCurve(ellipse));
            103 
            104     // 3. Build Hyperbola curve.
            105     Geom_Hyperbola hyperbola(gp::XOY(), 1.00.6);
            106 
            107     root->addChild(buildCurve(hyperbola));
            108 
            109     // 4. Build parabola curve.
            110     Geom_Parabola parabola(gp::ZOX(), 1.0);
            111 
            112     root->addChild(buildCurve(parabola));
            113 
            114     // 5. Build Bezier curve.
            115     TColgp_Array1OfPnt poles(14);
            116     poles.SetValue(1, gp_Pnt(-1-10));
            117     poles.SetValue(2, gp_Pnt(120));
            118     poles.SetValue(3, gp_Pnt(300));
            119     poles.SetValue(4, gp_Pnt(410));
            120     Geom_BezierCurve bezierCurve(poles);
            121 
            122     root->addChild(buildCurve(bezierCurve));
            123 
            124     // 6. Build BSpline curve.
            125     TColgp_Array1OfPnt ctrlPnts(13);
            126     TColStd_Array1OfReal knots(15);
            127     TColStd_Array1OfInteger mults(15);
            128     
            129     ctrlPnts.SetValue(1, gp_Pnt(010));
            130     ctrlPnts.SetValue(2, gp_Pnt(1-20));
            131     ctrlPnts.SetValue(3, gp_Pnt(230));
            132 
            133     knots.SetValue(10.0);
            134     knots.SetValue(20.25);
            135     knots.SetValue(30.5);
            136     knots.SetValue(40.75);
            137     knots.SetValue(51.0);
            138 
            139     mults.Init(1);
            140 
            141     Geom_BSplineCurve bsplineCurve(ctrlPnts, knots, mults, 1);
            142 
            143     root->addChild(buildCurve(bsplineCurve));
            144 
            145     return root.release();
            146 }
            147 
            148 int main(int argc, char* argv[])
            149 {
            150     osgViewer::Viewer myViewer;
            151 
            152     myViewer.setSceneData(buildScene());
            153 
            154     myViewer.addEventHandler(new osgGA::StateSetManipulator(myViewer.getCamera()->getOrCreateStateSet()));
            155     myViewer.addEventHandler(new osgViewer::StatsHandler);
            156     myViewer.addEventHandler(new osgViewer::WindowSizeHandler);
            157 
            158     return myViewer.run();
            159 }

            因拋物線和雙曲線的FirstParameter()和LastParameter()為負無窮和正無窮,所以對其進行處理,只輸出了部分曲線。

            程序效果如下圖所示:

            wps_clip_image-7357

            Figure 2.1 OpenCascade Geometry Curves in OpenSceneGraph

            三、結論 Conclusion

            OpenCascade的幾何數據使用還是很方便的,只要將相應的曲線構造出來之后,計算曲線上的點使用函數Value()即可,還可計算相應參數處的微分值等。

            通過理解《BRep Format Description White Paper》,可將BRep文件中數據導入OpenCascade中與上面實現的程序進行對比,結果正確。如下圖所示:

            wps_clip_image-13312

            Figure 3.1 B-Spline in OpenSceneGraph

            wps_clip_image-6019

            Figure 3.2 B-Spline in OpenCascade Draw

             

            久久国产成人| 国产精品九九久久免费视频| 亚洲精品无码久久久久AV麻豆| 色偷偷88欧美精品久久久 | 99久久精品免费观看国产| 国产L精品国产亚洲区久久| 久久精品亚洲欧美日韩久久| 久久天天躁狠狠躁夜夜躁2014| 久久久久亚洲AV片无码下载蜜桃 | 欧美精品国产综合久久| 麻豆AV一区二区三区久久| 99久久精品久久久久久清纯| 国产亚洲精品久久久久秋霞| 老司机国内精品久久久久| 国产成人精品综合久久久| 亚洲国产精品热久久| 亚洲va久久久噜噜噜久久天堂| 久久九九免费高清视频| 久久国产免费观看精品3| 欧美性猛交xxxx免费看久久久| 日本欧美久久久久免费播放网| 久久婷婷五月综合色99啪ak| 久久国产精品-国产精品| 久久棈精品久久久久久噜噜| 一级做a爰片久久毛片毛片| 日韩欧美亚洲综合久久影院d3| 久久香蕉国产线看观看精品yw | 97精品伊人久久久大香线蕉| 久久播电影网| 久久精品国产99久久久香蕉| 国产精品美女久久久久网| 国产午夜福利精品久久2021| 国产毛片欧美毛片久久久 | 久久人人爽人人爽人人片AV高清| 丰满少妇人妻久久久久久4| 99久久精品国内| 久久狠狠高潮亚洲精品| 国产精品久久成人影院| 久久亚洲高清观看| 久久久久亚洲AV无码专区网站| 青青青青久久精品国产h久久精品五福影院1421 |