Added osg::Geometry::setPrimtiveSet,removePrimtiiveSet, insertPrimitiveSet

and getPrimitiveSetIndex().

Renamed osg::Group::findChildNum(..) to getChildIndex().

Renamed osg::Geode::findDrawableNum(..) to getDrawableIndex().
This commit is contained in:
Robert Osfield 2002-11-21 09:07:11 +00:00
parent f2fc281b00
commit 5ddcd5d878
8 changed files with 109 additions and 14 deletions

View File

@ -34,13 +34,13 @@ class SG_EXPORT Geode : public Node
virtual bool addDrawable( Drawable *drawable );
/** Remove Drawable from Geode.
* Equivalent to setDrawabke(findDrawableNum(orignChild),node),
* Equivalent to setDrawabke(getDrawableIndex(orignChild),node),
* see docs for setNode for futher details on implementation.*/
virtual bool removeDrawable( Drawable *drawable );
/** Replace specified Drawable with another Drawable.
* Equivalent to setDrawable(findDrawableNum(orignChild),node),
* Equivalent to setDrawable(getDrawableIndex(orignChild),node),
* see docs for setDrawable for futher details on implementation.*/
virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
@ -107,10 +107,10 @@ class SG_EXPORT Geode : public Node
return _drawables.end();
}
/** Find the index number of drawable, return a value between
/** Get the index number of drawable, return a value between
* 0 and _drawables.size()-1 if found, if not found then
* return _drawables.size().*/
inline unsigned int findDrawableNum( const Drawable* node ) const
inline unsigned int getDrawableIndex( const Drawable* node ) const
{
for (unsigned int drawableNum=0;drawableNum<_drawables.size();++drawableNum)
{

View File

@ -128,7 +128,22 @@ class SG_EXPORT Geometry : public Drawable
PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); }
const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); }
void addPrimitiveSet(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); dirtyBound(); }
/** Add a primtive set to the geometry.*/
bool addPrimitiveSet(PrimitiveSet* primitiveset);
/** Set a primtive set to the specified position in geometry's primtive set list.*/
bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
/** Insert a primtive set to the specified position in geometry's primtive set list.*/
bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
/** Remove primtive set(s) from the specified position in geometry's primtive set list.*/
bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1);
/** Get the index number of a primitive set, return a value between
* 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet().
* When checking for a valid find value use if ((value=geoemtry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet()) as*/
unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
/** return true if OpenGL fast paths will be used with drawing this Geometry.

View File

@ -50,7 +50,7 @@ class SG_EXPORT Group : public Node
virtual bool removeChild( Node *child );
/** Replace specified Node with another Node.
* Equivalent to setChild(findChildNum(orignChild),node),
* Equivalent to setChild(getChildIndex(orignChild),node),
* see docs for setChild for futher details on implementation.*/
virtual bool replaceChild( Node *origChild, Node* newChild );
@ -116,10 +116,10 @@ class SG_EXPORT Group : public Node
return _children.end();
}
/** Find the index number of child, return a value between
/** Get the index number of child, return a value between
* 0 and _children.size()-1 if found, if not found then
* return _children.size().*/
inline unsigned int findChildNum( const Node* node ) const
inline unsigned int getChildIndex( const Node* node ) const
{
for (unsigned int childNum=0;childNum<_children.size();++childNum)
{

View File

@ -84,7 +84,7 @@ bool Geode::replaceDrawable( Drawable *origDrawable, Drawable *newDrawable )
{
if (newDrawable==NULL || origDrawable==newDrawable) return false;
unsigned int pos = findDrawableNum(origDrawable);
unsigned int pos = getDrawableIndex(origDrawable);
if (pos<_drawables.size())
{
return setDrawable(pos,newDrawable);

View File

@ -269,6 +269,86 @@ const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const
else return 0;
}
bool Geometry::addPrimitiveSet(PrimitiveSet* primitiveset)
{
if (primitiveset)
{
_primitives.push_back(primitiveset);
dirtyDisplayList();
dirtyBound();
return true;
}
notify(WARN)<<"Warning: invalid index i or primitiveset passed to osg::Geometry::addPrimitiveSet(i,primitiveset), ignoring call."<<std::endl;
return false;
}
bool Geometry::setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
{
if (i<_primitives.size() && primitiveset)
{
_primitives[i] = primitiveset;
dirtyDisplayList();
dirtyBound();
return true;
}
notify(WARN)<<"Warning: invalid index i or primitiveset passed to osg::Geometry::setPrimitiveSet(i,primitiveset), ignoring call."<<std::endl;
return false;
}
bool Geometry::insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
{
if (primitiveset)
{
if (i<_primitives.size())
{
_primitives.insert(_primitives.begin()+i,primitiveset);
dirtyDisplayList();
dirtyBound();
return true;
}
else if (i==_primitives.size())
{
return addPrimitiveSet(primitiveset);
}
}
notify(WARN)<<"Warning: invalid index i or primitiveset passed to osg::Geometry::insertPrimitiveSet(i,primitiveset), ignoring call."<<std::endl;
return false;
}
bool Geometry::removePrimitiveSet(unsigned int i, unsigned int numElementsToRemove)
{
if (i<_primitives.size() && numElementsToRemove>0)
{
if (i+numElementsToRemove<_primitives.size())
{
_primitives.erase(_primitives.begin()+i,_primitives.begin()+i+numElementsToRemove);
}
else
{
// asking to delete too many elements, report a warning, and delete to
// the end of the primitive list.
notify(WARN)<<"Warning: osg::Geometry::removePrimitiveSet(i,numElementsToRemove) has been asked to remove more elements than are available,"<<std::endl;
notify(WARN)<<" removing on from i to the end of the list of primitive sets."<<endl;
_primitives.erase(_primitives.begin()+i,_primitives.end());
}
dirtyDisplayList();
dirtyBound();
return true;
}
notify(WARN)<<"Warning: invalid index i passed to osg::Geometry::removePrimitiveSet(i,numElementsToRemove), ignoring call."<<std::endl;
return false;
}
unsigned int Geometry::getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const
{
for (unsigned int primitiveSetIndex=0;primitiveSetIndex<_primitives.size();++primitiveSetIndex)
{
if (_primitives[primitiveSetIndex]==primitiveset) return primitiveSetIndex;
}
return _primitives.size(); // node not found.
}
bool Geometry::areFastPathsUsed() const
{
if (_fastPathComputed) return _fastPath;

View File

@ -146,7 +146,7 @@ bool Group::replaceChild( Node *origNode, Node *newNode )
{
if (newNode==NULL || origNode==newNode) return false;
unsigned int pos = findChildNum(origNode);
unsigned int pos = getChildIndex(origNode);
if (pos<_children.size())
{
return setChild(pos,newNode);

View File

@ -69,7 +69,7 @@ bool LOD::addChild(Node *child, float min, float max)
bool LOD::removeChild( Node *child )
{
// find the child's position.
unsigned int pos=findChildNum(child);
unsigned int pos=getChildIndex(child);
if (pos==_children.size()) return false;
_rangeList.erase(_rangeList.begin()+pos);

View File

@ -61,7 +61,7 @@ bool Switch::addChild( Node *child, bool value )
bool Switch::removeChild( Node *child )
{
// find the child's position.
unsigned int pos=findChildNum(child);
unsigned int pos=getChildIndex(child);
if (pos==_children.size()) return false;
_values.erase(_values.begin()+pos);
@ -78,7 +78,7 @@ void Switch::setValue(unsigned int pos,bool value)
void Switch::setValue(const Node* child,bool value)
{
// find the child's position.
unsigned int pos=findChildNum(child);
unsigned int pos=getChildIndex(child);
if (pos==_children.size()) return;
_values[pos]=value;
@ -93,7 +93,7 @@ bool Switch::getValue(unsigned int pos) const
bool Switch::getValue(const Node* child) const
{
// find the child's position.
unsigned int pos=findChildNum(child);
unsigned int pos=getChildIndex(child);
if (pos==_children.size()) return false;
return _values[pos];