osg::Group源码
osg::Group源码
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/ #include <osg/Group>
#include <osg/BoundingBox>
#include <osg/Transform>
#include <osg/OccluderNode>
#include <osg/Geometry>
#include <osg/Notify> #include <stdio.h>
#include <math.h> #include <algorithm> using namespace osg; Group::Group()
{
} Group::Group(const Group& group,const CopyOp& copyop):
Node(group,copyop)
{
for(NodeList::const_iterator itr=group._children.begin();
itr!=group._children.end();
++itr)
{
Node* child = copyop(itr->get());
if (child) addChild(child);
}
} Group::~Group()
{
// remove reference to this from children's parent lists.
for(NodeList::iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->removeParent(this);
} } void Group::traverse(NodeVisitor& nv)
{
for(NodeList::iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->accept(nv);
}
} bool Group::addChild( Node *child )
{
return Group::insertChild( _children.size(), child );
} bool Group::insertChild( unsigned int index, Node *child )
{
if (!child) return false; #if ENSURE_CHILD_IS_UNIQUE
if (containsNode(child))
{
OSG_WARN<<"Adding non unique child to osg::Group, ignoring call"<<std::endl;
return false;
}
#endif // handle deprecated geometry configurations by calling fixDeprecatedData().
osg::Geometry* geometry = child->asGeometry();
if (geometry && geometry->containsDeprecatedData()) geometry->fixDeprecatedData(); // note ref_ptr<> automatically handles incrementing child's reference count.
if (index >= _children.size())
{
index = _children.size(); // set correct index value to be passed to the "childInserted" method
_children.push_back(child);
}
else
{
_children.insert(_children.begin()+index, child);
} // register as parent of child.
child->addParent(this); // tell any subclasses that a child has been inserted so that they can update themselves.
childInserted(index); dirtyBound(); // could now require app traversal thanks to the new subgraph,
// so need to check and update if required.
if (child->getNumChildrenRequiringUpdateTraversal()> ||
child->getUpdateCallback())
{
setNumChildrenRequiringUpdateTraversal(
getNumChildrenRequiringUpdateTraversal()+
);
} // could now require app traversal thanks to the new subgraph,
// so need to check and update if required.
if (child->getNumChildrenRequiringEventTraversal()> ||
child->getEventCallback())
{
setNumChildrenRequiringEventTraversal(
getNumChildrenRequiringEventTraversal()+
);
} // could now require disabling of culling thanks to the new subgraph,
// so need to check and update if required.
if (child->getNumChildrenWithCullingDisabled()> ||
!child->getCullingActive())
{
setNumChildrenWithCullingDisabled(
getNumChildrenWithCullingDisabled()+
);
} if (child->getNumChildrenWithOccluderNodes()> ||
dynamic_cast<osg::OccluderNode*>(child))
{
setNumChildrenWithOccluderNodes(
getNumChildrenWithOccluderNodes()+
);
} return true;
} unsigned int Group::getNumChildren() const
{
return static_cast<unsigned int>(_children.size());
} bool Group::removeChild( Node *child )
{
unsigned int pos = getChildIndex(child);
if (pos<_children.size()) return removeChildren(pos,);
else return false;
} bool Group::removeChildren(unsigned int pos,unsigned int numChildrenToRemove)
{
if (pos<_children.size() && numChildrenToRemove>)
{
unsigned int endOfRemoveRange = pos+numChildrenToRemove;
if (endOfRemoveRange>_children.size())
{
OSG_DEBUG<<"Warning: Group::removeChild(i,numChildrenToRemove) has been passed an excessive number"<<std::endl;
OSG_DEBUG<<" of chilren to remove, trimming just to end of child list."<<std::endl;
endOfRemoveRange=_children.size();
} unsigned int updateCallbackRemoved = ;
unsigned int eventCallbackRemoved = ;
unsigned int numChildrenWithCullingDisabledRemoved = ;
unsigned int numChildrenWithOccludersRemoved = ; for(unsigned i=pos;i<endOfRemoveRange;++i)
{
osg::Node* child = _children[i].get();
// remove this Geode from the child parent list.
child->removeParent(this); if (child->getNumChildrenRequiringUpdateTraversal()> || child->getUpdateCallback()) ++updateCallbackRemoved; if (child->getNumChildrenRequiringEventTraversal()> || child->getEventCallback()) ++eventCallbackRemoved; if (child->getNumChildrenWithCullingDisabled()> || !child->getCullingActive()) ++numChildrenWithCullingDisabledRemoved; if (child->getNumChildrenWithOccluderNodes()> || dynamic_cast<osg::OccluderNode*>(child)) ++numChildrenWithOccludersRemoved; } childRemoved(pos,endOfRemoveRange-pos); _children.erase(_children.begin()+pos,_children.begin()+endOfRemoveRange); if (updateCallbackRemoved)
{
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-updateCallbackRemoved);
} if (eventCallbackRemoved)
{
setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-eventCallbackRemoved);
} if (numChildrenWithCullingDisabledRemoved)
{
setNumChildrenWithCullingDisabled(getNumChildrenWithCullingDisabled()-numChildrenWithCullingDisabledRemoved);
} if (numChildrenWithOccludersRemoved)
{
setNumChildrenWithOccluderNodes(getNumChildrenWithOccluderNodes()-numChildrenWithOccludersRemoved);
} dirtyBound(); return true;
}
else return false;
} bool Group::replaceChild( Node *origNode, Node *newNode )
{
if (newNode==NULL || origNode==newNode) return false; unsigned int pos = getChildIndex(origNode);
if (pos<_children.size())
{
return setChild(pos,newNode);
}
return false;
} bool Group::setChild( unsigned int i, Node* newNode )
{
if (i<_children.size() && newNode)
{ ref_ptr<Node> origNode = _children[i]; // first remove for origNode's parent list.
origNode->removeParent(this); // note ref_ptr<> automatically handles decrementing origNode's reference count,
// and inccrementing newNode's reference count.
_children[i] = newNode; // register as parent of child.
newNode->addParent(this); dirtyBound(); // could now require update traversal thanks to the new subgraph,
// so need to check and update if required.
int delta_numChildrenRequiringUpdateTraversal = ;
if (origNode->getNumChildrenRequiringUpdateTraversal()> ||
origNode->getUpdateCallback())
{
--delta_numChildrenRequiringUpdateTraversal;
}
if (newNode->getNumChildrenRequiringUpdateTraversal()> ||
newNode->getUpdateCallback())
{
++delta_numChildrenRequiringUpdateTraversal;
} if (delta_numChildrenRequiringUpdateTraversal!=)
{
setNumChildrenRequiringUpdateTraversal(
getNumChildrenRequiringUpdateTraversal()+delta_numChildrenRequiringUpdateTraversal
);
} // could now require event traversal thanks to the new subgraph,
// so need to check and Event if required.
int delta_numChildrenRequiringEventTraversal = ;
if (origNode->getNumChildrenRequiringEventTraversal()> ||
origNode->getEventCallback())
{
--delta_numChildrenRequiringEventTraversal;
}
if (newNode->getNumChildrenRequiringEventTraversal()> ||
newNode->getEventCallback())
{
++delta_numChildrenRequiringEventTraversal;
} if (delta_numChildrenRequiringEventTraversal!=)
{
setNumChildrenRequiringEventTraversal(
getNumChildrenRequiringEventTraversal()+delta_numChildrenRequiringEventTraversal
);
} // could now require disabling of culling thanks to the new subgraph,
// so need to check and update if required.
int delta_numChildrenWithCullingDisabled = ;
if (origNode->getNumChildrenWithCullingDisabled()> ||
!origNode->getCullingActive())
{
--delta_numChildrenWithCullingDisabled;
}
if (newNode->getNumChildrenWithCullingDisabled()> ||
!newNode->getCullingActive())
{
++delta_numChildrenWithCullingDisabled;
} if (delta_numChildrenWithCullingDisabled!=)
{
setNumChildrenWithCullingDisabled(
getNumChildrenWithCullingDisabled()+delta_numChildrenWithCullingDisabled
);
} // could now require disabling of culling thanks to the new subgraph,
// so need to check and update if required.
int delta_numChildrenWithOccluderNodes = ;
if (origNode->getNumChildrenWithOccluderNodes()> ||
dynamic_cast<osg::OccluderNode*>(origNode.get()))
{
--delta_numChildrenWithOccluderNodes;
}
if (newNode->getNumChildrenWithOccluderNodes()> ||
dynamic_cast<osg::OccluderNode*>(newNode))
{
++delta_numChildrenWithOccluderNodes;
} if (delta_numChildrenWithOccluderNodes!=)
{
setNumChildrenWithOccluderNodes(
getNumChildrenWithOccluderNodes()+delta_numChildrenWithOccluderNodes
);
} return true;
}
else return false; } BoundingSphere Group::computeBound() const
{
BoundingSphere bsphere;
if (_children.empty())
{
return bsphere;
} // note, special handling of the case when a child is an Transform,
// such that only Transforms which are relative to their parents coordinates frame (i.e this group)
// are handled, Transform relative to and absolute reference frame are ignored. BoundingBox bb;
bb.init();
NodeList::const_iterator itr;
for(itr=_children.begin();
itr!=_children.end();
++itr)
{
osg::Node* child = itr->get();
const osg::Transform* transform = child->asTransform();
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
osg::Drawable* drawable = child->asDrawable();
if (drawable)
{
bb.expandBy(drawable->getBoundingBox());
}
else
{
const osg::BoundingSphere& bs = child->getBound();
bb.expandBy(bs);
}
}
} if (!bb.valid())
{
return bsphere;
} bsphere._center = bb.center();
bsphere._radius = 0.0f;
for(itr=_children.begin();
itr!=_children.end();
++itr)
{
osg::Node* child = itr->get();
const osg::Transform* transform = child->asTransform();
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
const BoundingSphere& bs = child->getBound();
bsphere.expandRadiusBy(bs);
}
} return bsphere;
} void Group::setThreadSafeRefUnref(bool threadSafe)
{
Node::setThreadSafeRefUnref(threadSafe); for(NodeList::const_iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->setThreadSafeRefUnref(threadSafe);
}
} void Group::resizeGLObjectBuffers(unsigned int maxSize)
{
Node::resizeGLObjectBuffers(maxSize); for(NodeList::const_iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->resizeGLObjectBuffers(maxSize);
}
} void Group::releaseGLObjects(osg::State* state) const
{
Node::releaseGLObjects(state); for(NodeList::const_iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->releaseGLObjects(state);
}
}
osg::Group源码的更多相关文章
- osg::Node源码
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...
- [源码解析] GroupReduce,GroupCombine 和 Flink SQL group by
[源码解析] GroupReduce,GroupCombine和Flink SQL group by 目录 [源码解析] GroupReduce,GroupCombine和Flink SQL grou ...
- 多线程爬坑之路-Thread和Runable源码解析之基本方法的运用实例
前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...
- 【原】AFNetworking源码阅读(四)
[原]AFNetworking源码阅读(四) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇还遗留了很多问题,包括AFURLSessionManagerTaskDe ...
- 多线程爬坑之路-Thread和Runable源码解析
多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...
- 搭建LNAMP环境(二)- 源码安装Nginx1.10
上一篇:搭建LNAMP环境(一)- 源码安装MySQL5.6 1.yum安装编译nginx需要的包 yum -y install pcre pcre-devel zlib zlib-devel ope ...
- iOS开发之Alamofire源码解析前奏--NSURLSession全家桶
今天博客的主题不是Alamofire, 而是iOS网络编程中经常使用的NSURLSession.如果你想看权威的NSURLSession的东西,那么就得去苹果官方的开发中心去看了,虽然是英文的,但是结 ...
- CRL2.3(ORM开发框架)源码github发布
简介 CRL是一个面向对象的轻便型ORM业务框架 此框架追求的是使用简单,方便,因此设计为: 不需要代码生成器生成对象类,按标准方式写即可 依托lambda,实现语法解析转换为等效的SQL查询,完全以 ...
- ZFPlayer 源码解读
源码下载地址:https://github.com/renzifeng/ZFPlayer 之前自己实现过一个模仿百思不得姐的demo https://github.com/agelessman/FFm ...
随机推荐
- 2019年牛客多校第一场 I题Points Division 线段树+DP
题目链接 传送门 题意 给你\(n\)个点,每个点的坐标为\((x_i,y_i)\),有两个权值\(a_i,b_i\). 现在要你将它分成\(\mathbb{A},\mathbb{B}\)两部分,使得 ...
- app开发-2
一.app登录注册实现 1.首先进行布局,mhead,mbody 在app index.html内创建一个 a链接通过mui.openWindow跳到登录页面 <a class="mu ...
- 微信小程序~页面注册page
一 什么是page() page(),是一个函数,用来注册一个页面, 接受一个object参数, 指定页面的初始数据,生命周期函数,事件处理函数 等等 object参数说明: (1)data (obj ...
- 为什么管理人员都喜欢用Visio画图
一.形状数据一体化 这是管理者最喜欢的功能了,这也Visio的最核心的功能: 操作如下: 例如流程中的步骤.开始日期或结束日期.成本.设备部件等.数字.图标.颜色.标志和进度条等图形有助于快速方便地浏 ...
- 读取txt写入excel
import csv #实现的思想:首先从txt中读取所有的内容,NUM=1当做键,其他当做值,如果查找缺少a,b,c,d,e,f,g# 则NUM不会添加到字典中,然后通过所有的NUM和字典中的KEY ...
- jquery ajax请求数据超时设置
var ajaxTimeoutTest = $.ajax({ url:'', //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : 'get', //请求方式,g ...
- web自动化测试-获得验证信息
一.概述 1.在编写功能测试用例时,会假定一个预期结果,在执行用例过程中把得到的实际结果与预期结果进行比较,从而判断用例的通过与失败 2.自动化测试用例是由机器去执行,通常机器并不像人一样有思维和判断 ...
- NOI2018游记【一年后的回忆】
今天是2019年9月6日,我坐在大学的宿舍里,同样敲着键盘,在一年前充满回忆与汗水的博客上,又一次地回忆往事. 那是2018年的7月,我停了三个月的课,攥着一张thusc的安慰约,放手在OI的生涯最后 ...
- L1141(bfs思想)
一,看 1,整个方格图其实可以看做是一些不连通的图. 当然图内部必然是联通的. 2,遍历的技巧没什么. 方格图入队的技巧..额,是这样的 int gtid(int x,int y) { return ...
- LeetCode 1087. Brace Expansion
原题链接在这里:https://leetcode.com/problems/brace-expansion/ 题目: A string S represents a list of words. Ea ...