Commit ee427a0d authored by Tomáš Jakubec's avatar Tomáš Jakubec
Browse files

VTKMeshDataReader and VTKMeshDataWriter are now specialized for 2D and

3D cases.
parent d44c22a8
......@@ -9,6 +9,7 @@
template <unsigned int MeshDimension, typename IndexType>
class VTKMeshDataReader {
static_assert (MeshDimension == 2 || MeshDimension == 3, "The VTK file format can represent data only in 2D or 3D");
/**
* @brief readColumn
* reads a single column of traited data
......@@ -21,7 +22,8 @@ class VTKMeshDataReader {
template<typename T, unsigned int Index, unsigned int Position>
static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
-> typename std::enable_if<
Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value
Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value &&
MeshDimension == 3
>::type
{
......@@ -33,7 +35,32 @@ class VTKMeshDataReader {
for (unsigned int j = 0; j < Traits<T>::ttype::template getValue<Index>(data.at(i)).size(); j++){
ist >> value[j];
}
DBGVAR(value);
Traits<T>::ttype::template setValue<Index>(data.at(i), value);
}
}
template<typename T, unsigned int Index, unsigned int Position>
static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
-> typename std::enable_if<
Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value &&
MeshDimension == 2
>::type
{
ist.seekg(dataPositions[Traits<T>::ttype::template getName<Index>()]);
typename Traits<T>::ttype::template type<Index> value;
typename Traits<T>::ttype::template type<Index> dummy;
for (IndexType i = 0; i < data.size(); i++) {
for (unsigned int j = 0; j < Traits<T>::ttype::template getValue<Index>(data.at(i)).size(); j++){
ist >> value[j];
}
ist >> dummy[0];
Traits<T>::ttype::template setValue<Index>(data.at(i), value);
}
......
......@@ -9,6 +9,7 @@
template <unsigned int MeshDimension>
class VTKMeshDataWriter {
static_assert (MeshDimension == 2 || MeshDimension ==3, "The VTK format can hold only 2D or 3D data");
/**
* @brief writeColumn
......@@ -22,7 +23,8 @@ class VTKMeshDataWriter {
template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
-> typename std::enable_if<
Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value
Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value &&
MeshDimension == 3
>::type
{
......@@ -59,6 +61,48 @@ class VTKMeshDataWriter {
}
template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
-> typename std::enable_if<
Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value &&
MeshDimension == 2
>::type
{
if (Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size() == MeshDimension)
ost << "VECTORS ";
else if (Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size() == MeshDimension * MeshDimension)
ost << "TENZORS ";
ost << Traits<T>::ttype::template getName<Index>() << " double\n";
IndexType realIndex = 0;
IndexType localIndex = 0;
for(const std::pair<IndexType, IndexType>& key : writer.backwardCellIndexMapping) {
while (localIndex < key.first) {
for (unsigned int j = 0; j < Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size(); j++) {
ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex))[j] << " 0.0 ";
}
realIndex++;
localIndex++;
}
realIndex = key.second;
localIndex++;
for (unsigned int j = 0; j < Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size(); j++) {
ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex))[j] << " 0.0 ";
}
}
while (realIndex < data.size() - 1) {
for (unsigned int j = 0; j < Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size(); j++) {
ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex))[j] << " 0.0 ";
}
realIndex++;
}
}
template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
-> typename std::enable_if<
......@@ -161,5 +205,4 @@ public:
}
};
#endif // VTKMESHDATAWRITER_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment