看着图很漂亮
vtk流程基本就是管线设置数据,获取数据。看看多了,习惯了就好了。
- /
- //指数余弦函数的可视化。函数值用表面位移表示。颜色表示导数值。
-
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
-
- #include
- VTK_MODULE_INIT(vtkRenderingOpenGL2);
- VTK_MODULE_INIT(vtkInteractionStyle);
- VTK_MODULE_INIT(vtkRenderingContextOpenGL2);
- int main(int, char*[])
- {
- vtkNew
colors; - vtkNew
ren; - vtkNew
renWin; - renWin->AddRenderer(ren);
-
- vtkNew
iren; - iren->SetRenderWindow(renWin);
-
- // create plane to warp
- vtkNew
plane; //创建一个平面 - plane->SetResolution(300, 300);
-
- vtkNew
transform; //转换矩阵 - transform->Scale(10.0, 10.0, 1.0); //x,y,z对角数值
-
- vtkNew
transF; //对vtkPolyData 移动、旋转、平移, - transF->SetInputConnection(plane->GetOutputPort());
- transF->SetTransform(transform);
- transF->Update();
-
- // compute Bessel function and derivatives. This portion could be
- // encapsulated into source or filter object.
- auto input = transF->GetOutput(); //获取输出后的数据
- auto numPts = input->GetNumberOfPoints(); //获取输出后的点的数量
-
- vtkNew
newPts; - newPts->SetNumberOfPoints(numPts);
-
- vtkNew
derivs; - derivs->SetNumberOfTuples(numPts);
-
- vtkNew
bessel; //处理后的数据 - bessel->CopyStructure(input);
- bessel->SetPoints(newPts);
- bessel->GetPointData()->SetScalars(derivs); //设置标量数据
-
- double x[3];
-
- for (auto i = 0; i < numPts; i++)
- {
- input->GetPoint(i, x);
- auto r = sqrt(static_cast<double>(x[0] * x[0]) + x[1] * x[1]);
- x[2] = exp(-r) * cos(10.0 * r);
- newPts->SetPoint(i, x);
- auto deriv = -exp(-r) * (cos(10.0 * r) + 10.0 * sin(10.0 * r));
- derivs->SetValue(i, deriv);
- } //处理过程
-
- // warp plane
- vtkNew
warp; - warp->SetInputData(bessel);
- warp->XYPlaneOn();
- warp->SetScaleFactor(0.5);
-
- // mapper and actor
- vtkNew
mapper; - mapper->SetInputConnection(warp->GetOutputPort());
- double tmp[2];
- bessel->GetScalarRange(tmp);
- mapper->SetScalarRange(tmp[0], tmp[1]);
-
- vtkNew
carpet; - carpet->SetMapper(mapper);
-
- // assign our actor to the renderer
- ren->AddActor(carpet);
- ren->SetBackground(colors->GetColor3d("Beige").GetData());
- renWin->SetSize(640, 480);
- renWin->SetWindowName("ExponentialCosine");
-
- // draw the resulting scene
- ren->ResetCamera();
- ren->GetActiveCamera()->Zoom(1.35);
- ren->GetActiveCamera()->Elevation(-55);
- ren->GetActiveCamera()->Azimuth(25);
- ren->ResetCameraClippingRange();
- renWin->Render();
-
- iren->Start();
-
- return EXIT_SUCCESS;
- }