[vtkusers] how can I scale a vtkActor2D?

Peter F Bradshaw pfb at exadios.com
Wed Nov 26 19:25:56 EST 2008


Hi Liang Ma;

You may need to set the camera into parallel projection mode.

On Wed, 26 Nov 2008, Liang Ma wrote:

> Sorry, still not clear last time.
>
>
> // remove old actors
>     this->pvtkRenderer->RemoveActor(this->pvtkActor);
>     this->pvtkRenderer->RemoveActor(this->pvtkActor2D);
>
>     // read new data of 3D model from a STL file
>     if (!this->pvtkSTLReader)
>       this->pvtkSTLReader = vtkSTLReader::New();
>     this->pvtkSTLReader->SetFileName(cFileDialog.GetPathName());
>
>  //Cut the 3D model
>     m_VTKPD_data = pvtkSTLReader->GetOutput();
>     m_VTKPD_data->Update();
>     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);
>
>     planeCut->SetInput(m_VTKPD_data);
>     planeCut->SetCutFunction(cplane);
>
> // Setmapper
>  this->pvtkDataSetMapper->SetInput(planeCut->GetOutput());
>  this->pvtkActor->SetMapper(this->pvtkDataSetMapper);
>
> // 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 thefile 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();

Try:
      this->pvtkRenderer->GetActiveCamera()->ParallelProjectionOn();
      this->pvtkRenderer->GetActiveCamera()->Zoom(5);
      this->pvtkRenderer->GetRenderWindow()->Render();

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.



More information about the vtkusers mailing list