Trouble using VTK Widget with QVTK

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble using VTK Widget with QVTK

AdrienV
Hi,


I'm working on an application using C++, VTK and Qt framework. I have integrated a vtk window in a Qt widget and all work fine.

But now I want to use vtkWidget (vtkContourWidget) with the QVTK interactor. As for others vtk Widget, it is not working (nothing happens, but the compilation/execution steps are ok. For example, if the widget is a vtkCaptionWidget, nothing appears on the rendering window)

Here a piece of my code :

   vtkSmartPointer<vtkContourWidget> contourWidget =
       vtkSmartPointer<vtkContourWidget>::New();
      // The QVTK related part
     contourWidget->SetInteractor(ui->vtkWidget->GetRenderWindow()->GetInteractor());
 

     vtkOrientedGlyphContourRepresentation* rep =
       vtkOrientedGlyphContourRepresentation::SafeDownCast(
       contourWidget->GetRepresentation());

     vtkSmartPointer<vtkPolygonalSurfacePointPlacer> pointPlacer =
       vtkSmartPointer<vtkPolygonalSurfacePointPlacer>::New();
     pointPlacer->AddProp(actor);
     pointPlacer->GetPolys()->AddItem(sphereSource->GetOutput());

     rep->GetLinesProperty()->SetColor(1, 0, 0);
     rep->GetLinesProperty()->SetLineWidth(3.0);
     rep->SetPointPlacer(pointPlacer);

If I use the native interactor

     vtkSmartPointer<vtkRenderWindowInteractor> interactor =
       vtkSmartPointer<vtkRenderWindowInteractor>::New();
     interactor->SetRenderWindow(renderWindow);

 vtkSmartPointer<vtkContourWidget> contourWidget =
       vtkSmartPointer<vtkContourWidget>::New();
     contourWidget->SetInteractor(interactor);

It works.
But I have to use the QVTK interactor instead.

Any idea?


Thanks a lot


Adrien
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Hi

Old post but I am having the same issue too, with the same example - the
contour widget point placer found here :
https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator
<https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator>  

The issue seems to be that you cannot define a new interactor for a qvtk
widget. ie you cannot do :

vtkSmartPointer<vtkRenderWindowInteractor> interactor =
       vtkSmartPointer<vtkRenderWindowInteractor>::New();
this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);

This breaks the qvtkwidget (nothing appears on screen), even if you call:
ui->qvtkwidget->update();

or (out of desparation!) :

interactor->Initialise();
ui->qvtkwidget->update();
interactor->Start()

However, you can grab the exisiting qvtkwidget interactor and work with it
for some widgets:

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
this->ui->qvtkWidget->GetRenderWindow()->GetInteractor();

BUT This doesn't work for the contour widget.

Heres what I tried (mostly from the example posted above). This version
won't even display my QT ui....

vtkSmartPointer<vtkRenderWindow> renderWindow =
this->ui->qvtkWidget->GetRenderWindow();
        vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
        interactor->SetRenderWindow(renderWindow);
/*
         // I already have a renderer set up with an actor
        // Add the actors to the renderer, set the background and size
        renderer->AddActor(tw_data_.pre_actor);
        renderer->SetBackground(.3, .4, .5);
*/
        // Here comes the contour widget stuff...
        vtkSmartPointer<vtkContourWidget> contourWidget =
vtkSmartPointer<vtkContourWidget>::New();
        contourWidget->SetInteractor(interactor);
        vtkSmartPointer<vtkOrientedGlyphContourRepresentation> rep =
                vtkOrientedGlyphContourRepresentation::SafeDownCast(
                        contourWidget->GetRepresentation());
        rep->GetLinesProperty()->SetColor(0, 0, 1.0);
        rep->GetLinesProperty()->SetLineWidth(3.0);
        rep->GetProperty()->SetPointSize(10);
        rep->GetProperty()->SetRenderPointsAsSpheres(1);

        vtkSmartPointer<vtkPolygonalSurfacePointPlacer> pointPlacer =
vtkSmartPointer<vtkPolygonalSurfacePointPlacer>::New();
        pointPlacer->AddProp(tw_data_.pre_actor);
        pointPlacer->GetPolys()->AddItem(tw_data_.pre_poly);
        rep->SetPointPlacer(pointPlacer);
       
        this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);
        this->ui->qvtkWidget->update();
       
        renderWindow->Render();
        interactor->Initialize();
        contourWidget->EnabledOn();
        renderer_->ResetCamera();
        interactor->Start();
       
If I comment out :
        // this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);

and change:
contourWidget->SetInteractor(interactor);
to
contourWidget->SetInteractor(this->ui->qvtkWidget->GetRenderWindow()->GetInteractor());

then I get the QT ui displaying, and normal interaction working but no
contour widget.

If I set everything up on a separate vtk renderer/renderwindow (ie like a
non-QT pop-up window, the contour widget works fine).


Can anyone helps as to why QVTK interactor  doesn't work with contour
widget?
It seems that the contourwidget requires an uninitialised interactor, but
the qvtkwidget interactor is always initialised before we can do anything
with it.





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

Mathieu Westphal
Hello Andrew,

QVTKWidget is deprecated, you may want to try with QVTKOpenGLSimpleWidget and QVTKOpenGLWidget
 if they are available in the version of VTK you are using.

Best regards,

Mathieu Westphal

On Thu, Jul 5, 2018 at 10:23 AM, andyjk <[hidden email]> wrote:
Hi

Old post but I am having the same issue too, with the same example - the
contour widget point placer found here :
https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator
<https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator

The issue seems to be that you cannot define a new interactor for a qvtk
widget. ie you cannot do :

vtkSmartPointer<vtkRenderWindowInteractor> interactor =
       vtkSmartPointer<vtkRenderWindowInteractor>::New();
this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);

This breaks the qvtkwidget (nothing appears on screen), even if you call:
ui->qvtkwidget->update();

or (out of desparation!) :

interactor->Initialise();
ui->qvtkwidget->update();
interactor->Start()

However, you can grab the exisiting qvtkwidget interactor and work with it
for some widgets:

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
this->ui->qvtkWidget->GetRenderWindow()->GetInteractor();

BUT This doesn't work for the contour widget.

Heres what I tried (mostly from the example posted above). This version
won't even display my QT ui....

vtkSmartPointer<vtkRenderWindow> renderWindow =
this->ui->qvtkWidget->GetRenderWindow();
        vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
        interactor->SetRenderWindow(renderWindow);
/*
         // I already have a renderer set up with an actor
        // Add the actors to the renderer, set the background and size
        renderer->AddActor(tw_data_.pre_actor);
        renderer->SetBackground(.3, .4, .5);
*/
        // Here comes the contour widget stuff...
        vtkSmartPointer<vtkContourWidget> contourWidget =
vtkSmartPointer<vtkContourWidget>::New();
        contourWidget->SetInteractor(interactor);
        vtkSmartPointer<vtkOrientedGlyphContourRepresentation> rep =
                vtkOrientedGlyphContourRepresentation::SafeDownCast(
                        contourWidget->GetRepresentation());
        rep->GetLinesProperty()->SetColor(0, 0, 1.0);
        rep->GetLinesProperty()->SetLineWidth(3.0);
        rep->GetProperty()->SetPointSize(10);
        rep->GetProperty()->SetRenderPointsAsSpheres(1);

        vtkSmartPointer<vtkPolygonalSurfacePointPlacer> pointPlacer =
vtkSmartPointer<vtkPolygonalSurfacePointPlacer>::New();
        pointPlacer->AddProp(tw_data_.pre_actor);
        pointPlacer->GetPolys()->AddItem(tw_data_.pre_poly);
        rep->SetPointPlacer(pointPlacer);

        this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);
        this->ui->qvtkWidget->update();

        renderWindow->Render();
        interactor->Initialize();
        contourWidget->EnabledOn();
        renderer_->ResetCamera();
        interactor->Start();

If I comment out :
        // this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);

and change:
contourWidget->SetInteractor(interactor);
to
contourWidget->SetInteractor(this->ui->qvtkWidget->GetRenderWindow()->GetInteractor());

then I get the QT ui displaying, and normal interaction working but no
contour widget.

If I set everything up on a separate vtk renderer/renderwindow (ie like a
non-QT pop-up window, the contour widget works fine).


Can anyone helps as to why QVTK interactor  doesn't work with contour
widget?
It seems that the contourwidget requires an uninitialised interactor, but
the qvtkwidget interactor is always initialised before we can do anything
with it.





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Thanks

I am on VTK 8-1

I did try the qvtkOpenGLWidget but I have several problems, and I think I
read it was still unstable.

Problem 1: No QVTKOpenGLWidget in the QT designer - so I insert a
qvtkwidget, then in the .ui file I manually change it to qvtkOpenGLWidget
(this compiles fine).

Problem 2: If I try to drag a generic OpenGL widget into a window in QT
designer, the designer crashes and closes.

Problem 3: Running the code from 1 gives me an error:
QVTKOpenGLWidget requires a `vtkGenericOpenGLRenderWindow`. `
vtkWin32OpenGLRenderWindow ` is not supported.

I understand QVTKWidget is deprecated, but it also seems the OpenGL widget
is too unstable at the moment ?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

Mathieu Westphal
Hi,

QVTKOpenGLWindow in 8.1.0 and 8.1.1 is very stable and is used by all VTK/Qt based application, like ParaView for example.

Problem 1 and Problem 2 are QTCreator related. I would suggest adding a simple QWidget in Qt creator, and once you're finished,
juste change it manually in the .ui.

Regarding Problem 3, well the answer is in the question. Juste use a vtkGenericOpenGLRenderWindow instead of a win32 specific.
The vtkGenericOpenGLRenderWindow implementation is newer and will work on all platform.

See attached for a QVTKOpenGLWidget usage example (found in VTK/GUISupport/Qt/Testing/Cxx/)

Best regards,




Mathieu Westphal

On Thu, Jul 5, 2018 at 11:06 AM, andyjk <[hidden email]> wrote:
Thanks

I am on VTK 8-1

I did try the qvtkOpenGLWidget but I have several problems, and I think I
read it was still unstable.

Problem 1: No QVTKOpenGLWidget in the QT designer - so I insert a
qvtkwidget, then in the .ui file I manually change it to qvtkOpenGLWidget
(this compiles fine).

Problem 2: If I try to drag a generic OpenGL widget into a window in QT
designer, the designer crashes and closes.

Problem 3: Running the code from 1 gives me an error:
QVTKOpenGLWidget requires a `vtkGenericOpenGLRenderWindow`. `
vtkWin32OpenGLRenderWindow ` is not supported.

I understand QVTKWidget is deprecated, but it also seems the OpenGL widget
is too unstable at the moment ?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

TestQVTKOpenGLWidget.cxx (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Thanks Mathieu

That was a big help.
I added the line:

QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());

in main.cpp (plus a couple of includes).

then in my derived QMainWindow class I have done:

vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;

/* Set up the contour stuff as before with a new interactor */

then:
        renderWindow->Render();
        interactor->Initialize();
        contourWidget->EnabledOn();
       
       
        this->ui->qvtkWidget->SetRenderWindow(renderWindow);
       
        renderer_->ResetCamera();

This works for other widgets, but still does not work for contour widget.
The window renders and I can move the camera around etc, but left click does
nothing.

Do you think this means it is not possible to use the
PolygonalSurfaceContourLineInterpolator with a QVTKOpenGL widget either ?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
I have created a minimal compilable example complete with CMake file to show
the problem.

Would someone be kind enough to take a look and see if this is a bug or my
error in understanding?

I am trying to run this example
https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator
<https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator>  

but using a QT widget to display (QVTKOpenGLWidget).

In the mainwindow.cpp file I have three small sets of comments to remove/use
certain code.

1) Basically, as it stands, it will create a non-QT 'normal' VTK window and
works perfectly

2) By uncommenting a couple of lines as per the code in mainwindow.cpp, I
try to move the renderwindow into the QVTKOpenGLWidget. Depending on which
of the 3 or 4 lines you uncomment/comment, we either get :
a) Nothing - a black screen. Probably due to no valid interactor started
b) The sphere correctly rendered but unable to interact
c) The sphere and a moveable camera, but no polygonalSurfaceContour
functionality (cannot 'draw' on sphere)

Could someone help by running the simple code attached to reproduce the
issue ?

Thanks

SimpleTest.zip
<http://vtk.1045678.n5.nabble.com/file/t325404/SimpleTest.zip>  



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
I'm still having no luck and suspect this is a bug in VTK, when using
QVTKOpenGLWidget.

The full QT mainwindow.cpp code is pasted below with the various lines that
don't work in comments.
I've tried every combination and nothing worked - how do I report this as a
bug ?

Thanks!

#include "mainwindow.h"
#include "build/ui_mainwindow.h"

#include <vtkVersion.h>
#include "vtkSmartPointer.h"

#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkImageDataGeometryFilter.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataCollection.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkTriangleFilter.h"

#include <vtkRendererCollection.h>

#include "vtkContourWidget.h"
#include "vtkOrientedGlyphContourRepresentation.h"
#include "vtkPolygonalSurfacePointPlacer.h"
#include "vtkPolygonalSurfaceContourLineInterpolator.h"

#include <vtkGenericOpenGLRenderWindow.h>
#include <QVTKWidget.h>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

        vtkSmartPointer<vtkPolyData> polyData;

        vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
        sphereSource->SetThetaResolution(40);
        sphereSource->SetPhiResolution(20);
        sphereSource->Update();

        polyData = sphereSource->GetOutput();
       

        // The Dijkistra interpolator will not accept cells that aren't triangles
        vtkSmartPointer<vtkTriangleFilter> triangleFilter =
                vtkSmartPointer<vtkTriangleFilter>::New();
#if VTK_MAJOR_VERSION <= 5
        triangleFilter->SetInput(polyData);
#else
        triangleFilter->SetInputData(polyData);
#endif
        triangleFilter->Update();

        vtkSmartPointer<vtkPolyData> pd = triangleFilter->GetOutput();

        //Create a mapper and actor
        vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputConnection(triangleFilter->GetOutputPort());

        vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
        actor->SetMapper(mapper);
        actor->GetProperty()->SetInterpolationToFlat();

        // Create the render window, renderer and interactor.
        vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();


/////////////////////////////////////////////////////////////////////////////////////////////////////
        // OPTION 1: Use this for a plain non-QT VTK window. The
Polygonalsurfaceinteractor works fine
        //vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();

        // OPTION 2: ....but if we use this instead and set the renderwindow of the
qvtkOpenGL widget to this, the polygonalsurfaceintaeractor does not work
        // although at least the sphere displays. We cannot move the camera though
        // Remember to comment out the interactor->Start() line at the bottom of
the code, or everything freezes with no display!
        //vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
       
        vtkSmartPointer<vtkRenderWindow> renderWindow =
ui->widget->GetRenderWindow();

/////////////////////////////////////////////////////////////////////////////////////////////////////

        ui->widget->GetRenderWindow()->AddRenderer(renderer);
        ui->widget->GetRenderWindow()->Render();
        ui->widget->update();


/////////////////////////////////////////////////////////////////////////////////////////////////////
        // OPTION A: If we grab the interactor from the QVTKOpenGL widget, then at
least we can move the camera around, but we cannot use the polygonalsurface
placer
        vtkSmartPointer<vtkRenderWindowInteractor> interactor =
ui->widget->GetInteractor();

        // OPTION B: .....alternatively, if we set a new interactor and try to use
QVTKOpenGL, no interaction is possible.
        // Note We must set a new interactor if we are using the pure non-QT VTK
window (OPTION 1 above)
        //vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

/////////////////////////////////////////////////////////////////////////////////////////////////////
       
        //interactor->SetRenderWindow(ui->widget->GetRenderWindow());
       

        // Add the actors to the renderer, set the background and size
        renderer->AddActor(actor);
        renderer->SetBackground(.3, .4, .5);
        renderer->ResetCamera();

        // Here comes the contour widget stuff...
        vtkSmartPointer<vtkContourWidget> contourWidget =
vtkSmartPointer<vtkContourWidget>::New();
        contourWidget->SetInteractor(interactor);
       
        vtkSmartPointer<vtkOrientedGlyphContourRepresentation> rep =
                vtkOrientedGlyphContourRepresentation::SafeDownCast(
                        contourWidget->GetRepresentation());
        rep->GetLinesProperty()->SetColor(1, 0.2, 0);
        rep->GetLinesProperty()->SetLineWidth(3.0);
       
        vtkSmartPointer<vtkPolygonalSurfacePointPlacer> pointPlacer =
                vtkSmartPointer<vtkPolygonalSurfacePointPlacer>::New();
        pointPlacer->AddProp(actor);
        pointPlacer->GetPolys()->AddItem(pd);
        rep->SetPointPlacer(pointPlacer);


        vtkSmartPointer<vtkPolygonalSurfaceContourLineInterpolator> interpolator =
                vtkSmartPointer<vtkPolygonalSurfaceContourLineInterpolator>::New();
        interpolator->GetPolys()->AddItem(pd);
        rep->SetLineInterpolator(interpolator);

        //renderWindow->Render();
       
        //interactor->Initialize();

        contourWidget->EnabledOn();
       
       

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // OPTION 1: We have to uncomment this for the pure VTK version
        // OPTION 2: ....But comment it out if using the QVTKOpenGL Widget,
otherwise everything freezes with no rendering
        //interactor->Start();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

MainWindow::~MainWindow()
{
    delete ui;
}




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

terminator via vtkusers
Have you checked the class of the renderWindow object in comparison with ui->widget->GetRenderWindow()?

/////////////////////////////////////////////////////////////////////////////////////////////////////
    // OPTION 1: Use this for a plain non-QT VTK window. The
Polygonalsurfaceinteractor works fine
    //vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();

Have you tried
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
ui->widget->SetRenderWindow(renderWindow);


Todd


--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

terminator via vtkusers

/////////////////////////////////////////////////////////////////////////////////////////////////////
    // OPTION 1: Use this for a plain non-QT VTK window. The
Polygonalsurfaceinteractor works fine
    //vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();

Have you checked the class of the renderWindow object in comparison with ui->widget->GetRenderWindow()?

Have you tried
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
ui->widget->SetRenderWindow(renderWindow);


Todd



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Thanks

I tried:

        vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
        ui->widget->SetRenderWindow(renderWindow);

This compiles OK, but when I run, it immediately gives the error:

QVTKOpenGLWidget requires a `vtkGenericOpenGLRenderWindow`. `
vtkWin32OpenGLRenderWindow ` is not supported.

because I presume this is the wrong type.
Strangely,
     
          vtkSmartPointer<vtkRenderWindow> renderWindow =
ui->widget->GetRenderWindow();

is allowed, and runs - though it fails to render because I think the context
is wrong (ie in main.cpp I have the line
     
         
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());

which allows me to render in the QVTKpenGLWidget

However,

       vtkNew<vtkGenericOpenGLRenderWindow> renderWindow =
ui->widget->GetRenderWindow()

is not allowed by the compiler - telling me that GetRenderWindow() is
expecting a vtkRenderWindow, not an OpenGL one.

So it seems I can create a new OpenGL RenderWindow and set the widget Window
to this :

     vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
     ui->widget->SetRenderWindow(renderWindow);

and this gives be the sphere on screen, moveable mouse, but no contour
widget.

But I can't grab the existing render window from the widget, because

    vtkSmartPointer<vtkRenderWindow> renderWindow =
ui->widget->GetRenderWindow();

compiles, but fails at runtime (I think due to the mismatch between a
vtkRenderWindow and an OpenGL one), and

    vtkNew<vtkGenericOpenGLRenderWindow> renderWindow =
ui->widget->GetRenderWindow()

will not compile because of the perceived type mismatch.




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

terminator via vtkusers

Thanks

I tried:

        vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
ui->widget->SetRenderWindow(renderWindow);

This compiles OK, but when I run, it immediately gives the error:

QVTKOpenGLWidget requires a `vtkGenericOpenGLRenderWindow`. `
vtkWin32OpenGLRenderWindow ` is not supported.

because I presume this is the wrong type.
Strangely,
       


That's expected. It's why I said to check the type of the returned render window object. If it is a vtkGenericOpenGLRenderWindow you need to dynamically cast it before passing it to SetRenderWindow()

Are you able to debug your code with break points?

vtkSmartPointer<vtkRenderWindow> renderWindow =
ui->widget->GetRenderWindow();

is allowed, and runs - though it fails to render because I think the context
is wrong (ie in main.cpp I have the line
    
        
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());

which allows me to render in the QVTKpenGLWidget

However,

       vtkNew<vtkGenericOpenGLRenderWindow> renderWindow =
ui->widget->GetRenderWindow()

is not allowed by the compiler - telling me that GetRenderWindow() is
expecting a vtkRenderWindow, not an OpenGL one.

So it seems I can create a new OpenGL RenderWindow and set the widget Window
to this :

     vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
     ui->widget->SetRenderWindow(renderWindow);

and this gives be the sphere on screen, moveable mouse, but no contour
widget.

But I can't grab the existing render window from the widget, because

    vtkSmartPointer<vtkRenderWindow> renderWindow =
ui->widget->GetRenderWindow();

compiles, but fails at runtime (I think due to the mismatch between a
vtkRenderWindow and an OpenGL one), and

    vtkNew<vtkGenericOpenGLRenderWindow> renderWindow =
ui->widget->GetRenderWindow()

will not compile because of the perceived type mismatch.




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Thanks again

We're getting to the edge of my knowledge, I'm afraid!

I can do
   vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
   ui->widget->SetRenderWindow(vtkRenderWindow::SafeDownCast(renderWindow));

and this runs (displays sphere, allows me to move it, but no contour widget
still). It seems to be no different from:
   vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
   ui->widget->SetRenderWindow(renderWindow);

If I try to grab the existing widget window (I think this is casting???):
  vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
     
vtkGenericOpenGLRenderWindow::SafeDownCast(ui->widget->GetRenderWindow());

it compiles but I don't even see a renderwindow when I run the code, the
executable just closes gracefully.

I am not sure about breakpoints, I'm afraid.








--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

terminator via vtkusers



I can do
   vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
   ui->widget->SetRenderWindow(vtkRenderWindow::SafeDownCast(renderWindow));

That won't work. You haven't even assigned an object to your renderWindow variable. You need something like

vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New(); 
vtkGenericOpenGLRenderWindow openGLWindow = vtkGenericOpenGLRenderWindow::SafeDownCast(renderWindow);
ui->widget->SetRenderWindow(openGLWindow); 

You need to put a breakpoint after casting to see if openGLWindow is null or not.

I advise you to figure out how to setup your code for debugging and learn some more about polymorphism before continuing.

Todd


and this runs (displays sphere, allows me to move it, but no contour widget
still). It seems to be no different from:
   vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
   ui->widget->SetRenderWindow(renderWindow);

If I try to grab the existing widget window (I think this is casting???):
  vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
    
vtkGenericOpenGLRenderWindow::SafeDownCast(ui->widget->GetRenderWindow());

it compiles but I don't even see a renderwindow when I run the code, the
executable just closes gracefully.

I am not sure about breakpoints, I'm afraid.








--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Thanks again for the advice, Todd.

Yes - I do need to delve a bit deeper re debugging.

I thought vtkNew<...>, and vtksmartPointer<...>::New() both create instances
(the former being the preferred method now?)

To check, I tried both:
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
       

and

vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();

(then ui->widget->SetRenderWindow(renderWindow); in both instances)

Both work and produce the rendered sphere, but no contour widget. So I think
the assignment is happening identically with either method.

I also did the following, with two breakpoints (before and after the safe
down cast):

vtkSmartPointer<vtkRenderWindow> vtkrenderWindow =
                vtkSmartPointer<vtkRenderWindow>::New();
        vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
vtkGenericOpenGLRenderWindow::SafeDownCast(vtkrenderWindow);

        ui->widget->SetRenderWindow(renderWindow);

I notice that the vtkrenderwindow gets a valid pointer, and seems to be
reading from vtkRenderingOpenGL2-8.1.dll  - so is presumably already
something opengl based ?

At the subsequent break point (so after the line
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
vtkGenericOpenGLRenderWindow::SafeDownCast(vtkrenderWindow); ) I notice that
the renderWindow pointer is still NULL.

So the SafeDownCast seems to fail -but of course I can bypass this line by
just doing
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
ui->widget->SetRenderWindow(renderWindow);

which seems to render fine but ignores the contour widget.

Frustrating! But thanks for your help anyway.

Andy








--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

kenichiro yoshimi
Hi,

How about you replace the macros in the following way in CMakeLists.txt?
 QT4_WRAP_CPP -> QT5_WRAP_CPP
 QT4_WRAP_UI -> QT5_WRAP_UI

Best
2018年7月8日(日) 19:35 andyjk <[hidden email]>:

>
> Thanks again for the advice, Todd.
>
> Yes - I do need to delve a bit deeper re debugging.
>
> I thought vtkNew<...>, and vtksmartPointer<...>::New() both create instances
> (the former being the preferred method now?)
>
> To check, I tried both:
> vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
>
>
> and
>
> vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
> vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
>
> (then ui->widget->SetRenderWindow(renderWindow); in both instances)
>
> Both work and produce the rendered sphere, but no contour widget. So I think
> the assignment is happening identically with either method.
>
> I also did the following, with two breakpoints (before and after the safe
> down cast):
>
> vtkSmartPointer<vtkRenderWindow> vtkrenderWindow =
>                 vtkSmartPointer<vtkRenderWindow>::New();
>         vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
> vtkGenericOpenGLRenderWindow::SafeDownCast(vtkrenderWindow);
>
>         ui->widget->SetRenderWindow(renderWindow);
>
> I notice that the vtkrenderwindow gets a valid pointer, and seems to be
> reading from vtkRenderingOpenGL2-8.1.dll  - so is presumably already
> something opengl based ?
>
> At the subsequent break point (so after the line
> vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
> vtkGenericOpenGLRenderWindow::SafeDownCast(vtkrenderWindow); ) I notice that
> the renderWindow pointer is still NULL.
>
> So the SafeDownCast seems to fail -but of course I can bypass this line by
> just doing
> vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
> vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
> ui->widget->SetRenderWindow(renderWindow);
>
> which seems to render fine but ignores the contour widget.
>
> Frustrating! But thanks for your help anyway.
>
> Andy
>
>
>
>
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
This post was updated on .
Thanks

I have tried this but it made no difference.

There just seems to be no way to set a new custom iterator in a
QVTKOpenGLWidget  (or a QVTKWidget).

I think the issue is that I can grab the existing interactor, from the QWidget
but it has already been initialised, so any custom interactor that requires
setting up prior to initialisation fails.

The only solution if you want to use a contour widget and pointplacer, is to
use a normal VTK window as a pop-up. It looks like it cannot be displayed
inside QT which is a shame as this spoils the look of the UI.

Not sure this is a bug, just a lack of functionality. We need a way to be
able to insert our own (new) interactor into a QVTKOpenGLWidget, which
completely replaces the widgets existing interactor. I think at the moment
they clash.

I've tried all combinations of grabbing the existing QVTKWidget
RenderWindow, the renderer and the iterator vs creating New RenderWindow,
renderer, iterator and Setting them via the QWidget methods.
No combination works - you cannot create a new window, renderer and iterator
then apply the lot via
ui->widget->SetRenderWindow(..)
neither can you grab them all from the widget and modify them via
ui->widget->GetRenderWindow(..)

Ideally both of the above methods should be valid ways of modify the
QVTKWidget, but it seems they are not, once a custom interactor is involved.




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

kenichiro yoshimi
Hi,

The solution may be to move the declaration of the vtkContourWidget to
a member of MainWindow class according to the link below:
https://www.vtk.org/pipermail/vtkusers/2010-August/061942.html

Thanks
2018年7月9日(月) 22:56 andyjk <[hidden email]>:

>
> Thanks
>
> I have tried this but it made no difference.
>
> There just seems to be no way to set a new custom iterator in a
> QVTKOpenGLWidget  (or a QVTKWidget).
>
> I think the issue is that I can grab the existing iterator, from the QWidget
> but it has already been initialised, so any custom interactor that requires
> setting up prior to initialisation fails.
>
> The only solution if you want to use a contour widget and pointplacer, is to
> use a normal VTK window as a pop-up. It looks like it cannot be displayed
> inside QT which is a shame as this spoils the look of the UI.
>
> Not sure this is a bug, just a lack of functionality. We need a way to be
> able to insert our own (new) interactor into a QVTKOpenGLWidget, which
> completely replaces the widgets existing iterator. I think at the moment
> they clash.
>
> I've tried all combinations of grabbing the existing QVTKWidget
> RenderWindow, the renderer and the iterator vs creating New RenderWindow,
> renderer, iterator and Setting them via the QWidget methods.
> No combination works - you cannot create a new window, renderer and iterator
> then apply the lot via
> ui->widget->SetRenderWindow(..)
> neither can you grab them all from the widget and modify them via
> ui->widget->GetRenderWindow(..)
>
> Ideally both of the above methods should be valid ways of modify the
> QVTKWidget, but it seems they are not, once a custom interactor is involved.
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using VTK Widget with QVTK

andyjk
Thankyou!

Yes - putting the widget in the QT mainwindow class as a member solves this!

I think this is true of all VTKWidgets when used with QT, so everyone be
aware of this.

Thanks again.

Andy



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers