本文主要是介绍【VTK】create spline points,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
定义5个点
double p[5][3] = { {0.0, 4.0, 0.0},{2.0, 0.0, 0.0},{4.0, 2.0, 0.0},{6.0, 0.0, 0.0},{8.0, 4.0, 0.0} };
定义500个插值点
示例代码:
double p[5][3] = { {0.0, 4.0, 0.0},{2.0, 0.0, 0.0},{4.0, 2.0, 0.0},{6.0, 0.0, 0.0},{8.0, 4.0, 0.0} };vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();for( int i = 0; i < 5; ++i ){points->InsertNextPoint( p[i] );}vtkSmartPointer<vtkParametricSpline> spline =vtkSmartPointer<vtkParametricSpline>::New();spline->SetPoints(points);vtkSmartPointer<vtkPoints> betaPoints = vtkSmartPointer<vtkPoints>::New();int index = 0;int countOfDeltaPoints = 500;double step = 1.0 / ( countOfDeltaPoints - 1 );for( double i = 0; i <= 1; i = i + step ){double tmp[3] = { i, 0, 0 };spline->Evaluate( tmp, tmp, NULL );betaPoints->InsertPoint( index++, tmp );}
使用vtkParametricFunctionSource的polyData,不用开发者自己来create points:
示例代码:
#include <vtkSmartPointer.h>
#include <vtkParametricFunctionSource.h>
#include <vtkParametricSpline.h>#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkProperty.h>#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkTransform.h>#include <vtkSphereSource.h>
#include <vtkNamedColors.h>
#include <vtkTextSource.h>
#include <vtkCoordinate.h>
#include <vtkPolyDataMapper2D.h>
#include <vtkActor2D.h>#include <QString>
#include <iostream>
using namespace std;int main(int, char *[])
{vtkSmartPointer<vtkNamedColors> colors =vtkSmartPointer<vtkNamedColors>::New();double p[5][3] = { {0.0, 4.0, 0.0},{2.0, 0.0, 0.0},{4.0, 2.0, 0.0},{6.0, 0.0, 0.0},{8.0, 4.0, 0.0} };vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::Ne
这篇关于【VTK】create spline points的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!