#ifndef VTKHSWPOLYLINEWIDGET_H
#define VTKHSWPOLYLINEWIDGET_H
/*
* ModuleName: vtkHSWPolylineWidget
* Description: 實現多邊形折線
* Author: hsw
* Date: 2020-03-22
*
*/
#include <vtkSmartPointer.h>
#include <vtkDataSetMapper.h>
#include <vtkLine.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
class vtkHSWPolylineWidget
{
public:
vtkHSWPolylineWidget();
~vtkHSWPolylineWidget();
public:
vtkSmartPointer<vtkDataSetMapper> createPolyLine(int pointCnt, double* points);
private:
vtkSmartPointer<vtkPoints> _polylinePoints;
vtkSmartPointer<vtkLine > _polylineCell;
vtkSmartPointer<vtkCellArray> _polylineCellArray;
vtkSmartPointer<vtkPolyData> _polylineData;
vtkSmartPointer<vtkDataSetMapper> _polylineMapper;
};
#endif // VTKHSWPOLYLINEWIDGET_H
#include "vtkhswpolylinewidget.h"
vtkHSWPolylineWidget::vtkHSWPolylineWidget()
{
}
vtkHSWPolylineWidget::~vtkHSWPolylineWidget()
{
//TODO...
}
vtkSmartPointer<vtkDataSetMapper> vtkHSWPolylineWidget::createPolyLine(int pointCnt, double *points)
{
_polylinePoints = vtkSmartPointer<vtkPoints>::New();
for(int i = 0; i < pointCnt; ++i)
{
_polylinePoints->InsertNextPoint(points + i * 3);
}
_polylineCellArray = vtkSmartPointer<vtkCellArray>::New();
for(int i = 0; i < pointCnt - 1; ++i)
{
_polylineCell = vtkSmartPointer<vtkLine>::New();
_polylineCell->GetPointIds()->SetId(0, i);
_polylineCell->GetPointIds()->SetId(1, i+1);
_polylineCellArray->InsertNextCell(_polylineCell);
}
_polylineData = vtkSmartPointer<vtkPolyData>::New();
_polylineData->SetPoints(_polylinePoints);
_polylineData->SetLines(_polylineCellArray);
_polylineMapper = vtkSmartPointer<vtkDataSetMapper>::New();
_polylineMapper->SetInputData(_polylineData);
return _polylineMapper;
}