[vtkusers] Qt & VTK 2d plotting

Clinton Stimpson clinton at elemtech.com
Mon Feb 23 14:05:50 EST 2009


Maybe you're just missing a
renderer->ResetCamera();

If you're just viewing an image, have a look at the image viewer example 
in VTK/Examples/GUI/Qt/ImageViewer

Clint

Justin Giles wrote:
> Ok, I added a style to my interactor in the following way:
>
> //code
>     vtkRenderWindow *renderWindow = vtkRenderWindow::New();
>     renderWindow->SetSize(550, 450);
>     renderWindow->AddRenderer(renderer);
>     vtkRenderWindowInteractor* inter = QVTKInteractor::New();
>     renderWindow->SetInteractor(inter);
>     vtkInteractorStyleImage* interstyle = vtkInteractorStyleImage::New();
>     inter->SetInteractorStyle(interstyle);
>     view->SetRenderWindow(renderWindow);
> //end code
>
> (where view = QVTKWidget)
>
> And, I still get the same results.  Instead of a nice plot, I just get 
> a blank white screen.  Thoughts?  Am I doing something wrong?
>
> Thanks,
>
> Justin
>
> On Mon, Feb 23, 2009 at 11:20 AM, Clinton Stimpson 
> <clinton at elemtech.com <mailto:clinton at elemtech.com>> wrote:
>
>
>     Interaction is handled by the interactor style classes.
>     http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html
>
>     You can use an existing style, or make your own and give it to the
>     interactor.
>
>     Clint
>
>     Justin Giles wrote:
>
>         I am able to create a 2d plot using a QVTKWidget, however I am
>         unable to interact with that plot.  I pretty much new to VTK,
>         so I am kind of at a loss as to how to connect the vtk
>         interactors and Qt.  I have poked around a bit and noticed a
>         QVTKInteractor class, but anything I do with that results in
>         my 2d plot going away to be replaced with a blank white area.
>          Below is the code that I am using.  Just as a note, this is
>         being done in a class that extends a QMainWindow.
>
>         //snippet//
>
>
>            view = new QVTKWidget;
>            setCentralWidget(view);
>
>            int DIM = 500;
>            vtkDataArray *dataArray1 =
>         vtkDataArray::CreateDataArray(VTK_FLOAT);
>            dataArray1->SetNumberOfTuples(DIM);
>
>            vtkDataArray *dataArray2 =
>         vtkDataArray::CreateDataArray(VTK_FLOAT);
>            dataArray2->SetNumberOfTuples(DIM);
>
>            int t;
>            for (t = 0; t < DIM; t++)
>            {
>                float x = t;
>                float y = vtkMath::Random(0.0f,1.0f);
>                dataArray1->SetTuple(t, &x);
>                dataArray2->SetTuple(t, &y);
>            }
>
>            vtkFieldData *fieldData = vtkFieldData::New();
>            fieldData->AllocateArrays(2);
>            fieldData->AddArray(dataArray1);
>            fieldData->AddArray(dataArray2);
>
>            vtkDataObject *dataObject = vtkDataObject::New();
>            dataObject->SetFieldData(fieldData);
>
>            vtkXYPlotActor *plot = vtkXYPlotActor::New();
>            plot->AddDataObjectInput(dataObject);
>            plot->SetTitle("Plot");
>            plot->SetXTitle("X-Axis");
>            plot->SetYTitle("Y-Axis");
>            plot->SetXValuesToValue();
>            plot->SetWidth(0.9);
>            plot->SetHeight(0.9);
>            plot->SetPosition(0.05, 0.05);
>            plot->LegendOn();
>            plot->PickableOff();
>            plot->PlotCurvePointsOn();
>            plot->PlotCurveLinesOff();
>
>            plot->SetDataObjectXComponent(0, 0);
>            plot->SetDataObjectYComponent(0, 1);
>            plot->SetPlotColor(0, 1.0, 0.0, 0.0);
>            plot->SetPlotLabel(0, "My Label");
>            //plot->GetProperty()->SetColor(0.0, 0.0, 0.0);
>
>            vtkRenderer *renderer = vtkRenderer::New();
>            renderer->SetBackground(0, 0, 0);
>            renderer->AddActor2D(plot);
>
>            vtkRenderWindow *renderWindow = vtkRenderWindow::New();
>            renderWindow->SetSize(550, 450);
>            renderWindow->AddRenderer(renderer);
>         //    vtkRenderWindowInteractor* inter = QVTKInteractor::New();
>         //    renderWindow->SetInteractor(inter);
>            view->SetRenderWindow(renderWindow);
>
>         //end-snippet//
>         ------------------------------------------------------------------------
>
>         _______________________________________________
>         Powered by www.kitware.com <http://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
>          
>
>
>




More information about the vtkusers mailing list