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

VTKMeshDataWriter checks in the MeshDataContainer for DataContainer of

given mesh dimension and exports it if it has default traits.
parent 05d0e514
Loading
Loading
Loading
Loading
+34 −3
Original line number Original line Diff line number Diff line
@@ -10,11 +10,11 @@ template<typename DataType, unsigned int Position, unsigned int MappedDimenion>
struct DataContainer : public std::vector<DataType> {
struct DataContainer : public std::vector<DataType> {
    using type = DataType;
    using type = DataType;


    constexpr unsigned int getPosition() {
    static constexpr unsigned int getPosition() {
        return Position;
        return Position;
    }
    }


    constexpr unsigned int getMappedDimension() {
    static constexpr unsigned int getMappedDimension() {
        return MappedDimenion;
        return MappedDimenion;
    }
    }
};
};
@@ -56,9 +56,25 @@ public:
    };
    };


    template<typename _DataType>
    template<typename _DataType>
    struct _DataContainer<_DataType, 0> : public std::vector<_DataType>{
    struct _DataContainer<_DataType, 0>{
        DataContainer<_DataType, 0, dimensionAt<0U>()> _data;
        DataContainer<_DataType, 0, dimensionAt<0U>()> _data;
    };
    };

    /**
     * Data container type according to pos
     */
    template <unsigned int Pos>
    using DataContainerType = DataContainer<DataType, 0, dimensionAt<Pos>()>;

    /**
     * @brief size<HR>
     * Returns the number of vectors contained in the MeshDataContainer.
    * @return
    */
   static constexpr unsigned int size() {
       return sizeof... (Dimensions);
   }

private:
private:
    template<unsigned int pos, typename dummy = void>
    template<unsigned int pos, typename dummy = void>
    struct Alocator{
    struct Alocator{
@@ -227,6 +243,21 @@ public:
        //std::vector<DataType<0>> _data;
        //std::vector<DataType<0>> _data;
    };
    };


    /**
     * Data container type according to pos
     */
    template <unsigned int Pos>
    using DataContainerType = DataContainer<DataType<Pos>, 0, dimensionAt<Pos>()>;

    /**
     * @brief size<HR>
     * Returns the number of vectors contained in the MeshDataContainer.
    * @return
    */
   static constexpr unsigned int size() {
       return sizeof... (Dimensions);
   }

    template<unsigned int pos, typename _DataType, typename... _DataTypes>
    template<unsigned int pos, typename _DataType, typename... _DataTypes>
    struct Alocator{
    struct Alocator{
        template<unsigned int Dimension, typename IndexType, typename Real, unsigned int ...Reserve>
        template<unsigned int Dimension, typename IndexType, typename Real, unsigned int ...Reserve>
+34 −2
Original line number Original line Diff line number Diff line
@@ -110,7 +110,40 @@ class VTKMeshDataWriter {
    };
    };




public:
    template<typename T,typename IndexType, typename Real, unsigned int Position>
    static void writeToStream(std::ostream& ost, DataContainer<T, Position, MeshDimension>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
        using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
        static_assert (Detail::has_default_traits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
        ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl;
        writeCellData<typename Traits<type>::ttype>::write(ost, data, writer);
    }

private:
    template <unsigned int Index, bool OK = false>
    struct MeshDataIterator{
        template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
        static void writeToStream(std::ostream& ost, MeshDataContainer<T, Dimensions...>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
            using type = typename MeshDataContainer<T, Dimensions...>::template DataContainerType<Index>::type;

            if constexpr (Detail::has_default_traits<type>::value && MeshDataContainer<T, Dimensions...>::template DataContainerType<Index>::getMappedDimension() == MeshDimension){
                VTKMeshDataWriter<MeshDimension>::writeCellData<typename Traits<type>::ttype>::write(ost, data.template getDataByPos<Index>(), writer);
            }
            MeshDataIterator<Index - 1, OK | Detail::has_default_traits<type>::value>:: writeToStream(ost, data, writer);
        }
    };


    template <bool OK>
    struct MeshDataIterator <0, OK> {
        template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
        static void writeToStream(std::ostream& ost, MeshDataContainer<T, Dimensions...>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
            using type = typename MeshDataContainer<T, Dimensions...>::template DataContainerType<0>::type;
            static_assert (OK | Detail::has_default_traits<type>::value, "The mesh data container must have at least one DataContainer mapped to cells with traits for example using macro MAKE_ATTRIBUTE_TRAIT see header Traits.h");
            if constexpr (Detail::has_default_traits<type>::value && MeshDataContainer<T, Dimensions...>::template DataContainerType<0>::getMappedDimension() == MeshDimension){
                VTKMeshDataWriter<MeshDimension>::writeCellData<typename Traits<type>::ttype>::write(ost, data.template getDataByPos<0>(), writer);
            }
        }
    };


public:
public:
    template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
    template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
@@ -118,9 +151,8 @@ public:
        using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
        using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
        static_assert (Detail::has_default_traits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
        static_assert (Detail::has_default_traits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
        ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl;
        ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl;
        writeCellData<typename Traits<type>::ttype>::write(ost, data.template getDataByDim<MeshDimension>(), writer);
        MeshDataIterator<MeshDataContainer<T, Dimensions...>::size() - 1>::writeToStream(ost, data, writer);
    }
    }

};
};




+1 −1
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.10.0, 2019-11-06T13:58:55. -->
<!-- Written by QtCreator 4.10.0, 2019-11-07T00:24:09. -->
<qtcreator>
<qtcreator>
 <data>
 <data>
  <variable>EnvironmentId</variable>
  <variable>EnvironmentId</variable>