#include "nmWxGridVTKContainerWidget.h" // qglobal.h #include #include #include #include #pragma comment(lib,"User32.lib") #pragma comment(lib,"gdi32.lib") #pragma comment(lib,"OpenGL32.lib") //#pragma comment(lib,"DbgHelp.lib") //#pragma comment(lib,"Psapi.lib") //#pragma comment(lib,"WS2_32.lib") #pragma comment(lib,"AdvAPI32.lib") #pragma comment(lib,"shell32.lib") #include #ifdef QT_DEBUG VTK_MODULE_INIT(vtkRenderingOpenGL) #else VTK_MODULE_INIT(vtkRenderingOpenGL) #endif VTK_MODULE_INIT(vtkInteractionStyle) //VTK_MODULE_INIT(vtkRenderingFreeType) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include "nmWxGridVTKWidget.h" nmWxGridVTKContainerWidget::nmWxGridVTKContainerWidget(QWidget *parent) : QWidget(parent) { this->initLayout(); this->initVTKWidgetFromFile(); this->showVTK(); } void nmWxGridVTKContainerWidget::initVTKWidget() { // 初始化QVTKWidget QVTKWidget* w = new QVTKWidget; // This creates a polygonal cylinder model with eight circumferential facets // (i.e, in practice an octagonal prism). vtkNew cylinder; cylinder->SetResolution(8); // The mapper is responsible for pushing the geometry into the graphics // library. It may also do color mapping, if scalars or other attributes are // defined. vtkSmartPointer cylinderMapper = vtkSmartPointer::New(); cylinderMapper->SetInputConnection(cylinder->GetOutputPort()); // The actor is a grouping mechanism: besides the geometry (mapper), it // also has a property, transformation matrix, and/or texture map. // Here we set its color and rotate it around the X and Y axes. vtkSmartPointer cylinderActor = vtkSmartPointer::New(); cylinderActor->SetMapper(cylinderMapper); cylinderActor->RotateX(30.0); cylinderActor->RotateY(-45.0); // The renderer generates the image // which is then displayed on the render window. // It can be thought of as a scene to which the actor is added vtkSmartPointer renderer = vtkSmartPointer::New(); renderer->AddActor(cylinderActor); // Zoom in a little by accessing the camera and invoking its "Zoom" method. renderer->ResetCamera(); renderer->GetActiveCamera()->Zoom(1.5); // The render window is the actual GUI window // that appears on the computer screen vtkSmartPointer renderWindow = vtkSmartPointer::New(); renderWindow->SetSize(800, 600); renderWindow->AddRenderer(renderer); renderWindow->SetWindowName("Cylinder"); // The render window interactor captures mouse events // and will perform appropriate camera or actor manipulation // depending on the nature of the events. vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); renderWindowInteractor->SetRenderWindow(renderWindow); // This starts the event loop and as a side effect causes an initial render. renderWindowInteractor->Initialize(); w->SetRenderWindow(renderWindow.Get()); renderWindow->Render(); w->showMaximized(); // w.show(); // vLayout.addWidget(&w); m_frameLaoyt->addWidget(w); } void nmWxGridVTKContainerWidget::initVTKWidgetFromFile() { // 初始化QVTKWidget QVTKWidget* w = new QVTKWidget; // This creates a polygonal cylinder model with eight circumferential facets // (i.e, in practice an octagonal prism). QString vtkFilePath = "D:/geomodelFineGrid.vtk"; vtkSmartPointer m_reader = vtkSmartPointer::New(); m_reader->SetFileName(vtkFilePath.toStdString().c_str()); m_reader->Update(); // The mapper is responsible for pushing the geometry into the graphics // library. It may also do color mapping, if scalars or other attributes are // defined. vtkSmartPointer cylinderMapper = vtkSmartPointer::New(); cylinderMapper->SetInputConnection(m_reader->GetOutputPort()); // The actor is a grouping mechanism: besides the geometry (mapper), it // also has a property, transformation matrix, and/or texture map. // Here we set its color and rotate it around the X and Y axes. vtkNew m_colors; vtkSmartPointer cylinderActor = vtkSmartPointer::New(); cylinderActor->SetMapper(cylinderMapper); // cylinderActor->RotateX(30.0); // cylinderActor->RotateY(-45.0); cylinderActor->GetProperty()->SetColor(m_colors->GetColor3d("Red").GetData()); cylinderActor->GetProperty()->SetOpacity(0.6); // 线actor vtkSmartPointer m_wireframeActor = vtkSmartPointer::New(); m_wireframeActor->SetMapper(cylinderMapper); m_wireframeActor->GetProperty()->SetRepresentationToWireframe(); m_wireframeActor->GetProperty()->SetColor(m_colors->GetColor3d("Black").GetData()); m_wireframeActor->GetProperty()->SetSpecular(1.0); m_wireframeActor->GetProperty()->SetSpecularPower(50.0); m_wireframeActor->GetProperty()->SetAmbient(0.2); m_wireframeActor->GetProperty()->SetDiffuse(0.8); // The renderer generates the image // which is then displayed on the render window. // It can be thought of as a scene to which the actor is added vtkSmartPointer renderer = vtkSmartPointer::New(); renderer->AddActor(cylinderActor); renderer->AddActor(m_wireframeActor); // Zoom in a little by accessing the camera and invoking its "Zoom" method. renderer->ResetCamera(); renderer->GetActiveCamera()->Zoom(1.5); // The render window is the actual GUI window // that appears on the computer screen vtkSmartPointer renderWindow = vtkSmartPointer::New(); renderWindow->SetSize(800, 600); renderWindow->AddRenderer(renderer); renderWindow->SetWindowName("Cylinder"); // The render window interactor captures mouse events // and will perform appropriate camera or actor manipulation // depending on the nature of the events. vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); renderWindowInteractor->SetRenderWindow(renderWindow); // This starts the event loop and as a side effect causes an initial render. renderWindowInteractor->Initialize(); w->SetRenderWindow(renderWindow.Get()); renderWindow->Render(); w->showMaximized(); // w.show(); // vLayout.addWidget(&w); m_frameLaoyt->addWidget(w); } void nmWxGridVTKContainerWidget::showVTK() { //QString vtkFilePath = "D:/geomodelFineGrid.vtk"; //nmWxGridVTKWidget* vtkWidget = new nmWxGridVTKWidget(vtkFilePath); //m_frameLaoyt->addWidget(vtkWidget); } void nmWxGridVTKContainerWidget::initLayout() { m_mainLayout = new QVBoxLayout; this->setLayout(m_mainLayout); QFrame* frame = new QFrame; m_frameLaoyt = new QVBoxLayout; frame->setLayout(m_frameLaoyt); m_mainLayout->addWidget(frame); qDebug() << "in initLayout"; }