2012-12-28 20:21:05 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class to represent a group node. This node can contains several children.
|
|
|
|
|
* \brief It also contains a transform matrix indicating the transform state of the underlying children.
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
#include "NodeGroup.h"
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
void NodeGroup::AddChild(Node *iChild)
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (NULL == iChild)
|
|
|
|
|
return;
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_Children.push_back(iChild);
|
|
|
|
|
iChild->addRef();
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NodeGroup::destroy()
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
/*! Node::destroy makes a release on the object and then returns the reference counter.
|
|
|
|
|
* If the reference counter is equal to 0, that means that nobody else is linking this node group and
|
|
|
|
|
* that we can destroy the whole underlying tree.
|
|
|
|
|
* Else, one or several Node link this node group, and we only returns the reference counter
|
|
|
|
|
* decremented by Node::destroy();
|
|
|
|
|
*/
|
|
|
|
|
int refThis = Node::destroy();
|
|
|
|
|
|
|
|
|
|
// if refThis != 0, we can't destroy the tree
|
|
|
|
|
if (0 != refThis)
|
|
|
|
|
return refThis;
|
|
|
|
|
|
|
|
|
|
// If we are here, that means that nobody else needs our NodeGroup and we can destroy it.
|
|
|
|
|
int refCount = 0;
|
|
|
|
|
vector<Node *>::iterator node;
|
|
|
|
|
|
|
|
|
|
for (node = _Children.begin(); node != _Children.end(); ++node) {
|
|
|
|
|
refCount = (*node)->destroy();
|
|
|
|
|
if (0 == refCount)
|
|
|
|
|
delete (*node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_Children.clear();
|
|
|
|
|
|
|
|
|
|
return refThis;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void NodeGroup::accept(SceneVisitor& v)
|
|
|
|
|
{
|
|
|
|
|
v.visitNodeGroup(*this);
|
|
|
|
|
|
|
|
|
|
v.visitNodeGroupBefore(*this);
|
|
|
|
|
for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node)
|
|
|
|
|
(*node)->accept(v);
|
|
|
|
|
v.visitNodeGroupAfter(*this);
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NodeGroup::DetachChildren()
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
vector<Node *>::iterator node;
|
|
|
|
|
|
|
|
|
|
for (node = _Children.begin(); node != _Children.end(); ++node) {
|
|
|
|
|
(*node)->release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_Children.clear();
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NodeGroup::DetachChild(Node *iChild)
|
|
|
|
|
{
|
2013-01-18 02:13:36 +00:00
|
|
|
/* int found = 0; */ /* UNUSED */
|
2012-12-28 20:21:05 +00:00
|
|
|
vector<Node*>::iterator node;
|
|
|
|
|
|
|
|
|
|
for (node = _Children.begin(); node != _Children.end(); ++node) {
|
|
|
|
|
if ((*node) == iChild) {
|
|
|
|
|
(*node)->release();
|
|
|
|
|
_Children.erase(node);
|
2013-01-18 02:13:36 +00:00
|
|
|
/* found = 1; */ /* UNUSED */
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void NodeGroup::RetrieveChildren(vector<Node*>& oNodes)
|
|
|
|
|
{
|
|
|
|
|
oNodes = _Children;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BBox<Vec3r>& NodeGroup::UpdateBBox()
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
vector<Node *>::iterator node;
|
|
|
|
|
clearBBox();
|
|
|
|
|
for (node = _Children.begin(); node != _Children.end(); ++node) {
|
|
|
|
|
AddBBox((*node)->UpdateBBox());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Node::UpdateBBox();
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|