定义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>::New();
for( int i = 0; i < 5; ++i )
{
points->InsertNextPoint( p[i] );
}
vtkSmartPointer<vtkPar