Index: experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp
===================================================================
--- experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp	(revision 382)
+++ experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp	(revision 383)
@@ -28,5 +28,6 @@
 	_blendmapFilename = "";
 	_frustumFilename = "";
-	_distortionFilename = "";
+	_vertexDistortionFilename = "";
+	_texCoordDistortionFilename = "";
 	_distortionType = DistortionSetupStrategy::UNDEFINED;
 
@@ -39,10 +40,11 @@
 }
 
-void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string distortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)
+void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)
 {
 	_distortionType = type;
 	_blendmapFilename = blendmapFile;
 	_frustumFilename = frustumFile;
-	_distortionFilename = distortionFile;
+	_vertexDistortionFilename = vertexDistortionFile;
+	_texCoordDistortionFilename = texCoordDistortionFile;
 }
 
@@ -231,7 +233,12 @@
 	}
 
-	if(	_distortionType == DistortionSetupStrategy::UNDEFINED || _blendmapFilename.empty() || _frustumFilename.empty() || _distortionFilename.empty() )
-	{
-		OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames and distortion type!"<<std::endl;
+	if(	_distortionType == DistortionSetupStrategy::UNDEFINED 
+			|| _blendmapFilename.empty()
+			|| _frustumFilename.empty()
+			|| ( _vertexDistortionFilename.empty() && _distortionType == DistortionSetupStrategy::VERTEXDISTORTION )
+			|| ( _texCoordDistortionFilename.empty() && _distortionType == DistortionSetupStrategy::TEXCOORDDISTORTION )
+	)
+	{
+		OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames and distortion type correctly!"<<std::endl;
 		return;
 	}
@@ -242,5 +249,7 @@
 	{
 		_distortionInitialized=true;
-		distortionSet->dirty();
+		distortionSet->dirtyMesh();
+		distortionSet->dirtyMatrix();
+
 
 		// ******************** //
@@ -317,5 +326,5 @@
 			//*******************************************************************************************//
 			
-#if 1
+#if 0
 			osg::Vec3Array* vertices =  (osg::Vec3Array*) distortionMeshGeometry->getVertexArray();
 			osg::Vec2Array* texcoords0 = (osg::Vec2Array*) distortionMeshGeometry->getTexCoordArray(0);
@@ -338,34 +347,90 @@
 			//*******************************************************************************************//
 
-			// Exctract mesh dimensions from file and pass them to the container
+			// Exctract mesh dimensions from file and pass them to the container.
+			// If soley texCoordDistortion is used, _texCoordDistortionFilename is used to determine the dimensions, otherwise _vertexDistortionFilename
 			int distortionMeshRows=0, distortionMeshColumns=0;
-			readMeshDimensionsFromCSVFile(_distortionFilename, &distortionMeshRows, &distortionMeshColumns);
+			readMeshDimensionsFromCSVFile(_distortionType==DistortionSetupStrategy::TEXCOORDDISTORTION?_texCoordDistortionFilename:_vertexDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
 
 			distortionSet->setDistortionMeshRows(distortionMeshRows);
 			distortionSet->setDistortionMeshColumns(distortionMeshColumns);
 
-			osg::Vec2Array* tmpMeshVec2 = new osg::Vec2Array;
-			osg::Vec3Array* vertexMeshVec3 = new osg::Vec3Array;
-
-			readMeshPointsFromCSVFile(_distortionFilename, tmpMeshVec2);
+			// If vertex- and texCoord distortion is combined: Ensure both files have the same dimensions
+			if(_distortionType==DistortionSetupStrategy::COMBINEDDISTORTION)
+			{
+				int texCoordRows=0, texCoordColumns=0;
+				readMeshDimensionsFromCSVFile(_texCoordDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
+				if(distortionMeshRows!=texCoordRows || distortionMeshColumns!=texCoordColumns)
+				{
+					OSG_ALWAYS<<"The mesh dimensions of the vertex- and textureCoordinate-distortion differ!"<<std::endl;
+					return;
+				}
+			}
+
+			// Read in the mesh arrays
+			osg::Vec2Array* vertexMeshVec2 = new osg::Vec2Array;
+			osg::Vec2Array* texCoordMeshVec2 = new osg::Vec2Array;
+			osg::Vec4Array* distortionMesh = new osg::Vec4Array(distortionMeshRows*distortionMeshColumns);
+			
+			if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION))
+			{
+				readMeshPointsFromCSVFile(_vertexDistortionFilename, vertexMeshVec2);
+			}
 
 			if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION))
 			{
-				distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray(0,tmpMeshVec2);
-			}
-
-			if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION))
-			{
-				for(unsigned int i=0;i<tmpMeshVec2->size();i++)
-				{
-					// Scale vector with the screen resolution
-					osg::Vec3 tmpVec = osg::Vec3(	tmpMeshVec2->at(i).x()*width,
-													tmpMeshVec2->at(i).y()*height,
-													0.0	);
-					vertexMeshVec3->push_back( tmpVec );
-				}
-				distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setVertexArray(vertexMeshVec3);
-
-			}
+				readMeshPointsFromCSVFile(_texCoordDistortionFilename, texCoordMeshVec2);
+			}
+
+			// Transfer the read values into the combinedArray
+			for(int row=0;row<distortionMeshRows;row++)
+			{
+				for(int col=0;col<distortionMeshColumns;col++)
+				{
+					float x=col/distortionMeshColumns;	// Vertex X
+					float y=row/distortionMeshRows;		// Vertex Y
+					float z=col/distortionMeshColumns;	// TexCoord X
+					float w=row/distortionMeshRows;		// TexCoord Y
+					if(_distortionType==VERTEXDISTORTION || _distortionType==COMBINEDDISTORTION)
+					{
+						x = vertexMeshVec2->at(row*col).x();
+						y = vertexMeshVec2->at(row*col).y();
+					}
+					if(_distortionType==TEXCOORDDISTORTION || _distortionType==COMBINEDDISTORTION)
+					{
+						z = texCoordMeshVec2->at(row*col).x();
+						w = texCoordMeshVec2->at(row*col).y();
+					}
+
+					distortionMesh->at(row*distortionMeshColumns+col).set(x,y,z,w);
+				}
+			}
+
+			distortionSet->setDistortionMesh(distortionMesh);
+			distortionSet->setDistortionMeshColumns(distortionMeshColumns);
+			distortionSet->setDistortionMeshRows(distortionMeshRows);
+
+			// apply new settings
+			//if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION))
+			//{
+			//	distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray(0,tmpMeshVec2);
+			//}
+
+			//if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION))
+			//{
+			//	OSG_ALWAYS<<"New mesh ---------------------------"<<std::endl;
+			//	for(unsigned int i=0;i<tmpMeshVec2->size();i++)
+			//	{
+			//		// Scale vector with the screen resolution
+			//		osg::Vec3 tmpVec = osg::Vec3(	tmpMeshVec2->at(i).x()*width,
+			//										tmpMeshVec2->at(i).y()*height,
+			//										0.0	);
+			//		vertexMeshVec3->push_back( tmpVec );
+			//		OSG_ALWAYS<<"X:"<<tmpVec.x()<<" Y:"<<tmpVec.y()<<" Z:"<<tmpVec.z()<<std::endl;
+			//	}
+			//	OSG_ALWAYS<<"tmpMeshVec2 size:"<<tmpMeshVec2->size()<<std::endl;
+			//	distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setVertexArray(vertexMeshVec3);
+			//	distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray
+			//	distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->dirtyDisplayList();
+			//}
 		}
 	}
