-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into bug
- Loading branch information
Showing
8 changed files
with
260 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#include "QtVTKHook.h" | ||
#include "Model.h" | ||
#include <vtkCubeSource.h> | ||
#include <vtkPolyDataMapper.h> | ||
#include <vtkActor.h> | ||
#include <vtkRenderer.h> | ||
#include <vtkRenderWindow.h> | ||
#include <vtkGenericOpenGLRenderWindow.h> | ||
#include <vtkRenderWindowInteractor.h> | ||
#include <vtkCamera.h> | ||
#include <vtkInteractorStyleTrackballCamera.h> | ||
#include <QHBoxLayout> | ||
#include <vtkProperty.h> | ||
|
||
|
||
DisplayWindow::DisplayWindow(QWidget *parent) : QWidget(parent) | ||
{ | ||
setWindowTitle("VTK in Qt"); | ||
resize(800, 600); | ||
|
||
setupGUI(); | ||
|
||
addCube(); | ||
|
||
} | ||
|
||
DisplayWindow::~DisplayWindow() | ||
{ | ||
} | ||
|
||
void | ||
DisplayWindow::setupGUI() | ||
{ | ||
this->vtkwidget = new QVTKOpenGLNativeWidget(this); | ||
|
||
vtkNew<vtkGenericOpenGLRenderWindow> window; | ||
vtkwidget->setRenderWindow(window.Get()); | ||
|
||
// Camera | ||
// vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New(); | ||
// camera->SetViewUp(0, 1, 0); | ||
// camera->SetPosition(0, 0, 10); | ||
// camera->SetFocalPoint(0, 0, 0); | ||
|
||
// Renderer | ||
renderer = vtkSmartPointer<vtkRenderer>::New(); | ||
// renderer->SetActiveCamera(camera); | ||
renderer->SetBackground(1.0, 1.0, 1.0); | ||
vtkwidget->renderWindow()->AddRenderer(renderer); | ||
|
||
// Reset the camera | ||
renderer->ResetCamera(); | ||
|
||
// Layout Qt | ||
QHBoxLayout *hbox = new QHBoxLayout(); | ||
this->setLayout(hbox); | ||
hbox->addWidget(this->vtkwidget); | ||
} | ||
|
||
void | ||
DisplayWindow::addCube() | ||
{ | ||
// Create a cube source | ||
vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New(); | ||
|
||
// Create a mapper | ||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); | ||
mapper->SetInputConnection(cubeSource->GetOutputPort()); | ||
|
||
// Create an actor | ||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); | ||
actor->SetMapper(mapper); | ||
actor->GetProperty()->SetColor(1.0, 0.0, 0.0); // Set color to red | ||
actor->GetProperty()->SetSpecular(1.0); // Enable specular reflection | ||
actor->GetProperty()->SetSpecularPower(50.0); // Set specular power | ||
|
||
// Add the actor to the scene | ||
renderer->AddActor(actor); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
QtVTKHook::QtVTKHook(int &argc, char **argv, | ||
Model &model) : DisplayHook(), model(model) | ||
{ | ||
app = new QApplication(argc, argv); | ||
|
||
window = new DisplayWindow(); | ||
//window->show(); | ||
|
||
//window->setAttribute(Qt::WA_QuitOnClose); | ||
QObject::connect( app, SIGNAL( lastWindowClosed() ), app, SLOT( quit() ) ); | ||
|
||
// app->exec(); | ||
|
||
|
||
model.displayHook = this; | ||
} | ||
|
||
QtVTKHook::~QtVTKHook() | ||
{ | ||
delete app; | ||
} | ||
|
||
void | ||
QtVTKHook::display() | ||
{ | ||
//window->show(); | ||
|
||
// app->exec(); | ||
// std::cout << "quit()" << std::endl; | ||
} | ||
|
||
|
||
void | ||
QtVTKHook::loop() | ||
{ | ||
//window->show(); | ||
|
||
app->exec(); | ||
std::cout << "quit()" << std::endl; | ||
} | ||
|
||
void | ||
QtVTKHook::demo() | ||
{ | ||
// Create a cube source | ||
vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New(); | ||
|
||
// Create a mapper | ||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); | ||
mapper->SetInputConnection(cubeSource->GetOutputPort()); | ||
|
||
// Create an actor | ||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); | ||
actor->SetMapper(mapper); | ||
|
||
// Create a renderer | ||
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); | ||
renderer->AddActor(actor); | ||
|
||
// Create a render window | ||
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); | ||
renderWindow->AddRenderer(renderer); | ||
|
||
// Create an interactor | ||
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); | ||
renderWindowInteractor->SetRenderWindow(renderWindow); | ||
|
||
// Initialize the interactor and start the rendering loop | ||
renderWindowInteractor->Initialize(); | ||
renderWindowInteractor->Start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef QTVTKHOOK_H | ||
#define QTVTKHOOK_H | ||
|
||
#include "sph.h" | ||
#include "DisplayHook.h" | ||
#include <QWidget> | ||
#include <QApplication> | ||
#include <QVTKOpenGLNativeWidget.h> | ||
#include <vtkSmartPointer.h> | ||
#include <vtkRenderer.h> | ||
|
||
class DisplayWindow : public QWidget | ||
{ | ||
Q_OBJECT; | ||
|
||
QVTKOpenGLNativeWidget *vtkwidget; | ||
vtkSmartPointer<vtkRenderer> renderer; | ||
|
||
public: | ||
DisplayWindow(QWidget *parent = nullptr); | ||
~DisplayWindow(); | ||
|
||
private: | ||
void setupGUI(); | ||
void addCube(); | ||
}; | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
class QtVTKHook : public DisplayHook | ||
{ | ||
QApplication *app; | ||
DisplayWindow *window; | ||
Model &model; | ||
|
||
public: | ||
QtVTKHook(int &argc, char **argv, Model &model); | ||
virtual ~QtVTKHook(); | ||
virtual void display() override; | ||
|
||
virtual void loop() override; | ||
|
||
void demo(); | ||
}; | ||
|
||
#endif // QTVTKHOOK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters