• Activiz快速显示大量球体


    之前学习了下activiz,可以通过以下方式显示球体

    1. vtkSphereSource sphere = vtkSphereSource.New(); // 新建球
    2. vtkShrinkPolyData shrink = vtkShrinkPolyData.New(); // 新建数据收缩操作器
    3. shrink.SetInputConnection(sphere.GetOutputPort()); // 连接管道
    4. shrink.SetShrinkFactor(1.0);
    5. vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New(); // 新建制图器
    6. sphereMapper.SetInputConnection(shrink.GetOutputPort()); // 连接管道
    7. vtkActor sphereActor = vtkActor.New(); // 新建角色
    8. sphereActor.SetMapper(sphereMapper); // 传递制图器
    9. renderer.AddActor(sphereActor);
    10. sphere.SetCenter(top_xyz[0], top_xyz[1], top_xyz[2]);
    11. sphere.SetThetaResolution(8); // 设置球纬度参数
    12. sphere.SetPhiResolution(16); // 设置球经度参数
    13. sphere.SetRadius(0.1); // 设置球的半径
    14. sphereActor.GetProperty().SetColor(1, 0, 0); // 设置“角色”颜色[RGB]

    但现在我需要显示大量球体,不想通过循环上面的代码或者搞很多个Actor来显示

    我测试了100个球体的显示

    用以下方法更快显示出来,同时还能设置颜色和大小

    1. void ShowManySpheres()
    2. {
    3. vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
    4. vtkRenderer render = renderWindow.GetRenderers().GetFirstRenderer();
    5. vtkPoints vtkpoints = vtkPoints.New();
    6. vtkFloatArray scales=vtkFloatArray.New();
    7. scales.SetName("scales");
    8. vtkFloatArray col=vtkFloatArray.New();
    9. col.SetName("col");
    10. // setup lookupTable and add some colors
    11. vtkLookupTable colors = vtkLookupTable.New();
    12. colors.SetNumberOfTableValues(4);
    13. colors.SetTableValue(0, 1.0, 0.0, 0.0, 1.0); //red
    14. colors.SetTableValue(1, 0.0, 1.0, 0.0, 1.0); //green
    15. colors.SetTableValue(2, 0.0, 0.0, 1.0, 1.0); //blue
    16. colors.SetTableValue(3, 1.0, 1.0, 0.0, 1.0); //yellow
    17. // the last double value is for opacity (1->max, 0->min)
    18. for (int i = 0; i < 100; i++)
    19. {
    20. vtkpoints.InsertPoint(i, 15 * Math.Cos(i * Math.PI / 50), 15 * Math.Sin(i * Math.PI / 50), 0); // sphere in circle
    21. scales.InsertNextValue(0.5f); // random radius between 0 and 0.99
    22. col.InsertNextValue((i*1.0f) % 4); // random color label
    23. }
    24. // grid structured to append center, radius and color label
    25. vtkUnstructuredGrid grid = vtkUnstructuredGrid.New();
    26. grid.SetPoints(vtkpoints);
    27. grid.GetPointData().AddArray(scales);
    28. grid.GetPointData().SetActiveScalars("scales"); // !!!to set radius first
    29. grid.GetPointData().AddArray(col);
    30. // create anything you want here, we will use a sphere for the demo
    31. vtkSphereSource sphereSource = vtkSphereSource.New();
    32. // object to group sphere and grid and keep smooth interaction
    33. vtkGlyph3D glyph3D = vtkGlyph3D.New();
    34. glyph3D.SetInput(grid);
    35. glyph3D.SetSourceConnection(sphereSource.GetOutputPort());
    36. // create a mapper and actor
    37. vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
    38. mapper.SetInputConnection(glyph3D.GetOutputPort());
    39. mapper.SetScalarModeToUsePointFieldData(); // without, color are displayed regarding radius and not color label
    40. mapper.SetScalarRange(0,3); // to scale color label (without, col should be between 0 and 1)
    41. mapper.SelectColorArray("col"); // !!!to set color (nevertheless you will have nothing)
    42. mapper.SetLookupTable(colors);
    43. vtkActor actor = vtkActor.New();
    44. actor.SetMapper(mapper);
    45. render.AddActor(actor);
    46. render.ResetCamera();
    47. Refresh();
    48. }

  • 相关阅读:
    C++Atomic与内存序
    【数据结构】——双链表(增删查改)
    【音视频】MP4封装格式
    LeetCode之二叉树
    Spring Boot 整合Redis实现消息发布与订阅
    sklearn机器学习——day07
    linux学习-文件搜索
    每日三题 6.28
    时间序列的数据分析(六):指数平滑预测法
    Redis(十一) 分布式锁
  • 原文地址:https://blog.csdn.net/Isaac320/article/details/133163299