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源码的更多相关文章

  1. osg::Node源码

    /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...

  2. [源码解析] GroupReduce,GroupCombine 和 Flink SQL group by

    [源码解析] GroupReduce,GroupCombine和Flink SQL group by 目录 [源码解析] GroupReduce,GroupCombine和Flink SQL grou ...

  3. 多线程爬坑之路-Thread和Runable源码解析之基本方法的运用实例

    前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...

  4. 【原】AFNetworking源码阅读(四)

    [原]AFNetworking源码阅读(四) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇还遗留了很多问题,包括AFURLSessionManagerTaskDe ...

  5. 多线程爬坑之路-Thread和Runable源码解析

    多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...

  6. 搭建LNAMP环境(二)- 源码安装Nginx1.10

    上一篇:搭建LNAMP环境(一)- 源码安装MySQL5.6 1.yum安装编译nginx需要的包 yum -y install pcre pcre-devel zlib zlib-devel ope ...

  7. iOS开发之Alamofire源码解析前奏--NSURLSession全家桶

    今天博客的主题不是Alamofire, 而是iOS网络编程中经常使用的NSURLSession.如果你想看权威的NSURLSession的东西,那么就得去苹果官方的开发中心去看了,虽然是英文的,但是结 ...

  8. CRL2.3(ORM开发框架)源码github发布

    简介 CRL是一个面向对象的轻便型ORM业务框架 此框架追求的是使用简单,方便,因此设计为: 不需要代码生成器生成对象类,按标准方式写即可 依托lambda,实现语法解析转换为等效的SQL查询,完全以 ...

  9. ZFPlayer 源码解读

    源码下载地址:https://github.com/renzifeng/ZFPlayer 之前自己实现过一个模仿百思不得姐的demo https://github.com/agelessman/FFm ...

随机推荐

  1. 进程中join方法的使用

    在进程中:join方法 是让主进程等待子进程运行完毕后再执行主进程的.(即主进程阻塞) 示例 # -*- coding: utf-8 -*- from multiprocessing import P ...

  2. 树莓派安装系统+ssh登录

    一.准备工作: (1)树莓派3b (2)官网下载系统 (3)SD卡 (4)网线 (5)SDFormatter.exe (6)win32diskimager.exe (7)putty (7)笔记本 二. ...

  3. P2606 [ZJOI2010]排列计数

    P2606 [ZJOI2010]排列计数 因为每个结点至多有一个前驱,所以我们可以发现这是一个二叉树.现在我们要求的就是以1为根的二叉树中,有多少种情况,满足小根堆的性质. 设\(f(i)\)表示以\ ...

  4. ASP.NET Core ---- 系列文章

    (13)ASP.NET Core 中的选项模式(Options) (12)ASP.NET Core 中的配置二(Configuration) (11)ASP.NET Core 中的配置一(Config ...

  5. 数据库jdbc链接:mysql, oracle, postgresql

    #db mysql#jdbc.driver=com.mysql.jdbc.Driver#jdbc.url=jdbc:mysql://localhost:3306/mysql?&useUnico ...

  6. 独角兽估值30亿美金,我们聊聊RPA是什么

    https://www.jianshu.com/p/397ecd238ffc 缩短法定工作时间,已成国际劳动立法趋势,全球政府都曾面对这样的议题,过往企业IT也在思考这件事,开发出更好的软件系统帮助员 ...

  7. mssql 清理死锁

    -存储过程 我们可以使用以下存储过程来检测,就可以查出引起死锁的进程和SQL语句.SQL Server自带的系统存储过程sp_who和sp_lock也可以用来查找阻塞和死锁, 但没有这里介绍的方法好用 ...

  8. LeetCode 979. Distribute Coins in Binary Tree

    原题链接在这里:https://leetcode.com/problems/distribute-coins-in-binary-tree/ 题目: Given the root of a binar ...

  9. javascript 终极循环方法for... of ..推荐

    js目前有很多的循环方法,如for, forEach,  for .. in,  for of 等等,而在ES6里面,我们又增加了一些数据结构,比如set,map,Symbol等. 那么我们该选取哪一 ...

  10. Truffle - 以太坊Solidity编程语言开发框架

    http://truffle.tryblockchain.org/ Truffle框架 Truffle是什么? Truffle是针对基于以太坊的Solidity语言的一套开发框架. 本身基于JavaS ...