[vtkusers] vtkXYPlotActor : X range problem

REGAT-BARREL Aurélien arbvtk at yahoo.fr
Mon Jun 7 07:48:42 EDT 2004


Hi,
I have a problem with vtkXYPlotActor on the X axis : I want to draw a curve in X range [ 20, 330 ], it works, but the X axis range is from 20 to 420 (look at the screenshot).
I tried to call SetXRange( 20, 330 ), or to change the number of X labels with SetNumberOfXLabels( 10 ) but nothing change (there are still 5 X labels).
What's wrong ?
 
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkXYPlotActor.h>
#include <vtkFloatArray.h>
#include <vtkFieldData.h>
#include <vtkDataObject.h>
 
int main()
{
    // rendering stuff
    vtkRenderWindow * renWin = vtkRenderWindow::New();
    vtkRenderWindowInteractor * Iter = vtkRenderWindowInteractor::New();
    renWin->SetInteractor( Iter );
    vtkRenderer * ren = vtkRenderer::New();
    renWin->AddRenderer( ren );
 
    // plot actor
    vtkXYPlotActor * xyplot = vtkXYPlotActor::New();        
    xyplot->SetWidth( 1 );
    xyplot->SetHeight( 1 );
    xyplot->SetPosition( 0, 0 );
    ren->AddActor2D( xyplot );
 
    // simple line x = [ 20, 330 ]
    vtkFloatArray * xarray = vtkFloatArray::New();
    vtkFloatArray * yarray = vtkFloatArray::New();
    const int start = 20;
    const int end = 330;
    for ( int i = start; i <= end; ++i )
    {
        xarray->InsertNextValue( i );
        yarray->InsertNextValue( 100 );
    }
    //xyplot->SetXRange( start, end );
    //xyplot->SetNumberOfXLabels( 10 );
 
    // add the line
    vtkFieldData * values = vtkFieldData::New();
    values->AllocateArrays( 2 );
    values->AddArray( xarray );
    values->AddArray( yarray );
    
    vtkDataObject * data = vtkDataObject::New();
    data->SetFieldData( values );
    xyplot->AddDataObjectInput( data );
    xyplot->SetXValuesToValue();
    xyplot->SetDataObjectYComponent( 0, 1 );
    
    // render
    renWin->SetSize( 500, 500 );
    renWin->Render();
    Iter->Initialize();
    Iter->Start();
}
 
 



Aurélien REGAT-BARREL
		
---------------------------------
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail

Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040607/5df5ad60/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xyactor.gif
Type: image/gif
Size: 6196 bytes
Desc: xyactor.gif
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040607/5df5ad60/attachment.gif>


More information about the vtkusers mailing list