diff --git a/src/Cxx/Qt/BorderWidgetQt.cxx b/src/Cxx/Qt/BorderWidgetQt.cxx index 6f9f5d33e1ab4170fcc58cf2d16fb43ed74a928c..3a81a6f8170e66be24d45a060872e98653670623 100644 --- a/src/Cxx/Qt/BorderWidgetQt.cxx +++ b/src/Cxx/Qt/BorderWidgetQt.cxx @@ -1,41 +1,55 @@ #include "BorderWidgetQt.h" #include "ui_BorderWidgetQt.h" +#include <vtkBorderRepresentation.h> #include <vtkBorderWidget.h> +#include <vtkCamera.h> #include <vtkCommand.h> #include <vtkGenericOpenGLRenderWindow.h> +#include <vtkLookupTable.h> #include <vtkNamedColors.h> #include <vtkNew.h> +#include <vtkPlatonicSolidSource.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> -#include <vtkSphereSource.h> #include <vtkVersion.h> +#include <vtkWidgetCallbackMapper.h> +#include <vtkWidgetEvent.h> #if VTK_VERSION_NUMBER >= 89000000000ULL #define VTK890 1 #endif -class BorderCallback : public vtkCommand +namespace { +/** Get a specialised lookup table for the platonic solids. + * + * Since each face of a vtkPlatonicSolidSource has a different + * cell scalar, we create a lookup table with a different colour + * for each face. + * The colors have been carefully chosen so that adjacent cells + * are colored distinctly. + * + * @return The lookup table. + */ +vtkNew<vtkLookupTable> GetPlatonicLUT(); + +class vtkCustomBorderWidget : public vtkBorderWidget { public: - BorderCallback() - { - } - - static BorderCallback* New() - { - return new BorderCallback; - } - - virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long, void*) - { - // vtkBorderWidget *borderWidget = - // reinterpret_cast<vtkBorderWidget*>(caller); - } + static vtkCustomBorderWidget* New(); + vtkTypeMacro(vtkCustomBorderWidget, vtkBorderWidget); + + static void EndSelectAction(vtkAbstractWidget* w); + + vtkCustomBorderWidget(); }; +vtkStandardNewMacro(vtkCustomBorderWidget); + +} // namespace + // Constructor BorderWidgetQt::BorderWidgetQt(QWidget* parent) : QMainWindow(parent), ui(new Ui::BorderWidgetQt) @@ -51,18 +65,24 @@ BorderWidgetQt::BorderWidgetQt(QWidget* parent) this->ui->qvtkWidget->SetRenderWindow(renderWindow); #endif - // Sphere - vtkNew<vtkSphereSource> sphereSource; - sphereSource->Update(); - vtkNew<vtkPolyDataMapper> sphereMapper; - sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); - vtkNew<vtkActor> sphereActor; - sphereActor->SetMapper(sphereMapper); - sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); + auto lut = GetPlatonicLUT(); + + vtkNew<vtkPlatonicSolidSource> source; + source->SetSolidTypeToDodecahedron(); + + vtkNew<vtkPolyDataMapper> mapper; + mapper->SetInputConnection(source->GetOutputPort()); + mapper->SetLookupTable(lut); + mapper->SetScalarRange(0, 19); + + vtkNew<vtkActor> actor; + actor->SetMapper(mapper); - // VTK Renderer vtkNew<vtkRenderer> renderer; - renderer->AddActor(sphereActor); + renderer->AddActor(actor); + renderer->GetActiveCamera()->Elevation(30.0); + renderer->GetActiveCamera()->Azimuth(180.0); + renderer->ResetCamera(); renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData()); // Connect VTK with Qt @@ -73,13 +93,14 @@ BorderWidgetQt::BorderWidgetQt(QWidget* parent) #endif // Add a border widget to the renderer - vtkNew<vtkBorderWidget> bw; - this->BorderWidget = bw; + this->BorderWidget = vtkNew<vtkCustomBorderWidget>(); #if VTK890 this->BorderWidget->SetInteractor(this->ui->qvtkWidget->interactor()); #else - this->BorderWidget->SetInteractor(this->ui->qvtkWidget->GetInteractor()); + this->borderWidget->SetInteractor(this->ui->qvtkWidget->GetInteractor()); #endif + this->BorderWidget->CreateDefaultRepresentation(); + this->BorderWidget->SelectableOff(); this->BorderWidget->On(); } @@ -87,3 +108,66 @@ BorderWidgetQt::~BorderWidgetQt() { delete this->ui; } + +namespace { + +vtkNew<vtkLookupTable> GetPlatonicLUT() +{ + vtkNew<vtkLookupTable> lut; + lut->SetNumberOfTableValues(20); + lut->SetTableRange(0.0, 19.0); + lut->Build(); + lut->SetTableValue(0, 0.1, 0.1, 0.1); + lut->SetTableValue(1, 0, 0, 1); + lut->SetTableValue(2, 0, 1, 0); + lut->SetTableValue(3, 0, 1, 1); + lut->SetTableValue(4, 1, 0, 0); + lut->SetTableValue(5, 1, 0, 1); + lut->SetTableValue(6, 1, 1, 0); + lut->SetTableValue(7, 0.9, 0.7, 0.9); + lut->SetTableValue(8, 0.5, 0.5, 0.5); + lut->SetTableValue(9, 0.0, 0.0, 0.7); + lut->SetTableValue(10, 0.5, 0.7, 0.5); + lut->SetTableValue(11, 0, 0.7, 0.7); + lut->SetTableValue(12, 0.7, 0, 0); + lut->SetTableValue(13, 0.7, 0, 0.7); + lut->SetTableValue(14, 0.7, 0.7, 0); + lut->SetTableValue(15, 0, 0, 0.4); + lut->SetTableValue(16, 0, 0.4, 0); + lut->SetTableValue(17, 0, 0.4, 0.4); + lut->SetTableValue(18, 0.4, 0, 0); + lut->SetTableValue(19, 0.4, 0, 0.4); + return lut; +} + +vtkCustomBorderWidget::vtkCustomBorderWidget() +{ + this->CallbackMapper->SetCallbackMethod( + vtkCommand::MiddleButtonReleaseEvent, vtkWidgetEvent::EndSelect, this, + vtkCustomBorderWidget::EndSelectAction); +} + +void vtkCustomBorderWidget::EndSelectAction(vtkAbstractWidget* w) +{ + vtkBorderWidget* borderWidget = dynamic_cast<vtkBorderWidget*>(w); + + // Get the actual box coordinates/planes + // vtkNew<vtkPolyData> polydata; + + // Get the bottom left corner + auto lowerLeft = + static_cast<vtkBorderRepresentation*>(borderWidget->GetRepresentation()) + ->GetPosition(); + std::cout << "Lower left: " << lowerLeft[0] << " " << lowerLeft[1] + << std::endl; + + auto upperRight = + static_cast<vtkBorderRepresentation*>(borderWidget->GetRepresentation()) + ->GetPosition2(); + std::cout << "Upper right: " << lowerLeft[0] + upperRight[0] << " " + << lowerLeft[1] + upperRight[1] << std::endl; + + vtkBorderWidget::EndSelectAction(w); +} + +} // namespace diff --git a/src/Cxx/Qt/EventQtSlotConnect.cxx b/src/Cxx/Qt/EventQtSlotConnect.cxx index 8c004cce203a9cc181f73e31db0ebbcfd5b27828..3a22a3414bf87e3b7522e4e011095476a025e6b8 100644 --- a/src/Cxx/Qt/EventQtSlotConnect.cxx +++ b/src/Cxx/Qt/EventQtSlotConnect.cxx @@ -4,20 +4,35 @@ #include <vtkEventQtSlotConnect.h> #include <vtkGenericOpenGLRenderWindow.h> #include <vtkInteractorStyleTrackballActor.h> +#include <vtkLookupTable.h> #include <vtkNamedColors.h> #include <vtkNew.h> +#include <vtkPlatonicSolidSource.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkRenderer.h> -#include <vtkSphereSource.h> #include <vtkVersion.h> #if VTK_VERSION_NUMBER >= 89000000000ULL #define VTK890 1 #endif +namespace { +/** Get a specialised lookup table for the platonic solids. + * + * Since each face of a vtkPlatonicSolidSource has a different + * cell scalar, we create a lookup table with a different colour + * for each face. + * The colors have been carefully chosen so that adjacent cells + * are colored distinctly. + * + * @return The lookup table. + */ +vtkNew<vtkLookupTable> GetPlatonicLUT(); +} // namespace + // Constructor EventQtSlotConnect::EventQtSlotConnect(QWidget* parent) : QMainWindow(parent), ui(new Ui::EventQtSlotConnect) @@ -36,19 +51,21 @@ EventQtSlotConnect::EventQtSlotConnect(QWidget* parent) vtkNew<vtkEventQtSlotConnect> slotConnector; this->Connections = slotConnector; - // Sphere - vtkNew<vtkSphereSource> sphereSource; - sphereSource->Update(); - vtkNew<vtkPolyDataMapper> sphereMapper; - sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); + auto lut = GetPlatonicLUT(); + + vtkNew<vtkPlatonicSolidSource> source; + source->SetSolidTypeToOctahedron(); - vtkNew<vtkActor> sphereActor; - sphereActor->SetMapper(sphereMapper); - sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); + vtkNew<vtkPolyDataMapper> mapper; + mapper->SetInputConnection(source->GetOutputPort()); + mapper->SetLookupTable(lut); + mapper->SetScalarRange(0, 19); + + vtkNew<vtkActor> actor; + actor->SetMapper(mapper); - // VTK Renderer vtkNew<vtkRenderer> renderer; - renderer->AddActor(sphereActor); + renderer->AddActor(actor); renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData()); #if VTK890 @@ -79,3 +96,36 @@ void EventQtSlotConnect::slot_clicked(vtkObject*, unsigned long, void*, void*) { std::cout << "Clicked." << std::endl; } + +namespace { + +vtkNew<vtkLookupTable> GetPlatonicLUT() +{ + vtkNew<vtkLookupTable> lut; + lut->SetNumberOfTableValues(20); + lut->SetTableRange(0.0, 19.0); + lut->Build(); + lut->SetTableValue(0, 0.1, 0.1, 0.1); + lut->SetTableValue(1, 0, 0, 1); + lut->SetTableValue(2, 0, 1, 0); + lut->SetTableValue(3, 0, 1, 1); + lut->SetTableValue(4, 1, 0, 0); + lut->SetTableValue(5, 1, 0, 1); + lut->SetTableValue(6, 1, 1, 0); + lut->SetTableValue(7, 0.9, 0.7, 0.9); + lut->SetTableValue(8, 0.5, 0.5, 0.5); + lut->SetTableValue(9, 0.0, 0.0, 0.7); + lut->SetTableValue(10, 0.5, 0.7, 0.5); + lut->SetTableValue(11, 0, 0.7, 0.7); + lut->SetTableValue(12, 0.7, 0, 0); + lut->SetTableValue(13, 0.7, 0, 0.7); + lut->SetTableValue(14, 0.7, 0.7, 0); + lut->SetTableValue(15, 0, 0, 0.4); + lut->SetTableValue(16, 0, 0.4, 0); + lut->SetTableValue(17, 0, 0.4, 0.4); + lut->SetTableValue(18, 0.4, 0, 0); + lut->SetTableValue(19, 0.4, 0, 0.4); + return lut; +} + +} // namespace diff --git a/src/Cxx/Qt/RenderWindowNoUiFile.cxx b/src/Cxx/Qt/RenderWindowNoUiFile.cxx index fa7997531de1c98cb1472381de5291b70eae7d25..2396cc7954269c769ae4277731c01ad1e52e4e93 100644 --- a/src/Cxx/Qt/RenderWindowNoUiFile.cxx +++ b/src/Cxx/Qt/RenderWindowNoUiFile.cxx @@ -2,8 +2,10 @@ #include <vtkActor.h> #include <vtkGenericOpenGLRenderWindow.h> +#include <vtkLookupTable.h> #include <vtkNamedColors.h> #include <vtkNew.h> +#include <vtkPlatonicSolidSource.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkRenderWindow.h> @@ -18,6 +20,20 @@ #include <QSurfaceFormat> #include <QVTKOpenGLNativeWidget.h> +namespace { +/** Get a specialised lookup table for the platonic solids. + * + * Since each face of a vtkPlatonicSolidSource has a different + * cell scalar, we create a lookup table with a different colour + * for each face. + * The colors have been carefully chosen so that adjacent cells + * are colored distinctly. + * + * @return The lookup table. + */ +vtkNew<vtkLookupTable> GetPlatonicLUT(); +} // namespace + int main(int argc, char** argv) { // Needed to ensure appropriate OpenGL context is created for VTK rendering. @@ -38,17 +54,21 @@ int main(int argc, char** argv) widget.resize(600, 600); - vtkNew<vtkSphereSource> sphereSource; + auto lut = GetPlatonicLUT(); + + vtkNew<vtkPlatonicSolidSource> source; + source->SetSolidTypeToIcosahedron(); - vtkNew<vtkPolyDataMapper> sphereMapper; - sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); + vtkNew<vtkPolyDataMapper> mapper; + mapper->SetInputConnection(source->GetOutputPort()); + mapper->SetLookupTable(lut); + mapper->SetScalarRange(0, 19); - vtkNew<vtkActor> sphereActor; - sphereActor->SetMapper(sphereMapper); - sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); + vtkNew<vtkActor> actor; + actor->SetMapper(mapper); vtkNew<vtkRenderer> renderer; - renderer->AddActor(sphereActor); + renderer->AddActor(actor); renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData()); #if VTK890 @@ -64,3 +84,36 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } + +namespace { + +vtkNew<vtkLookupTable> GetPlatonicLUT() +{ + vtkNew<vtkLookupTable> lut; + lut->SetNumberOfTableValues(20); + lut->SetTableRange(0.0, 19.0); + lut->Build(); + lut->SetTableValue(0, 0.1, 0.1, 0.1); + lut->SetTableValue(1, 0, 0, 1); + lut->SetTableValue(2, 0, 1, 0); + lut->SetTableValue(3, 0, 1, 1); + lut->SetTableValue(4, 1, 0, 0); + lut->SetTableValue(5, 1, 0, 1); + lut->SetTableValue(6, 1, 1, 0); + lut->SetTableValue(7, 0.9, 0.7, 0.9); + lut->SetTableValue(8, 0.5, 0.5, 0.5); + lut->SetTableValue(9, 0.0, 0.0, 0.7); + lut->SetTableValue(10, 0.5, 0.7, 0.5); + lut->SetTableValue(11, 0, 0.7, 0.7); + lut->SetTableValue(12, 0.7, 0, 0); + lut->SetTableValue(13, 0.7, 0, 0.7); + lut->SetTableValue(14, 0.7, 0.7, 0); + lut->SetTableValue(15, 0, 0, 0.4); + lut->SetTableValue(16, 0, 0.4, 0); + lut->SetTableValue(17, 0, 0.4, 0.4); + lut->SetTableValue(18, 0.4, 0, 0); + lut->SetTableValue(19, 0.4, 0, 0.4); + return lut; +} + +} // namespace diff --git a/src/Cxx/Qt/RenderWindowUISingleInheritance.cxx b/src/Cxx/Qt/RenderWindowUISingleInheritance.cxx index 5724c66e7af89ada6a4beb343974251c2c9bde3d..3da583c6d20351b3deaa36823fa8435589b7219b 100644 --- a/src/Cxx/Qt/RenderWindowUISingleInheritance.cxx +++ b/src/Cxx/Qt/RenderWindowUISingleInheritance.cxx @@ -1,9 +1,12 @@ #include "RenderWindowUISingleInheritance.h" #include "ui_RenderWindowUISingleInheritance.h" +#include <vtkCamera.h> #include <vtkGenericOpenGLRenderWindow.h> +#include <vtkLookupTable.h> #include <vtkNamedColors.h> #include <vtkNew.h> +#include <vtkPlatonicSolidSource.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkRenderWindow.h> @@ -15,6 +18,20 @@ #define VTK890 1 #endif +namespace { +/** Get a specialised lookup table for the platonic solids. + * + * Since each face of a vtkPlatonicSolidSource has a different + * cell scalar, we create a lookup table with a different colour + * for each face. + * The colors have been carefully chosen so that adjacent cells + * are colored distinctly. + * + * @return The lookup table. + */ +vtkNew<vtkLookupTable> GetPlatonicLUT(); +} // namespace + // Constructor RenderWindowUISingleInheritance::RenderWindowUISingleInheritance( QWidget* parent) @@ -31,18 +48,23 @@ RenderWindowUISingleInheritance::RenderWindowUISingleInheritance( this->ui->qvtkWidget->SetRenderWindow(renderWindow); #endif - // Sphere - vtkNew<vtkSphereSource> sphereSource; - sphereSource->Update(); - vtkNew<vtkPolyDataMapper> sphereMapper; - sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); - vtkNew<vtkActor> sphereActor; - sphereActor->SetMapper(sphereMapper); - sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); + auto lut = GetPlatonicLUT(); + + vtkNew<vtkPlatonicSolidSource> source; + source->SetSolidTypeToIcosahedron(); + + vtkNew<vtkPolyDataMapper> mapper; + mapper->SetInputConnection(source->GetOutputPort()); + mapper->SetLookupTable(lut); + mapper->SetScalarRange(0, 19); + + vtkNew<vtkActor> actor; + actor->SetMapper(mapper); - // VTK Renderer vtkNew<vtkRenderer> renderer; - renderer->AddActor(sphereActor); + renderer->AddActor(actor); + renderer->GetActiveCamera()->Azimuth(180.0); + renderer->ResetCamera(); renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData()); // VTK/Qt wedded @@ -68,3 +90,36 @@ void RenderWindowUISingleInheritance::slotExit() { qApp->exit(); } + +namespace { + +vtkNew<vtkLookupTable> GetPlatonicLUT() +{ + vtkNew<vtkLookupTable> lut; + lut->SetNumberOfTableValues(20); + lut->SetTableRange(0.0, 19.0); + lut->Build(); + lut->SetTableValue(0, 0.1, 0.1, 0.1); + lut->SetTableValue(1, 0, 0, 1); + lut->SetTableValue(2, 0, 1, 0); + lut->SetTableValue(3, 0, 1, 1); + lut->SetTableValue(4, 1, 0, 0); + lut->SetTableValue(5, 1, 0, 1); + lut->SetTableValue(6, 1, 1, 0); + lut->SetTableValue(7, 0.9, 0.7, 0.9); + lut->SetTableValue(8, 0.5, 0.5, 0.5); + lut->SetTableValue(9, 0.0, 0.0, 0.7); + lut->SetTableValue(10, 0.5, 0.7, 0.5); + lut->SetTableValue(11, 0, 0.7, 0.7); + lut->SetTableValue(12, 0.7, 0, 0); + lut->SetTableValue(13, 0.7, 0, 0.7); + lut->SetTableValue(14, 0.7, 0.7, 0); + lut->SetTableValue(15, 0, 0, 0.4); + lut->SetTableValue(16, 0, 0.4, 0); + lut->SetTableValue(17, 0, 0.4, 0.4); + lut->SetTableValue(18, 0.4, 0, 0); + lut->SetTableValue(19, 0.4, 0, 0.4); + return lut; +} + +} // namespace diff --git a/src/Cxx/Qt/ShareCameraQt.cxx b/src/Cxx/Qt/ShareCameraQt.cxx index 4050a4ed1ced19258f0d420104ccbd2dbb837691..2866b31b59fb64b1b6677dfe62955f18738d5fcd 100644 --- a/src/Cxx/Qt/ShareCameraQt.cxx +++ b/src/Cxx/Qt/ShareCameraQt.cxx @@ -3,6 +3,7 @@ #include <vtkCamera.h> #include <vtkCommand.h> +#include <vtkConeSource.h> #include <vtkCubeSource.h> #include <vtkDataObjectToTable.h> #include <vtkElevationFilter.h> @@ -14,7 +15,6 @@ #include <vtkQtTableView.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> -#include <vtkSphereSource.h> #include <vtkVersion.h> #if VTK_VERSION_NUMBER >= 89000000000ULL @@ -39,18 +39,20 @@ ShareCameraQt::ShareCameraQt(QWidget* parent) this->ui->qvtkWidgetRight->SetRenderWindow(renderWindowRight); #endif - // Sphere - vtkNew<vtkSphereSource> sphereSource; - sphereSource->Update(); - vtkNew<vtkPolyDataMapper> sphereMapper; - sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); - vtkNew<vtkActor> sphereActor; - sphereActor->SetMapper(sphereMapper); - sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); + // Cone + vtkNew<vtkConeSource> coneSource; + coneSource->SetDirection(0.0, 1.0, 0.0); + vtkNew<vtkPolyDataMapper> coneMapper; + coneMapper->SetInputConnection(coneSource->GetOutputPort()); + vtkNew<vtkActor> coneActor; + coneActor->SetMapper(coneMapper); + coneActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); // Cube vtkNew<vtkCubeSource> cubeSource; - cubeSource->Update(); + cubeSource->SetXLength(0.8); + cubeSource->SetYLength(0.8); + cubeSource->SetZLength(0.8); vtkNew<vtkPolyDataMapper> cubeMapper; cubeMapper->SetInputConnection(cubeSource->GetOutputPort()); vtkNew<vtkActor> cubeActor; @@ -60,7 +62,7 @@ ShareCameraQt::ShareCameraQt(QWidget* parent) // VTK Renderer vtkNew<vtkRenderer> leftRenderer; - leftRenderer->AddActor(sphereActor); + leftRenderer->AddActor(coneActor); leftRenderer->SetBackground(colors->GetColor3d("LightSteelBlue").GetData()); vtkNew<vtkRenderer> rightRenderer; @@ -85,10 +87,8 @@ ShareCameraQt::ShareCameraQt(QWidget* parent) rightRenderer->SetActiveCamera(leftRenderer->GetActiveCamera()); // Position the cube using the left renderer active camera - leftRenderer->GetActiveCamera()->SetPosition(1.0, 0.8, 1.0); - leftRenderer->GetActiveCamera()->SetFocalPoint(0, 0, 0); + leftRenderer->GetActiveCamera()->Azimuth(60); leftRenderer->ResetCamera(); - leftRenderer->GetActiveCamera()->Zoom(0.8); // Set up action signals and slots connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit())); diff --git a/src/Cxx/Qt/SideBySideRenderWindowsQt.cxx b/src/Cxx/Qt/SideBySideRenderWindowsQt.cxx index 80927f4c37ba38a71ed6d42d713a4e311c30abdb..fffd7dc1c979ed3d58f2928950dbee9bd21adb86 100644 --- a/src/Cxx/Qt/SideBySideRenderWindowsQt.cxx +++ b/src/Cxx/Qt/SideBySideRenderWindowsQt.cxx @@ -41,7 +41,6 @@ SideBySideRenderWindowsQt::SideBySideRenderWindowsQt(QWidget* parent) vtkNew<vtkSphereSource> sphereSource; sphereSource->SetPhiResolution(30); sphereSource->SetThetaResolution(30); - sphereSource->Update(); vtkNew<vtkElevationFilter> sphereElev; sphereElev->SetInputConnection(sphereSource->GetOutputPort()); sphereElev->SetLowPoint(0, -1.0, 0); @@ -53,7 +52,9 @@ SideBySideRenderWindowsQt::SideBySideRenderWindowsQt(QWidget* parent) // Cube vtkNew<vtkCubeSource> cubeSource; - cubeSource->Update(); + cubeSource->SetXLength(0.8); + cubeSource->SetYLength(0.8); + cubeSource->SetZLength(0.8); vtkNew<vtkElevationFilter> cubeElev; cubeElev->SetInputConnection(cubeSource->GetOutputPort()); cubeElev->SetLowPoint(0, -1.0, 0); @@ -72,11 +73,10 @@ SideBySideRenderWindowsQt::SideBySideRenderWindowsQt(QWidget* parent) // Add Actor to renderer rightRenderer->AddActor(cubeActor); - rightRenderer->GetActiveCamera()->SetPosition(1.0, 0.8, 1.0); - rightRenderer->GetActiveCamera()->SetFocalPoint(0, 0, 0); - rightRenderer->SetBackground(colors->GetColor3d("LightSteelBlue").GetData()); + rightRenderer->GetActiveCamera()->Azimuth(60); rightRenderer->ResetCamera(); rightRenderer->GetActiveCamera()->Zoom(0.8); + rightRenderer->SetBackground(colors->GetColor3d("LightSteelBlue").GetData()); // VTK/Qt wedded #if VTK890 diff --git a/src/Cxx/Widgets/BorderWidget.cxx b/src/Cxx/Widgets/BorderWidget.cxx index 75cfdc6b5059309f9038513e65a524d5a7da222a..4e0eb5c7733258709c16a33d1ace841b5540a7c6 100644 --- a/src/Cxx/Widgets/BorderWidget.cxx +++ b/src/Cxx/Widgets/BorderWidget.cxx @@ -1,21 +1,35 @@ #include <vtkActor.h> #include <vtkBorderRepresentation.h> #include <vtkBorderWidget.h> +#include <vtkCamera.h> #include <vtkCommand.h> +#include <vtkLookupTable.h> #include <vtkNamedColors.h> #include <vtkNew.h> #include <vtkObjectFactory.h> +#include <vtkPlatonicSolidSource.h> #include <vtkPolyData.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkRenderer.h> -#include <vtkSphereSource.h> #include <vtkWidgetCallbackMapper.h> #include <vtkWidgetEvent.h> namespace { +/** Get a specialised lookup table for the platonic solids. + * + * Since each face of a vtkPlatonicSolidSource has a different + * cell scalar, we create a lookup table with a different colour + * for each face. + * The colors have been carefully chosen so that adjacent cells + * are colored distinctly. + * + * @return The lookup table. + */ +vtkNew<vtkLookupTable> GetPlatonicLUT(); + class vtkCustomBorderWidget : public vtkBorderWidget { public: @@ -35,23 +49,27 @@ int main(int, char*[]) { vtkNew<vtkNamedColors> colors; - // Sphere - vtkNew<vtkSphereSource> sphereSource; - sphereSource->SetRadius(4.0); - sphereSource->Update(); + auto lut = GetPlatonicLUT(); + + vtkNew<vtkPlatonicSolidSource> source; + source->SetSolidTypeToDodecahedron(); vtkNew<vtkPolyDataMapper> mapper; - mapper->SetInputConnection(sphereSource->GetOutputPort()); + mapper->SetInputConnection(source->GetOutputPort()); + mapper->SetLookupTable(lut); + mapper->SetScalarRange(0, 19); vtkNew<vtkActor> actor; actor->SetMapper(mapper); - actor->GetProperty()->SetColor( - colors->GetColor3d("DarkOliveGreen").GetData()); + // actor->GetProperty()->SetColor( + // colors->GetColor3d("DarkOliveGreen").GetData()); // A renderer and render window vtkNew<vtkRenderer> renderer; vtkNew<vtkRenderWindow> renderWindow; renderWindow->AddRenderer(renderer); + renderer->GetActiveCamera()->Elevation(30.0); + renderer->GetActiveCamera()->Azimuth(180.0); renderWindow->SetWindowName("BorderWidget"); // An interactor @@ -69,6 +87,7 @@ int main(int, char*[]) // Render an image (lights and cameras are created automatically) renderWindowInteractor->Initialize(); + renderer->ResetCamera(); renderWindow->Render(); borderWidget->On(); @@ -79,6 +98,36 @@ int main(int, char*[]) } namespace { + +vtkNew<vtkLookupTable> GetPlatonicLUT() +{ + vtkNew<vtkLookupTable> lut; + lut->SetNumberOfTableValues(20); + lut->SetTableRange(0.0, 19.0); + lut->Build(); + lut->SetTableValue(0, 0.1, 0.1, 0.1); + lut->SetTableValue(1, 0, 0, 1); + lut->SetTableValue(2, 0, 1, 0); + lut->SetTableValue(3, 0, 1, 1); + lut->SetTableValue(4, 1, 0, 0); + lut->SetTableValue(5, 1, 0, 1); + lut->SetTableValue(6, 1, 1, 0); + lut->SetTableValue(7, 0.9, 0.7, 0.9); + lut->SetTableValue(8, 0.5, 0.5, 0.5); + lut->SetTableValue(9, 0.0, 0.0, 0.7); + lut->SetTableValue(10, 0.5, 0.7, 0.5); + lut->SetTableValue(11, 0, 0.7, 0.7); + lut->SetTableValue(12, 0.7, 0, 0); + lut->SetTableValue(13, 0.7, 0, 0.7); + lut->SetTableValue(14, 0.7, 0.7, 0); + lut->SetTableValue(15, 0, 0, 0.4); + lut->SetTableValue(16, 0, 0.4, 0); + lut->SetTableValue(17, 0, 0.4, 0.4); + lut->SetTableValue(18, 0.4, 0, 0); + lut->SetTableValue(19, 0.4, 0, 0.4); + return lut; +} + vtkCustomBorderWidget::vtkCustomBorderWidget() { this->CallbackMapper->SetCallbackMethod( @@ -103,9 +152,10 @@ void vtkCustomBorderWidget::EndSelectAction(vtkAbstractWidget* w) auto upperRight = static_cast<vtkBorderRepresentation*>(borderWidget->GetRepresentation()) ->GetPosition2(); - std::cout << "Upper right: " << upperRight[0] << " " << upperRight[1] - << std::endl; + std::cout << "Upper right: " << lowerLeft[0] + upperRight[0] << " " + << lowerLeft[1] + upperRight[1] << std::endl; vtkBorderWidget::EndSelectAction(w); } + } // namespace diff --git a/src/Testing/Baseline/Cxx/Qt/TestBorderWidgetQt.png b/src/Testing/Baseline/Cxx/Qt/TestBorderWidgetQt.png index 32f57396e31e48b1435c7d69af9e950667ca9929..6dd417fee87586083584d17c7bdd80b27ba2baef 100644 --- a/src/Testing/Baseline/Cxx/Qt/TestBorderWidgetQt.png +++ b/src/Testing/Baseline/Cxx/Qt/TestBorderWidgetQt.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ff3ebbce0cea291de1480576e346fb4f73fd242312af7d342c708ace46fe379 -size 47403 +oid sha256:6eb7d4e2d7aec86d81974e19c38961f125aa848176e8246790b91edee0870434 +size 14892 diff --git a/src/Testing/Baseline/Cxx/Qt/TestEventQtSlotConnect.png b/src/Testing/Baseline/Cxx/Qt/TestEventQtSlotConnect.png index c4d2942a9cd8ce9b8732aeac8d7461c634f443d7..f9194f851ac38ef8ba2073af786c2139988be12b 100644 --- a/src/Testing/Baseline/Cxx/Qt/TestEventQtSlotConnect.png +++ b/src/Testing/Baseline/Cxx/Qt/TestEventQtSlotConnect.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e995e1cf698e6d690224485a8f0349266fa509169fe20f6ecc9e4e1e80e7fc6c -size 50504 +oid sha256:140de15b0aa1f63e24881856636580be5ae05ab603a48a8959580c6398ec5344 +size 7192 diff --git a/src/Testing/Baseline/Cxx/Qt/TestRenderWindowNoUiFile.png b/src/Testing/Baseline/Cxx/Qt/TestRenderWindowNoUiFile.png index d610f01e3b1d67acaa70ee231f4b1f9db63acb34..adbfcd0d3ba1e0f9a47fe353c47290e07137629b 100644 --- a/src/Testing/Baseline/Cxx/Qt/TestRenderWindowNoUiFile.png +++ b/src/Testing/Baseline/Cxx/Qt/TestRenderWindowNoUiFile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cd16f26ad9a98fb7dd718c0d1eacdce4318a9559891271aafff0d3e251ba8a2a -size 61197 +oid sha256:934930e8ed2039a6ef96f5f90aee83f1cf9739f53377e66e46b40276f644524a +size 16171 diff --git a/src/Testing/Baseline/Cxx/Qt/TestRenderWindowUISingleInheritance.png b/src/Testing/Baseline/Cxx/Qt/TestRenderWindowUISingleInheritance.png index c7ce0397fa7c6a4ebe0b468aaf042f0f2e11ad14..6bd6bc20b2600a37731b8a3c7f79ae7cbcc7e901 100644 --- a/src/Testing/Baseline/Cxx/Qt/TestRenderWindowUISingleInheritance.png +++ b/src/Testing/Baseline/Cxx/Qt/TestRenderWindowUISingleInheritance.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fd71d089bea133fd3099e7343dcd356bfbbe2838324f330701e8ef135d65b8dc -size 47391 +oid sha256:94643f182b931ac4012043cbb7ab978b4c5021d5335dbfc590abf1874425771d +size 14497 diff --git a/src/Testing/Baseline/Cxx/Qt/TestShareCameraQt.png b/src/Testing/Baseline/Cxx/Qt/TestShareCameraQt.png index 89563004597807b9cabdd555277c7263dede6d79..1fb9883b27b41b6d1bbc67dc55e5e7d3527af44f 100644 --- a/src/Testing/Baseline/Cxx/Qt/TestShareCameraQt.png +++ b/src/Testing/Baseline/Cxx/Qt/TestShareCameraQt.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:348d72a62d61203f6ad75f09542ed37827f1034297843fff09c3ff27fd08adad -size 48497 +oid sha256:992803cf107e109ea874079cba8bc4f167551f2a00801bc1389ad88fb0e5658d +size 17822 diff --git a/src/Testing/Baseline/Cxx/Qt/TestSideBySideRenderWindowsQt.png b/src/Testing/Baseline/Cxx/Qt/TestSideBySideRenderWindowsQt.png index dc4484bba1967fef6690aaa2854d070f17bb7853..fc89454adf835667d9d2c9f9bf9de93cb9067e8e 100644 --- a/src/Testing/Baseline/Cxx/Qt/TestSideBySideRenderWindowsQt.png +++ b/src/Testing/Baseline/Cxx/Qt/TestSideBySideRenderWindowsQt.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d5b6260f1803273472844e1e2f566ad7917479ed0374c667810f31fae76c3cd2 -size 79297 +oid sha256:a46ed3c315ae6d3ba260ae8d08176f4b3d03587eb2bd1412b10e9efcae1de490 +size 121219 diff --git a/src/Testing/Baseline/Cxx/Widgets/TestBorderWidget.png b/src/Testing/Baseline/Cxx/Widgets/TestBorderWidget.png index 08d46771d9ced9d40b52f03ff045ed6d3f20c94e..1785686db4c8b74d1e3c0e26b4e005c9e27eecd4 100644 --- a/src/Testing/Baseline/Cxx/Widgets/TestBorderWidget.png +++ b/src/Testing/Baseline/Cxx/Widgets/TestBorderWidget.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:27d251db89f44b65682ed002021d639e950c0420a55d61f9acd2b8fc83311758 -size 14659 +oid sha256:ba65c407c19a373d3796b0ebe950bd71849306a098b57a4295708ab9bfe336dc +size 4369