• VTK学习笔记(十八)指数余弦函数的可视化


     看着图很漂亮

     vtk流程基本就是管线设置数据,获取数据。看看多了,习惯了就好了。

    1. /
    2. //指数余弦函数的可视化。函数值用表面位移表示。颜色表示导数值。
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include
    12. #include
    13. #include
    14. #include
    15. #include
    16. #include
    17. #include
    18. #include
    19. #include
    20. VTK_MODULE_INIT(vtkRenderingOpenGL2);
    21. VTK_MODULE_INIT(vtkInteractionStyle);
    22. VTK_MODULE_INIT(vtkRenderingContextOpenGL2);
    23. int main(int, char*[])
    24. {
    25. vtkNew colors;
    26. vtkNew ren;
    27. vtkNew renWin;
    28. renWin->AddRenderer(ren);
    29. vtkNew iren;
    30. iren->SetRenderWindow(renWin);
    31. // create plane to warp
    32. vtkNew plane; //创建一个平面
    33. plane->SetResolution(300, 300);
    34. vtkNew transform; //转换矩阵
    35. transform->Scale(10.0, 10.0, 1.0); //x,y,z对角数值
    36. vtkNew transF; //对vtkPolyData 移动、旋转、平移,
    37. transF->SetInputConnection(plane->GetOutputPort());
    38. transF->SetTransform(transform);
    39. transF->Update();
    40. // compute Bessel function and derivatives. This portion could be
    41. // encapsulated into source or filter object.
    42. auto input = transF->GetOutput(); //获取输出后的数据
    43. auto numPts = input->GetNumberOfPoints(); //获取输出后的点的数量
    44. vtkNew newPts;
    45. newPts->SetNumberOfPoints(numPts);
    46. vtkNew derivs;
    47. derivs->SetNumberOfTuples(numPts);
    48. vtkNew bessel; //处理后的数据
    49. bessel->CopyStructure(input);
    50. bessel->SetPoints(newPts);
    51. bessel->GetPointData()->SetScalars(derivs); //设置标量数据
    52. double x[3];
    53. for (auto i = 0; i < numPts; i++)
    54. {
    55. input->GetPoint(i, x);
    56. auto r = sqrt(static_cast<double>(x[0] * x[0]) + x[1] * x[1]);
    57. x[2] = exp(-r) * cos(10.0 * r);
    58. newPts->SetPoint(i, x);
    59. auto deriv = -exp(-r) * (cos(10.0 * r) + 10.0 * sin(10.0 * r));
    60. derivs->SetValue(i, deriv);
    61. } //处理过程
    62. // warp plane
    63. vtkNew warp;
    64. warp->SetInputData(bessel);
    65. warp->XYPlaneOn();
    66. warp->SetScaleFactor(0.5);
    67. // mapper and actor
    68. vtkNew mapper;
    69. mapper->SetInputConnection(warp->GetOutputPort());
    70. double tmp[2];
    71. bessel->GetScalarRange(tmp);
    72. mapper->SetScalarRange(tmp[0], tmp[1]);
    73. vtkNew carpet;
    74. carpet->SetMapper(mapper);
    75. // assign our actor to the renderer
    76. ren->AddActor(carpet);
    77. ren->SetBackground(colors->GetColor3d("Beige").GetData());
    78. renWin->SetSize(640, 480);
    79. renWin->SetWindowName("ExponentialCosine");
    80. // draw the resulting scene
    81. ren->ResetCamera();
    82. ren->GetActiveCamera()->Zoom(1.35);
    83. ren->GetActiveCamera()->Elevation(-55);
    84. ren->GetActiveCamera()->Azimuth(25);
    85. ren->ResetCameraClippingRange();
    86. renWin->Render();
    87. iren->Start();
    88. return EXIT_SUCCESS;
    89. }

     

  • 相关阅读:
    聚类算法笔记【零基础数模系列】
    运算放大器的电路模型
    【LLM】提示工程技术提炼精华分享
    C++(第一篇):C++基础入门知识
    玫琳凯公司助力大自然保护协会和全球合作伙伴在联合国海洋大会上举办活动,讨论改善海洋保护区
    【Apollo】开启Apollo之旅:让自动驾驶如此简单
    java-net-php-python-JSP学校教育论坛管理系统开题任务书PPT计算机毕业设计程序
    50.【动态二维数组的运用】
    Vue CLI的Runtime + Compiler和Runtime-only选项的区别和render渲染机制原理解析
    小程序微信支付功能逻辑
  • 原文地址:https://blog.csdn.net/yxmlhc/article/details/127427461