BioDynaMo  v1.05.120-25dc9790
parallel_vti_writer.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_VISUALIZATION_PARAVIEW_PARALLEL_VTI_WRITER_H_
16 #define CORE_VISUALIZATION_PARAVIEW_PARALLEL_VTI_WRITER_H_
17 
18 // std
19 #include <array>
20 #include <fstream>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 // Paraview
25 #include <vtkImageData.h>
26 #include <vtkXMLImageDataWriter.h>
27 
28 namespace bdm {
29 
30 // -----------------------------------------------------------------------------
31 class VtiWriter : public vtkXMLImageDataWriter {
32  public:
33  vtkTypeMacro(VtiWriter, vtkXMLImageDataWriter);
34  static VtiWriter* New();
35 
36  VtiWriter();
37 
38  void SetWholeExtent(const int* whole_extent);
39 
40  void WritePrimaryElementAttributes(std::ostream& os,
41  vtkIndent indent) override;
42 
43  private:
44  const int* whole_extent_;
45 };
46 
47 // -----------------------------------------------------------------------------
48 class PvtiWriter {
49  public:
50  void Write(const std::string& folder, const std::string& file_prefix,
51  const std::array<int, 6>& whole_extent,
52  const std::vector<std::array<int, 6>>& piece_extents,
53  vtkImageData* img, VtiWriter* vti);
54 
55  private:
56  template <typename T>
57  std::string ArrayToString(T* data, int length) const {
58  std::stringstream stream;
59  stream << data[0];
60  for (int i = 1; i < length; ++i) {
61  stream << " " << data[i];
62  }
63  return stream.str();
64  }
65 };
66 
67 // -----------------------------------------------------------------------------
69  void operator()(const std::string& folder, const std::string& file_prefix,
70  const std::vector<vtkImageData*>& images, uint64_t num_pieces,
71  const std::array<int, 6>& whole_extent,
72  const std::vector<std::array<int, 6>>& piece_extents) const;
73 };
74 
75 } // namespace bdm
76 
77 #endif // CORE_VISUALIZATION_PARAVIEW_PARALLEL_VTI_WRITER_H_
bdm::VtiWriter::whole_extent_
const int * whole_extent_
Definition: parallel_vti_writer.h:44
bdm::VtiWriter
Definition: parallel_vti_writer.h:31
bdm::VtiWriter::SetWholeExtent
void SetWholeExtent(const int *whole_extent)
Definition: parallel_vti_writer.cc:33
bdm::ParallelVtiWriter
Definition: parallel_vti_writer.h:68
bdm
Definition: agent.cc:39
bdm::PvtiWriter::ArrayToString
std::string ArrayToString(T *data, int length) const
Definition: parallel_vti_writer.h:57
bdm::VtiWriter::VtiWriter
VtiWriter()
bdm::VtiWriter::WritePrimaryElementAttributes
void WritePrimaryElementAttributes(std::ostream &os, vtkIndent indent) override
Definition: parallel_vti_writer.cc:38
bdm::PvtiWriter
Definition: parallel_vti_writer.h:48
bdm::VtiWriter::vtkTypeMacro
vtkTypeMacro(VtiWriter, vtkXMLImageDataWriter)
bdm::PvtiWriter::Write
void Write(const std::string &folder, const std::string &file_prefix, const std::array< int, 6 > &whole_extent, const std::vector< std::array< int, 6 >> &piece_extents, vtkImageData *img, VtiWriter *vti)
Definition: parallel_vti_writer.cc:50
bdm::ParallelVtiWriter::operator()
void operator()(const std::string &folder, const std::string &file_prefix, const std::vector< vtkImageData * > &images, uint64_t num_pieces, const std::array< int, 6 > &whole_extent, const std::vector< std::array< int, 6 >> &piece_extents) const
Definition: parallel_vti_writer.cc:107
bdm::VtiWriter::New
static VtiWriter * New()