@@ -152,10 +152,94 @@ bool GeoDataLoader::init()
152152
153153 geoDataMenu = new ui::Menu (" GeoData" , this );
154154 geoDataMenu->setText (" GeoData" );
155+ terrainMenu = new ui::Menu (geoDataMenu, " Terrain" );
156+ terrainMenu->setText (" Terrain" );
157+ buildingMenu = new ui::Menu (geoDataMenu, " Buildings" );
158+ buildingMenu->setText (" Buildings" );
155159 rootNode = new osg::MatrixTransform ();
156160 skyRootNode = new osg::MatrixTransform ();
157161 cover->getObjectsRoot ()->addChild (rootNode);
158162 cover->getScene ()->addChild (skyRootNode);
163+
164+ // create Button for each terrain file in config
165+ std::map<std::string, ui::Button*> terrainButtons;
166+ std::map<std::string, ui::Button*> buildingButtons;
167+
168+ auto configFile = config ();
169+ auto terrainFiles = configFile->entries (" terrain" );
170+
171+ for (const auto & terrainFile : terrainFiles)
172+ {
173+ std::vector<std::string> defaultArray = {" " , " " , " " };
174+ std::vector<std::string> terrainArray = configStringArray (" terrain" , terrainFile, defaultArray)->value ();
175+
176+ std::string terrain_name = terrainArray[0 ];
177+ std::string terrain_path = terrainArray[1 ];
178+ std::string lod_path = terrainArray[2 ];
179+
180+ if (terrain_path != " " )
181+ {
182+ ui::Button* terrainButton = new ui::Button (terrainMenu, terrain_name);
183+ terrainButton->setText (terrain_name);
184+ terrainButton->setState (false );
185+ terrainButton->setCallback ([this , terrain_path, terrain_name](bool state)
186+ {
187+ if (state)
188+ {
189+ if (loadedTerrains.find (terrain_name) == loadedTerrains.end ())
190+ {
191+ osg::ref_ptr<osg::Node> terrainNode = loadTerrain (terrain_path,osg::Vec3d (0 ,0 ,0 ));
192+ if (terrainNode)
193+ {
194+ loadedTerrains[terrain_name] = terrainNode;
195+ rootNode->addChild (terrainNode);
196+ }
197+ }
198+ }
199+ else
200+ {
201+ if (loadedTerrains.find (terrain_name) != loadedTerrains.end ())
202+ {
203+ rootNode->removeChild (loadedTerrains[terrain_name]);
204+ loadedTerrains.erase (terrain_name);
205+ }
206+ }
207+ });
208+ terrainButtons[terrain_name] = terrainButton;
209+ }
210+
211+ if (lod_path != " " )
212+ {
213+ ui::Button* buildingButton = new ui::Button (buildingMenu, terrain_name);
214+ buildingButton->setText (terrain_name);
215+ buildingButton->setState (false );
216+ buildingButton->setCallback ([this , lod_path, terrain_name](bool state)
217+ {
218+ if (state)
219+ {
220+ if (loadedBuildings.find (terrain_name) == loadedBuildings.end ())
221+ {
222+ osg::ref_ptr<osg::Node> buildingNode = loadTerrain (lod_path,osg::Vec3d (0 ,0 ,0 ));
223+ if (buildingNode)
224+ {
225+ loadedBuildings[terrain_name] = buildingNode;
226+ rootNode->addChild (buildingNode);
227+ }
228+ }
229+ }
230+ else
231+ {
232+ if (loadedBuildings.find (terrain_name) != loadedBuildings.end ())
233+ {
234+ rootNode->removeChild (loadedBuildings[terrain_name]);
235+ loadedBuildings.erase (terrain_name);
236+ }
237+ }
238+ });
239+ buildingButtons[terrain_name] = buildingButton;
240+ }
241+ }
242+
159243 // Restart Button
160244 skyButton = new ui::Button (geoDataMenu, " Sky" );
161245 skyButton->setText (" Sky" );
@@ -209,9 +293,6 @@ bool GeoDataLoader::init()
209293 std::string coord = getCoordinates (val);
210294 parseCoordinates (coord);
211295 });
212-
213- terrainFile = configString (" terrain" ," file" , " D:/QSync/visnas/Data/Suedlink/out/vpb_DGM1m_FDOP20/vpb_DGM1m_FDOP20.ive" )->value ();
214- loadTerrain (terrainFile,osg::Vec3d (0 ,0 ,0 ));
215296 return true ;
216297}
217298
@@ -275,7 +356,7 @@ GeoDataLoader *GeoDataLoader::instance()
275356}
276357
277358
278- bool GeoDataLoader::loadTerrain (std::string filename, osg::Vec3d offset)
359+ osg::ref_ptr<osg::Node> GeoDataLoader::loadTerrain (std::string filename, osg::Vec3d offset)
279360{
280361 VRViewer *viewer = VRViewer::instance ();
281362 osgDB::DatabasePager *pager = viewer->getDatabasePager ();
@@ -354,16 +435,14 @@ bool GeoDataLoader::loadTerrain(std::string filename, osg::Vec3d offset)
354435 terrainTransform->addChild (terrain);
355436 terrainTransform->setPosition (-offset);
356437
357- rootNode->addChild (terrainTransform);
358-
359438 const osg::BoundingSphere &terrainBS = terrain->getBound ();
360439 std::cout << " Terrain BB: center: (" << terrainBS.center ()[0 ] << " , " << terrainBS.center ()[1 ] << " , " << terrainBS.center ()[2 ] << " ), radius: " << terrainBS.radius () << std::endl;
361440
362- return true ;
441+ return terrainTransform ;
363442 }
364443 else
365444 {
366- return false ;
445+ return nullptr ;
367446 }
368447}
369448
0 commit comments