[vtkusers] Is it possible to change size of a vtkActor2D?

Öner F luxtheme at yahoo.de
Tue May 26 07:35:31 EDT 2009


Hi,

I want to display analog & digital signals in a cartesian coordinate system which 
should be zoomable. I have tried several approaches and simply do not get further.
So I need help.

One of the approaches which I try is vtkActor2D. Problem is, that if I change the
window size, it does not change the size of the 2D actor. First position of the
2D actor I can wonderfully set up, but position2 cannot be changed. Height and
width of the 2D actor remains always constant.
Is it possible to zoom with vtkActor2D? If so, how?
Which additional functions do I need?

.luxtheme.

my code:

#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkActor2D.h"
#include "vtkcamera.h"

#include <cstdlib>
#include <ctime>

//random signal
void random_Signal (int timeLine, int *event_array_time, 
                    int *event_array_bit, int &array_index) 
{
    srand((unsigned)time(0));
    int time=0;
    int counter=0;
    int start_bit = 0;

    while(time<timeLine)
    {
        counter++;
        event_array_time[counter-1]=time;
        event_array_bit[counter-1]=start_bit;

        int random_event = (rand()%500)+1;
        time+=random_event;
        start_bit=(start_bit+1)%2;
    }
    event_array_time[counter-1]=timeLine;

    array_index=counter;
}

//line
void create_Line(double x1, double y1, double x2, double y2, 
                 vtkPoints *points, vtkCellArray *lines, int &pID)
{
    points->InsertNextPoint(x1,y1,0);        
    points->InsertNextPoint(x2,y2,0);        

    lines->InsertNextCell(2);                    
    lines->InsertCellPoint(pID);    
    lines->InsertCellPoint(pID+1);    

    pID+=2;                            
}

//MAIN
void main()
{
    const int events=100; 
    int event_array_time[events];
    int event_array_bit[events];
    int timeLine = 2000;  
    int array_index = 0;

    vtkPoints *points = vtkPoints::New();
    vtkCellArray *lines = vtkCellArray::New();
    int pID = 0;

    // generate random signal
    random_Signal(timeLine, event_array_time, event_array_bit, array_index);
    cout << "\n\nAI: " << array_index << endl;

    //plot signal
    create_Line(800.0/timeLine*event_array_time[0],
        300*event_array_bit[0],                     //position1
        800.0/timeLine*event_array_time[1],    
        300*event_array_bit[0],                        //position2
        points, lines, pID);

    for (int i=1; i<array_index-1; i++) {

        // toggle line
        create_Line(800.0/timeLine*event_array_time[i], 300*event_array_bit[i],
            800.0/timeLine*event_array_time[i], 300*event_array_bit[i+1],
            points, lines, pID);

        // High-/ Low-line
        create_Line(800.0/timeLine*event_array_time[i], 300*event_array_bit[i],
            800.0/timeLine*event_array_time[i+1], 300*event_array_bit[i],
            points, lines, pID);
    }

    // Create 2d-actor
    vtkPolyData* polyData = vtkPolyData::New();
        polyData->SetPoints(points);    
        polyData->SetLines(lines);    

    vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
        mapper->SetInput(polyData);                

    vtkActor2D *actor = vtkActor2D::New();
        actor->SetMapper(mapper);
        //actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(); //OK
        //actor->GetPositionCoordinate()->SetValue(.2,.5); //OK
        actor->SetWidth(0.7); // no effect
        actor->SetHeight(0.1); // no effect
        //actor->SetPosition(0.1,0.1); //OK
        actor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport(); 
        //^no effect
        actor->GetPosition2Coordinate()->SetValue(.2,.5); //no effect
        actor->SetPosition2(0.9,0.9); //no effect

    // Create a renderer
    vtkRenderer* ren = vtkRenderer::New();
        ren->SetBackground(0.75,0.25,0.25);
        ren->AddActor(actor);
        ren->GetActiveCamera()->ParallelProjectionOff(); //no effect
        ren->GetActiveCamera()->Zoom(5); //no effect

    // Create a render window
    vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
    vtkRenderWindow* renWin = vtkRenderWindow::New();
        renWin->AddRenderer(ren);
        renWin->SetSize( 800,300 );
        renWin->SetInteractor( iren );

    iren->Initialize();
    renWin->Render();
    iren->Start();

    //...
}


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090526/df63c734/attachment.htm>


More information about the vtkusers mailing list