vtkimagedatawriter.hh 2.58 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include <array>
#include <iosfwd>
#include <map>

7
#include <dune/vtk/filewriter.hh>
Stenger, Florian's avatar
Stenger, Florian committed
8
9
#include <dune/vtk/function.hh>
#include <dune/vtk/types.hh>
10
11
#include <dune/vtk/datacollectors/structureddatacollector.hh>

12
#include <dune/vtk/vtkwriterinterface.hh>
13

14
namespace Dune
15
{
16
17
18
19
20
  /// File-Writer for ImageData VTK .vti files
  /**
   * Requirement:
   * - DataCollector must be a model of \ref StructuredDataCollector
   **/
21
  template <class GridView, class DataCollector = Vtk::StructuredDataCollector<GridView>>
22
  class VtkImageDataWriter
23
      : public VtkWriterInterface<GridView, DataCollector>
24
25
26
  {
    static constexpr int dimension = GridView::dimension;

27
    using Super = VtkWriterInterface<GridView, DataCollector>;
28
29
30
    using pos_type = typename Super::pos_type;

  public:
31
32
    /// forwarding constructor to \ref VtkWriterInterface
    using Super::Super;
33
34
35

  private:
    /// Write a serial VTK file in Unstructured format
36
    virtual void writeSerialFile (std::ofstream& out) const override;
37
38
39
40

    /// Write a parallel VTK file `pfilename.pvtu` in Unstructured format,
    /// with `size` the number of pieces and serial files given by `pfilename_p[i].vtu`
    /// for [i] in [0,...,size).
41
    virtual void writeParallelFile (std::ofstream& out, std::string const& pfilename, int size) const override;
42
43
44
45
46
47

    virtual std::string fileExtension () const override
    {
      return "vti";
    }

48
49
    virtual void writeGridAppended (std::ofstream& /*out*/, std::vector<std::uint64_t>& /*blocks*/) const override {}

50
51
52
53
  private:
    using Super::dataCollector_;
    using Super::format_;
    using Super::datatype_;
54
    using Super::headertype_;
55
56
57
58
59
60

    // attached data
    using Super::pointData_;
    using Super::cellData_;
  };

61
62
63
64
  // deduction guides
  template <class GridView,
    class = std::void_t<typename GridView::IndexSet>>
  VtkImageDataWriter(GridView const&, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
Stenger, Florian's avatar
Stenger, Florian committed
65
    -> VtkImageDataWriter<GridView, Vtk::StructuredDataCollector<GridView>>;
66
67
68
69
70
71
72
73
74
75
76

  template <class DataCollector,
    class = std::void_t<typename DataCollector::GridView>>
  VtkImageDataWriter(DataCollector&, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
    -> VtkImageDataWriter<typename DataCollector::GridView, DataCollector>;

  template <class DataCollector,
    class = std::void_t<typename DataCollector::GridView>>
  VtkImageDataWriter(std::shared_ptr<DataCollector>, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
    -> VtkImageDataWriter<typename DataCollector::GridView, DataCollector>;

77
} // end namespace Dune
78

79
#include "vtkimagedatawriter.impl.hh"