00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <fstream>
00026 #include <string>
00027 #include <vector>
00028
00029 #include <boost/shared_ptr.hpp>
00030
00031 #include "../../common/WIOTools.h"
00032 #include "../exceptions/WDHIOFailure.h"
00033 #include "WWriterMatrixSymVTK.h"
00034
00035 WWriterMatrixSymVTK::WWriterMatrixSymVTK( std::string fname, bool overwrite )
00036 : WWriter( fname, overwrite )
00037 {
00038 }
00039
00040 void WWriterMatrixSymVTK::writeTable( const std::vector< double > &table, size_t dim ) const
00041 {
00042 using std::fstream;
00043 fstream out( m_fname.c_str(), fstream::out | fstream::in | fstream::trunc );
00044 if( !out || out.bad() )
00045 {
00046 throw WDHIOFailure( std::string( "Invalid file, or permission: " + m_fname ) );
00047 }
00048 out << "# vtk DataFile Version 3.0" << std::endl;
00049 out << "WMatrixSym from OpenWalnut" << std::endl;
00050 out << "BINARY" << std::endl;
00051
00052 out << "FIELD WMatrixSym 1" << std::endl;
00053 unsigned int numDistances = table.size() + 1;
00054 out << "ELEMENTS " << numDistances << " 1 float" << std::endl;
00055 float *data = new float[numDistances];
00056
00057 for( size_t i = 0; i < table.size() ; ++i )
00058 {
00059 data[i] = static_cast< float >( table[i] );
00060 }
00061 data[ numDistances - 1 ] = static_cast< float >( dim );
00062
00063 switchByteOrderOfArray< float >( data, numDistances );
00064 out.write( reinterpret_cast< char* >( data ), sizeof( float ) * numDistances );
00065 out << std::endl;
00066 out.close();
00067 }