VTK根据几个点插值成样条曲线,然后以样条曲线为中心线,生成圆柱体管道
#include "vtkActor.h" #include "vtkCamera.h" #include "vtkCellArray.h" #include "vtkPoints.h" #include "vtkPolyData.h" #include "vtkPolyDataMapper.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkProperty.h" #include "vtkTubeFilter.h" #include "vtkParametricSpline.h" #include "vtkParametricFunctionSource.h" int main() { vtkPoints *points=vtkPoints::New(); points->InsertPoint(0, 0.0 ,0.0 ,0.0); points->InsertPoint(1 ,1.0 ,1.0 ,1.0); points->InsertPoint(2 ,1.0, 0.0 ,0.0); points->InsertPoint(3, 1.0 ,0.0, 1.0); ////////////////////////////////////////////////////////////////////////// //插值为样条曲线 vtkParametricSpline *spline = vtkParametricSpline::New(); spline->SetPoints(points); spline->ClosedOff(); vtkParametricFunctionSource *splineSource = vtkParametricFunctionSource::New(); splineSource->SetParametricFunction(spline); vtkPolyDataMapper *splineMapper = vtkPolyDataMapper::New(); splineMapper->SetInputConnection(splineSource->GetOutputPort()); vtkActor *splineActor = vtkActor::New(); splineActor->SetMapper(splineMapper); splineActor->GetProperty()->SetColor(0.3800 ,0.7000 ,0.1600); ////////////////////////////////////////////////////////////////////////// vtkTubeFilter *tube=vtkTubeFilter::New(); tube->SetInput(splineSource->GetOutput()); tube->SetNumberOfSides(20); tube->SetRadius(0.05); vtkPolyDataMapper *tubeMapper=vtkPolyDataMapper::New(); tubeMapper->SetInput(tube->GetOutput()); vtkActor *tubeActor=vtkActor::New(); tubeActor->SetMapper(tubeMapper); vtkRenderer *ren1=vtkRenderer::New(); vtkRenderWindow *renWin=vtkRenderWindow::New(); renWin->AddRenderer(ren1); vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(splineActor); ren1->AddActor(tubeActor); ren1->SetBackground(1, 1, 1); renWin->SetSize(250 ,250); renWin->Render(); iren->Start(); return 0; }