[vtkusers] Qt & VTK 2d plotting
Shakes
Shekhar.Chandra at sci.monash.edu.au
Mon Feb 23 17:37:43 EST 2009
Hi Justin,
Someone correct me if I'm wrong, but I don't think u can interact with
it as the plot is not in a 3D scene (i.e., its a not plane in a 3D scene).
This is difference between vtkImageViewer and vtkImageViewer2, the
latter is in a 3D scene and you can interact with it.
I used the following to "zoom" XY Plots:
//Scale
plotActor->SetWidth(factor);
plotActor->SetHeight(factor);
//Reposition
plotActor->SetPosition(pos[0]-factor*pos[0], pos[1]-factor*pos[1]);
HTH
Cheers
Shakes
Justin Giles wrote:
> That didn't seem to work either. I'm trying to view a xy plot.
>
> Justin
>
> On Mon, Feb 23, 2009 at 1:05 PM, Clinton Stimpson <clinton at elemtech.com
> <mailto:clinton at elemtech.com>> wrote:
>
>
> 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>
> <mailto: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>
> <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
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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 --------------
A non-text attachment was scrubbed...
Name: Shekhar_Chandra.vcf
Type: text/x-vcard
Size: 247 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090224/0cd3d0c4/attachment.vcf>
More information about the vtkusers
mailing list