Index: /experimental/distortionNG/ReaderWriterDist.cpp
===================================================================
--- /experimental/distortionNG/ReaderWriterDist.cpp	(revision 365)
+++ /experimental/distortionNG/ReaderWriterDist.cpp	(revision 366)
@@ -5,42 +5,95 @@
 {
 	supportsExtension( "dist", "distortion set loader");
+	extensionToAdd = ".dist";
 
+	// Configure Compression and instantiate read/write-options
+	bool asAscii = true;
+	bool compressionEnabled = false;
 
-	extensionToAdd = ".dist";
+	std::string readOptionString = "";
+	std::string writeOptionString = "";
+	if(asAscii)
+	{
+		readOptionString = "Ascii";
+		writeOptionString = "Ascii";
+	}
+	if (compressionEnabled)
+		writeOptionString+=" Compressor=zlib";
+	readOptions = new osgDB::Options( readOptionString.c_str() );
+	writeOptions = new osgDB::Options( writeOptionString.c_str() );
+
+	// Get ReaderWriter
+	rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgt");	
+
 }
 
 ReaderWriterDist::ReadResult ReaderWriterDist::readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const
 {
-	// Check if its a valid file for this pseudo loader
 	std::string ext = osgDB::getLowerCaseFileExtension( file );
 	if( !acceptsExtension(ext) )
 		return ReadResult::FILE_NOT_HANDLED;
 
-	// Strip the pseudo-loader extension
-    std::string realName = osgDB::getNameLessExtension( file );
-
-	// check if stripped file exists
-	std::string fileName = osgDB::findDataFile( realName, options );
+	// check if file exists
+	std::string fileName = osgDB::findDataFile( file, options );
 	if( fileName.empty() )
 		return ReadResult::FILE_NOT_FOUND;
 
-	// If options are available: Save it'S original KdTree Hint.
-	Options::BuildKdTreesHint originalHint = Options::NO_PREFERENCE;
-	if(options)
+	std::ifstream stream( fileName.c_str(), std::ios::in );
+	if (!stream)	return ReadResult::ERROR_IN_READING_FILE;
+	return readNode( stream, options );
+}
+
+ReaderWriterDist::ReadResult ReaderWriterDist:: readNode( std::istream& fin, const osgDB::ReaderWriter::Options* options ) const
+{
+	if ( rw )
 	{
-		originalHint = options->getBuildKdTreesHint();
-		const_cast<osgDB::ReaderWriter::Options*>(options)->setBuildKdTreesHint(Options::DO_NOT_BUILD_KDTREES);
+		osgDB::ReaderWriter::ReadResult rr = rw->readObject( fin, readOptions );
+		if (rr.success())
+		{
+			return( rr.takeObject() );
+		}
+		else
+			OSG_NOTIFY( osg::WARN ) << "ERROR: Unable to convert stream to node" << std::endl;
 	}
+	else
+		OSG_NOTIFY( osg::WARN ) << "ERROR: Unable to get ReaderWriter for internally used extension" << std::endl;
+}
 
-	// Load real file
-	osg::Node *node = osgDB::readNodeFile( fileName, options );
-    if( !node )
-    {
-        // propagate the read failure upwards
-        OSG_WARN << "Subfile \"" << fileName << "\" could not be loaded" << std::endl;
-        return ReadResult::FILE_NOT_HANDLED;
-    }
+ReaderWriterDist::WriteResult writeNode( const osg::Node& node, const std::string& fileName, const Options* options ) const
+{
+	std::string ext = osgDB::getLowerCaseFileExtension( file );
+	if( !acceptsExtension(ext) )
+		return WriteResult::FILE_NOT_HANDLED;
 
-	return node;
+	std::ifstream stream( fileName.c_str(), std::ios::in );
+	if (!stream)	return ReadResult::ERROR_IN_READING_FILE;
+	return readNode( stream, options );
+// ------------------
+    WriteResult result = WriteResult::FILE_SAVED;
+    std::ios::openmode mode = std::ios::out;
+    osg::ref_ptr<Options> local_opt = prepareWriting( result, fileName, mode, options );
+    if ( !result.success() ) return result;
+
+    osgDB::ofstream fout( fileName.c_str(), mode );
+    if ( !fout ) return WriteResult::ERROR_IN_WRITING_FILE;
+
+    result = writeNode( node, fout, local_opt.get() );
+    fout.close();
+    return result;
+}
+
+ReaderWriterDist::WriteResult writeNode( const osg::Node& node, std::ostream& fout, const Options* options ) const
+{
+	if ( rw )
+	{
+		osgDB::ReaderWriter::WriteResult wr = rw->writeObject( node, fout, writeOptions );
+		if (wr.success() )			
+		{
+			OSG_NOTIFY( osg::WARN ) << "schreiben geschafft!"<< std::endl;
+		}
+		else OSG_NOTIFY( osg::WARN ) << "ERROR: Save failed: " << wr.message() << std::endl;
+		return(wr);
+	}
+	OSG_NOTIFY( osg::WARN ) << "ERROR: Unable to get ReaderWriter for internally used extension" << std::endl;
 }
 
Index: /experimental/distortionNG/ReaderWriterDist.h
===================================================================
--- /experimental/distortionNG/ReaderWriterDist.h	(revision 365)
+++ /experimental/distortionNG/ReaderWriterDist.h	(revision 366)
@@ -1,3 +1,5 @@
 #pragma once
+
+
 
 #include <osg/Notify>
@@ -14,8 +16,16 @@
 	ReaderWriterDist();
 
-	virtual const char* className() const { return "terrain modification pseudo-loader"; };
+	virtual const char* className() const { return "distortion set loader"; };
 	virtual ReadResult readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const;
+	virtual ReadResult readNode( std::istream& fin, const osgDB::ReaderWriter::Options* options ) const;
+    virtual WriteResult writeNode( const osg::Node& node, const std::string& fileName, const osgDB::ReaderWriter::Options* options ) const;
+    virtual WriteResult writeNode( const osg::Node& node, std::ostream& fout, const osgDB::ReaderWriter::Options* options ) const;
+
 
 private:
 	std::string extensionToAdd;
+
+	osg::ref_ptr<osgDB::Options> readOptions;
+	osg::ref_ptr<osgDB::Options> writeOptions;
+	osg::ref_ptr<osgDB::ReaderWriter> rw;
 };
Index: /experimental/distortionNG/main.cpp
===================================================================
--- /experimental/distortionNG/main.cpp	(revision 365)
+++ /experimental/distortionNG/main.cpp	(revision 366)
@@ -149,30 +149,42 @@
  * modul								Funktionen / Description
  * 
- * [postponed] plugin .dist				load / Save distContainers					loads and saves via serializers the distortion container from/to file.
+ * [] plugin .dist						load / Save distContainers					loads and saves via serializers the distortion container from/to file.
+ *																					Ensures the Coordinates are normalized before saving the container.
+ *										Load: 
+ *										* use serializer to load container
+ *										* invoke osgViewer::setUpViewForManualDistortion(distSet, screenNum, projectorMatrix) to set up distortion
+ *										Save:
+ *										* check if container is normalized. if not, copy and normalize container
+ *										* use serializer to save container
  *  
  * 
- * [done] Distortion Container					Beinhaltet die folgenden Distortion Details:
+ * [done] Distortion Container			Der Container wird immer normalisiert gespeichert, alle Koordinaten (Mesh+TexCoords) werden im Range [0-1]angespeichert.
+ *										Er beinhaltet die folgenden Distortion Details:
  *										- Blendmap (osgImage) 
  *										- Mesh Dimensions (rows, columns)
  * 										- Mesh Type (GLenum QUAD_STRIP, ...)
+ *										- Mesh Coordinates [0-1]
+ *										- Texture Coordinates [0-1]
  * 										- textureUnit for Scene RTT (z.B.: 0)
  * 										- textureUnit for blendmap (z.B.: 1)
  * 										- screenNum
- * 										- slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist identity)
+ * 										- slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist Identity)
  * 										- slaveCam viewOffset	(wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset)
  * 										
  *										need to add setter/getter as well as the serializer macros.
  *										
- *										Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der COntainer vom Vierwer verwaltet werden.
- * 
- * osgViewer							load and apply distortion (apply via setupDistortion(...)
- *										setUpIntensityMapBlending(string filepath, int rrtTexUnit=1, int scenTexUnit=0): simple function providing a file path, and optionally the texUnits to use. Wil invoke the more detailed funtion for setup.
+ *										Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der Container vom Viewer verwaltet werden. der manipulator greift darauf zu, das plugin kann container entgegen nehmen oder zurückgeben, hat aber keinen direkten kontakt zur container instanz von osgViewer
+ * 
+ * osgViewer							im construtor (anfangs ersatzweise in der main.cpp) : -dist <distFile> => load and apply distortion [via setUpViewForManualDistortion(std::string distFile)]
+ *										setUpIntensityMapBlending(string filepath, int rrtTexUnit=1, int scenTexUnit=0):	Simple function providing a file path, and optionally the texUnits to use. 
+ *																															Will invoke the more detailed funtion (below) for setup.
  *										setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
- * 
+ *										setUpViewForManualDistortion(osgViewer::DistortionSet* distSet, unsigned int screenNum, const osg::Matrixd& projectorMatrix)
+ *										setUpViewForManualDistortion(std::string distFile, unsigned int screenNum, const osg::Matrixd& projectorMatrix)	is invoked by -dist <distFile>, reads distSet via osgDB::readObjectFile(), calls setUpViewForManualDistortion(osgViewer::DistortionSet* distSet, unsigned int screenNum, const osg::Matrixd& projectorMatrix) to setup the distortion.
  * 
  * distortionManipulator				abgeleitet von osgGA::GUIEventHandler
  *										Grundfunktionen:
  *							[done]		- Key to Show Distortion Mesh / Intensity Map / none
- *										- Key to Save distortion Container  - via plugin
+ *										- Key to Save distortion Container  - via osgDB::writeObjectFile(const osg::Object& object, const std::string& filename, const Options* options). osgDB & registry determines and loads the approriate plugin bythe file ending (.dist).
  *							[.]		- Key to toggle MANUAL mode between blending und distortion setup
  *							[done]		- Key to toggle distortion setup: 
@@ -196,13 +208,12 @@
  * direct to do:
  * 
- * speichern des containers in ein .dist file
+ * Plugin fertigstellen
+ * save funktion des manipulators via osgDB::writeObjectFile fertig stellen
+ * extViewer::setUpViewForManualDistortion(std::string distFile)
+ * Load Funktion vom osgViewer (ersatzweise Anfangs in der main.cpp) fertigstellen : -dist <distFile> weiterreichen and extViewer::setUpViewForManualDistortion(std::string distFile)
  * Laden des Containers.
- * reset distortion funktioniert.
+ * reset distortion implementieren.
  * Anwenden der distortion auf die Meshknoten oder die texturekoordinaten
  * 
- * - umstellung der koordinaten auf [0-1]
- * oder alternativ: 
- * - speichern der hieght und width im container so daß das mesh an andere Bildschirmgrößen angepasst werden kann.
- 
  * 
 */
