QVTKOpenGLNativeWidget在Qt中的用法

#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
	QVTKOpenGLNativeWidget *widget = new QVTKOpenGLNativeWidget();

	vtkSmartPointer colors = vtkSmartPointer::New();

	vtkSmartPointer sphereSource = vtkSmartPointer::New();

	vtkSmartPointer sphereMapper = vtkSmartPointer::New();

	sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
	vtkSmartPointer sphereActor = vtkSmartPointer::New();

	sphereActor->SetMapper(sphereMapper);
	sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData());

	vtkSmartPointer renderer = vtkSmartPointer::New();
	renderer->AddActor(sphereActor);
	renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData());

	vtkSmartPointer renderWindow = vtkSmartPointer::New();
	renderWindow->AddRenderer(renderer);
	renderWindow->SetWindowName("RenderWindowNoUIFile");

	widget->SetRenderWindow(renderWindow);
	widget->resize(800, 600);
	widget->show();

	return a.exec();
}

 

你可能感兴趣的:(VTK)