Changeset 7840
- Timestamp:
- 01/28/08 17:13:42
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/src/osgPlugins/ogr/ReaderWriterOGR.cpp
r7827 r7840 37 37 #include <ogrsf_frmts.h> 38 38 39 //#include <iostream> 40 41 #define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) 39 #define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) 42 40 43 41 static osg::Material* createDefaultMaterial() … … 82 80 class ReaderWriterOGR : public osgDB::ReaderWriter 83 81 { 82 84 83 public: 84 ReaderWriterOGR() {} 85 85 virtual const char* className() const { return "OGR file reader"; } 86 86 virtual bool acceptsExtension(const std::string& extension) const … … 114 114 return 0; 115 115 116 bool useRandomColorByFeature = false; 117 if (options) 118 { 119 if (options->getOptionString() == "UseRandomColorByFeature") 120 useRandomColorByFeature = true; 121 } 122 116 123 osg::Group* group = new osg::Group; 117 124 118 125 for (int i = 0; i < file->GetLayerCount(); i++) 119 126 { 120 osg::Group* node = readLayer(file->GetLayer(i), file->GetName() );127 osg::Group* node = readLayer(file->GetLayer(i), file->GetName(), useRandomColorByFeature); 121 128 if (node) 122 129 group->addChild( node ); … … 126 133 } 127 134 128 osg::Group* readLayer(OGRLayer* ogrLayer, const std::string& name ) const135 osg::Group* readLayer(OGRLayer* ogrLayer, const std::string& name, bool useRandomColorByFeature) const 129 136 { 130 137 if (!ogrLayer) … … 138 145 while ((ogrFeature = ogrLayer->GetNextFeature()) != NULL) 139 146 { 140 osg::Geode* feature = readFeature(ogrFeature );147 osg::Geode* feature = readFeature(ogrFeature, useRandomColorByFeature); 141 148 if (feature) 142 149 layer->addChild(feature); … … 321 328 } 322 329 323 osg::Geode* readFeature(OGRFeature* ogrFeature ) const330 osg::Geode* readFeature(OGRFeature* ogrFeature, bool useRandomColorByFeature) const 324 331 { 325 332 … … 388 395 geode->setCullingActive(false); // because culling on one points geode is always true, so i disable it 389 396 geode->addDrawable(drawable); 390 geode->getOrCreateStateSet()->setAttributeAndModes(createDefaultMaterial(),true); 397 if (useRandomColorByFeature) 398 geode->getOrCreateStateSet()->setAttributeAndModes(createDefaultMaterial(),true); 391 399 for(int i = 0; i < ogrFeature->GetFieldCount(); i++) { 392 400 geode->addDescription(std::string(ogrFeature->GetFieldDefnRef(i)->GetNameRef()) + " : " + std::string(ogrFeature->GetFieldAsString(i)));
