[vtkusers] plotting one array of scalars as a dependent variable of another array of scalars using vtkXYPlotActor

Steve Chall stevec at renci.org
Mon Sep 28 13:06:15 EDT 2009


Several issues:

 

1) Getting the first array (dependent variable "num":  number of particles
per unit volume) into the vtkXYPlotActor.  Here's how I'm doing it now and I
have to believe there's a more direct way:

 

  int nPoints = 1000;

  double *num = new double[nPoints]; // dependent variable:  number of
particles per unit volume for each of nPoints diameters

  double *diam = new double[nPoints]; // independent variable:  nPoints
diameters, values monotonically increasing from 0th elt

 

  RunProcessToPopulateNumAndDiamArraysWithValues(num, diam) // Just assume
the array element values are correct 

 

  vtkXYPlotActor *plot = vtkXYPlotActor::New();

 

  vtkDoubleArray *numArray = vtkDoubleArray::New(); 

  numArray->SetArray(num, nPoints, 1); // put the straight C array of
doubles into a vtkDoubleArray

 

  vtkPointData *numPointData = vtkPointData::New();

  numPointData->SetScalars(numArray);  // put the vtkDoubleArray into a
vtkPointData object

 

  vtkPolyData *numPolyData = vtkPolyData::New();

  numPolyData->SetFieldData(numPointData);  // put the vtkPointData object
into a vtkPolyData object

 

  plot->AddDataObjectInput(numPolyData); // Add the vtkPolyData object to
the plot as a  vtkDataObject

 

When I do this, I can see the plotted data, with num as the y (dependent
variable) and array index by default as the independent variable.  

 

Question 1: Why can't I see the plotted values when I add numPolyData as
input (instead of as data object input), as in:

 

  plot->AddInput(numPolyData); // this builds and runs but doesn't display
the data

 

????

 

Question 2:  Isn't there an easier way to get an array of doubles into the
plot than array of doubles to vtkDoubleArray to vtkPointData to vtkPolyData
and then into the plot as a data object?  This seem so circuitous.

 

Question 3: How can I introduce the diam double array into the plot and use
its elements for the values for the independent variable, i.e., the x axis?
By doing exactly the same thing with diam as I did with num, I can get it
in, but I can't see it, on the x- axis or anywhere else:

 

  vtkDoubleArray *diamArray = vtkDoubleArray::New(); 

  diamArray->SetArray(diam, nPoints, 1); // put the straight C array of
doubles into a vtkDoubleArray

 

  vtkPointData *diamPointData = vtkPointData::New();

  diamPointData->SetScalars(diamArray);  // put the vtkDoubleArray into a
vtkPointData object

 

  vtkPolyData *diamPolyData = vtkPolyData::New();

  diamPolyData->SetFieldData(diamPointData);  // put the vtkPointData object
into a vtkPolyData object

 

  plot->AddDataObjectInput(diamPolyData); // Add the vtkPolyData object to
the plot as a  vtkDataObject

 

 

So, to summarize:

 

QUESTION 1:  Why does AddDataObjectInput(.) work when AddInput(.) doesn't?

 

QUESTION 2: Is there a more straightforward way to load values into a plot?

 

QUESTION 3:  How can I load a second array of doubles to use as the
independent variable, and see their values displayed along the x axis?

 

Thank you.

 

-Steve Chall

 Senior Research Software Developer

 Renaissance Computing Institute

 Phone: 919-515-0051

 Email: stevec at renci.org

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090928/10e044d9/attachment.htm>


More information about the vtkusers mailing list