Changeset 7003
- Timestamp:
- 06/18/07 14:10:46
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/examples/osgterrain/osgterrain.cpp
r6941 r7003 43 43 #include <osgGA/TerrainManipulator> 44 44 45 46 45 #include <osgTerrain/TerrainNode> 47 46 #include <osgTerrain/GeometryTechnique> … … 50 49 #include <iostream> 51 50 51 class OSGVIEWER_EXPORT FilterHandler : public osgGA::GUIEventHandler 52 { 53 public: 54 55 FilterHandler(osgTerrain::GeometryTechnique* gt): 56 _gt(gt) {} 57 58 bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) 59 { 60 if (!_gt) return false; 61 62 switch(ea.getEventType()) 63 { 64 case(osgGA::GUIEventAdapter::KEYDOWN): 65 { 66 if (ea.getKey() == 'g') 67 { 68 osg::notify(osg::NOTICE)<<"Gaussian"<<std::endl; 69 _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::GAUSSIAN); 70 return true; 71 } 72 else if (ea.getKey() == 's') 73 { 74 osg::notify(osg::NOTICE)<<"Smooth"<<std::endl; 75 _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::SMOOTH); 76 return true; 77 } 78 else if (ea.getKey() == 'S') 79 { 80 osg::notify(osg::NOTICE)<<"Sharpen"<<std::endl; 81 _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::SHARPEN); 82 return true; 83 } 84 else if (ea.getKey() == '+') 85 { 86 _gt->setFilterWidth(_gt->getFilterWidth()*1.1); 87 return true; 88 } 89 else if (ea.getKey() == '-') 90 { 91 _gt->setFilterWidth(_gt->getFilterWidth()/1.1); 92 return true; 93 } 94 break; 95 } 96 default: 97 break; 98 } 99 return false; 100 101 } 102 103 protected: 104 105 osg::observer_ptr<osgTerrain::GeometryTechnique> _gt; 106 107 }; 52 108 53 109 … … 58 114 59 115 // construct the viewer. 60 osgViewer::Viewer viewer ;116 osgViewer::Viewer viewer(arguments); 61 117 62 118 // set up the camera manipulators. … … 92 148 // add the stats handler 93 149 viewer.addEventHandler(new osgViewer::StatsHandler); 150 151 // add the record camera path handler 152 viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 153 94 154 95 155 double x = 0.0; … … 255 315 terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::NEAREST); 256 316 } 257 else if (filterName=="LINEA ER")317 else if (filterName=="LINEAR") 258 318 { 259 319 osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl; … … 299 359 terrain->setTerrainTechnique(geometryTechnique.get()); 300 360 361 viewer.addEventHandler(new FilterHandler(geometryTechnique.get())); 362 301 363 if (!terrain) return 0; 302 364 OpenSceneGraph/trunk/include/osgTerrain/GeometryTechnique
r6566 r7003 107 107 108 108 virtual void dirty(); 109 110 111 112 void setFilterWidth(float filterWidth); 113 float getFilterWidth() const { return _filterWidth; } 114 115 void setFilterMatrix(const osg::Matrix3& matrix); 116 osg::Matrix3& getFilterMatrix() { return _filterMatrix; } 117 const osg::Matrix3& getFilterMatrix() const { return _filterMatrix; } 118 119 enum FilterType 120 { 121 GAUSSIAN, 122 SMOOTH, 123 SHARPEN 124 }; 125 126 void setFilterMatrixAs(FilterType filterType); 127 109 128 110 129 protected: … … 117 136 osg::ref_ptr<TerrainGeometry> _terrainGeometry; 118 137 osg::ref_ptr<osg::Geometry> _geometry; 138 139 float _filterWidth; 140 osg::ref_ptr<osg::Uniform> _filterWidthUniform; 141 osg::Matrix3 _filterMatrix; 142 osg::ref_ptr<osg::Uniform> _filterMatrixUniform; 119 143 }; 120 144 OpenSceneGraph/trunk/src/osgTerrain/GeometryTechnique.cpp
r6655 r7003 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 3 * This library is open source and may be redistributed and/or modified under … … 30 30 GeometryTechnique::GeometryTechnique() 31 31 { 32 setFilterWidth(0.1); 33 setFilterMatrixAs(GAUSSIAN); 32 34 } 33 35 … … 40 42 { 41 43 } 44 45 void GeometryTechnique::setFilterWidth(float filterWidth) 46 { 47 _filterWidth = filterWidth; 48 if (!_filterWidthUniform) _filterWidthUniform = new osg::Uniform("filterWidth",_filterWidth); 49 else _filterWidthUniform->set(filterWidth); 50 } 51 52 void GeometryTechnique::setFilterMatrix(const osg::Matrix3& matrix) 53 { 54 _filterMatrix = matrix; 55 if (!_filterMatrixUniform) _filterMatrixUniform = new osg::Uniform("filterMatrix",_filterMatrix); 56 else _filterMatrixUniform->set(_filterMatrix); 57 } 58 59 void GeometryTechnique::setFilterMatrixAs(FilterType filterType) 60 { 61 switch(filterType) 62 { 63 case(SMOOTH): 64 setFilterMatrix(osg::Matrix3(0.0, 0.5/2.5, 0.0, 65 0.5/2.5, 0.5/2.5, 0.5/2.5, 66 0.0, 0.5/2.5, 0.0)); 67 break; 68 case(GAUSSIAN): 69 setFilterMatrix(osg::Matrix3(0.0, 1.0/8.0, 0.0, 70 1.0/8.0, 4.0/8.0, 1.0/8.0, 71 0.0, 1.0/8.0, 0.0)); 72 break; 73 case(SHARPEN): 74 setFilterMatrix(osg::Matrix3(0.0, -1.0, 0.0, 75 -1.0, 5.0, -1.0, 76 0.0, -1.0, 0.0)); 77 break; 78 79 }; 80 } 81 42 82 43 83 void GeometryTechnique::init() … … 418 458 419 459 // get shaders from source 420 std::string vertexShaderFile = osgDB::findDataFile(" lookup.vert");460 std::string vertexShaderFile = osgDB::findDataFile("shaders/lookup.vert"); 421 461 if (!vertexShaderFile.empty()) 422 462 { … … 428 468 } 429 469 430 std::string fragmentShaderFile = osgDB::findDataFile(" lookup.frag");470 std::string fragmentShaderFile = osgDB::findDataFile("shaders/lookup.frag"); 431 471 if (!fragmentShaderFile.empty()) 432 472 { … … 443 483 osg::Uniform* lookupTexture = new osg::Uniform("lookupTexture",tf_index); 444 484 stateset->addUniform(lookupTexture); 485 486 stateset->addUniform(_filterWidthUniform.get()); 487 stateset->addUniform(_filterMatrixUniform.get()); 488 489 osg::Uniform* lightingEnabled = new osg::Uniform("lightingEnabled",true); 490 stateset->addUniform(lightingEnabled); 445 491 446 492 osg::Uniform* minValue = new osg::Uniform("minValue", tf->getMinimum()); … … 478 524 void GeometryTechnique::update(osgUtil::UpdateVisitor* nv) 479 525 { 526 480 527 } 481 528
