18 #ifndef DUNE_GRIDGLUE_EXTRACTORS_VTKSURFACEWRITER_HH
19 #define DUNE_GRIDGLUE_EXTRACTORS_VTKSURFACEWRITER_HH
26 #include "../adapter/gridgluevtkwriter.hh"
45 if (std::strlen(name) > 0)
46 this->filename_ = name;
51 void writeSurface(
const std::vector<K>& coords,
const std::vector<unsigned int>& indices,
int corners,
int dim)
55 sprintf(buffer,
"%s.vtk", this->filename_);
57 fos << std::setprecision(8) << std::setw(1);
59 fos <<
"# vtk DataFile Version 2.0\nFilename: " << buffer <<
"\nASCII" << std::endl;
61 const int polycount = indices.size()/corners;
62 int corner_count[polycount];
63 for (
int i = 0; i < polycount; ++i)
64 corner_count[i] = corners;
65 this->
writePolygons(indices, corner_count, polycount, dim, fos);
70 template<
typename K,
typename T>
71 void writeSurfaceElementData(
const std::vector<K>& coords,
const std::vector<unsigned int>& indices,
int corners,
const std::vector<T>& data,
const char* dataname,
int dim)
75 sprintf(buffer,
"%s.vtk", this->filename_);
77 fos << std::setprecision(8) << std::setw(1);
79 fos <<
"# vtk DataFile Version 2.0\nFilename: " << buffer <<
"\nASCII" << std::endl;
81 const int polycount = indices.size()/corners;
82 int corner_count[polycount];
83 for (
int i = 0; i < polycount; ++i)
84 corner_count[i] = corners;
85 this->
writePolygons(indices, corner_count, polycount, dim, fos);
91 template<
typename K,
typename T>
92 void writeSurfaceVertexData(
const std::vector<K>& coords,
const std::vector<unsigned int>& indices,
int corners,
const std::vector<T>& data,
const char* dataname,
int dim)
96 sprintf(buffer,
"%s.vtk", this->filename_);
98 fos << std::setprecision(8) << std::setw(1);
100 fos <<
"# vtk DataFile Version 2.0\nFilename: " << buffer <<
"\nASCII" << std::endl;
102 const int polycount = indices.size()/corners;
103 int corner_count[polycount];
104 for (
int i = 0; i < polycount; ++i)
105 corner_count[i] = corners;
106 this->
writePolygons(indices, corner_count, polycount, dim, fos);
114 void writePoints(
const std::vector<K>& coords,
int dim, std::ofstream& fos)
116 fos <<
"DATASET POLYDATA\nPOINTS " << coords.size() <<
" " << TypeNames[Nametraits<K>::nameidx] << std::endl;
117 for (
unsigned int i = 0; i < coords.size(); ++i)
121 fos <<
" " << coords[i][1] <<
" 0 \n" << coords[i][0] <<
" " << coords[i][1] <<
" 0.01" << std::endl;
123 fos <<
" " << coords[i][1] <<
" " << coords[i][2] << std::endl;
127 void writePolygons(
const std::vector<unsigned int>& indices,
const int* corners,
int ncorners,
int dim, std::ofstream& fos)
131 fos <<
"POLYGONS " << indices.size()/2 <<
" " << 5*(indices.size() / 2) << std::endl;
132 for (
unsigned int i = 0; i < indices.size(); i += 2)
133 fos <<
"4 " << 2*indices[i] <<
" " << 2*indices[i+1] <<
" " << 2*indices[i+1]+1 <<
" "<< 2*indices[i]+1 << std::endl;
159 for (
int i = 0; i < ncorners; ++i)
161 fos <<
"POLYGONS " << ncorners <<
" " << sum << std::endl;
163 for (
int i = 0; i < ncorners; ++i)
166 for (
int j = 0; j < corners[i]; ++j)
167 fos <<
" " << indices[index++];
174 void writeCellData(
const std::vector<T>& data,
const char* dataname,
int dim, std::ofstream& fos)
176 fos <<
"CELL_DATA " << data.size()*(dim == 2 ? 2 : 1) << std::endl;
177 fos <<
"SCALARS " << dataname <<
" " << TypeNames[Nametraits<T>::nameidx] <<
" 1" << std::endl;
178 fos <<
"LOOKUP_TABLE default" << std::endl;
179 for (
unsigned int i = 0; i < data.size(); ++i)
181 fos << data[i] << std::endl;
183 fos << data[i] << std::endl;
188 void writePointData(
const std::vector<T>& data,
const char* dataname,
int dim, std::ofstream& fos)
190 fos <<
"POINT_DATA " << data.size()*(dim == 2 ? 2 : 1) << std::endl;
191 fos <<
"SCALARS " << dataname <<
" " << TypeNames[Nametraits<T>::nameidx] <<
" 1" << std::endl;
192 fos <<
"LOOKUP_TABLE default" << std::endl;
193 for (
unsigned int i = 0; i < data.size(); ++i)
195 fos << data[i] << std::endl;
197 fos << data[i] << std::endl;
203 const char* filename_;
210 #endif // DUNE_GRIDGLUE_EXTRACTORS_VTKSURFACEWRITER_HH