[vtkusers] vtkXYPlotActor2D strange behaviour ??

Yasin Alakese y_alakese at hotmail.com
Wed Apr 2 18:42:23 EST 2003


Hi

When we create a x-y plot, and we give x range, y range, everything is okay! 
But if I try to change y range or x range(like in code below), the title and 
the numbers glide! Can someone tell me how if we can avoid this??

Regards
Yasin Alakese






/****/


#include <vtkDataArray.h>
#include <vtkFieldData.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkXYPlotActor.h>
#include "vtkAxisActor2D.h"

#include <vtkTextProperty.h>


#define DIM 4

int main(int argc, char* argv[])
{
    vtkAxisActor2D *xAxis, *yAxis;
    vtkDataArray *dataArray1 = vtkDataArray::CreateDataArray(VTK_FLOAT);
    dataArray1->SetNumberOfTuples(DIM);
    vtkDataArray *dataArray2 = vtkDataArray::CreateDataArray(VTK_FLOAT);
    dataArray2->SetNumberOfTuples(DIM);


        vtkXYPlotActor *plot = vtkXYPlotActor::New();
	vtkFieldData *fieldData = vtkFieldData::New();
	vtkDataObject *dataObject = vtkDataObject::New();
	vtkRenderer *renderer = vtkRenderer::New();
	vtkRenderWindow *renderWindow = vtkRenderWindow::New();
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

	vtkTextProperty *text = vtkTextProperty::New();


	float x = 3;
	float y = 1;
	dataArray1->SetTuple(0, &x);
	dataArray2->SetTuple(0, &y);

	x = 2;
	y = 0.0;
	dataArray1->SetTuple(1, &x);
	dataArray2->SetTuple(1, &y);

	x = 1.0;
	y = 0.5;
	dataArray1->SetTuple(2, &x);
	dataArray2->SetTuple(2, &y);

	x = 0.0;
	y = 0.0;
    dataArray1->SetTuple(3, &x);
    dataArray2->SetTuple(3, &y);


    fieldData->AllocateArrays(2);
    fieldData->AddArray(dataArray1);
    fieldData->AddArray(dataArray2);
    dataObject->SetFieldData(fieldData);

    plot->AddDataObjectInput(dataObject);
    plot->SetTitle("Arc");
    plot->SetXTitle("cos(t)");
    plot->SetYTitle("sin(t)");
    plot->SetFontFamilyToTimes();


    plot->SetYRange(-1.0, 1.0);
    plot->SetXRange(0.0, 4.0);

    plot->SetXValuesToValue();
    plot->SetWidth(0.9);
    plot->SetHeight(0.9);
    plot->SetPosition(0.05, 0.05);
    plot->SetDataObjectXComponent(0, 0);
    plot->SetDataObjectYComponent(0, 1);

    xAxis = plot->GetXAxisActor2D();
    yAxis = plot->GetYAxisActor2D();
    xAxis->SetFontFactor(10);
    yAxis->SetFontFactor(10);

    renderer->AddActor2D(plot);
    renderWindow->AddRenderer(renderer);
    iren->SetRenderWindow(renderWindow);

    renderWindow->Render();


    //now it will do
    plot->SetYRange(-10.0, 10.0);

    renderWindow->Render();
    iren->Start();

    dataArray1->Delete();
    dataArray2->Delete();
    fieldData->Delete();
    dataObject->Delete();
    plot->Delete();
    renderer->Delete();
    renderWindow->Delete();
    iren->Delete();

    return 0;
}



_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail




More information about the vtkusers mailing list