• <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 場景節(jié)點

            Posted on 2012-04-30 18:45 eryar 閱讀(2600) 評論(1)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenSceneGraph 場景節(jié)點

            一、OSG場景節(jié)點簡介及組合模式介紹

            OSG中的場景是樹形結構表示的層次結構,如下圖所示:

            Scene node

            Figure 1.1 OpenSceneGraph場景樹形層次結構

            根據其源碼中的注釋得知,OSG中場景節(jié)點的管理采用了組合(Composite)模式。先簡要介紹一下組合模式,其類圖為:

            Composite

            Figure 1.2 Composite Pattern's Structure

            使用組合模式的目的是為了將對象合成樹形結構以表示“部分—整體”的層次結構。Composite使得用戶對單個對象和組合的使用具有一致性。組合模式通常用于以下情況:

            l 你想表示對象的部分—整體層次結構;

            l 你希望用戶忽略組合對象與單個對象的不同,用戶將統(tǒng)一地使用組合結構中的所有對象;

            為了達到葉子節(jié)點與組合節(jié)點的一致性,也可以給葉子節(jié)點定義與組合節(jié)點一樣的操作,但是這些操作什么也不做,與引入Null Object模式類似,這里引入Null Operation

            組合模式中主要的參與者有三個:

            l Component

            n Declares the interface for objects in the composition

            n Implements default behavior for the interface common to all classes, as appropriate;

            n Declares and interface for accessing and managing its child components;

            n (optional)Defines an interface for accessing a component's parent in the recursive structure and implements it if that's appropriate;

            l Leaf

            n Represents leaf objects in the composition. A leaf has no children;

            n Defines behavior for primitive objects in the composition;

            l Composite

            n Defines behavior for components having children;

            n Stores child components;

            l Client

            n Manipulates objects in the composition through the Component interface.

            二、OSG中組合Composite模式的應用

            根據OSG的文檔得到其場景節(jié)點的類圖,如下圖所示:

            class

            Figure 1.3 Inheritance Diagram for osg::Node

            結合紅星標示出的三個類:osg::Nodeosg::Geodeosg::Group來講述組合模式的具體應用。以下為聲明類osg::Node時給出的注釋:

            /** Base class for all internal nodes in the scene graph.

            Provides interface for most common node operations (Composite Pattern).

            */

            osg::Node類為所有場景圖形的基類,為大多數能用節(jié)點操作提供接口,采用提組合模式。

            以下為聲明類osg::Geode時給出的注釋:

            /** A \c Geode is a "geometry node", that is, a leaf node on the scene graph

            * that can have "renderable things" attached to it. In OSG, renderable things

            * are represented by objects from the \c Drawable class, so a \c Geode is a

            * \c Node whose purpose is grouping <tt>Drawable</tt>s.

            */

            osg::Geode類是一個幾何節(jié)點,即場景節(jié)點中的一個葉子節(jié)點,可以把可渲染的東西綁定在它上面。在OSG中,可渲染的東西表示為由類Drawable生成的對象。所以,一個Geode目的就是使Drawable成組。具體實現的程序代碼為:

            typedef std::vector< ref_ptr<Drawable> > DrawableList;

            保護成員變量:

            DrawableList _drawables;

            以下為聲明類osg::Group時給出的注釋:

            /** General group node which maintains a list of children.

            * Children are reference counted. This allows children to be shared

            * with memory management handled automatically via osg::Referenced.

            */

            osg::Group節(jié)點維護一個孩子表,孩子是引用計數的。這樣就可以由內存管理機制來管理這些孩子。具體實現的程序代碼為:

            typedef std::vector< ref_ptr<Node> > NodeList;

            保護成員變量:

            NodeList _children;

            綜上所述,得出它們的類圖:

            Figure 1.4 OSG Node Class Diagram

            由類圖可知,這個類圖與圖1.2所示的組合模式的類圖相似。其中,類osg::Node可以看成是Component類,為所有的場景節(jié)點的通用操作聲明接口;osg::Geode類可看作Leaf類,是一個具體的可渲染的場景節(jié)點;osg::Group類可看作Composite類,它可以包含葉節(jié)點或其它節(jié)點。

            三、程序示例

            編程實現由多個模型來構成一個場景,為了簡便起見,模型由文件得到。場景的樹形層次結構如下圖所示:

            node

            Figure 1.5 Add More Models to Scene Graph

            程序代碼如下:

            //--------------------------------------------------------------------------

            // Copyright (c) 2012 eryar All Rights Reserved.

            //

            // File : Main.cpp

            // Author : eryar@163.com

            // Date : 2012-1-3 20:58

            // Version : 1.0v

            //

            // Description : Add more models to the Secne.

            //

            //==========================================================================

            #include <osg/Node>

            #include <osgDB/ReadFile>

            #include <osgViewer/Viewer>

            #include <osgViewer/ViewerEventHandlers>

            int main(int argc, char* argv[])

            {

            osgViewer::Viewer viewer;

            osg::ref_ptr<osg::Group> root = new osg::Group;

            osg::ref_ptr<osg::Group> group = new osg::Group;

            root->addChild(osgDB::readNodeFile("glider.osg"));

            group->addChild(osgDB::readNodeFile("osgcool.osgt"));

            group->addChild(osgDB::readNodeFile("axes.osgt"));

            root->addChild(group);

            viewer.setSceneData(root);

            viewer.realize();

            viewer.addEventHandler(new osgViewer::WindowSizeHandler);

            viewer.addEventHandler(new osgViewer::StatsHandler);

            return viewer.run();

            }

            程序效果圖如下圖所示:

            Figure 1.6 Render OSG Node

             

            PDF Version

            久久强奷乱码老熟女| 亚洲国产精品狼友中文久久久| 综合久久一区二区三区 | 亚洲午夜精品久久久久久浪潮| 国内精品久久久久影院薰衣草 | 一本一道久久精品综合| 精品久久久久久久久久久久久久久| 伊人热热久久原色播放www| 色综合久久综合中文综合网| 久久久青草久久久青草| 久久精品国产色蜜蜜麻豆| 国产成人久久久精品二区三区| 77777亚洲午夜久久多喷| 国产精品九九九久久九九| 2021最新久久久视精品爱| 激情综合色综合久久综合| 少妇久久久久久被弄高潮| 亚洲国产高清精品线久久 | 国产精品99久久免费观看| 国产99久久久国产精品小说| 国产亚洲精久久久久久无码| 国产精品久久久久a影院| 久久亚洲国产精品123区| 欧美日韩中文字幕久久伊人| 伊人精品久久久久7777| 久久久久国产一级毛片高清板| 91亚洲国产成人久久精品网址| 久久夜色精品国产噜噜噜亚洲AV | 狠狠色丁香婷婷综合久久来| 久久99国产亚洲高清观看首页| 久久精品国产99国产精品亚洲 | 久久AⅤ人妻少妇嫩草影院| 国产精品久久午夜夜伦鲁鲁| 久久成人国产精品免费软件| 久久久久久久免费视频| 亚洲乱码日产精品a级毛片久久| 国产精品成人99久久久久 | 国产精品va久久久久久久| 91精品国产91久久久久久青草| 久久精品这里热有精品| 九九久久精品国产|