[vtkusers] how can I scale a vtkActor2D?

Liang Ma leo at esit.com
Wed Nov 26 09:56:38 EST 2008

Hi Peter,

Thanks. I tried the zoom code following your advice. The result is same as 
before. If I change the value in : 
this->pvtkActor->GetPositionCoordinate()->SetValue(0.5, 0.5);

Then I can move the 2D actor to any where. But Zoom() and position2 do not 

I think position2 should work on a 2D actor. Only some subclass of 2D actor 
will ignore it. So is it because VTK changed the 2D actor to one of it's sub 
class some where automatically? Thanks.

The following is my code on this part for your information.


Liang Ma

    // remove old actors

    // read new data of 3D model from a STL file
    if (!this->pvtkSTLReader)
      this->pvtkSTLReader = vtkSTLReader::New();

 //Cut the 3D model
    m_VTKPD_data = pvtkSTLReader->GetOutput();
    m_dOrigin1 = m_VTKPD_data->GetCenter();
    this->cplane->SetOrigin(m_dOrigin1[0], m_dOrigin1[1], m_dOrigin1[2]);
    float normal_x = 0;
    float normal_y = 0;
    float normal_z = 1;
    cplane->SetNormal(normal_x, normal_y, normal_z);


// Setmapper

// Try to scale the 2D actor
 this->pvtkActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(); this->pvtkActor->GetPositionCoordinate()->SetValue(0.3, 0.5); this->pvtkActor->GetPosition2Coordinate()->SetValue(0.9, 0.9); this->pvtkActor->GetProperty()->SetColor(1, 0, 0);// Add the txt of the file name    this->pvtkTextMapper->SetInput(pvtkSTLReader->GetFileName());    this->pvtkTextMapper->GetTextProperty()->SetFontSize(12);    this->pvtkActor2D->SetMapper(this->pvtkTextMapper);// Set background and add actors to render    this->pvtkRenderer->SetBackground(0.4,0.4,0.4);    this->pvtkRenderer->AddActor(this->pvtkActor);    this->pvtkRenderer->AddActor(this->pvtkActor2D);// try to zoom, then render   this->pvtkRenderer->GetActiveCamera()->Zoom(5);    this->pvtkRenderer->GetRenderWindow()->Render();----- Original Message -----From: "Peter F Bradshaw" <pfb at exadios.com>To: "VTK users" <vtkusers at vtk.org>Sent: Tuesday, November 25, 2008 8:39 PMSubject: Re: [vtkusers] how can I scale a vtkActor2D?> Hi Liang Ma;>> On Tue, 25 Nov 2008, Liang Ma wrote:>>> Dear Peter,>>>> Thank you so much for your reply. I did try  this->pvtkRenderer->Render()>> after     this->pvtkRenderer->AddActor(this->pvtkActor); It does notwork.>> I think that this may be the wrong place to call Render().>> I should have been a little clearer. The way vtkRenderer works is that> you make changes to the components of the scene (actors, camera, etc.)> and then, as the very last thing to do, to implement the change you call> Render(). This is because rendering is an expensive process.>> So, applying this to your zoom code:>> this->pvtkRenderer->GetActiveCamera()->Zoom(5);> this->pvtkRenderer->GetRenderWindow()->Render();>>>>> my pvtkActor is a vtkActor2D:>>>>   vtkActor2D            *pvtkActor2D;>>>> In fact  this->pvtkActor->GetPositionCoordinate()->SetValue(0.5, 0.5);will>> move the actor to the center. But>> this->pvtkActor->GetPosition2Coordinate()->SetValue(0.9, 0.9);  will not>> scale the actor.>>>> I searched in the archive of  vtkuser and could not fond the answer. Iread>> from the help that  vtkActor2D->GetPosition2Coordinate()->SetValuesometims>> will not work "Some 2D actor subclasses ignore the position2 variable ".But>> I do not know why. Will a vtkXYPlotActor be better? I can change the sizeof>> the font in the same program.Whould you please give me some more advices?>> Thanks again.>>>> Best regards>>>> Liang Ma>>>>>>>> ----- Original Message ----->> From: "Peter F Bradshaw" <pfb at exadios.com>>> To: "VTK Users" <vtkusers at vtk.org>>> Sent: Tuesday, November 25, 2008 11:15 AM>> Subject: Re: [vtkusers] how can I scale a vtkActor2D?>>>>>> > Hi Liang Ma;>> >>> > Are you calling this->pvtkRenderer->Render() anywhere?>> >>> > On Mon, 24 Nov 2008, Liang Ma wrote:>> >>> >> Hi all,>> >>>> >> I tried to scale a 2D actor but it doesn't work. I tried>> >> GetPosition2Coordinate() function but it doesn't work.  Also I triedto>> >> zoom the camera. It does not work either.>> >>>> >> Whould you give me some advices? Thanks.>> >>>> >> Regards>> >>>> >> Liang Ma>> >>>> >> Here is the code:>> >>>> >>   vtkActor2D   *pvtkActor;>> >>            ..........................>> >>>> >>this->pvtkActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();>> >>  this->pvtkActor->GetPositionCoordinate()->SetValue(0.5, 0.5);  //>> >> works, could move the actor to the center>> >>  this->pvtkActor->GetPosition2Coordinate()->SetValue(0.9, 0.9); //does>> >> not work, no effect>> >>  this->pvtkActor->GetProperty()->SetColor(1, 0, 0);>> >>>> >> the code for zoom:>> >>>> >>////////////////////////////////////////////////////////////////////////>> >>         this->pvtkCamera = this->pvtkRenderer->GetActiveCamera ();>> >>         this->pvtkCamera->Zoom(5);    //     zoom doesn't work>> >>         this->pvtkRenderer->SetActiveCamera (this->pvtkCamera) ;>> >>///////////////////////////////////////////////////////////////////////////>> >>>> >>> > Cheers>> >>> Cheers>> --> Peter F Bradshaw: http://www.exadios.com (public keys avaliable there).> Personal site: http://personal.exadios.com> "I love truth, and the way the government still uses it occasionally to> keep us guessing." - Sam Kekovich.> _______________________________________________> This is the private VTK discussion list.> Please keep messages on-topic. Check the FAQ at:http://www.vtk.org/Wiki/VTK_FAQ> Follow this link to subscribe/unsubscribe:> http://www.vtk.org/mailman/listinfo/vtkusers

More information about the vtkusers mailing list