我正在尝试编写一个基本的二进制 VTK 文件来使用 ParaView 显示一些数据,但我有一些错误,我不明白为什么。这是我在 C++ 中的测试代码:
#include <iostream>
#include <fstream>
double myarray[72] = {
0,0,0,1,0,0,2,0,0,3,0,0,4,0,0,
5,0,0,0,1,0,1,1,0,2,1,0,3,1,0,
4,1,0,5,1,0,0,2,0,1,2,0,2,2,0,
3,2,0,4,2,0,5,2,0,0,3,0,1,3,0,
2,3,0,3,3,0,4,3,0,5,3,0};
int main()
{
std::ofstream vtkstream("test01.vtk", std::ios::out | std::ios::trunc);
bool ascii = false;
if (vtkstream) {
vtkstream<<"# vtk DataFile Version 2.0"<<"\n";
vtkstream<<"Exemple"<<"\n";
if (ascii) {
vtkstream<<"ASCII"<<"\n";
vtkstream.close();
vtkstream.clear();
vtkstream.open("test01.vtk", std::ios::out | std::ios::app);
vtkstream<<"DATASET STRUCTURED_GRID"<<std::endl;
vtkstream<<"DIMENSIONS 6 4 1"<<std::endl;
vtkstream<<"POINTS 24 double"<<std::endl;
for (unsigned int i = 0; i < 72; ++i) {
vtkstream<<myarray[i]<<" ";
}
} else {
vtkstream<<"BINARY"<<"\n";
vtkstream.close();
vtkstream.clear();
vtkstream.open("test01.vtk", std::ios::out | std::ios::app | std::ios::binary);
vtkstream<<"DATASET STRUCTURED_GRID"<<std::endl;
vtkstream<<"DIMENSIONS 6 4 1"<<std::endl;
vtkstream<<"POINTS 24 double"<<std::endl;
for (unsigned int i = 0; i < 72; ++i) {
vtkstream<<myarray[i];
}
}
vtkstream.close();
} else {
std::cout<<"ERROR"<<std::endl;
}
return 0;
}
ASCII 文件格式完美运行,但二进制版本在 ParaView 中产生以下错误:
一般警告:在 ........\src\VTK\IO\vtkDataReader.cxx,第 1363 行读取二进制数据时出错!
我在 VTK 格式中的错误在哪里?