osg::SharePtrGraphOp Class Reference
[Rendering Backend]

#include <OSGSharePtrGraphOp.h>

Inheritance diagram for osg::SharePtrGraphOp:

osg::GraphOp

List of all members.

Public Member Functions

Constructors


 SharePtrGraphOp (const char *name="SharePtr")
GraphOpcreate ()
Destructors


virtual ~SharePtrGraphOp (void)
Main methods


bool traverse (NodePtr &root)
Parameters


void setParams (const std::string params)
void setIncludes (const std::string &includes)
void setExcludes (const std::string &excludes)
std::string usage (void)
Main methods


const std::string & getName (void)
void setName (const char *name)
Exclusion


void addToExcludeList (NodePtr &node)
void addToExcludeList (const std::string &name)
void removeFromExcludeList (NodePtr &node)
void removeFromExcludeList (const std::string &name)
void clearExcludeList (void)
bool isInExcludeListNodes (NodePtr &node)
bool isInExcludeListNames (const std::string &name)
bool isInExcludeList (NodePtr &node)

Static Public Member Functions

Class Get


static const char * getClassname (void)

Protected Attributes

std::list< NodePtr_excludeListNodes
std::list< std::string > _excludeListNames

Private Types

typedef std::set
< FieldContainerPtr
fcsSet
typedef std::map< std::string,
fcsSet
fcsMap

Private Member Functions

Action::ResultE traverseEnter (NodePtr &node)
Action::ResultE traverseLeave (NodePtr &node, Action::ResultE res)
bool isInList (const std::vector< std::string > &tlist, const FieldContainerPtr &fc)
FieldContainerPtr compareFCs (const FieldContainerPtr &fc)

Static Private Member Functions

static bool isEqual (const osg::FieldContainerPtr &a, const osg::FieldContainerPtr &b)
 Compares to field containers.
static Action::ResultE clearAttachmentParent (NodePtr &node)
static Action::ResultE addAttachmentParent (NodePtr &node)
static void fillAttachmentParents (const NodePtr &node)

Private Attributes

fcsMap _fctypes
std::vector< std::string > _includes
std::vector< std::string > _excludes
UInt32 _share_counter

Static Private Attributes

static std::set
< FieldContainerPtr
_added_cores


Detailed Description

GraphOp class

Definition at line 60 of file OSGSharePtrGraphOp.h.


Member Typedef Documentation

typedef std::set<FieldContainerPtr> osg::SharePtrGraphOp::fcsSet [private]

Definition at line 127 of file OSGSharePtrGraphOp.h.

typedef std::map<std::string, fcsSet> osg::SharePtrGraphOp::fcsMap [private]

Definition at line 128 of file OSGSharePtrGraphOp.h.


Constructor & Destructor Documentation

SharePtrGraphOp::SharePtrGraphOp ( const char *  name = "SharePtr"  ) 

Definition at line 83 of file OSGSharePtrGraphOp.cpp.

Referenced by create().

00083                                                 : 
00084     GraphOp(name),
00085     _fctypes(),
00086     _includes(),
00087     _excludes(),
00088     _share_counter(0)
00089 {
00090 }

SharePtrGraphOp::~SharePtrGraphOp ( void   )  [virtual]

Definition at line 92 of file OSGSharePtrGraphOp.cpp.

00093 {
00094 }


Member Function Documentation

static const char* osg::SharePtrGraphOp::getClassname ( void   )  [inline, static]

Reimplemented from osg::GraphOp.

Definition at line 69 of file OSGSharePtrGraphOp.h.

00069 { return "SharePtrGraphOp"; };

GraphOp * SharePtrGraphOp::create ( void   )  [virtual]

Implements osg::GraphOp.

Definition at line 96 of file OSGSharePtrGraphOp.cpp.

References SharePtrGraphOp().

00097 {
00098     return new SharePtrGraphOp();
00099 }

bool SharePtrGraphOp::traverse ( NodePtr root  )  [virtual]

Reimplemented from osg::GraphOp.

Definition at line 101 of file OSGSharePtrGraphOp.cpp.

References _excludes, _fctypes, _includes, _share_counter, compareFCs(), FFATAL, fillAttachmentParents(), and FINFO.

00102 {
00103     if(!_includes.empty() && !_excludes.empty())
00104     {
00105         FFATAL(("SharePtrGraphOp : Setting both the includes and excludes"
00106                 "is not allowed!\n"));
00107         return false;
00108     }
00109     
00110     _fctypes.clear();
00111     _share_counter = 0;
00112 
00113     bool result = true;
00114     compareFCs(root);
00115     // HACK but doing it directly in compareFCs() leads to crash while destroying the
00116     // scenegraph and this only with one special geometry file ...
00117     fillAttachmentParents(root);
00118 
00119     FINFO(("Shared %u ptrs with types:\n", _share_counter));
00120 
00121     for(fcsMap::iterator i = _fctypes.begin();i != _fctypes.end();++i)
00122         FINFO(("\t'%s'\n", (*i).first.c_str()));
00123 
00124     return result;
00125 }

void SharePtrGraphOp::setParams ( const std::string  params  )  [virtual]

Implements osg::GraphOp.

Definition at line 127 of file OSGSharePtrGraphOp.cpp.

References FWARNING, osg::GraphOp::ParamSet::getUnusedParams(), setExcludes(), and setIncludes().

00128 {
00129     ParamSet ps(params);   
00130     std::string incl, excl;
00131     
00132     ps("includes",  incl);
00133     ps("excludes",  excl);
00134     
00135     if(incl.length() && excl.length())
00136     {
00137         FWARNING(("SharePtrGraphOp: can't set includes and excludes\n"));
00138     }
00139     else
00140     {
00141         setIncludes(incl);
00142         setExcludes(excl);
00143     }
00144     
00145     std::string out = ps.getUnusedParams();
00146     if(out.length())
00147     {
00148         FWARNING(("SharePtrGraphOp doesn't have parameters '%s'.\n",
00149                 out.c_str()));
00150     }
00151 }

void SharePtrGraphOp::setIncludes ( const std::string &  includes  ) 

Definition at line 167 of file OSGSharePtrGraphOp.cpp.

References _includes.

Referenced by setParams().

00168 {
00169     _includes.clear();
00170     // parse comma separated names.
00171     std::string::const_iterator nextComma;
00172     std::string::const_iterator curPos = includes.begin();
00173     while(curPos < includes.end())
00174     {
00175         nextComma = std::find(curPos, includes.end(), ',');
00176         // strip leading spaces
00177         curPos = std::find_if(curPos, nextComma,
00178                               std::not1(std::ptr_fun(isspace)));
00179         _includes.push_back(std::string(curPos, nextComma));
00180         if(nextComma != includes.end())
00181             ++nextComma;
00182         curPos = nextComma;
00183     }
00184 }

void SharePtrGraphOp::setExcludes ( const std::string &  excludes  ) 

Definition at line 186 of file OSGSharePtrGraphOp.cpp.

References _excludes.

Referenced by setParams().

00187 {
00188     _excludes.clear();
00189     // parse comma separated names.
00190     std::string::const_iterator nextComma;
00191     std::string::const_iterator curPos = excludes.begin();
00192     while(curPos < excludes.end())
00193     {
00194         nextComma = std::find(curPos, excludes.end(), ',');
00195         // strip leading spaces
00196         curPos = std::find_if(curPos, nextComma,
00197                               std::not1(std::ptr_fun(isspace)));
00198         _excludes.push_back(std::string(curPos, nextComma));
00199         if(nextComma != excludes.end())
00200             ++nextComma;
00201         curPos = nextComma;
00202     }
00203 }

std::string SharePtrGraphOp::usage ( void   )  [virtual]

Implements osg::GraphOp.

Definition at line 153 of file OSGSharePtrGraphOp.cpp.

00154 {
00155     return 
00156     "SharePtr: try to share FieldContainers in a subtree\n"
00157     "  Compares the values of all referenced FieldContainers in the\n"
00158     "  subtree and shares them if possible. Primarily useful for\n"
00159     "  Geometries and Materials, but works for everything.\n"
00160     "Params: name (type, default)\n"
00161     "  includes (string, ""): comma-separated list of types to share\n"
00162     "  excludes (string, ""): comma-separated list of types not to share\n"
00163     "  (Only one of the two can be used, not both at the same time)\n"
00164     ;
00165 }

Action::ResultE SharePtrGraphOp::traverseEnter ( NodePtr node  )  [private, virtual]

Implements osg::GraphOp.

Definition at line 205 of file OSGSharePtrGraphOp.cpp.

References osg::Action::Continue.

00206 {
00207     return Action::Continue;
00208 }

Action::ResultE SharePtrGraphOp::traverseLeave ( NodePtr node,
Action::ResultE  res 
) [private, virtual]

Implements osg::GraphOp.

Definition at line 210 of file OSGSharePtrGraphOp.cpp.

References osg::Action::Continue.

00212 {
00213     return Action::Continue;
00214 }

bool SharePtrGraphOp::isInList ( const std::vector< std::string > &  tlist,
const FieldContainerPtr fc 
) [private]

Definition at line 220 of file OSGSharePtrGraphOp.cpp.

References osg::FieldContainerFactory::findType(), FWARNING, and osg::FieldContainerFactory::the().

Referenced by compareFCs().

00222 {
00223     for(UInt32 k=0;k<tlist.size();++k)
00224     {
00225         FieldContainerType *fct = FieldContainerFactory::the()
00226                                         ->findType(tlist[k].c_str());
00227         if(fct == NULL)
00228         {
00229             FWARNING(("SharePtrGraphOp: Unknown type '%s'!\n", tlist[k].c_str()));
00230             break;
00231         }
00232 
00233         if(fc->getType().isDerivedFrom(*fct))
00234             return true;
00235     }
00236 
00237     return false;
00238 }

FieldContainerPtr SharePtrGraphOp::compareFCs ( const FieldContainerPtr fc  )  [private]

Definition at line 240 of file OSGSharePtrGraphOp.cpp.

References _excludes, _fctypes, _includes, _share_counter, osg::addRefCP(), osg::beginEditCP(), osg::AttachmentPtr::dcast(), osg::endEditCP(), FDEBUG, osg::Field::getCardinality(), osg::TypeBase::getCName(), osg::FieldDescription::getCName(), osg::FieldContainerType::getFieldDescription(), osg::FieldDescription::getFieldId(), osg::FieldDescription::getFieldMask(), osg::TypeBase::getName(), osg::FieldContainerType::getNumFieldDescs(), osg::Field::getType(), isEqual(), isInList(), osg::FieldDescription::isInternal(), osg::FieldType::MULTI_FIELD, osg::NullFC, osg::Attachment::ParentsFieldMask, osg::FieldContainerPtrBase::setParentFieldPos(), osg::FieldType::SINGLE_FIELD, osg::IDString::str(), and osg::subRefCP().

Referenced by traverse().

00241 {
00242     if(fc == NullFC)
00243         return fc;
00244 
00245     const FieldContainerType &type = fc->getType();
00246     UInt32 fcount = type.getNumFieldDescs();
00247 
00248     for(UInt32 i=1;i <= fcount;++i)
00249     {
00250         const FieldDescription* fdesc = type.getFieldDescription(i);
00251     
00252         if(fdesc->isInternal())
00253             continue;
00254         
00255         // ignore attachments
00256         if(strcmp(fdesc->getCName(), "attachments") == 0)
00257             continue;
00258 
00259         BitVector mask = fdesc->getFieldMask();
00260 
00261         Field *fc_field = fc->getField(i);
00262         const FieldType &ftype = fc_field->getType();
00263         std::string fieldType = ftype.getName().str();
00264         
00265         // field
00266         if(strstr(ftype.getCName(), "Ptr") != NULL)
00267         {
00268             if(fc_field->getCardinality() == FieldType::SINGLE_FIELD)
00269             {
00270                 FieldContainerPtr ffc = ((SFFieldContainerPtr *) fc_field)
00271                                         ->getValue();
00272                 
00273                 FieldContainerPtr nffc = compareFCs(ffc);
00274                 
00275                 if(nffc != ffc)
00276                 {
00277                     addRefCP(nffc);
00278                     beginEditCP(fc, mask);
00279                         ((SFFieldContainerPtr *) fc_field)->setValue(nffc);
00280                     endEditCP(fc, mask);
00281 #if 0
00282                     // for attachments we need to update the parents field!
00283                     AttachmentPtr attachment = AttachmentPtr::dcast(nffc);
00284                     if(attachment != NullFC)
00285                     {
00286                         AttachmentPtr attorg = AttachmentPtr::dcast(ffc);
00287                         beginEditCP(attorg, Attachment::ParentsFieldMask);
00288                             attorg->subParent(fc);
00289                         endEditCP(attorg, Attachment::ParentsFieldMask);
00290 
00291                         FieldContainerPtr fcb = fc;
00292                         fcb.setParentFieldPos(fdesc->getFieldId());
00293                         beginEditCP(attachment, Attachment::ParentsFieldMask);
00294                             attachment->addParent(fc);
00295                             //attachment->getParents().clear();
00296                         endEditCP(attachment, Attachment::ParentsFieldMask);
00297                     }
00298 #endif
00299                     subRefCP(ffc);
00300                 }
00301             }
00302             else if(fc_field->getCardinality() == FieldType::MULTI_FIELD)
00303             {
00304                 beginEditCP(fc, mask);
00305                 for(UInt32 j=0;j < ((MFFieldContainerPtr*)fc_field)->size();++j)
00306                 {
00307                     FieldContainerPtr ffc = (*(((MFFieldContainerPtr *)fc_field)))[j];
00308                     
00309                     FieldContainerPtr nffc = compareFCs(ffc);
00310                     
00311                     if(nffc != ffc)
00312                     {
00313                         addRefCP(nffc);
00314                         (*(((MFFieldContainerPtr *)fc_field)))[j] = nffc;
00315 #if 0
00316                         // for attachments we need to update the parents field!
00317                         AttachmentPtr attachment = AttachmentPtr::dcast(nffc);
00318                         if(attachment != NullFC)
00319                         {
00320                             AttachmentPtr attorg = AttachmentPtr::dcast(ffc);
00321                             beginEditCP(attorg, Attachment::ParentsFieldMask);
00322                                 attorg->subParent(fc);
00323                             endEditCP(attorg, Attachment::ParentsFieldMask);
00324 
00325                             FieldContainerPtr fcb = fc;
00326                             fcb.setParentFieldPos(fdesc->getFieldId());
00327                             beginEditCP(attachment, Attachment::ParentsFieldMask);
00328                                 attachment->addParent(fc);
00329                             endEditCP(attachment, Attachment::ParentsFieldMask);
00330                         }
00331 #endif
00332                         subRefCP(ffc);
00333                     }
00334                 }
00335                 endEditCP(fc, mask);
00336             }
00337         }
00338     }
00339 
00340     std::string typestr = fc->getType().getCName();
00341     
00342     if(!_includes.empty())
00343     {
00344         if(!isInList(_includes, fc))
00345             return fc;
00346     }
00347     
00348     if(!_excludes.empty())
00349     {
00350         if(isInList(_excludes, fc))
00351             return fc;
00352     }
00353 
00354     fcsMap::iterator fi = _fctypes.find(typestr);
00355     
00356     if(fi == _fctypes.end())
00357     {
00358         fcsSet fcs;
00359         _fctypes[typestr] = fcs;
00360         fi = _fctypes.find(typestr);
00361     }
00362 
00363     fcsSet &fcs = (*fi).second;
00364     
00365     // already shared?
00366     if(fcs.count(fc))
00367         return fc;
00368     
00369     for(fcsSet::iterator i=fcs.begin();i!=fcs.end();++i)
00370     {
00371         if(isEqual(*i, fc))
00372         {
00373             if(*i != fc)
00374             {
00375                 ++_share_counter;
00376                 FDEBUG(("Shared %u ptrs.\r", _share_counter));
00377             }
00378             return *i;
00379         }
00380     }
00381     
00382     fcs.insert(fc);
00383 
00384     return fc;
00385 }

bool SharePtrGraphOp::isEqual ( const osg::FieldContainerPtr a,
const osg::FieldContainerPtr b 
) [static, private]

Parameters:
field container a
field container b
Returns:
true if equal.

Definition at line 421 of file OSGSharePtrGraphOp.cpp.

References FINFO, osg::Field::getCardinality(), osg::TypeBase::getCName(), osg::FieldDescription::getCName(), osg::FieldContainerType::getFieldDescription(), osg::FieldContainerType::getNumFieldDescs(), osg::Field::getType(), osg::Field::getValueByStr(), osg::FieldDescription::isInternal(), osg::FieldType::MULTI_FIELD, osg::NullFC, osg::osgMin(), and osg::FieldType::SINGLE_FIELD.

Referenced by compareFCs().

00423 {
00424     // Compare the pointers.
00425     if(a == b)
00426         return true;
00427 
00428     if(a == NullFC || b == NullFC)
00429         return false;
00430 
00431     if(a->getType() != b->getType())
00432         return false;
00433     
00434     //printf("comparing: %s\n", a->getType().getName().str());
00435     
00436     const FieldContainerType &type = a->getType();
00437     //UInt32 fcount = type.getNumFieldDescs();
00438     // ignore dynamic fields.
00439     UInt32 fcount = osgMin(type.getNumFieldDescs(), b->getType().getNumFieldDescs());
00440     
00441     for(UInt32 i=1;i <= fcount;++i)
00442     {
00443         const FieldDescription* fdesc = type.getFieldDescription(i);
00444     
00445         if(fdesc->isInternal())
00446             continue;
00447     
00448         // ignore attachments
00449         if(strcmp(fdesc->getCName(), "attachments") == 0)
00450             continue;
00451     
00452         Field *a_field = a->getField(i);
00453         Field *b_field = b->getField(i);
00454     
00455         const FieldType &a_ftype = a_field->getType();
00456         const FieldType &b_ftype = b_field->getType();
00457 
00458         //printf("comparing field %s\n", a_ftype.getCName());
00459 
00460         if(a_ftype != b_ftype)
00461             return false;
00462     
00463         if(strstr(a_ftype.getCName(), "Ptr") == NULL)
00464         {
00465             // some speedup.
00466             // This is a HACK this will be changed in near future.
00467             if(a_field->getCardinality() == FieldType::MULTI_FIELD)
00468             {
00469                 if(dynamic_cast<MField<UInt8> *>(a_field) != NULL)
00470                 {
00471                     if(!compareMField<UInt8>(a_field, b_field))
00472                         return false;
00473                 }
00474                 else if(dynamic_cast<MField<Int32> *>(a_field) != NULL)
00475                 {
00476                     if(!compareMField<Int32>(a_field, b_field))
00477                         return false;
00478                 }
00479                 else if(dynamic_cast<MField<UInt32> *>(a_field) != NULL)
00480                 {
00481                     if(!compareMField<UInt32>(a_field, b_field))
00482                         return false;
00483                 }
00484                 else if(dynamic_cast<MField<Real32> *>(a_field) != NULL)
00485                 {
00486                     if(!compareMField<Real32>(a_field, b_field))
00487                         return false;
00488                 }
00489                 else if(dynamic_cast<MField<Vec2f> *>(a_field) != NULL)
00490                 {
00491                     if(!compareMField<Vec2f>(a_field, b_field))
00492                         return false;
00493                 }
00494                 else if(dynamic_cast<MField<Vec3f> *>(a_field) != NULL)
00495                 {
00496                     if(!compareMField<Vec3f>(a_field, b_field))
00497                         return false;
00498                 }
00499                 else if(dynamic_cast<MField<Pnt3f> *>(a_field) != NULL)
00500                 {
00501                     if(!compareMField<Pnt3f>(a_field, b_field))
00502                         return false;
00503                 }
00504                 else if(dynamic_cast<MField<Color3f> *>(a_field) != NULL)
00505                 {
00506                     if(!compareMField<Color3f>(a_field, b_field))
00507                         return false;
00508                 }
00509                 else if(dynamic_cast<MField<Color4f> *>(a_field) != NULL)
00510                 {
00511                     if(!compareMField<Color4f>(a_field, b_field))
00512                         return false;
00513                 }
00514                 else
00515                 {
00516                     FINFO(("Slow multi field string compare for '%s'!\n",
00517                           a_ftype.getCName()));
00518                     std::string av, bv;
00519                     a_field->getValueByStr(av);
00520                     b_field->getValueByStr(bv);
00521                     if(av != bv)
00522                         return false;
00523                 }
00524             }
00525             else
00526             {
00527                 // This is very slow with multi fields!!!!
00528                 std::string av, bv;
00529                 a_field->getValueByStr(av);
00530                 b_field->getValueByStr(bv);
00531                 if(av != bv)
00532                     return false;
00533             }
00534         }
00535         else
00536         {
00537             if(a_field->getCardinality() == FieldType::SINGLE_FIELD)
00538             {
00539                 if(!isEqual(((SFFieldContainerPtr *) a_field)->getValue(),
00540                             ((SFFieldContainerPtr *) b_field)->getValue()))
00541                     return false;
00542             }
00543             else if(a_field->getCardinality() == FieldType::MULTI_FIELD)
00544             {
00545                 if(((MFFieldContainerPtr*)a_field)->size() !=
00546                    ((MFFieldContainerPtr*)b_field)->size())
00547                    return false;
00548     
00549                 for(UInt32 j=0;j < ((MFFieldContainerPtr*)a_field)->size();++j)
00550                 {
00551                     if(!isEqual((*(((MFFieldContainerPtr *)a_field)))[j],
00552                                 (*(((MFFieldContainerPtr *)b_field)))[j]))
00553                         return false;
00554                 }
00555             }
00556         }
00557     }
00558     return true;
00559 }

Action::ResultE SharePtrGraphOp::clearAttachmentParent ( NodePtr node  )  [static, private]

Definition at line 561 of file OSGSharePtrGraphOp.cpp.

References _added_cores, osg::beginEditCP(), osg::Action::Continue, osg::AttachmentPtr::dcast(), osg::endEditCP(), osg::TypeBase::getCName(), osg::NodePtr::getCore(), osg::FieldContainerType::getFieldDescription(), osg::FieldDescription::getFieldId(), osg::FieldDescription::getFieldMask(), osg::FieldContainerType::getNumFieldDescs(), osg::Field::getType(), osg::FieldDescription::isInternal(), osg::NullFC, osg::Attachment::ParentsFieldMask, osg::FieldContainerPtrBase::setParentFieldPos(), and osg::MField< FieldTypeT, fieldNameSpace >::size().

Referenced by fillAttachmentParents().

00562 {
00563     if(node == NullFC)
00564         return Action::Continue;
00565 
00566     FieldContainerPtr fc = node->getCore();
00567 
00568     if(fc == NullFC)
00569         return Action::Continue;
00570 
00571     // the core could be shared this would lead to duplicated parent entries.
00572     if(_added_cores.count(fc) == 1)
00573         return Action::Continue;
00574 
00575     _added_cores.insert(fc);
00576 
00577     FieldContainerType  &fcType = fc->getType();
00578 
00579     //go through all fields
00580     for(UInt32 i = 1; i <= fcType.getNumFieldDescs(); ++i)
00581     {
00582         FieldDescription    *fDesc = fcType.getFieldDescription(i);
00583         Field               *fieldPtr = fc->getField(i);
00584         const FieldType     &fType = fieldPtr->getType();
00585         std::string         fieldType = fType.getCName();
00586         BitVector           mask = fDesc->getFieldMask();
00587 
00588         if(fDesc->isInternal())
00589         {
00590             continue;
00591         }
00592 
00593         if(strstr(fieldType.c_str(), "Ptr") != NULL)
00594         {
00595             if(fieldType[0] == 'S' && fieldType[1] == 'F') // single field
00596             {
00597                 AttachmentPtr attachment =
00598                     AttachmentPtr::dcast(((SFFieldContainerPtr *) fieldPtr)
00599                     ->getValue());
00600                 if(attachment != NullFC)
00601                 {
00602                     fc.setParentFieldPos(fDesc->getFieldId());
00603                     beginEditCP(attachment, Attachment::ParentsFieldMask);
00604                         attachment->getParents().clear();
00605                     endEditCP(attachment, Attachment::ParentsFieldMask);
00606                 }
00607             }
00608             else if(fieldType[0] == 'M' && fieldType[1] == 'F') // multi field
00609             {
00610                 MFFieldContainerPtr *mfield = (MFFieldContainerPtr *) fieldPtr;
00611                 UInt32 noe = mfield->size();
00612                 for(UInt32 j = 0; j < noe; ++j)
00613                 {
00614                     AttachmentPtr attachment =
00615                         AttachmentPtr::dcast((*(mfield))[j]);
00616                     if(attachment != NullFC)
00617                     {
00618                         fc.setParentFieldPos(fDesc->getFieldId());
00619                         beginEditCP(attachment, Attachment::ParentsFieldMask);
00620                             attachment->getParents().clear();
00621                         endEditCP(attachment, Attachment::ParentsFieldMask);
00622                     }
00623                 }
00624             }
00625         }
00626     }
00627 
00628     return Action::Continue;
00629 }

Action::ResultE SharePtrGraphOp::addAttachmentParent ( NodePtr node  )  [static, private]

Definition at line 631 of file OSGSharePtrGraphOp.cpp.

References _added_cores, osg::beginEditCP(), osg::Action::Continue, osg::AttachmentPtr::dcast(), osg::endEditCP(), osg::TypeBase::getCName(), osg::NodePtr::getCore(), osg::FieldContainerType::getFieldDescription(), osg::FieldDescription::getFieldId(), osg::FieldDescription::getFieldMask(), osg::FieldContainerType::getNumFieldDescs(), osg::Field::getType(), osg::FieldDescription::isInternal(), osg::NullFC, osg::Attachment::ParentsFieldMask, osg::FieldContainerPtrBase::setParentFieldPos(), and osg::MField< FieldTypeT, fieldNameSpace >::size().

Referenced by fillAttachmentParents().

00632 {
00633     if(node == NullFC)
00634         return Action::Continue;
00635 
00636     FieldContainerPtr fc = node->getCore();
00637 
00638     if(fc == NullFC)
00639         return Action::Continue;
00640 
00641     // the core could be shared this would lead to duplicated parent entries.
00642     if(_added_cores.count(fc) == 1)
00643         return Action::Continue;
00644 
00645     _added_cores.insert(fc);
00646 
00647     FieldContainerType  &fcType = fc->getType();
00648 
00649     //go through all fields
00650     for(UInt32 i = 1; i <= fcType.getNumFieldDescs(); ++i)
00651     {
00652         FieldDescription    *fDesc = fcType.getFieldDescription(i);
00653         Field               *fieldPtr = fc->getField(i);
00654         const FieldType     &fType = fieldPtr->getType();
00655         std::string         fieldType = fType.getCName();
00656         BitVector           mask = fDesc->getFieldMask();
00657 
00658         if(fDesc->isInternal())
00659         {
00660             continue;
00661         }
00662 
00663         if(strstr(fieldType.c_str(), "Ptr") != NULL)
00664         {
00665             if(fieldType[0] == 'S' && fieldType[1] == 'F') // single field
00666             {
00667                 AttachmentPtr attachment =
00668                     AttachmentPtr::dcast(((SFFieldContainerPtr *) fieldPtr)
00669                     ->getValue());
00670                 if(attachment != NullFC)
00671                 {
00672                     fc.setParentFieldPos(fDesc->getFieldId());
00673                     beginEditCP(attachment, Attachment::ParentsFieldMask);
00674                         attachment->addParent(fc);
00675                     endEditCP(attachment, Attachment::ParentsFieldMask);
00676                 }
00677             }
00678             else if(fieldType[0] == 'M' && fieldType[1] == 'F') // multi field
00679             {
00680                 MFFieldContainerPtr *mfield = (MFFieldContainerPtr *) fieldPtr;
00681                 UInt32 noe = mfield->size();
00682                 for(UInt32 j = 0; j < noe; ++j)
00683                 {
00684                     AttachmentPtr attachment =
00685                         AttachmentPtr::dcast((*(mfield))[j]);
00686                     if(attachment != NullFC)
00687                     {
00688                         fc.setParentFieldPos(fDesc->getFieldId());
00689                         beginEditCP(attachment, Attachment::ParentsFieldMask);
00690                             attachment->addParent(fc);
00691                         endEditCP(attachment, Attachment::ParentsFieldMask);
00692                     }
00693                 }
00694             }
00695         }
00696     }
00697 
00698     return Action::Continue;
00699 }

void SharePtrGraphOp::fillAttachmentParents ( const NodePtr node  )  [static, private]

const std::string & GraphOp::getName ( void   )  [inherited]

Definition at line 112 of file OSGGraphOp.cpp.

References osg::GraphOp::_name.

Referenced by osg::GraphOpFactory::registerOp(), and osg::GraphOpFactory::unRegisterOp().

00113 {
00114     return _name;
00115 };

void GraphOp::setName ( const char *  name  )  [inherited]

Definition at line 117 of file OSGGraphOp.cpp.

References osg::GraphOp::_name.

00118 {
00119     _name = name;
00120 };

void GraphOp::addToExcludeList ( NodePtr node  )  [inherited]

Definition at line 124 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNodes, and osg::GraphOp::isInExcludeListNodes().

Referenced by osg::MergeGraphOp::excludeListLeave(), and osg::GraphOpSeq::setGraphOps().

00125 {
00126     if (!isInExcludeListNodes(node))
00127         _excludeListNodes.push_back(node);
00128 }

void GraphOp::addToExcludeList ( const std::string &  name  )  [inherited]

Definition at line 130 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames, and osg::GraphOp::isInExcludeListNames().

00131 {
00132     if (!isInExcludeListNames(name))
00133         _excludeListNames.push_back(name);
00134 }

void GraphOp::removeFromExcludeList ( NodePtr node  )  [inherited]

Definition at line 136 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNodes.

00137 {
00138     _excludeListNodes.remove(node);
00139 }

void GraphOp::removeFromExcludeList ( const std::string &  name  )  [inherited]

Definition at line 141 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames.

00142 {
00143     _excludeListNames.remove(name);
00144 }

void GraphOp::clearExcludeList ( void   )  [inherited]

Definition at line 146 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames, and osg::GraphOp::_excludeListNodes.

00147 {
00148     _excludeListNames.clear();
00149     _excludeListNodes.clear();
00150 }

bool GraphOp::isInExcludeListNodes ( NodePtr node  )  [inherited]

Definition at line 152 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNodes.

Referenced by osg::GraphOp::addToExcludeList(), and osg::GraphOp::isInExcludeList().

00153 {
00154     std::list<NodePtr>::iterator list_iter;
00155     list_iter = std::find(_excludeListNodes.begin(),_excludeListNodes.end(),node);
00156 
00157     if (list_iter==_excludeListNodes.end()) 
00158         return false;
00159     else 
00160         return true;
00161 }

bool GraphOp::isInExcludeListNames ( const std::string &  name  )  [inherited]

Definition at line 163 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames.

Referenced by osg::GraphOp::addToExcludeList(), and osg::GraphOp::isInExcludeList().

00164 {
00165     std::list<std::string>::iterator namelist_iter;
00166     namelist_iter = std::find(_excludeListNames.begin(),_excludeListNames.end(),name);
00167 
00168     if (namelist_iter==_excludeListNames.end()) 
00169         return false;
00170     else 
00171         return true;
00172 }

bool GraphOp::isInExcludeList ( NodePtr node  )  [inherited]


Member Data Documentation

Definition at line 129 of file OSGSharePtrGraphOp.h.

Referenced by compareFCs(), and traverse().

std::vector<std::string> osg::SharePtrGraphOp::_includes [private]

Definition at line 131 of file OSGSharePtrGraphOp.h.

Referenced by compareFCs(), setIncludes(), and traverse().

std::vector<std::string> osg::SharePtrGraphOp::_excludes [private]

Definition at line 132 of file OSGSharePtrGraphOp.h.

Referenced by compareFCs(), setExcludes(), and traverse().

Definition at line 133 of file OSGSharePtrGraphOp.h.

Referenced by compareFCs(), and traverse().

std::set< FieldContainerPtr > SharePtrGraphOp::_added_cores [static, private]

std::list<NodePtr> osg::GraphOp::_excludeListNodes [protected, inherited]

std::list<std::string> osg::GraphOp::_excludeListNames [protected, inherited]


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:05:34 2008 for OpenSG by  doxygen 1.5.5