[vtkusers] A Problem About vtkXYPlotActor

LiuNiansheng phenome at live.cn
Thu Jul 8 22:56:29 EDT 2010


Hi everyone:
I'm a user of vtk. When I use vtkXYPlotActor to draw some lines at a XYPlot, I found vtk miss one line.That's my sample code of vtkXYPlotActor:=========================================================================
#include "vtkFloatArray.h"
#include "vtkFieldData.h"
#include "vtkDataObject.h"
#include "vtkXYPlotActor.h"
#include "vtkXYPlotWidget.h"
#include "vtkMath.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"

int main()
{

  vtkFloatArray* vtkXYValues = vtkFloatArray::New();

  vtkXYValues->SetNumberOfComponents( static_cast<vtkIdType>(2) );


  float xy[2];
  xy[0] = static_cast<float>(0);
  xy[1] = static_cast<float>(0) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(2);
  xy[1] = static_cast<float>(3) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(4);
  xy[1] = static_cast<float>(15) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(6);
  xy[1] = static_cast<float>(1) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(7);
  xy[1] = static_cast<float>(0.1) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(8);
  xy[1] = static_cast<float>(10) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(9);
  xy[1] = static_cast<float>(9) ;
  vtkXYValues->InsertNextTuple( xy );

  xy[0] = static_cast<float>(10);
  xy[1] = static_cast<float>(0) ;
  vtkXYValues->InsertNextTuple( xy );

  vtkFieldData* vtkGraphFieldData = vtkFieldData::New();
  vtkGraphFieldData->AddArray( vtkXYValues );
  vtkXYValues->Delete();

  vtkDataObject* vtkGraphDataObject = vtkDataObject::New();
  vtkGraphDataObject->SetFieldData( vtkGraphFieldData );
  vtkGraphFieldData->Delete();

  vtkXYPlotActor* vtkGraph = vtkXYPlotActor::New();
  vtkGraph->AddDataObjectInput( vtkGraphDataObject );
  vtkGraphDataObject->Delete();

  vtkGraph->SetDataObjectPlotModeToColumns(); 
  vtkGraph->SetXValuesToValue();
  int curve = 0;
  vtkGraph->SetDataObjectXComponent( curve, 0 );   
  vtkGraph->SetDataObjectYComponent( curve, 1 );
  vtkGraph->SetXRange( 0, 10);
  vtkGraph->SetYRange( 0, 8);
  vtkGraph->SetPlotColor( curve, 1,0,0 );

  vtkRenderer* renderer = vtkRenderer::New();
  renderer->AddActor2D( vtkGraph );
  vtkRenderWindow* renderWin = vtkRenderWindow::New();
  renderWin->AddRenderer( renderer );

  vtkRenderWindowInteractor* interactor =vtkRenderWindowInteractor::New();
  interactor->SetRenderWindow( renderWin );
  vtkXYPlotWidget* vtkXYPlotWidget = vtkXYPlotWidget::New(); 
  vtkXYPlotWidget->SetXYPlotActor( vtkGraph );
  vtkXYPlotWidget->SetInteractor( interactor );
  vtkXYPlotWidget->SetEnabled( true );

  interactor->Initialize();
  interactor->Start();
  return 0;

}
=========================================================================
I define eight points,a(0,0), b(2,3), c(4,15), d(6,1), e(7,0), f(8,10), g(9,9),h(10,0). And the range of xy  axis is defined from point (0,0) to (10,8). So there are three points(cfg) out of range. There should be six lines except the line fg which is out of range, but only five lines have been drawn. when I change these point to test, I found the line which the value of y axis is from 0(the min value of y axis) to a value bigger than the max value of y axis will be ignored by vtk. 
 I guess the problem maybe happen when clipping data. So I debugged vtkXYPlotActor source, and I found the function named ClipPlotData() have been called in the function CreatPlotData().The algorithm of clipping data is no problem. the number of lines which should be drawn is six.
Cause I don't have enough time to do further research. If anyone has any information about this problem, please let me know.
thanks.
sincerely yours:Elo

 		 	   		  
搜索本应是彩色的,快来体验新一代搜索引擎-必应,精美图片每天换哦! 立即试用! 		 	   		  
_________________________________________________________________
MSN十年回馈,每位用户可免费获得价值25元的卡巴斯基反病毒软件2010激活码,快来领取!
http://kaba.msn.com.cn/?k=1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100709/b2c04b95/attachment.htm>


More information about the vtkusers mailing list