osgEarth 2.1.1

/home/cube/sources/osgearth/src/applications/osgearth_symbology/osgearth_symbology.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003 * Copyright 2008-2009 Pelican Ventures, Inc.
00004 * http://osgearth.org
00005 *
00006 * osgEarth is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU Lesser General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU Lesser General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU Lesser General Public License
00017 * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018 */
00019 
00020 
00021 #include <sstream>
00022 #include <osg/Notify>
00023 #include <osgGA/StateSetManipulator>
00024 #include <osgGA/GUIEventHandler>
00025 #include <osgGA/TrackballManipulator>
00026 #include <osgDB/FileNameUtils>
00027 #include <osgViewer/Viewer>
00028 #include <osgViewer/ViewerEventHandlers>
00029 #include <osgDB/ReadFile>
00030 #include <osgEarthSymbology/GeometryExtrudeSymbolizer>
00031 #include <osgEarthSymbology/GeometrySymbolizer>
00032 #include <osgEarthSymbology/Style>
00033 #include <osgEarthSymbology/SymbolicNode>
00034 #include <osgEarthSymbology/MarkerSymbol>
00035 #include <osgEarthSymbology/MarkerSymbolizer>
00036 #include <osgEarthSymbology/ExtrudedSymbol>
00037 #include <osgEarthSymbology/ModelSymbolizer>
00038 #include <osgEarthUtil/Popups>
00039 //#include <osgEarthUtil/PopupManager>
00040 //#include <osgEarthUtil/TextPopup>
00041 //#include <osgEarthUtil/WidgetIcon>
00042 //#include <osgEarthUtil/WidgetNode>
00043 #include <osg/MatrixTransform>
00044 #include <osg/Geometry>
00045 #include <osgUtil/Tessellator>
00046 #include <osg/LineWidth>
00047 #include <osg/Point>
00048 #include <osg/Material>
00049 
00050 using namespace osgEarth::Symbology;
00051 using namespace osgEarthUtil;
00052 
00053 static double getRandomValueInOne()
00054 {
00055     return ((rand() * 1.0)/(RAND_MAX-1));
00056 }
00057 
00058 
00059 Geometry* createLineGeometry(const osg::Vec3d& start)
00060 {
00061     osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
00062     array->push_back(start + osg::Vec3d(-100,-100,0));
00063     array->push_back(start + osg::Vec3d(100,-100,0));
00064     array->push_back(start + osg::Vec3d(100,100,0));
00065     array->push_back(start + osg::Vec3d(-100,100,0));
00066     return Geometry::create(Geometry::TYPE_LINESTRING, array);
00067 }
00068 
00069 Geometry* createRingGeometry(const osg::Vec3d& start)
00070 {
00071     osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
00072     array->push_back(start + osg::Vec3d(-100,-100,0));
00073     array->push_back(start + osg::Vec3d(100,-100,0));
00074     array->push_back(start + osg::Vec3d(100,100,0));
00075     array->push_back(start + osg::Vec3d(-100,100,0));
00076     return Geometry::create(Geometry::TYPE_RING, array);
00077 }
00078 
00079 
00080 Geometry* createPolygonGeometry(const osg::Vec3d& start)
00081 {
00082     osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
00083     array->push_back(start + osg::Vec3d(-100,-100,0));
00084     array->push_back(start + osg::Vec3d(-10,-10,0));
00085     array->push_back(start + osg::Vec3d(100,-100,0));
00086     array->push_back(start + osg::Vec3d(100,100,0));
00087     array->push_back(start + osg::Vec3d(-100,100,0));
00088     return Geometry::create(Geometry::TYPE_POLYGON, array);
00089 }
00090 
00091 
00092 Geometry* createPointsGeometry(const osg::Vec3d& start)
00093 {
00094     osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
00095     array->push_back(start + osg::Vec3d(-100,-100,0));
00096     array->push_back(start + osg::Vec3d(100,-100,0));
00097     array->push_back(start + osg::Vec3d(100,100,0));
00098     array->push_back(start + osg::Vec3d(-100,100,0));
00099     return Geometry::create(Geometry::TYPE_POINTSET, array);
00100 }
00101 
00102 struct SampleGeometryInput : public GeometryContent
00103 {
00104     SampleGeometryInput()
00105     {
00106         // points
00107         {
00108         _geometryList.push_back(createPointsGeometry(osg::Vec3d(-250,0,0)));
00109         }
00110 
00111         // ring
00112         {
00113         _geometryList.push_back(createRingGeometry(osg::Vec3d(0,0,0)));
00114         }
00115 
00116         // line
00117         {
00118         _geometryList.push_back(createLineGeometry(osg::Vec3d(250,0,0)));
00119         }
00120 
00121         // polygon
00122         {
00123         _geometryList.push_back(createPolygonGeometry(osg::Vec3d(500,0,0)));
00124         }
00125     }
00126 };
00127 
00128 
00129 struct PopUpSymbolizerContext : public SymbolizerContext
00130 {
00131     typedef std::vector<osg::ref_ptr<TextPopup> > TextPopupList;
00132 
00133     PopUpSymbolizerContext(PopupManager* windowmanager)  : _wm(windowmanager) {}
00134     osg::ref_ptr<PopupManager> _wm;
00135     TextPopupList _widgetList;
00136 };
00137 
00138 
00139 
00140 struct PopUpSymbolizer : public Symbolizer< State<GeometryContent> >
00141 {
00142     static int PopUpIndex;
00143 
00144     bool compile(State<GeometryContent>* state,
00145                  osg::Group* attachPoint)
00146     {
00147         if ( !state || !attachPoint || !state->getContent() || !state->getStyle() )
00148             return false;
00149 
00150         PopUpSymbolizerContext* ctx = dynamic_cast<PopUpSymbolizerContext*>( state->getContext() );
00151         if (!ctx)
00152             return false;
00153 
00154         osg::ref_ptr<osg::Group> newSymbolized = new osg::Group;
00155 
00156         const GeometryList& geometryList = state->getContent()->getGeometryList();
00157         for (GeometryList::const_iterator it = geometryList.begin(); it != geometryList.end(); ++it)
00158         {
00159             Geometry* geometry = *it;
00160             if (!geometry)
00161                 continue;
00162 
00163             osg::ref_ptr<osg::Geometry> osgGeom = new osg::Geometry;
00164             switch( geometry->getType())
00165             {
00166             case Geometry::TYPE_POINTSET:
00167             case Geometry::TYPE_LINESTRING:
00168             case Geometry::TYPE_RING:
00169             case Geometry::TYPE_POLYGON:
00170             {
00171                 const PopupSymbol* symbol = state->getStyle()->getSymbol<PopupSymbol>();
00172                 if (symbol)
00173                 {
00174                     //osg::Image* image = 0;
00175                     //if (!symbol->theme()->empty())
00176                     //    image = osgDB::readImageFile(symbol->theme().value());
00177                     //osgText::Font* font = 0;
00178                     //if (!symbol->font()->empty())
00179                     //    font = osgText::readFontFile(symbol->font().value());
00180                     //float size = symbol->size().value();
00181                     //osg::Vec4 color = symbol->fill()->color();
00182                     
00183                     for ( osg::Vec3dArray::iterator it = geometry->begin(); it != geometry->end(); ++it)
00184                     {
00185                         osg::MatrixTransform* transform = new osg::MatrixTransform;
00186                         transform->setMatrix(osg::Matrix::translate(*it));
00187                         if (!PopUpIndex) {
00188                             std::stringstream ss;
00189                             ss << "Hit i Key to see more popup" << std::endl;
00190                             ss << "And hit a second time to hide them" << std::endl;
00191                             std::string text = ss.str();
00192                             std::string title = "Info";
00193 
00194                             TextPopup* popup = ctx->_wm->createTextPopup(title, text, symbol);
00195                             //popup->setFocusColor(osg::Vec4(getRandomValueInOne(), getRandomValueInOne() , getRandomValueInOne(), 1.0));
00196                             popup->attach(transform);
00197                             popup->setAppear();
00198 
00199                         } else {
00200                             std::stringstream ss;
00201                             ss << "osgEarth" << std::endl;
00202                             ss << "rocks at " << *it << " miles" << std::endl;
00203                             std::string text = ss.str();
00204                             std::string title = "osgEarthUtil";
00205                             TextPopup* popup = ctx->_wm->createTextPopup(title, text, symbol);
00206                             //popup->setFocusColor(osg::Vec4(getRandomValueInOne(), getRandomValueInOne() , getRandomValueInOne(), 1.0));
00207                             popup->attach(transform);
00208                             ctx->_widgetList.push_back(popup);
00209                         }
00210                         PopUpIndex++;
00211                         newSymbolized->addChild(transform);
00212                         transform->addChild(osgDB::readNodeFile("../data/tree.ive"));
00213                     }
00214                 }
00215             }
00216             break;
00217             }
00218         }
00219 
00220         if (newSymbolized->getNumChildren()) 
00221         {
00222             attachPoint->removeChildren(0, attachPoint->getNumChildren());
00223             attachPoint->addChild(newSymbolized.get());
00224             return true;
00225         }
00226 
00227         return false;
00228     }
00229 };
00230 int PopUpSymbolizer::PopUpIndex = 0;
00231 
00232 struct PolygonPointSizeSymbol : public PolygonSymbol
00233 {
00234     PolygonPointSizeSymbol() : _size (1.0) {}
00235     float& size() { return _size; }
00236     const float& size() const { return _size; }
00237 
00238 protected:
00239     float _size;
00240 };
00241 
00242 struct GeometryPointSymbolizer : public GeometrySymbolizer
00243 {
00244     bool update(State<GeometryContent>* state,
00245                 osg::Group* attachPoint,
00246                 SymbolizerContext* context )
00247     {
00248         if ( !state || !attachPoint || !state->getContent() || !state->getStyle() )
00249             return false;
00250 
00251         osg::ref_ptr<osg::Group> newSymbolized = new osg::Group;
00252         osg::ref_ptr<osg::Geode> geode = new osg::Geode;
00253         newSymbolized->addChild(geode.get());
00254 
00255         const GeometryList& geometryList = state->getContent()->getGeometryList();
00256         for (GeometryList::const_iterator it = geometryList.begin(); it != geometryList.end(); ++it)
00257         {
00258             Geometry* geometry = *it;
00259             if (!geometry)
00260                 continue;
00261 
00262             osg::ref_ptr<osg::Geometry> osgGeom = new osg::Geometry;
00263             osg::PrimitiveSet::Mode primMode = osg::PrimitiveSet::POINTS;
00264 
00265             osg::Vec4 color = osg::Vec4(1.0, 0.0, 1.0, 1.);
00266 
00267             switch( geometry->getType())
00268             {
00269             case Geometry::TYPE_POINTSET:
00270             {
00271                 primMode = osg::PrimitiveSet::POINTS;
00272                 const PointSymbol* point = state->getStyle()->getSymbol<PointSymbol>();
00273                 if (point)
00274                 {
00275                     color = point->fill()->color();
00276 
00277                     float size = point->size().value();
00278                     osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::Point(size) );
00279                 }
00280             }
00281             break;
00282 
00283             case Geometry::TYPE_LINESTRING:
00284             {
00285                 primMode = osg::PrimitiveSet::LINE_STRIP;
00286                 const LineSymbol* line = state->getStyle()->getSymbol<LineSymbol>();
00287                 if (line) 
00288                 {
00289                     color = line->stroke()->color();
00290                     float size = line->stroke()->width().value();
00291                     osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::LineWidth(size));
00292                 }
00293             }
00294             break;
00295 
00296             case Geometry::TYPE_RING:
00297             {
00298                 primMode = osg::PrimitiveSet::LINE_LOOP;
00299                 const LineSymbol* line = state->getStyle()->getSymbol<LineSymbol>();
00300                 if (line)
00301                 {
00302                     color = line->stroke()->color();
00303                     float size = line->stroke()->width().value();
00304                     osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::LineWidth(size));
00305                 }
00306             }
00307             break;
00308 
00309             case Geometry::TYPE_POLYGON:
00310             {
00311                 // use polygon as point for this specific symbolizer
00312                 // it would be simpler to use the symbol style->getPoint but here
00313                 // we want to dmonstrate how to customize Symbol and Symbolizer
00314                 primMode = osg::PrimitiveSet::POINTS;
00315                 const PolygonPointSizeSymbol* poly = state->getStyle()->getSymbol<PolygonPointSizeSymbol>();
00316                 if (poly)
00317                 {
00318                     color = poly->fill()->color();
00319 
00320                     float size = poly->size();
00321                     osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::Point(size) );
00322                 }
00323             }
00324             break;
00325             }
00326 
00327             osg::Material* material = new osg::Material;
00328             material->setDiffuse(osg::Material::FRONT_AND_BACK, color);
00329 
00330             osgGeom->setVertexArray( geometry->toVec3Array() );
00331             osgGeom->addPrimitiveSet( new osg::DrawArrays( primMode, 0, geometry->size() ) );
00332 
00333             osgGeom->getOrCreateStateSet()->setAttributeAndModes(material);
00334             osgGeom->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
00335             geode->addDrawable(osgGeom);
00336 
00337         }
00338 
00339         if (geode->getNumDrawables()) 
00340         {
00341             attachPoint->removeChildren(0, attachPoint->getNumChildren());
00342             attachPoint->addChild(newSymbolized.get());
00343             return true;
00344         }
00345 
00346         return false;
00347     }
00348 };
00349 
00350 
00351 
00352 class StyleEditor : public osgGA::GUIEventHandler
00353 {
00354 public:
00355     osg::ref_ptr<PopUpSymbolizerContext> _popupContext;
00356     int _state;
00357 
00358     StyleEditor(const ::StyleList& styles) : _styles(styles)
00359     {
00360         _state = 0;
00361     }
00362 
00363     void setPopupContext(PopUpSymbolizerContext* context) { _popupContext = context; }
00364     
00365     virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
00366     {
00367         switch(ea.getEventType())
00368         {
00369         case(osgGA::GUIEventAdapter::KEYUP):
00370         {
00371             if (ea.getKey() == 'i') {
00372                 if (_popupContext.valid()) {
00373                     for (int i = 0; i < _popupContext->_widgetList.size(); ++i) {
00374                         if (_state) {
00375                             _popupContext->_widgetList[i]->setDisappear();
00376                         } else { 
00377                             _popupContext->_widgetList[i]->setAppear();
00378                         }
00379                     }
00380                     if (_state)
00381                         _state = 0;
00382                     else 
00383                         _state = 1;
00384                 }
00385                 return true;
00386             } else if (ea.getKey() == 'q') {
00387                 osgEarth::Symbology::Style* style = _styles[0].get();
00388                 PolygonSymbol* p = style->getSymbol<PolygonSymbol>();
00389                 if (p)
00390                 {
00391                     osg::Vec4 color = p->fill()->color();
00392                     color[0] = fmod(color[0]+0.5, 1.0);
00393                     color[2] = fmod(1 + color[0]-0.3, 1.0);
00394                     p->fill()->color() = color;
00395                     style->dirty();
00396                 }
00397                 return true;
00398             } else if (ea.getKey() == 'a') {
00399                 Style* style = _styles[1].get();
00400                 PolygonPointSizeSymbol* p = style->getSymbol<PolygonPointSizeSymbol>();
00401                 if (p)
00402                 {
00403                     osg::Vec4 color = p->fill()->color();
00404                     color[0] = fmod(color[0]+0.5, 1.0);
00405                     color[2] = fmod(1 + color[0]-0.3, 1.0);
00406                     p->fill()->color() = color;
00407                     p->size() = 0.1 + color[2] * 10;
00408                     style->dirty();
00409                 }
00410                 return true;
00411             } else if (ea.getKey() == 'z') {
00412                 Style* style = _styles[2].get();
00413                 ExtrudedLineSymbol* l = style->getSymbol<ExtrudedLineSymbol>();
00414                 if (l)
00415                 {
00416                     osg::Vec4 color = l->stroke()->color();
00417                     color[0] = fmod(color[0]+0.5, 1.0);
00418                     color[2] = fmod(1 + color[0]-0.3, 1.0);
00419                     l->stroke()->color() = color;
00420                     l->extrude()->height() = l->extrude()->height() + 200;
00421                 }
00422                 ExtrudedPolygonSymbol* p = style->getSymbol<ExtrudedPolygonSymbol>();
00423                 if (p)
00424                 {
00425                     osg::Vec4 color = p->fill()->color();
00426                     color[0] = fmod(color[0]+0.5, 1.0);
00427                     color[2] = fmod(1 + color[0]-0.3, 1.0);
00428                     p->fill()->color() = color;
00429                     p->extrude()->height() = p->extrude()->height() + 50;
00430                 }
00431                 style->dirty();
00432                 return true;
00433 
00434             } else if (ea.getKey() == 'x') {
00435                 Style* style = _styles[3].get();
00436                 MarkerLineSymbol* l = style->getSymbol<MarkerLineSymbol>();
00437                 if (l)
00438                 {
00439                     if (l->interval().value() < 10)
00440                         l->interval() = 15;
00441                     else
00442                         l->interval() = 5;
00443                 }
00444 
00445                 MarkerPolygonSymbol* p = style->getSymbol<MarkerPolygonSymbol>();
00446                 if (p)
00447                 {
00448                     if (p->interval().value() < 10) {
00449                         p->interval() = 15;
00450                         p->randomRatio() = 0.1;
00451                     } else {
00452                         p->interval() = 5;
00453                         p->randomRatio() = 0.9;
00454                     }
00455                 }
00456                 style->dirty();
00457                 return true;
00458             }
00459         }
00460         break;
00461         }
00462         return false;
00463     }
00464     
00465     ::StyleList _styles;
00466 };
00467 
00468 
00469 typedef SymbolicNode< State<GeometryContent> > GeometrySymbolicNode;
00470 
00471 
00472 osg::Group* createSymbologyScene(PopupManager* wm)
00473 {
00474     osg::Group* grp = new osg::Group;
00475 
00476     osg::ref_ptr<SampleGeometryInput> dataset = new SampleGeometryInput;
00477     StyleList styles;
00478 
00479     {
00480         osg::ref_ptr<Style> style = new Style;
00481         style->setName("PolygonSymbol-color");
00482         osg::ref_ptr<PolygonSymbol> polySymbol = new PolygonSymbol;
00483         polySymbol->fill()->color() = osg::Vec4(0,1,1,1);
00484         style->addSymbol(polySymbol.get());
00485         styles.push_back(style.get());
00486     }
00487 
00488     {
00489         osg::ref_ptr<Style> style = new Style;
00490         style->setName("Custom-PolygonPointSizeSymbol-size&color");
00491         osg::ref_ptr<PolygonPointSizeSymbol> polySymbol = new PolygonPointSizeSymbol;
00492         polySymbol->fill()->color() = osg::Vec4(1,0,0,1);
00493         polySymbol->size() = 2.0;
00494         style->addSymbol(polySymbol.get());
00495         styles.push_back(style.get());
00496     }
00497 
00498 
00499     // style for extruded
00500     {
00501         osg::ref_ptr<Style> style = new Style;
00502         style->setName("Extrude-Polygon&Line-height&color");
00503         osg::ref_ptr<ExtrudedPolygonSymbol> polySymbol = new ExtrudedPolygonSymbol;
00504         polySymbol->fill()->color() = osg::Vec4(1,0,0,1);
00505         polySymbol->extrude()->height() = 100;
00506         polySymbol->extrude()->offset() = 10;
00507         style->addSymbol(polySymbol.get());
00508 
00509         osg::ref_ptr<ExtrudedLineSymbol> lineSymbol = new ExtrudedLineSymbol;
00510         lineSymbol->stroke()->color() = osg::Vec4(0,0,1,1);
00511         lineSymbol->extrude()->height() = 150;
00512         lineSymbol->extrude()->offset() = 10;
00513         style->addSymbol(lineSymbol.get());
00514         styles.push_back(style.get());
00515     }
00516 
00517 
00518     // style for marker
00519     {
00520         osg::ref_ptr<Style> style = new Style;
00521         style->setName("Marker");
00522         osg::ref_ptr<MarkerSymbol> pointSymbol = new MarkerSymbol;
00523         pointSymbol->marker() = "../data/tree.ive";
00524         style->addSymbol(pointSymbol.get());
00525 
00526         osg::ref_ptr<MarkerLineSymbol> lineSymbol = new MarkerLineSymbol;
00527         lineSymbol->marker() = "../data/tree.ive";
00528         lineSymbol->interval() = 5;
00529         style->addSymbol(lineSymbol.get());
00530 
00531         osg::ref_ptr<MarkerPolygonSymbol> polySymbol = new MarkerPolygonSymbol;
00532         polySymbol->marker() = "../data/tree.ive";
00533         polySymbol->interval() = 20;
00534         polySymbol->randomRatio() = 1.0;
00535         style->addSymbol(polySymbol.get());
00536 
00537         styles.push_back(style.get());
00538     }
00539 
00540 
00541     // style for popup
00542     {
00543         osg::ref_ptr<Style> style = new Style;
00544         style->setName("Popup");
00545         osg::ref_ptr<TextSymbol> symbol = new TextSymbol;
00546         //symbol->theme() = "../data/popup-theme.png";
00547         symbol->font() = "arial.ttf";
00548         symbol->size() = 14;
00549         symbol->fill()->color() = osg::Vec4(getRandomValueInOne(), getRandomValueInOne() , getRandomValueInOne(), 0.7);
00550         style->addSymbol(symbol.get());
00551         styles.push_back(style.get());
00552     }
00553 
00554 
00556     {
00557         GeometrySymbolicNode* node = new GeometrySymbolicNode();
00558         node->setSymbolizer( new GeometrySymbolizer() );
00559 
00560         node->getState()->setStyle( styles[0].get() );
00561         node->getState()->setContent( dataset.get() );
00562 
00563         osg::MatrixTransform* tr = new osg::MatrixTransform;
00564         tr->setMatrix(osg::Matrix::translate(0, -250 , 0));
00565         tr->addChild(node);
00566         grp->addChild(tr);
00567     }
00568 
00569 
00570     {
00571         GeometrySymbolicNode* node = new GeometrySymbolicNode();
00572         node->setSymbolizer( new GeometryPointSymbolizer() );
00573         node->getState()->setStyle(styles[1].get());
00574         node->getState()->setContent(dataset.get());
00575         osg::MatrixTransform* tr = new osg::MatrixTransform;
00576         tr->addChild(node);
00577         tr->setMatrix(osg::Matrix::translate(0, 0 , 0));
00578         grp->addChild(tr);
00579     }
00580 
00581 
00582     {
00583         GeometrySymbolicNode* node = new GeometrySymbolicNode();
00584         node->setSymbolizer( new GeometryExtrudeSymbolizer() );
00585         node->getState()->setStyle(styles[2].get());
00586         node->getState()->setContent(dataset.get());
00587         osg::MatrixTransform* tr = new osg::MatrixTransform;
00588         tr->addChild(node);
00589         tr->setMatrix(osg::Matrix::translate(0, 250 , 0));
00590         grp->addChild(tr);
00591     }
00592 
00593 
00594     {
00595         GeometrySymbolicNode* node = new GeometrySymbolicNode();
00596         node->setSymbolizer( new MarkerSymbolizer() );
00597         node->getState()->setStyle(styles[3].get());
00598         node->getState()->setContent(dataset.get());
00599         osg::MatrixTransform* tr = new osg::MatrixTransform;
00600         tr->addChild(node);
00601         tr->setMatrix(osg::Matrix::translate(0, 500 , 0));
00602         grp->addChild(tr);
00603     }
00604 
00605 
00606 
00607     //{
00608     //    osg::ref_ptr<ModelSymbolizer> symbolizer = new ModelSymbolizer();
00609     //    osg::ref_ptr<SymbolicNode> node = new SymbolicNode;
00610     //    node->setSymbolizer(symbolizer.get());
00611     //    Style* style = new Style;
00612     //    std::string real = osgDB::getRealPath("../data/tree.ive");
00613     //    MarkerSymbol* marker = new MarkerSymbol;
00614     //    marker->marker() = real;
00615     //    node->setDataSet(dataset.get());
00616     //    style->addSymbol(marker);
00617     //    node->setStyle(style);
00618     //    osg::MatrixTransform* tr = new osg::MatrixTransform;
00619     //    tr->addChild(node);
00620     //    tr->setMatrix(osg::Matrix::scale(10,10,10) * osg::Matrix::translate(0, 750 , 0));
00621     //    grp->addChild(tr);
00622     //}
00623 
00624     StyleEditor* styleEditor = new StyleEditor(styles);
00625     {
00626         PopUpSymbolizerContext* ctx = new PopUpSymbolizerContext(wm);
00627         styleEditor->setPopupContext(ctx);
00628 
00629         SymbolicNode< State<GeometryContent> >* node = new SymbolicNode< State<GeometryContent> >();
00630         node->setSymbolizer( new PopUpSymbolizer() );
00631         node->getState()->setStyle(styles[4]);
00632         node->getState()->setContent(dataset.get());
00633         node->getState()->setContext(ctx);
00634         osg::MatrixTransform* tr = new osg::MatrixTransform;
00635         tr->addChild(node);
00636         tr->setMatrix(osg::Matrix::translate(0, 1000 , 0));
00637         grp->addChild(tr);
00638     }
00639     
00640     grp->addEventCallback(styleEditor);
00641     return grp;
00642 }
00643 
00644 
00645 
00646 
00647 int main(int argc, char** argv)
00648 {
00649     osg::ArgumentParser arguments(&argc,argv);
00650 
00651     osgViewer::Viewer viewer(arguments);
00652 
00653     // add some stock OSG handlers:
00654     viewer.setCameraManipulator(new osgGA::TrackballManipulator());
00655     viewer.addEventHandler(new osgViewer::StatsHandler());
00656     viewer.addEventHandler(new osgViewer::WindowSizeHandler());
00657     viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
00658     
00659     osg::Group* root = new osg::Group;
00660     viewer.setSceneData(root);
00661     viewer.realize();
00662 
00663     PopupManager* wm = new PopupManager(&viewer);
00664     osg::Node* node = createSymbologyScene(wm);
00665     root->addChild(node);
00666     return viewer.run();
00667 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines