[vtkusers] Change Objects in active vtkRenderWindow (using QT)

Arnaud BARRE arnaud.barre at gmail.com
Mon Oct 29 09:57:20 EDT 2012


Dear Fabian,

As you suggested, I think you have to split your code in at least two
functions. The first one will initialize you data, while the second will
modify only the object 'PointCloudColors'. You don't need to save the
configuration of the camera as you won't reset any part of the rendering
pipeline. You will modify only the input. So by calling for example
'PointCloudRenderWindow->Render();' in the second function, VTK will check
for you if something changed and then will update the rendering.

Moreover, I don't see any Qt objects in your code. With Qt and a
QVTKWidget, you won't have to use the last three lines (at least, I never
used them). You have some example on the wiki to use VTK with Qt:
http://www.vtk.org/Wiki/VTK/Examples/Cxx#Qt

Arnaud

On Mon, Oct 29, 2012 at 2:29 PM, Fabian <fabian-richter at gmx.de> wrote:

> Hello Arnaud BARRE,
>
> thanks for Your answer.
>
> My code looks like this (my pointcloud is a list already processed in the
> vector called 'Data'):
>
> My Code wrote
> > void PCV_VTKOps::PCV_Visualize(std::vector
> > <STRUCT_7Values>
> >  Data)
> > {
> >       int i;
> >       PickedPoints.clear();
> >
> >       //general vtk declarations
> >       vtkSmartPointer
> > <vtkRenderer>
> >                               PointCloudRenderer
>              = vtkSmartPointer
> > <vtkRenderer>
> > ::New();
> >       vtkSmartPointer
> > <vtkRenderWindow>
> >                       PointCloudRenderWindow                          =
> vtkSmartPointer
> > <vtkRenderWindow>
> > ::New();
> >       vtkSmartPointer
> > <vtkRenderWindowInteractor>
> >       PointCloudrenderWindowInteractor        = vtkSmartPointer
> > <vtkRenderWindowInteractor>
> > ::New();
> >       vtkSmartPointer
> > <PCV_VTKPickPoints>
> >                       style
>               = vtkSmartPointer
> > <PCV_VTKPickPoints>
> > ::New();
> >       vtkSmartPointer
> > <vtkBMPReader>
> >                               BackgroundTextureReader
>       = vtkSmartPointer
> > <vtkBMPReader>
> > ::New();
> >       vtkSmartPointer
> > <vtkTexture>
> >                                       BackgroundTexture
>                       = vtkSmartPointer
> > <vtkTexture>
> > ::New();
> >       vtkSmartPointer
> > <vtkInteractorStyleTrackballCamera>
> >  style2                                               = vtkSmartPointer
> > <vtkInteractorStyleTrackballCamera>
> > ::New();
> >       vtkSmartPointer
> > <vtkWindowToImageFilter>
> >               PointCloudToImageFilter                         =
> vtkSmartPointer
> > <vtkWindowToImageFilter>
> > ::New();
> >       vtkSmartPointer
> > <vtkBMPWriter>
> >                               PointCloudToImageWriter
>       = vtkSmartPointer
> > <vtkBMPWriter>
> > ::New();
> >
> >       vtkCamera
>               *PointCloudRendererCamera;
> >
> >       //vtkDeclarations PointCloud
> >       vtkSmartPointer
> > <vtkUnsignedCharArray>
> >               PointCloudColors                                        =
> vtkSmartPointer
> > <vtkUnsignedCharArray>
> > ::New();
> >       vtkSmartPointer
> > <vtkPoints>
> >                                       PointCloudPoints
>                      = vtkSmartPointer
> > <vtkPoints>
> > ::New();
> >       vtkSmartPointer
> > <vtkPolyData>
> >                               PointsPolydata
>              = vtkSmartPointer
> > <vtkPolyData>
> > ::New();
> >       vtkSmartPointer
> > <vtkPolyData>
> >                               PointCloudPolyData
>              = vtkSmartPointer
> > <vtkPolyData>
> > ::New();
> >       vtkSmartPointer
> > <vtkVertexGlyphFilter>
> >               PointCloudVertexFilter                          =
> vtkSmartPointer
> > <vtkVertexGlyphFilter>
> > ::New();
> >       vtkSmartPointer
> > <vtkPolyDataMapper>
> >                       PointCloudMapper
>      = vtkSmartPointer
> > <vtkPolyDataMapper>
> > ::New();
> >       vtkSmartPointer
> > <vtkActor>
> >                                       PointCloudActor
>                       = vtkSmartPointer
> > <vtkActor>
> > ::New();
> >
> >       PointCloudColors                                        ->
> SetNumberOfComponents(3);
> >       unsigned char Color[3] = {0, 0, 0};
> >
> >
> >
> >               for (i = 0; i < (int) Data.size(); i++)
> >               {
> >                       if(VTKPARMS.ColorMode == 1)
> >                       {
> >                               Color[0] = Data[i].R;
> >                               Color[1] = Data[i].G;
> >                               Color[2] = Data[i].B;
> >                       }
> >                       PointCloudColors                                ->
> InsertNextTupleValue(Color);
> >                       PointCloudPoints                                ->
> InsertNextPoint(Data[i].x,Data[i].y,Data[i].z);
> >               }
> >
> >       PointsPolydata                                                  ->
> SetPoints(PointCloudPoints);
> >       PointCloudVertexFilter                                  ->
> > SetInputConnection(PointsPolydata->GetProducerPort());
> >       PointCloudVertexFilter                                  ->
> Update();
> >       PointCloudPolyData                                              ->
> > ShallowCopy(PointCloudVertexFilter->GetOutput());
> >       PointCloudPolyData                                              ->
> GetPointData()->SetScalars(PointCloudColors);
> >
> >        //Visualization
> >       PointCloudMapper                                                ->
> > SetInputConnection(PointCloudPolyData->GetProducerPort());
> >       PointCloudActor                                                 ->
> SetMapper(PointCloudMapper);
> >       PointCloudActor                                                 ->
> GetProperty()->SetPointSize(VTKPARMS.PointSize);
> >
> >       PointCloudRenderer                                              ->
> AddActor(PointCloudActor);
> >
> >       BackgroundTextureReader                                 ->
> SetFileName
> > ("C:\\PunktWolkenTest\\VTKBACKGROUND.bmp");
> >       BackgroundTexture                                               ->
> > SetInputConnection(BackgroundTextureReader->GetOutputPort());
> >
> >       PointCloudRenderer->SetBackgroundTexture(BackgroundTexture);
> >       PointCloudRenderer->TexturedBackgroundOn();
> >
> >       PointCloudRenderWindow                                  ->
> AddRenderer(PointCloudRenderer);
> >
> >
> >       PointCloudrenderWindowInteractor                        ->
> > SetRenderWindow(PointCloudRenderWindow);
> >
> > VTKPARMS.QTRenderer = PointCloudRenderer;
> > VTKPARMS.QTRenderWindow = PointCloudRenderWindow;
> >
> >
> >       PointCloudRenderWindow                                  ->
> Render();
> >       PointCloudrenderWindowInteractor                        -> Start();
> >       PointCloudRenderWindow                                  ->
> Finalize();
> >
> > }
>
> But I am not sure if my question is more about structure. What this
> function
> does is basically take the points, process the pipeline and put the
> Renderer
> and RenderWindow somewhere where I can put it into a QVTKWidget.
>
> Now I am afraid, that 'sorting points out' (because they have a special
> color value) would mean that I need to walk through the whole pipeline
> again. I know how to connect the QTSlider, but I dont know, if my function
> allows to interact with it after it run through.
>
> I thought about reorganising the function in case it needs to be called
> every time when the slider is moved. In that case I would save the
> VTKcamera
> somehow, filter the pointcloud before it gets visualized and swap the
> RenderWindows in the QVTKWidget (if possible).
>
> Would You think this to be better?
>
> THANKS ALOT,
> Fabian
>
>
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Change-Objects-in-active-vtkRenderWindow-using-QT-tp5716830p5716869.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121029/4c4ee2fa/attachment.htm>


More information about the vtkusers mailing list