VTK初学一,c_Line_CellArray线段的CellArray绘制

时间:2022-06-28 05:46:53
VTK初学一,c_Line_CellArray线段的CellArray绘制

VTK窗口默认坐标方向:

VTK初学一,c_Line_CellArray线段的CellArray绘制

VTK初学一,c_Line_CellArray线段的CellArray绘制

#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>
using namespace std;
#include "vtkPolyDataMapper.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPoints.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkFloatArray.h"
#include "vtkPolyData.h"
#include "vtkDataSetMapper.h"
#include "vtkActor2D.h"
#include "vtkContourFilter.h"
#include "vtkContourValues.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPointData.h"
#include "vtkLine.h"
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCellArray.h>
void myShow(vtkPolyData* polydata)
{
//设置映射器
vtkSmartPointer<vtkPolyDataMapper> amapper=vtkSmartPointer<vtkPolyDataMapper>::New();
amapper->SetInputData(polydata);
// amapper->SetScalarVisibility(0);
amapper->ScalarVisibilityOn();
//声明一个演员
vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
anActor->SetMapper(amapper);
anActor->GetProperty()->SetRepresentationToWireframe();
anActor->GetProperty()->SetDiffuseColor(,,);
anActor->GetProperty()->SetLineWidth();
anActor->GetProperty()->SetPointSize();
//创建显示窗口
vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
ren1->AddActor(anActor);
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera>style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
renWin->SetSize(,);
ren1->ResetCamera();
iren->Start();
}
int main()
{
//几何数据
float pts[][]={{,,},{,,}};
vtkSmartPointer<vtkPoints> Pointes=vtkSmartPointer<vtkPoints>::New();
Pointes->SetNumberOfPoints();
Pointes->InsertPoint(,pts[]);
Pointes->InsertPoint(,pts[]);
//属性数据
vtkSmartPointer<vtkFloatArray> lineScalars=vtkSmartPointer<vtkFloatArray>::New();
lineScalars->SetNumberOfTuples();
lineScalars->InsertValue(,);
lineScalars->InsertValue(,);
//拓扑结构
vtkSmartPointer<vtkLine> aLine=vtkSmartPointer<vtkLine>::New();
aLine->GetPointIds()->SetNumberOfIds();
aLine->GetPointIds()->SetId(,);
aLine->GetPointIds()->SetId(,);
//创建单元数组
vtkSmartPointer<vtkCellArray> lineCells=vtkSmartPointer<vtkCellArray>::New();
lineCells->InsertNextCell(aLine);
//将以上数据组合成一个vtkPolyData
vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(Pointes);
polydata->SetLines(lineCells);
polydata->GetPointData()->SetScalars(lineScalars);
/**********在窗口中显示该结构元****************************************/
myShow(polydata);
return ;
}