You can directly use vtkXYPlotActor to get a plot of 2 arrays .<br><br>Here is a simple example to plot a array .<br>vtkSmartPointer<vtkXYPlotActor> plot = vtkSmartPointer<vtkXYPlotActor>::New();<br> plot->ExchangeAxesOff();<br>
plot->SetLabelFormat( "%g" );<br> plot->SetXTitle( "Level" );<br> plot->SetYTitle( "Frequency" );<br> plot->SetXValuesToIndex();<br><br>for ( i = 0 ; i < 2 ; i++)<br>
{<br> vtkSmartPointer<vtkDoubleArray> array_s = vtkSmartPointer<vtkDoubleArray>::New();<br> vtkSmartPointer<vtkFieldData> field = vtkSmartPointer<vtkFieldData>::New();<br> vtkSmartPointer<vtkDataObject> data = vtkSmartPointer<vtkDataObject>::New();<br>
<br> for (int b = 0; b < 30; b++) /// Assuming an array of 30 elements<br> {<br> hfile>>val; /// My input is a file . <br> array_s->InsertValue(b,val);<br> }<br> field->AddArray(array_s);<br>
data->SetFieldData(field);<br> plot->AddDataObjectInput(data); <br>}<br><br><br> plot->SetPlotColor(0,1,0,0);<br> plot->SetPlotColor(1,0,1,0);<br><br> vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();<br>
renderer->AddActor(plot);<br> renderer->AddActor(rightplot);<br> renderer->AddActor(leftplot);<br> <br> vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer( renderer );<br> renderWindow->SetSize(1000,1000);<br> <br> vtkSmartPointer<vtkRenderWindowInteractor> interactor =<br> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
interactor->SetRenderWindow( renderWindow );<br> <br> // Initialize the event loop and then start it<br> interactor->Initialize();<br> interactor->Start(); <br><br><br><br><div class="gmail_quote">On Sun, Mar 28, 2010 at 2:32 PM, <span dir="ltr"><<a href="mailto:edoardo.belletti@alice.it">edoardo.belletti@alice.it</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
<p><font size="2">I don't have the latests CVS version of VTK but VTK 5.4.2 that I have download from <a href="http://www.vtk.org" target="_blank">www.vtk.org</a><br>
and so the code that you suggest me it doesn't work because it don't found these files:<br>
vtkChartXY, vtkPlot.h.h, vtkContextView.h, vtkContextScene.h<br>
There is some way to simply have a XYPlot of two vectors with my VTK release?<br>
<br>
Thank you<br>
Edoardo<br>
<br>
-----Messaggio originale-----<br>
Da: <a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a> per conto di David Doria<br>
Inviato: dom 28/03/2010 20.10<br>
A: <a href="mailto:edoardo.belletti@alice.it" target="_blank">edoardo.belletti@alice.it</a><br>
Cc: VTK_forum<br>
Oggetto: Re: [vtkusers] Plot XY<div><div></div><div class="h5"><br>
<br>
On Sun, Mar 28, 2010 at 2:03 PM, <<a href="mailto:edoardo.belletti@alice.it" target="_blank">edoardo.belletti@alice.it</a>> wrote:<br>
<br>
> Hello,<br>
><br>
> I am new to VTK so please sorry if this problem is obvious.<br>
><br>
> I am trying to use the XYPlotActor object to create a simply plot of one<br>
> variable against another.<br>
><br>
> I have found a piece of code in a past discussion and I have tried to run<br>
> it but the problem is that it doesn't found the<br>
> vtkFloatScalars.h file<br>
> is there anything in particular that I should add in the CMakeLists.txt to<br>
> include this library?<br>
> the code is this:<br>
><br>
> int main()<br>
> {<br>
> int dataSize = 4;<br>
> float x[4] = { 0, 1.5, 6.2, 10.2 };<br>
> float y[4] = {8, 9.3, 10.9, 27};<br>
> vtkRectilinearGrid *curve1 = vtkRectilinearGrid::New();<br>
> curve1->SetDimensions(dataSize,1,1);<br>
> vtkFloatScalars *dataValues = vtkFloatScalars::New();<br>
> vtkFloatScalars *xCoords = vtkFloatScalars::New();<br>
><br>
> int w;<br>
> for(w=0; w<dataSize; w++)<br>
> {<br>
> dataValues->InsertScalar(w, y[w]);<br>
> xCoords->InsertScalar(w, x[w]);<br>
> }<br>
><br>
> curve1->SetXCoordinates(xCoords);<br>
> curve1->GetPointData()->SetScalars(dataValues);<br>
><br>
> vtkXYPlotActor *theXYPlot = vtkXYPlotActor::New();<br>
> theXYPlot->SetXValuesToArcLength();<br>
> theXYPlot->AddInput(curve1);<br>
> return 0;<br>
> }<br>
><br>
> Thank you very much for the interest<br>
> Edoardo<br>
><br>
><br>
> There is no file in the current CVS called vtkFloatScalars.h, so I'm<br>
assuming that is very old code.<br>
<br>
Marcus Hanwell has been working hard on new charting functionality - there<br>
is a simple example here:<br>
<a href="http://www.vtk.org/Wiki/VTK_Examples_Chart_XY" target="_blank">http://www.vtk.org/Wiki/VTK_Examples_Chart_XY</a><br>
<br>
You must have the latests CVS version of VTK built to use this new feature.<br>
<<a href="http://www.vtk.org/Wiki/VTK_Examples_Chart_XY" target="_blank">http://www.vtk.org/Wiki/VTK_Examples_Chart_XY</a>><br></div></div>
Thanks,<br>
<br>
David<br>
<br>
</font>
</p>
</div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br>