[vtkusers] Strange behaviour of vtkXYPlotActor class

Isidro Moreno morenoisidro at yahoo.com.ar
Mon Dec 10 17:32:32 EST 2007


Hi! I'm a beginer in VTK and I've been trying to draw the sinus func with vtkxyplotactor. The strange thing is that although I indicate which are the x-y components in the values array, the system draws the "arc sin" function. I don't know how to understand this; Am I wrong? or the system swap components?

Here's the code:

#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkPolyData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkXYPlotActor.h"
#include "vtkDataSetCollection.h"

int main(){

//  CONSOLE: how many points entry to form the "line".
//  CONSOLA: Ingreso de la cantidad de puntos que formarán la "curva".

    int data_puntos;
    cout<<"Ingrese cantidad de puntos (1-50): ";
    cin>>data_puntos;

//  Creación de una Celda - Definición topológica y geométrica

//  Definición Topológica
//  Inserción de 1(una) celda con 'n' puntos
    vtkCellArray *cellarray=vtkCellArray::New();
    cellarray->InsertNextCell(data_puntos);

//  Definición Geométrica y relación con la topología

    vtkPoints *puntos=vtkPoints::New();

    for(int j=0;j<data_puntos;j++){
        cellarray->InsertCellPoint(j); // ___ j = nºID de cada punto
        puntos->InsertPoint(
              j, // _________________________ nº ID
              j/5.0, // _____________________ valor de "x"
              sin(j/5.0), // ________________ valor de "y"
              0.0 // _________________________valor de "z"
              );}

//  Agregado de información topológica y geométrica al DataSet

    vtkPolyData *polydata=vtkPolyData::New();
    polydata->SetPoints(puntos);   // Puntos
    polydata->SetLines(cellarray); // Celdas - 1(una)

    polydata->GetPointData()->SetScalars(puntos->GetData());
    polydata->GetPointData()->Update();

//  Creación de un Actor

    vtkXYPlotActor *actor=vtkXYPlotActor::New();

    actor->SetXValuesToValue();
    actor->SetDataObjectXComponent(0,1);
    actor->SetDataObjectYComponent(0,2);

    actor->AddInput(polydata);
    
// The following didn't help me enough... : ( 
    cout<<endl
        <<"GetInputList()->GetNumberOfItems()="<<actor->GetInputList()->GetNumberOfItems()<<endl
        <<"GetDataObjectXComponent(0)="<<actor->GetDataObjectXComponent(0)<<endl
        <<"GetDataObjectYComponent(0)="<<actor->GetDataObjectYComponent(0)<<endl
        <<"GetXValues()="<<actor->GetXValues()<<endl
        <<"GetXValuesAsString()="<<actor->GetXValuesAsString()<<endl
        <<"GetPointComponent(0)="<<actor->GetPointComponent(0);

//  Creación de objetos de renderización

    vtkRenderer *renderer=vtkRenderer::New();
    renderer->AddActor2D(actor);
    renderer->SetBackground(0.0,0.0,0.0);

    vtkRenderWindow *ventana=vtkRenderWindow::New();
    ventana->AddRenderer(renderer);

    vtkRenderWindowInteractor *interac=vtkRenderWindowInteractor::New();
    interac->SetRenderWindow(ventana);

    ventana->Render(); // Inicio de la renderización
    interac->Initialize();
    interac->Start();  // Inicia el "looping"

    polydata->Delete();
    puntos->Delete();
    cellarray->Delete();
    actor->Delete();
    renderer->Delete();
    ventana->Delete();
    interac->Delete();

    return 0;}

Thanks in advance! Isidro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071210/028c5e93/attachment.htm>


More information about the vtkusers mailing list