#pragma once #include #include namespace meshless { template void writePntVTK(const std::string& path, const Eigen::MatrixXd& pnts, const std::vector& attri) { std::ofstream out(path); out << "# vtk DataFile Version 3.0\n" "Volume Mesh\n" "ASCII\n" "DATASET UNSTRUCTURED_GRID" << std::endl; out << "POINTS " << pnts.rows() << " float" << std::endl; for(int i = 0; i < pnts.rows(); ++i) { for(int j = 0; j < dim; ++j) { out << std::setprecision(4) << pnts(i, j) << " "; } for(int j = dim; j < 3; ++j) { out << "0 "; } out << std::endl; } int innersize = 0; int interSize = 0; int bounSize = 0; out << "CELLS " << pnts.rows() << " " << pnts.rows() * (1 + 1) << std::endl; for(int i = 0; i < pnts.rows(); ++i) { out << "1 " << i << std::endl; } out << "CELL_TYPES " << pnts.rows() << std::endl; for(int i = 0; i < pnts.rows(); ++i) { out << 1 << std::endl; } if(!attri.empty()) { out << "POINT_DATA " << attri.size() << "\n" << "SCALARS point_scalars double 1\n" << "LOOKUP_TABLE default" << std::endl; for(auto& d : attri) { out << d << std::endl; if(d == 1) innersize++; else bounSize++; } } std::cout << "内部点: " << innersize << "\n"; std::cout << "边界点: " << bounSize << "\n"; } };