[vtkusers] Strange behaviour of vtkXYPlotActor class
Isidro Moreno
morenoisidro at yahoo.com.ar
Fri Dec 14 08:18:09 EST 2007
Thanks John! Everything worked fine! Although I agree with you in the fact that it's easier to use data object rather than a dataset, I wondered If you could tell me why the SetDataObject...Component(... , ...) function doesn't work fine in my example and what's the difference between SetDataObjectPlotModeToColumns() and SetDataObjectPlotModeToRows(), since I don't know what columns and rows these functions refer to (I've already seen the HTML help).
Thanks again! Isidro.
----- Original Message -----
From: John Platt
To: 'Isidro Moreno'
Cc: vtk Users
Sent: Thursday, December 13, 2007 7:39 PM
Subject: RE: [vtkusers] Strange behaviour of vtkXYPlotActor class
Hi,
It may be easier to use data object input rather than a data set. You could try the following.
#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 APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
vtkFloatArray* vtkXYValues = vtkFloatArray::New();
vtkXYValues->SetNumberOfComponents( static_cast<vtkIdType>(2) );
for ( int i = 0; i < 360; ++i )
{
float xy[2];
xy[0] = static_cast<float>(i);
xy[1] = sin( xy[0]*vtkMath::DegreesToRadians() );
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();
// Must state the component for the X & Y otherwise 0 is assumed for both!!
int curve = 0;
vtkGraph->SetDataObjectXComponent( curve, 0 );
vtkGraph->SetDataObjectYComponent( curve, 1 );
vtkGraph->SetXRange( 0, 360 );
vtkGraph->SetYRange( -1, 1 );
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;
}
HTH John.
-----Original Message-----
From: vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org [mailto:vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org] On Behalf Of Isidro Moreno
Sent: 13 December 2007 18:37
To: vtkusers at vtk.org
Subject: [vtkusers] Strange behaviour of vtkXYPlotActor class
Hi! I'm a beginer in VTK and I've been trying to draw the sinus func with vtkxyplotactor for teaching purposes. 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.
--------------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.16.17/1177 - Release Date: 7/12/2007 13:11
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071214/4b2499a3/attachment.htm>
More information about the vtkusers
mailing list