[vtkusers] abnormal chart using scatter points

liuxy liuxy506 at gmail.com
Thu Mar 31 08:23:13 EDT 2011


Thank you for your help!!

The version of VTK I used is 5.6.1, and compile the source code with
Cmake2.8 and VS 2008, the code of drawing scatter points more than 40,000
 is that :

#include <vtkSmartPointer.h>
#include <vtkChartXY.h>
#include <vtkContextScene.h>
#include <vtkContextView.h>
#include <vtkFloatArray.h>
#include <vtkShortArray.h>
#include <vtkPlotPoints.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkTable.h>
#include <vtkAxis.h>

int main(int, char*[])
{
  // Set up a 2D scene, add an XY chart to it
  vtkSmartPointer<vtkContextView> view =
vtkSmartPointer<vtkContextView>::New();
  vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
  view->GetScene()->AddItem(chart);
  chart->SetShowLegend(true);

  // Create a table with some points in it...
  vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();

  // float 数组
  vtkSmartPointer<vtkFloatArray> arrX
=vtkSmartPointer<vtkFloatArray>::New();
  arrX->SetName("X Axis");
  table->AddColumn(arrX);
  vtkSmartPointer<vtkFloatArray> arrC =
vtkSmartPointer<vtkFloatArray>::New();
  arrC->SetName("sin");
  table->AddColumn(arrC);

  // amount of scatter points
  int numPoints =40000;

  float inc = 7.5 / (numPoints-1);
  table->SetNumberOfRows(numPoints);
  for (int i = 0; i < numPoints; ++i){
    table->SetValue(i, 0, i * inc);
    table->SetValue(i,1, sin(i * inc));
  }

  // Add multiple scatter plots, setting the colors etc
  vtkPlot *points = chart->AddPlot(vtkChart::POINTS);
  points->SetInput(table, 0, 1);
  points->SetColor(0, 0, 255, 255);
  points->SetWidth(2.0);

  //Finally render the scene
  view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
  view->GetRenderWindow()->SetSize(1024, 600);
  view->GetInteractor()->Initialize();
  view->GetInteractor()->Start();
  return EXIT_SUCCESS;
}


and the run effect is like 4000error.jpg, if  I replace vtkChart::POINTS
to vtkChart::LINE ,the result is right, why ?











2011/3/28 Eric E. Monson <emonson at cs.duke.edu>

> Hello,
>
> Which version of VTK are you using? I've definitely drawn scatter plots
> using the Charts API that had more than 40,000 points, and this is something
> the Charts are supposed to be good at, so it will be interesting to see what
> has gone wrong in your case. The VTK version is important because a lot of
> development has gone on in the Charts since 5.6, so if you're using 5.6 the
> bug may already have been fixed.
>
> Otherwise, if you're using the development head and this is still
> happening, maybe you can pass along a minimal piece of code that
> demonstrates the problem and we can help figure out what's going on.
>
> Talk to you later,
> -Eric
>
> ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・ ・
> Eric E Monson
> Duke Visualization Technology Group
>
>
> On Mar 28, 2011, at 1:43 AM, liuxy wrote:
>
> > I used vtkChart API to draw a line: y=sin(x) using "scatter points",
> >
> > the chart is abnormal when the number of points are more than 40,000.
> >
> > just like pictrue a.jpg in enclosure.
> >
> > but if the points are less than 40,000 or using "Line" to draw y=sin(x),
> >
> > the chart is correct. Just like pictrue b.jpg.
> >
> > I want to know how to use "scatter points" in drawing charts with huge
> scale of points ?
> >
> > or vtkChart may be not applicable in this situation ?
> >
> >
> > P.S:
> >
> > By reading the source Code of vtkChart,
> >
> > I found when drawing in "scatter points",
> >
> > it used function 'DrawPointSprites'.
> >
> > if replaced it with function 'DrawPoints',the chart shows correctly,
> >
> > even number of points more than 40,000.
> > <a.JPG><b.JPG>_______________________________________________
> > 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/20110331/40ecf710/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 40000error.JPG
Type: image/jpeg
Size: 52038 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110331/40ecf710/attachment.jpeg>


More information about the vtkusers mailing list