[vtkusers] R: R: Plot XY
edoardo.belletti at alice.it
edoardo.belletti at alice.it
Sun Mar 28 17:47:14 EDT 2010
Thank you very much!
Edoardo
-----Messaggio originale-----
Da: Darshan Pai [mailto:darshanpai at gmail.com]
Inviato: dom 28/03/2010 23.11
A: edoardo.belletti at alice.it
Cc: David Doria; VTK_forum
Oggetto: Re: [vtkusers] R: Plot XY
You can directly use vtkXYPlotActor to get a plot of 2 arrays .
Here is a simple example to plot a array .
vtkSmartPointer<vtkXYPlotActor> plot =
vtkSmartPointer<vtkXYPlotActor>::New();
plot->ExchangeAxesOff();
plot->SetLabelFormat( "%g" );
plot->SetXTitle( "Level" );
plot->SetYTitle( "Frequency" );
plot->SetXValuesToIndex();
for ( i = 0 ; i < 2 ; i++)
{
vtkSmartPointer<vtkDoubleArray> array_s =
vtkSmartPointer<vtkDoubleArray>::New();
vtkSmartPointer<vtkFieldData> field =
vtkSmartPointer<vtkFieldData>::New();
vtkSmartPointer<vtkDataObject> data =
vtkSmartPointer<vtkDataObject>::New();
for (int b = 0; b < 30; b++) /// Assuming an array of 30 elements
{
hfile>>val; /// My input is a file .
array_s->InsertValue(b,val);
}
field->AddArray(array_s);
data->SetFieldData(field);
plot->AddDataObjectInput(data);
}
plot->SetPlotColor(0,1,0,0);
plot->SetPlotColor(1,0,1,0);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(plot);
renderer->AddActor(rightplot);
renderer->AddActor(leftplot);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer( renderer );
renderWindow->SetSize(1000,1000);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow( renderWindow );
// Initialize the event loop and then start it
interactor->Initialize();
interactor->Start();
On Sun, Mar 28, 2010 at 2:32 PM, <edoardo.belletti at alice.it> wrote:
> I don't have the latests CVS version of VTK but VTK 5.4.2 that I have
> download from www.vtk.org
> and so the code that you suggest me it doesn't work because it don't found
> these files:
> vtkChartXY, vtkPlot.h.h, vtkContextView.h, vtkContextScene.h
> There is some way to simply have a XYPlot of two vectors with my VTK
> release?
>
> Thank you
> Edoardo
>
> -----Messaggio originale-----
> Da: daviddoria at gmail.com per conto di David Doria
> Inviato: dom 28/03/2010 20.10
> A: edoardo.belletti at alice.it
> Cc: VTK_forum
> Oggetto: Re: [vtkusers] Plot XY
>
>
> On Sun, Mar 28, 2010 at 2:03 PM, <edoardo.belletti at alice.it> wrote:
>
> > Hello,
> >
> > I am new to VTK so please sorry if this problem is obvious.
> >
> > I am trying to use the XYPlotActor object to create a simply plot of one
> > variable against another.
> >
> > I have found a piece of code in a past discussion and I have tried to run
> > it but the problem is that it doesn't found the
> > vtkFloatScalars.h file
> > is there anything in particular that I should add in the CMakeLists.txt
> to
> > include this library?
> > the code is this:
> >
> > int main()
> > {
> > int dataSize = 4;
> > float x[4] = { 0, 1.5, 6.2, 10.2 };
> > float y[4] = {8, 9.3, 10.9, 27};
> > vtkRectilinearGrid *curve1 = vtkRectilinearGrid::New();
> > curve1->SetDimensions(dataSize,1,1);
> > vtkFloatScalars *dataValues = vtkFloatScalars::New();
> > vtkFloatScalars *xCoords = vtkFloatScalars::New();
> >
> > int w;
> > for(w=0; w<dataSize; w++)
> > {
> > dataValues->InsertScalar(w, y[w]);
> > xCoords->InsertScalar(w, x[w]);
> > }
> >
> > curve1->SetXCoordinates(xCoords);
> > curve1->GetPointData()->SetScalars(dataValues);
> >
> > vtkXYPlotActor *theXYPlot = vtkXYPlotActor::New();
> > theXYPlot->SetXValuesToArcLength();
> > theXYPlot->AddInput(curve1);
> > return 0;
> > }
> >
> > Thank you very much for the interest
> > Edoardo
> >
> >
> > There is no file in the current CVS called vtkFloatScalars.h, so I'm
> assuming that is very old code.
>
> Marcus Hanwell has been working hard on new charting functionality - there
> is a simple example here:
> http://www.vtk.org/Wiki/VTK_Examples_Chart_XY
>
> You must have the latests CVS version of VTK built to use this new feature.
> <http://www.vtk.org/Wiki/VTK_Examples_Chart_XY>
> Thanks,
>
> David
>
>
> _______________________________________________
> 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/20100328/b169f5dc/attachment.htm>
More information about the vtkusers
mailing list