You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
7.4 KiB
C++
183 lines
7.4 KiB
C++
#include "nmWxGridVTKContainerWidget.h"
|
|
// qglobal.h
|
|
#include <QVBoxLayout>
|
|
#include <QFrame>
|
|
#include <QDebug>
|
|
#include <QtGlobal>
|
|
|
|
#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 <vtkAutoInit.h>
|
|
#ifdef QT_DEBUG
|
|
VTK_MODULE_INIT(vtkRenderingOpenGL)
|
|
#else
|
|
VTK_MODULE_INIT(vtkRenderingOpenGL)
|
|
#endif
|
|
|
|
VTK_MODULE_INIT(vtkInteractionStyle)
|
|
//VTK_MODULE_INIT(vtkRenderingFreeType)
|
|
|
|
#include <QVTKWidget.h>
|
|
#include <vtkImageData.h>
|
|
#include <vtkActor.h>
|
|
#include <vtkCamera.h>
|
|
#include <vtkCylinderSource.h>
|
|
#include <vtkNew.h>
|
|
#include <vtkDataSetMapper.h>
|
|
#include <vtkProperty.h>
|
|
#include <vtkRenderWindow.h>
|
|
#include <QVTKInteractor.h>
|
|
#include <vtkRenderer.h>
|
|
#include <vtkAlgorithmOutput.h>
|
|
#include <vtkSmartPointer.h>
|
|
#include <vtkGenericDataObjectReader.h>
|
|
#include <vtkNamedColors.h>
|
|
|
|
#include <QLabel>
|
|
|
|
//#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<vtkCylinderSource> 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<vtkDataSetMapper> cylinderMapper = vtkSmartPointer<vtkDataSetMapper>::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<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::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<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::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<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::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<QVTKInteractor> renderWindowInteractor = vtkSmartPointer<QVTKInteractor>::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<vtkGenericDataObjectReader> m_reader = vtkSmartPointer<vtkGenericDataObjectReader>::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<vtkDataSetMapper> cylinderMapper = vtkSmartPointer<vtkDataSetMapper>::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<vtkNamedColors> m_colors;
|
|
vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::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<vtkActor> m_wireframeActor = vtkSmartPointer<vtkActor>::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<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::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<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::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<QVTKInteractor> renderWindowInteractor = vtkSmartPointer<QVTKInteractor>::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";
|
|
}
|