• vtk文件编写


       在paraview中加载vtk文件,可以很好的显示三维空间图像,如下cpp代码:

    #include <iostream>
    #include <fstream>
    #include <windows.h>
    #include <ctime>
    
    using namespace std;
    int main() {
        cout << "this is beginning!" << endl;
        int Nx = 50, Ny = 50;
        fstream outfile;
        char filename[20] = "output.vtk";
        outfile.open(filename, ios::out);
        if (!outfile) {
            cout << "open failed" << endl;
        }
        outfile << "# vtk DataFile Version 2.0" << endl;
        outfile << filename << endl;
        outfile << "ASCII " << endl;
        outfile << "DATASET STRUCTURED_GRID" << endl;
        outfile << "DIMENSIONS " << Nx << " " << Ny << " " << 1 << endl;
        outfile << "POINTS " << Nx * Ny * 1 << " float" << endl;
        for (int i = 0; i < 50; i++) {
            for (int j = 0; j < 50; j++) {
                outfile << i << " " << j << " " << 0 << endl; 
            }
        }
    
        outfile << "POINT_DATA " << Nx * Ny * 1 << endl;
        outfile << "SCALARS CON float 1" << endl;
        outfile << "LOOKUP_TABLE default" << endl;
    
        // 获取随机数
        srand(time(0));
        for (int i = 0; i < 50; i++)
        {
            for (int j = 0; j < 50; j++)
            {
                outfile << rand() % 10 << "	";
            }
        }
        outfile.close();
        system("pause");
        return 0;
    }

    格式是固定的,将输出的文件在paraview中打开即可。如下:

  • 相关阅读:
    记录日常Linux常用软件
    CentOS7.2重置root密码的处理方法
    Nginx配置文件详细说明
    ES项目实战
    foreachRDD
    Hive的数据倾斜
    SparkStreaming实战(数据库(NoSQL))
    Spark(4)
    SparkStreming中 `transform()`算子的 的使用
    RDD源码分析
  • 原文地址:https://www.cnblogs.com/zhuzhenwei918/p/8809641.html
Copyright © 2020-2023  润新知