#include "iostream" #include "vector" #include "map" struct Vertex { float x, y, z; }; // 自定义稀疏矩阵的行和列索引 struct SparseMatrixIndex { int row, col; }; int main() { std::vector vertices; // 存储所有顶点 std::map<SparseMatrixIndex, Vertex> sparseMatrix; // 稀疏矩阵,用于存储顶点 // 假设有几万个三角形的顶点数据需要存储在稀疏矩阵中 // 将顶点数据添加到稀疏矩阵中 for (int i = 0; i < 10000; ++i) { // 假设每个三角形有3个顶点,顶点数据为(x, y, z) Vertex v1 = {i, i, i}; Vertex v2 = {i + 1, i + 1, i + 1}; Vertex v3 = {i + 2, i + 2, i + 2}; // 将三角形的3个顶点添加到稀疏矩阵中 sparseMatrix[{i * 3, 0}] = v1; sparseMatrix[{i * 3 + 1, 1}] = v2; sparseMatrix[{i * 3 + 2, 2}] = v3; } // 输出稀疏矩阵中的顶点数据 for (const auto& entry : sparseMatrix) { SparseMatrixIndex index = entry.first; Vertex vertex = entry.second; std::cout << "Row: " << index.row << ", Col: " << index.col << ", Vertex: (" << vertex.x << ", " << vertex.y << ", " << vertex.z << "\n" << std::endl; } return 0; }