Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::GeoTypeGraphOp Class Reference

#include <OSGGeoTypeGraphOp.h>

Inheritance diagram for osg::GeoTypeGraphOp:

osg::SingleTypeGraphOp< Geometry > osg::GraphOp List of all members.

Public Member Functions

 GeoTypeGraphOp (const char *name="GeoType")
GraphOpcreate ()
void setParams (const std::string params)
std::string usage (void)
void setFilter (const osg::BitVector &filter)
SingleTypeGraphOp (const char *name="")
Main methods
*virtual bool traverse (NodePtr &root)
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

static const char * getClassname (void)

Protected Attributes

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

Private Member Functions

bool travNodeEnter (NodePtr node)
bool travNodeLeave (NodePtr node)

Private Attributes

osg::BitVector _filter

Detailed Description

Definition at line 53 of file OSGGeoTypeGraphOp.h.


Constructor & Destructor Documentation

GeoTypeGraphOp::GeoTypeGraphOp const char *  name = "GeoType"  ) 
 

Definition at line 46 of file OSGGeoTypeGraphOp.cpp.

Referenced by create().

00047     : SingleTypeGraphOp<Geometry>(name),
00048     _filter(TypeTraits<OSG::BitVector>::getMax())
00049 {
00050 }


Member Function Documentation

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

Reimplemented from osg::SingleTypeGraphOp< Geometry >.

Definition at line 57 of file OSGGeoTypeGraphOp.h.

00057 { return "GeoTypeGraphOp"; };

GraphOp * GeoTypeGraphOp::create  )  [virtual]
 

Implements osg::GraphOp.

Definition at line 52 of file OSGGeoTypeGraphOp.cpp.

References GeoTypeGraphOp().

00053 {
00054     return new GeoTypeGraphOp();
00055 }

void GeoTypeGraphOp::setParams const std::string  params  )  [virtual]
 

Implements osg::GraphOp.

Definition at line 182 of file OSGGeoTypeGraphOp.cpp.

References _filter, FWARNING, osg::GeometryBase::IndicesFieldMask, osg::GeometryBase::LengthsFieldMask, and osg::GeometryBase::NormalsFieldMask.

00183 {
00184     ParamSet ps(params);   
00185     std::string filter;
00186     
00187     if(ps("filter", filter))
00188     {
00189         _filter = 0;
00190         if(filter.find("Nor") != std::string::npos ||
00191            filter.find("nor") != std::string::npos)
00192         {
00193             _filter |= Geometry::NormalsFieldMask;
00194         }
00195         if(filter.find("Ind") != std::string::npos ||
00196            filter.find("ind") != std::string::npos)
00197         {
00198             _filter |= Geometry::IndicesFieldMask;
00199         }
00200         if(filter.find("Len") != std::string::npos ||
00201            filter.find("len") != std::string::npos)
00202         {
00203             _filter |= Geometry::LengthsFieldMask;
00204         }
00205     }
00206     
00207     std::string out = ps.getUnusedParams();
00208     if(out.length())
00209     {
00210         FWARNING(("GeoTypeGraphOp doesn't have parameters '%s'.\n",
00211                 out.c_str()));
00212     }
00213 }

std::string GeoTypeGraphOp::usage void   )  [virtual]
 

Implements osg::GraphOp.

Definition at line 215 of file OSGGeoTypeGraphOp.cpp.

00216 {
00217     return 
00218     "GeoType: convert the types of a Geometry's attributes\n"
00219     "  Tries to convert the attributes of a Geometry to smaller/faster\n"
00220     "  types. By default only the lengths are changed to 16 bit.\n"
00221     "Params: name (type, default)\n"
00222     "  filter  (string, \"\"): fields to convert, can be a combination of\n"
00223     "                        Normals, Indices and Lengths, connected by +.\n"
00224     ;
00225 }

void GeoTypeGraphOp::setFilter const osg::BitVector filter  ) 
 

Definition at line 227 of file OSGGeoTypeGraphOp.cpp.

References _filter.

00228 {
00229     _filter = filter;
00230 }

bool GeoTypeGraphOp::travNodeEnter NodePtr  node  )  [private, virtual]
 

Implements osg::SingleTypeGraphOp< Geometry >.

Definition at line 58 of file OSGGeoTypeGraphOp.cpp.

References _filter, osg::beginEditCP(), osg::GeoProperty< GeoPropertyDesc >::create(), osg::AttachmentContainerPtr::dcast(), osg::endEditCP(), osg::NodePtr::getCore(), osg::GeometryBase::IndicesFieldMask, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::GeometryBase::LengthsFieldMask, osg::GeometryBase::NormalsFieldMask, osg::NullFC, osg::MField< FieldTypeT, fieldNameSpace >::push_back(), osg::MField< FieldTypeT, fieldNameSpace >::reserve(), and osg::MField< FieldTypeT, fieldNameSpace >::size().

00059 {
00060     GeometryPtr geo = GeometryPtr::dcast(node->getCore());
00061 
00062     if(geo == NullFC)
00063     {
00064         return true;
00065     }
00066 
00067     GeoPositionsPtr positions = geo->getPositions();
00068 
00069     // normals
00070     if(_filter & Geometry::NormalsFieldMask)
00071     {
00072         GeoNormalsPtr   normals   = geo->getNormals();
00073         GeoNormals3fPtr normals3f = GeoNormals3fPtr::dcast(normals);
00074         if (normals3f != NullFC)
00075         {
00076             MFVec3f &src = normals3f->getField();
00077             
00078             GeoNormals3bPtr normals3b = GeoNormals3b::create();
00079             MFVec3b &dst = normals3b->getField();
00080             dst.reserve(src.size());
00081             beginEditCP(normals3b);
00082                 for (UInt32 i = 0; i < src.size(); ++i)
00083                 {
00084                     Vec3f vec = src[i];
00085                     vec *= (0.9f / vec.length());
00086                     normals3b->push_back(vec);
00087                 }
00088             endEditCP(normals3b);
00089     
00090             beginEditCP(geo, Geometry::NormalsFieldMask);
00091                 geo->setNormals(normals3b);
00092             endEditCP(geo, Geometry::NormalsFieldMask);
00093         }
00094     }
00095 
00096     GeoColorsPtr    colors    = geo->getColors();
00097     GeoColorsPtr    scolors   = geo->getSecondaryColors();
00098 
00099     if(_filter & Geometry::LengthsFieldMask)
00100     {
00101         // lengths
00102         GeoPLengthsUI32Ptr lengthsUI32 = GeoPLengthsUI32Ptr::dcast(geo->getLengths());
00103         if(lengthsUI32 != NullFC)
00104         {
00105             MFUInt32 &src = lengthsUI32->getField();
00106     
00107             // now check if maximum length is greater than 65535
00108             UInt32 max_length = UInt32(TypeTraits<UInt16>::getMax());
00109             bool max_length_ok = true;
00110             for(UInt32 i=0;i<src.size();++i)
00111             {
00112                 if(src[i] > max_length)
00113                 {
00114                     max_length_ok = false;
00115                     break;
00116                 }
00117             }
00118     
00119             if(max_length_ok)
00120             {
00121                 GeoPLengthsUI16Ptr lengthsUI16 = GeoPLengthsUI16::create();
00122                 MFUInt16 &dst = lengthsUI16->getField();
00123                 dst.reserve(src.size());
00124                 beginEditCP(lengthsUI16);
00125                     for (UInt32 i = 0; i < src.size(); ++i)
00126                         dst.push_back(UInt16(src[i]));
00127                 endEditCP(lengthsUI16);
00128         
00129                 beginEditCP(geo, Geometry::LengthsFieldMask);
00130                     geo->setLengths(lengthsUI16);
00131                 endEditCP(geo, Geometry::LengthsFieldMask);
00132             }
00133         }
00134     }
00135 
00136     // indices
00137     if(_filter & Geometry::IndicesFieldMask)
00138     {
00139         GeoIndicesUI32Ptr indicesUI32 = GeoIndicesUI32Ptr::dcast(geo->getIndices());
00140         if(indicesUI32 != NullFC)
00141         {
00142             MFUInt32 &src = indicesUI32->getField();
00143     
00144             // now check if maximum index is greater than 65535
00145             UInt32 max_index = UInt32(TypeTraits<UInt16>::getMax());
00146             bool max_index_ok = true;
00147             for(UInt32 i=0;i<src.size();++i)
00148             {
00149                 if(src[i] > max_index)
00150                 {
00151                     max_index_ok = false;
00152                     break;
00153                 }
00154             }
00155     
00156             if(max_index_ok)
00157             {
00158                 GeoIndicesUI16Ptr indicesUI16 = GeoIndicesUI16::create();
00159                 MFUInt16 &dst = indicesUI16->getField();
00160                 dst.reserve(src.size());
00161                 beginEditCP(indicesUI16);
00162                     for (UInt32 i = 0; i < src.size(); ++i)
00163                         dst.push_back(src[i]);
00164                 endEditCP(indicesUI16);
00165         
00166                 beginEditCP(geo, Geometry::IndicesFieldMask);
00167                     geo->setIndices(indicesUI16);
00168                 endEditCP(geo, Geometry::IndicesFieldMask);
00169             }
00170         }
00171     }
00172 
00173     return true;
00174 }

bool GeoTypeGraphOp::travNodeLeave NodePtr  node  )  [private, virtual]
 

Implements osg::SingleTypeGraphOp< Geometry >.

Definition at line 177 of file OSGGeoTypeGraphOp.cpp.

00178 {
00179     return true;
00180 }

* osg::SingleTypeGraphOp< Geometry >::SingleTypeGraphOp const char *  name = ""  )  [inherited]
 

bool GraphOp::traverse NodePtr root  )  [virtual, inherited]
 

Reimplemented in osg::MakeTransparentGraphOp, osg::MaterialMergeGraphOp, osg::MergeGraphOp, osg::SharePtrGraphOp, osg::SplitGraphOp, and osg::VerifyGraphOp.

Definition at line 94 of file OSGGraphOp.cpp.

References osg::Action::Continue, osg::osgTypedMethodFunctor1ObjPtrCPtrRef(), osg::osgTypedMethodFunctor2ObjPtrCPtrRef(), osg::GraphOp::traverseEnter(), and osg::GraphOp::traverseLeave().

Referenced by osg::VerifyGraphOp::traverse(), osg::MaterialMergeGraphOp::traverse(), and osg::MakeTransparentGraphOp::traverse().

00095 {
00096     Action::ResultE res;
00097     res = ::traverse(node,
00098           osgTypedMethodFunctor1ObjPtrCPtrRef<Action::ResultE,
00099           GraphOp,
00100           NodePtr>(this,&GraphOp::traverseEnter),
00101           osgTypedMethodFunctor2ObjPtrCPtrRef<Action::ResultE,
00102           GraphOp,
00103           NodePtr,
00104           Action::ResultE>(this,&GraphOp::traverseLeave));
00105 
00106     if (res == Action::Continue) 
00107         return true;
00108     else 
00109         return false;
00110 }

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]
 

Definition at line 174 of file OSGGraphOp.cpp.

References osg::getName(), osg::GraphOp::isInExcludeListNames(), and osg::GraphOp::isInExcludeListNodes().

Referenced by osg::MergeGraphOp::processGeometries(), osg::MergeGraphOp::processGroups(), osg::MergeGraphOp::processTransformations(), osg::SplitGraphOp::splitNode(), and osg::SplitGraphOp::traverseLeave().

00175 {
00176     if (isInExcludeListNodes(node) || (OSG::getName(node)!=NULL && isInExcludeListNames(OSG::getName(node))))
00177         return true;
00178     else
00179         return false;
00180 }


Member Data Documentation

osg ::BitVector osg::GeoTypeGraphOp::_filter [private]
 

Definition at line 74 of file OSGGeoTypeGraphOp.h.

Referenced by setFilter(), setParams(), and travNodeEnter().

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

Definition at line 161 of file OSGGraphOp.h.

Referenced by osg::GraphOp::addToExcludeList(), osg::GraphOp::clearExcludeList(), osg::GraphOp::isInExcludeListNodes(), osg::MergeGraphOp::mergeOnce(), and osg::GraphOp::removeFromExcludeList().

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

Definition at line 162 of file OSGGraphOp.h.

Referenced by osg::GraphOp::addToExcludeList(), osg::GraphOp::clearExcludeList(), osg::GraphOp::isInExcludeListNames(), and osg::GraphOp::removeFromExcludeList().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:14:08 2005 for OpenSG by  doxygen 1.4.3