Added support for shallow and deep copy of nodes, drawables and state, via a

copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying.  The old functionality of clone() which was clone of type has
been renamed to cloneType().

Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc.  A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.

Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.

Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData.  These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.

method
This commit is contained in:
Robert Osfield
2002-01-28 21:17:01 +00:00
parent 7f65110322
commit f612924a45
74 changed files with 898 additions and 263 deletions

View File

@@ -124,9 +124,7 @@ int main( int argc, char **argv )
// run optimization over the scene graph
osgUtil::Optimizer optimzer;
// turn off temporarily since the above single child decorator group gets
// removed as the optimizer assumes its redundent. Will fix next. Robert.
// optimzer.optimize(rootnode);
optimzer.optimize(rootnode);
// add a viewport to the viewer and attach the scene graph.
viewer.addViewport( rootnode );

View File

@@ -14,6 +14,12 @@ Billboard::Billboard()
setCachedMode();
}
Billboard::Billboard(const Billboard& billboard,const Cloner& cloner):
Geode(billboard,cloner),
_mode(billboard._mode),
_axis(billboard._axis),
_positionList(billboard._positionList),
_cachedMode(billboard._cachedMode) {}
Billboard::~Billboard()
{
@@ -91,7 +97,7 @@ const bool Billboard::removeDrawable( Drawable *gset )
return false;
}
void Billboard::calcTransform(const Vec3& eye_local, const Vec3& up_local, const Vec3& pos_local, Matrix& mat) const
void Billboard::calcTransform(const Vec3& eye_local, const Vec3& /*up_local*/, const Vec3& pos_local, Matrix& mat) const
{
Vec3 ev(pos_local-eye_local);
switch(_cachedMode)

View File

@@ -49,6 +49,97 @@ GeoSet::GeoSet()
}
GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner):
Drawable(geoset,cloner)
{
// ensure that the num of vertices etc have been set up before we copy.
geoset.computeNumVerts();
_adf = geoset._adf;
_numprims = geoset._numprims;
_primtype = geoset._primtype;
_needprimlen = geoset._needprimlen;
_oglprimtype = geoset._oglprimtype;
_primlength = geoset._primlength;
_flat_shaded_skip = geoset._flat_shaded_skip;
if (geoset._primLengths)
{
_primLengths = new int [_primlength];
memcpy(_primLengths,geoset._primLengths,_primlength);
}
else
{
_primLengths = 0L;
}
_numcoords = geoset._numcoords;
_cindex = geoset._cindex;
if (geoset._coords)
{
_coords = new Vec3 [_numcoords];
memcpy(_coords,geoset._coords,_numcoords);
}
else
{
_coords = 0L;
}
_normal_binding = geoset._normal_binding;
_numnormals = geoset._numnormals;
_nindex = geoset._nindex;
if (geoset._normals)
{
_normals = new Vec3 [_numnormals];
memcpy(_normals,geoset._normals,_numnormals);
}
else
{
_normals = 0L;
}
_color_binding = geoset._color_binding;
_numcolors = geoset._numcolors;
_colindex = geoset._colindex;
if (geoset._colors)
{
_colors = new Vec4 [_numcolors];
memcpy(_colors,geoset._colors,_numcolors);
}
else
{
_colors = 0L;
}
_texture_binding = geoset._texture_binding;
_numtcoords = geoset._numtcoords;
_tindex = geoset._tindex;
if (geoset._tcoords)
{
_tcoords = new Vec2 [_numtcoords];
memcpy(_tcoords,geoset._tcoords,_numtcoords);
}
else
{
_tcoords = 0L;
}
_iaindex = geoset._iaindex;
_iaformat = geoset._iaformat;
_ogliaformat = geoset._ogliaformat;
_fast_path = geoset._fast_path;
if (geoset._iarray)
{
_iarray = 0L;
osg::notify(osg::WARN)<<"Warning :: GeoSet copy constructor error, copying of interleaved arrays unsupported."<<endl;
}
else
{
_iarray = 0L;
}
}
#define INDEX_ARRAY_DELETE(A) if (A._is_ushort) ushortList.insert(A._ptr._ushort); else uintList.insert(A._ptr._uint);
void GeoSet::AttributeDeleteFunctor::operator() (GeoSet* gset)

View File

@@ -10,6 +10,17 @@ Geode::Geode()
{
}
Geode::Geode(const Geode& geode,const Cloner& cloner):
Node(geode,cloner)
{
for(DrawableList::const_iterator itr=geode._drawables.begin();
itr!=geode._drawables.end();
++itr)
{
Drawable* drawable = cloner(itr->get());
if (drawable) _drawables.push_back(drawable);
}
}
Geode::~Geode()
{

View File

@@ -13,6 +13,17 @@ Group::Group()
{
}
Group::Group(const Group& group,const Cloner& cloner):
Node(group,cloner)
{
for(ChildList::const_iterator itr=group._children.begin();
itr!=group._children.end();
++itr)
{
Node* child = cloner(itr->get());
if (child) _children.push_back(child);
}
}
Group::~Group()
{

View File

@@ -26,6 +26,30 @@ Image::Image()
_modifiedTag = 0;
}
Image::Image(const Image& image,const Cloner& cloner):
Object(image,cloner),
_fileName(image._fileName),
_s(image._s), _t(image._t), _r(image._r),
_internalFormat(image._internalFormat),
_pixelFormat(image._pixelFormat),
_dataType(image._dataType),
_packing(image._packing),
_data(0L),
_modifiedTag(image._modifiedTag)
{
if (image._data)
{
int num_components =
_pixelFormat == GL_LUMINANCE ? 1 :
_pixelFormat == GL_LUMINANCE_ALPHA ? 2 :
_pixelFormat == GL_RGB ? 3 :
_pixelFormat == GL_RGBA ? 4 : 4;
int size = _s*_t*_r*num_components;
_data = (unsigned char*) malloc(size);
memcpy(_data,image._data,size);
}
}
Image::~Image()
{

View File

@@ -29,12 +29,9 @@ ImpostorSprite::ImpostorSprite()
_texture = NULL;
_s = 0;
_t = 0;
_t = 0;
}
ImpostorSprite::~ImpostorSprite()
{
if (_ism)

View File

@@ -4,6 +4,15 @@
using namespace osg;
LOD::LOD(const LOD& lod,const Cloner& cloner):
Group(lod,cloner),
_rangeList(lod._rangeList),
_rangeList2(lod._rangeList2),
_center(lod._center)
{
}
void LOD::traverse(NodeVisitor& nv)
{
switch(nv.getTraversalMode())

View File

@@ -77,6 +77,7 @@ TARGET_INCLUDE_FILES = \
osg/ColorMatrix\
osg/CullFace\
osg/Depth\
osg/DeepCopy\
osg/DisplaySettings\
osg/Drawable\
osg/EarthSky\
@@ -113,6 +114,7 @@ TARGET_INCLUDE_FILES = \
osg/Plane\
osg/Quat\
osg/Referenced\
osg/ShallowCopy\
osg/State\
osg/StateAttribute\
osg/StateSet\

View File

@@ -26,7 +26,7 @@ using namespace osg;
Matrix::Matrix() : Object(), fully_realized(false) {}
Matrix::Matrix( const Matrix& other ) : Object()
Matrix::Matrix( const Matrix& other) : Object()
{
set( (const float *) other._mat );
}

View File

@@ -20,6 +20,22 @@ Node::Node()
}
Node::Node(const Node& node,const Cloner& cloner):
Object(node,cloner),
_bsphere(_bsphere),
_bsphere_computed(node._bsphere_computed),
_name(node._name),
_parents(), // leave empty as parentList is managed by Group.
_appCallback(node._appCallback),
_numChildrenRequiringAppTraversal(node._numChildrenRequiringAppTraversal),
_cullingActive(node._cullingActive),
_numChildrenWithCullingDisabled(node._numChildrenWithCullingDisabled),
_userData(cloner(node._userData.get())),
_nodeMask(node._nodeMask),
_descriptions(node._descriptions),
_dstate(cloner(node._dstate.get()))
{
}
Node::~Node()
{

View File

@@ -2,4 +2,5 @@
using namespace osg;
// no non inline functions yet for Object...
Object::Object(const Object&,const Cloner&):
Referenced() {}

View File

@@ -21,8 +21,11 @@ StateSet::StateSet()
setRendingBinToInherit();
}
StateSet::StateSet(const StateSet& rhs):Object()
StateSet::StateSet(const StateSet& rhs,const Cloner& cloner):Object(rhs,cloner)
{
// shallow copy right now, we should go through each attribute and
// use the cloner instead of attribute list copy.. on the TODO list. Robert. Jan 2002.
_modeList = rhs._modeList;
_attributeList = rhs._attributeList;

View File

@@ -13,6 +13,11 @@ Switch::Switch()
_value = ALL_CHILDREN_OFF;
}
Switch::Switch(const Switch& sw,const Cloner& cloner):
Group(sw,cloner),
_value(sw._value)
{
}
void Switch::traverse(NodeVisitor& nv)
{

View File

@@ -16,6 +16,16 @@ Transform::Transform()
_worldToLocalDirty = false;
}
Transform::Transform(const Transform& transform,const Cloner& cloner):
Group(transform,cloner),
_type(transform._type),
_mode(transform._mode),
_localToWorldDirty(transform._localToWorldDirty),
_localToWorld(transform._localToWorld),
_worldToLocalDirty(transform._worldToLocalDirty),
_worldToLocal(transform._localToWorld)
{
}
Transform::Transform(const Matrix& mat )
{

View File

@@ -328,7 +328,7 @@ osg::Object* Registry::readObjectOfType(const osg::Object& compObj,Input& fr)
fr+=2;
const DotOsgWrapper::Associates& assoc = wrapper->getAssociates();
osg::Object* obj = proto->clone();
osg::Object* obj = proto->cloneType();
while(!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
@@ -396,7 +396,7 @@ osg::Object* Registry::readObject(DotOsgWrapperMap& dowMap,Input& fr)
fr+=2;
const DotOsgWrapper::Associates& assoc = wrapper->getAssociates();
osg::Object* obj = proto->clone();
osg::Object* obj = proto->cloneType();
while(!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{

View File

@@ -96,8 +96,8 @@ open(const std::string& font)
{
clear();
std::string filename = findFontFile(font);
if (filename.empty()) return false;
std::string filename = findFontFile(font);
if (filename.empty()) return false;
_font=createFontObj();
if( _font!=NULL && _font->Open(filename.c_str()) )
@@ -110,9 +110,10 @@ open(const std::string& font)
return false;
}
bool Font::
open(const char* font)
{ return open(std::string(font)); }
bool Font::open(const char* font)
{
return open(std::string(font));
}
bool Font::
create(osg::State& state,int pointSize,const unsigned int res)
@@ -123,8 +124,7 @@ create(osg::State& state,int pointSize,const unsigned int res)
return create(state);
}
bool Font::
create(osg::State& state)
bool Font::create(osg::State& state)
{
if(_init)
{
@@ -143,8 +143,7 @@ create(osg::State& state)
return false;
}
void Font::
output(osg::State& state,const char* text)
void Font::output(osg::State& state,const char* text)
{
if(_created)
_font->render(text,state.getContextID());
@@ -152,8 +151,7 @@ output(osg::State& state,const char* text)
create(state,_pointSize);
}
void Font::
clear()
void Font::clear()
{
_init=false;

View File

@@ -8,6 +8,16 @@ Paragraph::Paragraph()
_maxCharsPerLine = 80;
}
Paragraph::Paragraph(const Paragraph& paragraph,const osg::Cloner& cloner):
Geode(paragraph,cloner),
_position(paragraph._position),
_text(paragraph._text),
_font(dynamic_cast<Font*>(cloner(paragraph._font.get()))),
_alignment(paragraph._alignment),
_maxCharsPerLine(paragraph._maxCharsPerLine)
{
}
Paragraph::Paragraph(const osg::Vec3& position,const std::string& text,osgText::Font* font)
{
_maxCharsPerLine = 80;

View File

@@ -30,14 +30,27 @@ using namespace osgText;
///////////////////////////////////////////////////////////////////////////////
// Text
Text::
Text()
Text::Text()
{
setDefaults();
}
Text::
Text(Font* font)
Text::Text(const Text& text,const osg::Cloner& cloner):
Drawable(text,cloner),
_font(dynamic_cast<Font*>(cloner(text._font.get()))),
_init(text._init),
_initAlignment(text._initAlignment),
_text(text._text),
_fontType(text._fontType),
_alignment(text._alignment),
_drawMode(text._drawMode),
_boundingBoxType(text._boundingBoxType),
_pos(text._pos),
_alignmentPos(text._alignmentPos)
{
}
Text::Text(Font* font)
{
setDefaults();
@@ -60,8 +73,8 @@ Text(Font* font)
}
}
Text::
~Text()
Text::~Text()
{
}

View File

@@ -553,7 +553,12 @@ void Optimizer::RemoveRedundentNodesVisitor::apply(osg::Group& group)
{
if (group.getNumParents()>0 && group.getNumChildren()<=1)
{
_redundentNodeList.insert(&group);
if (!group.getUserData() &&
!group.getAppCallback() &&
!group.getStateSet())
{
_redundentNodeList.insert(&group);
}
}
}
traverse(group);

View File

@@ -29,7 +29,7 @@ RenderBin* RenderBin::createRenderBin(const std::string& binName)
// cout << "creating RB "<<binName<<std::endl;
RenderBinPrototypeList::iterator itr = renderBinPrototypeList()->find(binName);
if (itr != renderBinPrototypeList()->end()) return dynamic_cast<RenderBin*>(itr->second->clone());
if (itr != renderBinPrototypeList()->end()) return dynamic_cast<RenderBin*>(itr->second->cloneType());
else return NULL;
}