Index: /experimental/osgVisualNG/osgVisualNG.cpp
===================================================================
--- /experimental/osgVisualNG/osgVisualNG.cpp	(revision 417)
+++ /experimental/osgVisualNG/osgVisualNG.cpp	(revision 417)
@@ -0,0 +1,58 @@
+/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
+ *
+ * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under 
+ * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
+ * (at your option) any later version.  The full license is in LICENSE file
+ * included with this distribution, and on the openscenegraph.org website.
+ *
+ * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
+ * You have to aquire licenses for all used proprietary modules.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * OpenSceneGraph Public License for more details.
+*/
+
+const unsigned int MAX_NUM_EVENTS = 10;
+
+#ifdef _DEBUG
+	#ifdef WIN32
+		// Declare this in header.
+		#define _CRTDBG_MAP_ALLOC
+		#include <stdlib.h>
+		#include <crtdbg.h>
+	#endif 
+#endif 
+
+
+//#include <windows.h>
+
+#include <osg/ArgumentParser>
+#include <osg/Referenced>
+#include <osgDB/Registry>
+
+#include <visual_core.h>
+
+
+
+
+int main(int argc, char** argv)
+{
+    // Use an ArgumentParser object to manage the program arguments.
+	osg::ArgumentParser arguments(&argc,argv);
+
+    // Instantiate osgVisual main class
+	osg::ref_ptr<osgVisual::visual_core> core = new osgVisual::visual_core(arguments);
+
+    // Visual initialisieren
+    core->initialize();
+
+	// Shut osgVisual down
+	core->shutdown();
+
+	// Set Pointer to null to destroy the objects before this function ends
+	core = NULL;
+
+	return 0;
+}
Index: /experimental/osgVisualNG/osgVisualNG.vcproj
===================================================================
--- /experimental/osgVisualNG/osgVisualNG.vcproj	(revision 416)
+++ /experimental/osgVisualNG/osgVisualNG.vcproj	(revision 417)
@@ -42,4 +42,5 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
+				AdditionalIncludeDirectories="&quot;$(OSG_ROOT)\include&quot;;D:\OpenSceneGraph\3rdParty_x86_x64\x86\include;."
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 				MinimalRebuild="true"
@@ -115,4 +116,5 @@
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories="&quot;$(OSG_ROOT)\include&quot;;D:\OpenSceneGraph\3rdParty_x86_x64\x86\include;."
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 				RuntimeLibrary="2"
@@ -171,4 +173,16 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
 			>
+			<File
+				RelativePath=".\osgVisualNG.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\visual_core.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\visual_util.cpp"
+				>
+			</File>
 		</Filter>
 		<Filter
@@ -177,4 +191,12 @@
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
 			>
+			<File
+				RelativePath=".\visual_core.h"
+				>
+			</File>
+			<File
+				RelativePath=".\visual_util.h"
+				>
+			</File>
 		</Filter>
 		<Filter
Index: /experimental/osgVisualNG/visual_core.cpp
===================================================================
--- /experimental/osgVisualNG/visual_core.cpp	(revision 417)
+++ /experimental/osgVisualNG/visual_core.cpp	(revision 417)
@@ -0,0 +1,189 @@
+/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
+ *
+ * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under 
+ * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
+ * (at your option) any later version.  The full license is in LICENSE file
+ * included with this distribution, and on the openscenegraph.org website.
+ *
+ * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
+ * You have to aquire licenses for all used proprietary modules.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * OpenSceneGraph Public License for more details.
+*/
+
+
+#include <visual_core.h>
+#include <visual_util.h>
+#include <osgTerrain/Terrain>
+#include <osgDB/FileNameUtils>
+
+using namespace osgVisual;
+
+visual_core::visual_core(osg::ArgumentParser& arguments_) : arguments(arguments_)
+{
+	OSG_NOTIFY( osg::ALWAYS ) << "visual_core instantiated." << std::endl;
+}
+
+visual_core::~visual_core(void)
+{
+	OSG_NOTIFY( osg::ALWAYS ) << "visual_core destroyed." << std::endl;
+}
+
+void visual_core::initialize()
+{
+	OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_core..." << std::endl;
+
+
+	// Configure osg to use KdTrees
+	osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
+
+	// Configure Multisampling
+	osg::DisplaySettings::instance()->setNumMultiSamples(4);
+
+	// Setup pathes
+	osgDB::Registry::instance()->getDataFilePathList().push_back( "D:/DA/osgVisual/models" );
+	
+	// Setup viewer
+	viewer = new osgViewer::Viewer(arguments);
+
+	// Setup coordinate system node
+	rootNode = new osg::CoordinateSystemNode;	
+	rootNode->setEllipsoidModel(new osg::EllipsoidModel());
+
+
+	//osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( 8 );
+
+	// Show model
+	viewer->setSceneData( rootNode );
+
+	// create the windows and run the threads.
+	viewer->realize();
+
+	loadTerrain(arguments);
+
+	// All modules are initialized - now check arguments for any unused parameter.
+	checkCommandlineArgumentsForFinalErrors();
+
+	// Run visual main loop
+	mainLoop();
+}
+
+void visual_core::mainLoop()
+{
+	int framestoScenerySetup = 5;
+	// run main loop
+	while( !viewer->done() )
+    {
+		// setup scenery
+		if(framestoScenerySetup-- == 0)
+			setupScenery();
+
+		// next frame please....
+        viewer->advance();
+
+		/*double hat, hot, lat, lon, height;
+		util::getWGS84ofCamera( viewer->getCamera(), rootNode, lat, lon, height);
+		if (util::queryHeightOfTerrain( hot, rootNode, lat, lon) && util::queryHeightAboveTerrainInWGS84( hat, rootNode, lat, lon, height ) )
+			OSG_NOTIFY( osg::ALWAYS ) << "HOT is: " << hot << ", HAT is: " << hat << std::endl;*/
+	
+		// perform all queued events
+		viewer->eventTraversal();
+
+		// update the scene by traversing it with the the update visitor which will
+        // call all node update callbacks and animations.
+        viewer->updateTraversal();
+		
+        // Render the Frame.
+        viewer->renderingTraversals();
+
+    }	// END WHILE
+}
+
+void visual_core::shutdown()
+{
+	OSG_NOTIFY( osg::ALWAYS ) << "Shutdown visual_core..." << std::endl;
+
+	// Unset scene data
+	viewer->setSceneData( NULL );
+
+	// Shutdown data
+	rootNode = NULL;
+
+	// Destroy osgViewer
+	viewer = NULL;
+}
+
+bool visual_core::loadTerrain(osg::ArgumentParser& arguments_)
+{
+	//std::vector<std::string> terrainFile = util::getTerrainFromXMLConfig(configFilename);
+
+	// Add each terrain path to the FilePath list to help OSG to find the subtiles. 
+	for(unsigned int i=0;i<terrainFile.size();i++)
+		osgDB::Registry::instance()->getDataFilePathList().push_back(osgDB::getFilePath(terrainFile[i]));
+
+	osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(terrainFile);
+	if( model.valid() )
+	{
+        osgTerrain::Terrain* terrain = util::findTopMostNodeOfType<osgTerrain::Terrain>(model.get());
+		if (!terrain)
+		{
+			terrain = new osgTerrain::Terrain;
+			terrain->addChild(model.get());
+
+			model = terrain;			
+		}
+		rootNode->addChild( terrain );
+		return true;
+	}
+	else
+	{
+        OSG_NOTIFY( osg::FATAL ) << "Load terrain: No data loaded" << std::endl;
+        return false;
+    }    
+
+	return false;
+}
+
+bool visual_core::checkCommandlineArgumentsForFinalErrors()
+{
+	// Setup Application Usage
+	arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
+	arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the a new visualization tool, written by Torben Dannhauer");
+	arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
+
+
+    // if user request help write it out to cout.
+    if (arguments.read("-h") || arguments.read("--help"))
+    {
+        arguments.getApplicationUsage()->write(std::cout);
+		//cause the viewer to exit and shut down clean.
+        viewer->setDone(true);
+    }
+
+    // report any errors if they have occurred when parsing the program arguments.
+    if (arguments.errors())
+    {
+        arguments.writeErrorMessages(std::cout);
+		//cause the viewer to exit and shut down clean.
+        viewer->setDone(true);
+    }
+
+	 // any option left unread are converted into errors to write out later.
+    arguments.reportRemainingOptionsAsUnrecognized();
+
+    // report any errors if they have occurred when parsing the program arguments.
+    if (arguments.errors())
+    {
+        arguments.writeErrorMessages(std::cout);
+        return false;
+    }
+	return true;
+}
+
+void visual_core::setupScenery()
+{
+	// Nothing
+}
Index: /experimental/osgVisualNG/visual_core.h
===================================================================
--- /experimental/osgVisualNG/visual_core.h	(revision 417)
+++ /experimental/osgVisualNG/visual_core.h	(revision 417)
@@ -0,0 +1,73 @@
+#pragma once
+/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
+ *
+ * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under 
+ * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
+ * (at your option) any later version.  The full license is in LICENSE file
+ * included with this distribution, and on the openscenegraph.org website.
+ *
+ * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
+ * You have to aquire licenses for all used proprietary modules.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * OpenSceneGraph Public License for more details.
+*/
+
+
+#include <osg/Referenced>
+#include <osg/Notify>
+#include <osgViewer/Viewer>
+#include <osgDB/ReadFile>
+
+
+
+namespace osgVisual
+{
+
+class visual_core : public osg::Referenced
+{
+
+public:
+	visual_core(osg::ArgumentParser& arguments_);
+	void initialize();
+	void shutdown();
+
+	bool loadTerrain(osg::ArgumentParser& arguments_);
+	bool checkCommandlineArgumentsForFinalErrors();
+
+	void setupScenery();
+
+protected:
+	/**
+	 * \brief Destrcutor
+	 * 
+	 */ 
+	virtual ~visual_core(void);
+
+private:
+	/**
+	 * \brief This function starts the main rendering loop
+	 * 
+	 */ 
+	void mainLoop();
+
+	/**
+	 * Argument object, with contains all commandline arguments, which where called during programm sstartup
+	 */ 
+	osg::ArgumentParser& arguments;
+
+	/**
+	 * This CSN is at the top node on the complete scenery. Only the nodes for distortion are located above this node.
+	 */ 
+	osg::ref_ptr<osg::CoordinateSystemNode> rootNode;
+
+	/**
+	 * Reference pointer to the viewer instance. The viewer is the core of the graphical subsystem.
+	 */ 
+	osg::ref_ptr<osgViewer::Viewer> viewer;
+
+};
+
+}	// END NAMESPACE
Index: /experimental/osgVisualNG/visual_util.cpp
===================================================================
--- /experimental/osgVisualNG/visual_util.cpp	(revision 417)
+++ /experimental/osgVisualNG/visual_util.cpp	(revision 417)
@@ -0,0 +1,327 @@
+/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
+ *
+ * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under 
+ * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
+ * (at your option) any later version.  The full license is in LICENSE file
+ * included with this distribution, and on the openscenegraph.org website.
+ *
+ * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
+ * You have to aquire licenses for all used proprietary modules.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * OpenSceneGraph Public License for more details.
+*/
+
+#include <visual_util.h>
+#include <osg/Material>
+
+using namespace osgVisual;
+
+util::util(void)
+{
+}
+
+util::~util(void)
+{
+}
+
+osg::Node* util::findNamedNode(const std::string& searchName_, osg::Node* currNode_)
+{
+   osg::Group* currGroup;
+   osg::Node* foundNode;
+
+   // check to see if we have a valid (non-NULL) node.
+   // if we do have a null node, return NULL.
+   if ( !currNode_)
+   {
+      return NULL;
+   }
+
+   // We have a valid node, check to see if this is the node we 
+   // are looking for. If so, return the current node.
+   if (currNode_->getName() == searchName_)
+   {
+      return currNode_;
+   }
+
+   // We have a valid node, but not the one we are looking for.
+   // Check to see if it has children (non-leaf node). If the node
+   // has children, check each of the child nodes by recursive call.
+   // If one of the recursive calls returns a non-null value we have
+   // found the correct node, so return this node.
+   // If we check all of the children and have not found the node,
+   // return NULL
+   currGroup = currNode_->asGroup(); // returns NULL if not a group.
+   if ( currGroup ) 
+   {
+      for (unsigned int i = 0 ; i < currGroup->getNumChildren(); i ++)
+      { 
+         foundNode = findNamedNode(searchName_, currGroup->getChild(i));
+         if (foundNode)
+		 {
+			 std::cout << "Node gefunden in Ebene: " << i << std::endl;
+            return foundNode; // found a match!
+		}
+      }
+      return NULL; // We have checked each child node - no match found.
+   }
+   else 
+	   return NULL; // leaf node, no match 
+}
+
+osg::ref_ptr<osg::Geode> util::getDemoCylinder(double length_, double width_, osg::Vec3 offset_ )
+{
+	osg::ref_ptr<osg::Geode> cyl = new osg::Geode();
+	osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Cylinder( offset_, width_, length_ ));
+	osg::Vec4 color = osg::Vec4(255.0, 0.0, 0.0, 1.0);
+	shape->setColor( color );
+	cyl->addDrawable( shape );
+
+	return cyl;
+}
+
+osg::ref_ptr<osg::Geode> util::getDemoSphere(double radius_, osg::Vec3 offset_ )
+{
+	osg::ref_ptr<osg::Geode> sphere = new osg::Geode();
+	osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Sphere( offset_, radius_ ) );
+	osg::Vec4 color = osg::Vec4(255.0, 0.0, 0.0, 1.0);
+	shape->setColor( color );
+	sphere->addDrawable( shape );
+
+	return sphere;
+}
+
+bool util::intersect(const osg::Vec3d& start_, const osg::Vec3d& end_, osg::Vec3d& intersection_, osg::Node* node_, osg::Node::NodeMask intersectTraversalMask_ )
+{
+	osg::ref_ptr<osgUtil::LineSegmentIntersector> lsi = new osgUtil::LineSegmentIntersector(start_,end_);
+
+	osgUtil::IntersectionVisitor iv(lsi.get());
+	iv.setTraversalMask(intersectTraversalMask_);
+    
+	node_->accept(iv);
+    
+	if (lsi->containsIntersections())
+	{
+		intersection_ = lsi->getIntersections().begin()->getWorldIntersectPoint();
+		return true;	// Intersect found
+	}
+	return false;	// No intersect found
+}
+
+bool util::queryHeightOfTerrain(double& hot_, osg::Node* rootNode_, double lat_, double lon_, osg::Node::NodeMask traversalMask_)
+{
+	// Get ellipsoid model
+	osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(rootNode_);
+	if ( !csn )
+	{
+		OSG_NOTIFY( osg::FATAL ) << "util::queryHeightOfTerrain() :: Invalid CSN!" << std::endl;
+		return false;
+	}
+	osg::EllipsoidModel* ellipsoid = csn->getEllipsoidModel();
+	if ( !ellipsoid )
+	{
+		OSG_NOTIFY( osg::FATAL ) << "util::queryHeightOfTerrain() :: Invalid ellipsoid!" << std::endl;
+		return false;
+	}
+
+	// Setup both endpoints of intersect line
+	double X,Y,Z;
+	ellipsoid->convertLatLongHeightToXYZ(lat_, lon_, 30000, X, Y, Z);
+	osg::Vec3d s = osg::Vec3d(X, Y, Z);
+	ellipsoid->convertLatLongHeightToXYZ(lat_, lon_, -30000, X, Y, Z);
+	osg::Vec3d e = osg::Vec3d(X, Y, Z);
+
+	// Query intersection point
+	osg::Vec3d ip;
+	if ( util::intersect(s, e, ip, rootNode_, traversalMask_) )
+	{
+		double lat2_, lon2_;
+		ellipsoid->convertXYZToLatLongHeight( ip.x(), ip.y(), ip.z(), lat2_, lon2_, hot_ );	// Convert Intersection Point back to Lat Lon, HOT.
+		//OSG_NOTIFY(osg::ALWAYS) << "lat: "<< osg::RadiansToDegrees(lat2_) <<", Lon: " << osg::RadiansToDegrees(lon2_) << ", Hot: " << hot_ << std::endl;
+		return true;
+	}
+
+	// If no intersection point found: set HOT to zero and return false.
+	hot_ = 0;
+	return false;
+}
+
+bool util::queryHeightAboveTerrainInWGS84(double& hat_, osg::Node* rootNode_, double lat_, double lon_, double height_, osg::Node::NodeMask traversalMask_)
+{
+	// Get HOT by asking util::queryHeightOfTerrain() :)
+	double HOT;
+	if ( !util::queryHeightOfTerrain(HOT, rootNode_, lat_, lon_, traversalMask_) )
+	{
+		OSG_NOTIFY( osg::INFO ) << "util::queryHeightAboveTerrainInWGS84() :: Unable to get HOT, will use 0 for HOT!" << std::endl;
+	}
+
+	// Calculate HAT
+	hat_ = height_ - HOT;
+	return true;
+}
+
+bool util::queryHeightAboveTerrainInWorld(double& hat_, osg::Node* rootNode_, double x_, double y_, double z_, osg::Node::NodeMask traversalMask_)
+{
+	// Get ellipsoid model
+	osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(rootNode_);
+	if ( !csn )
+	{
+		OSG_NOTIFY( osg::FATAL ) << "util::queryHeightAboveTerrainInWorld() :: Invalid CSN!" << std::endl;
+		return false;
+	}
+	osg::EllipsoidModel* ellipsoid = csn->getEllipsoidModel();
+	if ( !ellipsoid )
+	{
+		OSG_NOTIFY( osg::FATAL ) << "util::queryHeightAboveTerrainInWorld() :: Invalid ellipsoid!" << std::endl;
+		return false;
+	}
+
+	// Transform XYZ into LatLonHeight
+	double lat_, lon_, height_;
+	ellipsoid->convertXYZToLatLongHeight(x_, y_, z_, lat_, lon_, height_);
+
+	// ask util::queryHeightAboveTerrainInWGS84() to calc HAT :)
+	if( !util::queryHeightAboveTerrainInWGS84(hat_, rootNode_, lat_, lon_, height_, traversalMask_ ) )
+	{
+		OSG_NOTIFY( osg::FATAL ) << "util::queryHeightAboveTerrainInWorld() :: Unable to get HAT!" << std::endl;
+		return false;
+	}
+
+	return true;
+}
+
+bool util::calculateEarthRadiusAtWGS84Coordinate(double lat_, double lon_, osg::Node* rootNode_, double& radius_)
+{
+	// Calculate radius:
+	double x, y, z;
+	
+	if ( util::calculateXYZAtWGS84Coordinate(lat_, lon_, 0.0, rootNode_, x, y, z) )
+	{
+		radius_ = sqrt( pow(x, 2) + pow(y, 2) + pow(z, 2) );
+		return true;
+	}
+	else
+	{
+		OSG_NOTIFY( osg::FATAL ) << "util::calculateEarthRadiusAtWGS84Coordinate() :: Unable to calculate Earth Radius!" << std::endl;
+		return false;
+	}
+}
+
+bool util::calculateXYZAtWGS84Coordinate(double lat_, double lon_, double height_, osg::Node* rootNode_, double& x_, double& y_, double& z_)
+{
+	// Get ellipsoid model
+	osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(rootNode_);
+	if ( !csn )
+		return false;
+	osg::EllipsoidModel* ellipsoid = csn->getEllipsoidModel();
+	if ( !ellipsoid )
+		return false;
+
+	// Calculate xyz:
+	ellipsoid->convertLatLongHeightToXYZ( lat_, lon_, height_, x_, y_, z_);
+	return true;
+}
+
+bool util::getWGS84ofCamera( osg::Camera* camera_, osg::Node* rootNode_, double& lat_, double& lon_, double& height_ )
+{
+	// Get ellipsoid model
+	osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(rootNode_);
+	if ( !csn )
+		return false;
+	osg::EllipsoidModel* ellipsoid = csn->getEllipsoidModel();
+	if ( !ellipsoid )
+		return false;
+
+	osg::Vec3d eye, dir, up;
+	camera_->getViewMatrixAsLookAt(eye,dir,up); // Get XYZ from camera
+	ellipsoid->convertXYZToLatLongHeight(eye.x(), eye.y(), eye.z(), lat_, lon_, height_);
+	return true;
+}
+
+void util::getXYZofCamera( osg::Camera* camera_, double& x_, double& y_, double& z_ )
+{
+	osg::Vec3d eye, dir, up;
+	camera_->getViewMatrixAsLookAt(eye,dir,up); // Get XYZ from camera
+	x_ = eye.x();
+	y_ = eye.y();
+	z_ = eye.z();
+}
+
+
+double util::strToDouble(std::string s)
+{
+	double tmp;
+	std::stringstream sstr(s);
+    if (!(sstr >> tmp))
+	{
+		OSG_ALWAYS << __FUNCTION__ << "Warning:Unable to convert "<< s <<" to double, using 0.0 as default!" << std::endl;
+		return 0.0;
+	}
+	else
+		return tmp;
+}
+
+int util::strToInt(std::string s)
+{
+	int tmp;
+	std::stringstream sstr(s);
+	if (!(sstr >> tmp))
+	{
+		OSG_ALWAYS << __FUNCTION__ << "Warning:Unable to convert "<< s <<" to int, using 0 as default!" << std::endl;
+		return 0;
+	}
+	else
+		return tmp;
+}
+
+bool util::strToBool(std::string s)
+{
+	if(s=="yes")
+		return(true);
+	if(s=="no")
+		return(false);
+	OSG_ALWAYS << __FUNCTION__ << "Warning:Unable to convert "<< s <<" to bool, using false as default!" << std::endl;
+	return(false);
+}
+
+void util::AddCylinderBetweenPoints(osg::Vec3d StartPoint, osg::Vec3d EndPoint, float radius, osg::Vec4d CylinderColor, osg::Group *pAddToThisGroup)
+{
+	osg::ref_ptr<osg::Geode> geode = new osg::Geode;
+	osg::Vec3d center;
+	float height;
+	osg::ref_ptr<osg::Cylinder> cylinder;
+	osg::ref_ptr<osg::Drawable> cylinderDrawable;
+	osg::ref_ptr<osg::Material> pMaterial;
+
+	height = (StartPoint-EndPoint).length();
+	center = osg::Vec3( (StartPoint.x() + EndPoint.x()) / 2, (StartPoint.y() + EndPoint.y()) / 2, (StartPoint.z() + EndPoint.z()) / 2);
+
+	// This is the default direction for the cylinders to face in OpenGL
+	osg::Vec3d z = osg::Vec3d(0,0,1);
+
+	// Get diff between two points you want cylinder along
+	osg::Vec3d p = StartPoint - EndPoint;
+
+	// Get CROSS product (the axis of rotation)
+	osg::Vec3d t = z ^ p;
+
+	// Get angle. length is magnitude of the vector
+	double angle = acos( (z * p) / p.length());
+
+	// Create a cylinder between the two points with the given radius
+	cylinder = new osg::Cylinder(center,radius,height);
+	cylinder->setRotation(osg::Quat(angle, osg::Vec3(t.x(), t.y(), t.z())));
+
+	cylinderDrawable = new osg::ShapeDrawable(cylinder );
+	geode->addDrawable(cylinderDrawable);
+
+	// Set the color of the cylinder that extends between the two points.
+	pMaterial = new osg::Material;
+	pMaterial->setDiffuse( osg::Material::FRONT, CylinderColor);
+	geode->getOrCreateStateSet()->setAttribute( pMaterial, osg::StateAttribute::OVERRIDE );
+
+	// Add the cylinder between the two points to an existing group
+	pAddToThisGroup->addChild(geode);
+}
Index: /experimental/osgVisualNG/visual_util.h
===================================================================
--- /experimental/osgVisualNG/visual_util.h	(revision 417)
+++ /experimental/osgVisualNG/visual_util.h	(revision 417)
@@ -0,0 +1,271 @@
+#pragma once
+/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
+ *
+ * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under 
+ * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
+ * (at your option) any later version.  The full license is in LICENSE file
+ * included with this distribution, and on the openscenegraph.org website.
+ *
+ * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
+ * You have to aquire licenses for all used proprietary modules.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * OpenSceneGraph Public License for more details.
+*/
+
+#include <string.h>
+#include <iostream>
+#include <sstream>
+
+
+#include <osg/Node>
+#include <osg/Group>
+#include <osg/Geode>
+#include <osg/CoordinateSystemNode>
+#include <osg/ShapeDrawable>
+
+#include <osgViewer/Viewer>
+
+#include <OpenThreads/ReentrantMutex>
+
+#include <osgUtil/LineSegmentIntersector>
+
+
+
+
+
+namespace osgVisual
+{ 
+
+/**
+ * \brief This class provides utility functions. 
+ * 
+ * The utility functions are implemented as static functions if possible for easy use in other classes.
+ * 
+ * \todo check why lineIntersector is unstable, check if newer and better system is available.
+ * 
+ * @author Torben Dannhauer
+ * @date  Jul 2009
+ */ 
+class util
+{
+
+public:
+	/**
+	 * \brief Construtor
+	 * 
+	 */ 
+	util();
+
+	/**
+	 * \brief Destructor
+	 * 
+	 */ 
+	~util();
+
+	/**
+	 * \brief This functions searches in the scene graph for a node with a name
+	 * 
+	 * This function searches in the scene graph unter the node "currNode" for a node named like the given search name.
+	 * The functions returns the first node with that name.
+	 * 
+	 * @param searchName_ : Nodename to search for
+	 * @param currNode_ : Scene graph to search in.
+	 * @return : if Node found: Pointer to the node. If not found: NULL
+	 */ 
+	static osg::Node* findNamedNode(const std::string& searchName_, osg::Node* currNode_);
+
+	/**
+	 * \brief This function creates a red cylinder of the specified size tor testing purposes.
+	 * 
+	 * @param length_ : Length of the cylinder in meter.
+	 * @param width_ : Diameter of the cylinder in meter.
+	 * @param offset_ : Offset of the cylinder's origin in meter.
+	 * @return : Referenced Pointer off the Geode with the created cylinder.
+	 */ 
+	static osg::ref_ptr<osg::Geode> getDemoCylinder(double length_, double width_, osg::Vec3 offset_ = osg::Vec3(0.0, 0.0, 0.0) );
+	
+	/**
+	 * \brief This function creates a red sphere of the specified size tor testing purposes.
+	 * 
+	 * @param radius_ : Radius of the sphere in meter.
+	 * @param offset_ : Offset of the sphere's origin in meter.
+	 * @return : Referenced Pointer off the Geode with the created cylinder.
+	 */ 
+	static osg::ref_ptr<osg::Geode> getDemoSphere(double radius_, osg::Vec3 offset_ = osg::Vec3(0.0, 0.0, 0.0) );
+
+	/**
+	 * \brief This functions searches the scene graph for intersections of a line between two points and the model.
+	 * 
+	 * @param start_ : Point 1 for the intersection line
+	 * @param end_ : Point 2 for the intersection line
+	 * @param intersection_ : vektor to the intersection point if any is found.
+	 * @param node_ : Node which is the root of the scene graph to check for intersections
+	 * @param intersectTraversalMask_ : Bitwise mask wich controls which nodes should be checked for intersections (e.g. to check only terrain but not clouds or sky)
+	 * @return returns : True if an intersection is found. 
+	 */ 
+	static bool intersect(const osg::Vec3d& start_, const osg::Vec3d& end_, osg::Vec3d& intersection_, osg::Node* node_, osg::Node::NodeMask intersectTraversalMask_=0xffffffff );
+
+	/**
+	 * \brief This function queries the height of terrain (hot) at a specified location.
+	 * 
+	 * @param hot_ : Reference to write the calculated hot into.
+	 * @param rootNode_ : Node which is the root of the scene graph to calculate the hot.
+	 * @param lat_ : Latitude of the position to calculate the hot.
+	 * @param lon_ : Longitude of the position to calculate the hot.
+	 * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hot (e.g. to check only terrain but not clouds or sky)
+	 * @return : True if hot calculation successful.
+	 */ 
+	static bool queryHeightOfTerrain(double& hot_, osg::Node* rootNode_, double lat_, double lon_, osg::Node::NodeMask traversalMask_=0xffffffff);
+
+	/**
+	 * \brief This function queries the height above terrain (hat) at a specified location in WGS84 coordinates.
+	 * 
+	 * @param hat_ : Reference to write the calculated hat into.
+	 * @param rootNode_ : Node which is the root of the scene graph to calculate the hat.
+	 * @param lat_ : Latitude of the position to calculate the hat. (e.g. lat of camera)
+	 * @param lon_ : Longitude of the position to calculate the hat.(e.g. lon of camera)
+	 * @param height_ : Height of the position to calculate the hat.(e.g. height of camera).
+	 * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hat (e.g. to check only terrain but not clouds or sky)
+	 * @return :  True if hat calculation successful.
+	 */ 
+	static bool queryHeightAboveTerrainInWGS84(double& hat_, osg::Node* rootNode_, double lat_, double lon_, double height_, osg::Node::NodeMask traversalMask_=0xffffffff);
+
+	/**
+	 * \brief This function queries the height above terrain (hat) at a specified location in world coordinates.
+	 * 
+	 * @param hat_ : Reference to write the calculated hat into.
+	 * @param rootNode_ : Node which is the root of the scene graph to calculate the hat.
+	 * @param x_ : First value of the pointer which points to the position to calculate hat for.
+	 * @param y_ : Second value of the pointer which points to the position to calculate hat for. 
+	 * @param z_ : Third value of the pointer which points to the position to calculate hat for.
+	 * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hat (e.g. to check only terrain but not clouds or sky)
+	 * @return :  True if hat calculation successful. 
+	 */ 
+	static bool queryHeightAboveTerrainInWorld(double& hat_, osg::Node* rootNode_, double x_, double y_, double z_, osg::Node::NodeMask traversalMask_=0xffffffff);
+
+	/**
+	 * \brief This function calculates the earth readius (vector length in world coordiantes from origin to location) at the specified location.
+	 * 
+	 * @param lat_ : Latitude in radians.
+	 * @param lon_ : Longitude in radians.
+	 * @param rootNode_ : Root node of the scene which coordinate system node should be used.
+	 * @param radius_ : Calculated earth readius in meter.
+	 * @return : True if calculation successful.
+	 */ 
+	static bool calculateEarthRadiusAtWGS84Coordinate(double lat_, double lon_, osg::Node* rootNode_, double& radius_);
+
+	/**
+	 * \brief This function converts a WGS84 position into global OpenGL XYZ coordinates.
+	 * 
+	 * @param lat_ : Latitude of the position to calculate XYZ.
+	 * @param lon_ : Longitude of the position to calculate XYZ.
+	 * @param height_ : Height of the position to calculate XYZ.
+	 * @param rootNode_ : Node which is the root of the scene graph to calculate XYZ.
+	 * @param x_ : X Coordinate in global OpenGL coordinates.
+	 * @param y_ : Y Coordinate in global OpenGL coordinates.
+	 * @param z_ : Z Coordinate in global OpenGL coordinates.
+	 * @return : True if calculation successful.
+	 */ 
+	static bool calculateXYZAtWGS84Coordinate(double lat_, double lon_, double height_, osg::Node* rootNode_, double& x_, double& y_, double& z_);
+
+	/**
+	 * \brief This function calculates lat, lon and height of a specified camera by a specified coordinate system node. 
+	 * 
+	 * @param camera_ : Camera node which position should be calculated.
+	 * @param rootNode_ : rootNode of the scene.
+	 * @param lat_ : Latitude variable to save value in.
+	 * @param lon_ : Longitude variable to save value in.
+	 * @param height_ : Height: variable to save value in.
+	 * @return : True if calculation was successful.
+	 */ 
+	static bool getWGS84ofCamera( osg::Camera* camera_, osg::Node* rootNode_, double& lat_, double& lon_, double& height_ ); 
+
+	/**
+	 * \brief This function returns the global XYZ coordinates of the specified camera.
+	 * 
+	 * @param camera_ : Camera to return the position.
+	 * @param x_ : X coordinate.
+	 * @param y_ : Y coordinate.
+	 * @param z_ : Z coordinate.
+	 */ 
+	static void getXYZofCamera( osg::Camera* camera_, double& x_, double& y_, double& z_ ); 
+
+
+	/**
+	 * \brief This function converts a string into a double.
+	 * 
+	 * @param s : String to convert.
+	 * @return : double representation of the string.
+	 */ 
+	static double strToDouble(std::string s);
+
+	/**
+	 * \brief This function converts a string into an Integer.
+	 * 
+	 * @param s : String to convert.
+	 * @return : Integer representation of the string.
+	 */ 
+	static int strToInt(std::string s);
+
+	/**
+	 * \brief This function converts a string into a bool.
+	 * 
+	 * @param s : String to convert.
+	 * @return : Bool representation of the string. Returns 'false' on error.
+	 */ 
+	static bool strToBool(std::string s);
+
+	/**
+	 * \brief \todo : Kommentieren
+	 * 
+	 * @param StartPoint 
+	 * @param EndPoint 
+	 * @param radius 
+	 * @param CylinderColor 
+	 * @param pAddToThisGroup 
+	 */ 
+	static void AddCylinderBetweenPoints(osg::Vec3d StartPoint, osg::Vec3d EndPoint, float radius, osg::Vec4d CylinderColor, osg::Group *pAddToThisGroup);
+
+	template<class T>
+	class FindTopMostNodeOfTypeVisitor : public osg::NodeVisitor
+	{
+	public:
+		FindTopMostNodeOfTypeVisitor():
+			osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
+			_foundNode(0)
+		{}
+
+		void apply(osg::Node& node)
+		{
+			T* result = dynamic_cast<T*>(&node);
+			if (result)
+			{
+				_foundNode = result;
+			}
+			else
+			{
+				traverse(node);
+			}
+		}
+
+		T* _foundNode;
+	};
+
+	template<class T>
+	static T* findTopMostNodeOfType(osg::Node* node)
+	{
+		if (!node) return 0;
+
+		FindTopMostNodeOfTypeVisitor<T> fnotv;
+		node->accept(fnotv);
+
+		return fnotv._foundNode;
+	}
+
+
+};
+
+} //END NAMESPACE
