vtk三维体模型渲染
2022/3/28 23:29:48
本文主要是介绍vtk三维体模型渲染,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
string Trim(string& str) { //str.find_first_not_of(" \t\r\n"),在字符串str中从索引0开始,返回首次不匹配"\t\r\n"的位置 str.erase(0, str.find_first_not_of(" \t\r\n")); str.erase(str.find_last_not_of(" \t\r\n") + 1); return str; } int main() { vtkSmartPointer<vtkNamedColors> color = vtkSmartPointer<vtkNamedColors>::New(); vtkSmartPointer<vtkPoints> ps = vtkSmartPointer<vtkPoints>::New(); double x, y, z; ifstream fin("D:\\QTData\\Vtk-new\\ceshi2.csv"); //打开文件流操作-绝对路径 string line; while (getline(fin, line)) //整行读取,换行符“\n”区分,遇到文件尾标志eof终止读取 { //cout <<"原始字符串:"<< line << endl; //整行输出 istringstream sin(line); //将整行字符串line读入到字符串流istringstream中 vector<string> fields; //声明一个字符串向量 string field; while (getline(sin, field, ',')) //将字符串流sin中的字符读入到field字符串中,以逗号为分隔符 { fields.push_back(field); //将刚刚读取的字符串添加到向量fields中 } string sx = Trim(fields[0]); string sy = Trim(fields[1]); string sz = Trim(fields[2]); //字符串转换成double型数字 istringstream streamx, streamy, streamz; streamx.str(sx), streamy.str(sy), streamz.str(sz); streamx >> x, streamy >> y, streamz >> z; ps->InsertNextPoint(x, y, z); //新读取的数据赋予点的几何结构 } fin.close(); //关闭文件 vtkSmartPointer<vtkPolyData>polydata = vtkSmartPointer<vtkPolyData>::New(); polydata->SetPoints(ps); vtkSmartPointer<vtkDelaunay3D> delaunay3D = vtkSmartPointer<vtkDelaunay3D>::New(); delaunay3D->SetInputData(polydata); delaunay3D->Update(); vtkSmartPointer<vtkDataSetMapper> delaunayMapper = vtkSmartPointer<vtkDataSetMapper>::New(); delaunayMapper->SetInputConnection(delaunay3D->GetOutputPort()); vtkSmartPointer<vtkActor> delaunayActor = vtkSmartPointer<vtkActor>::New(); delaunayActor->SetMapper(delaunayMapper); delaunayActor->GetProperty()->SetColor(color->GetColor3d("banana").GetData()); delaunayActor->GetProperty()->EdgeVisibilityOn(); vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New(); glyphFilter->SetInputData(delaunay3D->GetOutput()); vtkSmartPointer<vtkPolyDataMapper> pointMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); pointMapper->SetInputConnection(glyphFilter->GetOutputPort()); vtkSmartPointer<vtkActor> pointActor = vtkSmartPointer<vtkActor>::New(); pointActor->GetProperty()->SetColor(color->GetColor3d("Tomato").GetData()); pointActor->GetProperty()->SetPointSize(5); pointActor->SetMapper(pointMapper); vtkSmartPointer<vtkRenderer> delaunayRenderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->SetSize(900, 900); renderWindow->AddRenderer(delaunayRenderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); delaunayRenderer->AddActor(delaunayActor); delaunayRenderer->AddActor(pointActor); delaunayRenderer->SetBackground(color->GetColor3d("Mint").GetData()); // Render and interact renderWindowInteractor->Start(); return EXIT_SUCCESS; }
这篇关于vtk三维体模型渲染的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-01成为百万架构师的第一课:设计模式:Spring中的设计模式
- 2025-01-01一个基于注解驱动的可视化的DDD架构-超越COLA的设计
- 2025-01-01PlantUML 时序图 基本例子
- 2025-01-01plantuml 信号时序图
- 2025-01-01聊聊springboot项目如何优雅进行数据校验
- 2024-12-31自由职业者效率提升指南:3个时间管理技巧搞定多个项目
- 2024-12-31适用于咨询行业的项目管理工具:提升跨团队协作和工作效率的最佳选择
- 2024-12-31高效协作的未来:2024年实时文档工具深度解析
- 2024-12-31商务谈判者的利器!哪 6 款办公软件能提升春节合作成功率?
- 2024-12-31小团队如何选择最实用的项目管理工具?高效协作与任务追踪指南