17 #include <vtkDataArray.h>
18 #include <vtkDataCompressor.h>
19 #include <vtkObjectFactory.h>
20 #include <vtkPointData.h>
21 #include <vtkXMLPImageDataWriter.h>
40 this->WriteVectorAttribute(
"WholeExtent", 6,
const_cast<int*
>(
whole_extent_));
41 vtkImageData* input = this->GetInput();
42 this->WriteVectorAttribute(
"Origin", 3, input->GetOrigin());
43 this->WriteVectorAttribute(
"Spacing", 3, input->GetSpacing());
51 const std::string& file_prefix,
52 const std::array<int, 6>& whole_extent,
53 const std::vector<std::array<int, 6>>& piece_extents,
55 auto* origin = img->GetOrigin();
56 auto* spacing = img->GetSpacing();
57 auto endianess_str = vti->GetByteOrder() == vtkXMLWriter::LittleEndian
60 auto header_type_str =
61 vti->GetHeaderType() == vtkXMLWriter::UInt32 ?
"UInt32" :
"UInt64";
62 auto* compressor = vti->GetCompressor();
63 std::string compressor_str =
64 compressor !=
nullptr ? compressor->GetClassName() :
"";
67 auto version_str =
"0.1";
69 auto filename =
Concat(folder,
"/", file_prefix,
".pvti");
70 std::ofstream ofs(filename);
72 ofs <<
"<?xml version=\"1.0\"?>\n"
73 <<
"<VTKFile type=\"PImageData\" "
74 <<
"version=\"" << version_str <<
"\" "
75 <<
"byte_order=\"" << endianess_str <<
"\" "
76 <<
"header_type=\"" << header_type_str <<
"\" "
77 <<
"compressor=\"" << compressor_str <<
"\">\n";
78 ofs <<
"<PImageData WholeExtent=\"" <<
ArrayToString(whole_extent.data(), 6)
79 <<
"\" GhostLevel=\"0\" Origin=\"" <<
ArrayToString(origin, 3)
81 ofs <<
" <PPointData>\n";
84 auto* pd = img->GetPointData();
85 for (
int i = 0; i < pd->GetNumberOfArrays(); ++i) {
86 auto name = pd->GetArray(i)->GetName();
87 auto components = pd->GetArray(i)->GetNumberOfComponents();
88 auto float_size =
sizeof(
real_t) * 8;
89 ofs <<
" <PDataArray type=\"Float" << float_size <<
"\" Name=\""
90 << name <<
"\" NumberOfComponents=\"" << components <<
"\"/>\n";
92 ofs <<
" </PPointData>\n";
96 for (
auto& e : piece_extents) {
97 auto vti_filename =
Concat(file_prefix,
"_", counter++,
".vti");
99 <<
"\" Source=\"" << vti_filename <<
"\"/>\n";
102 ofs <<
" </PImageData>\n";
103 ofs <<
"</VTKFile>\n";
108 const std::string& folder,
const std::string& file_prefix,
109 const std::vector<vtkImageData*>& images, uint64_t num_pieces,
110 const std::array<int, 6>& whole_extent,
111 const std::vector<std::array<int, 6>>& piece_extents)
const {
114 #pragma omp parallel for schedule(static, 1)
115 for (uint64_t i = 0; i < num_pieces; ++i) {
116 auto vti_filename =
Concat(folder,
"/", file_prefix,
"_", i,
".vti");
117 vtkNew<VtiWriter> vti;
118 vti->SetFileName(vti_filename.c_str());
119 vti->SetInputData(images[i]);
120 vti->SetWholeExtent(whole_extent.data());
121 vti->SetDataModeToBinary();
122 vti->SetEncodeAppendedData(
false);
123 if (!param->visualization_compress_pv_files) {
124 vti->SetCompressorTypeToNone();
130 pvti.
Write(folder, file_prefix, whole_extent, piece_extents, images[0],