问题
I'm using vtkTexturedActor2D and vtkImageMapper to display a 2D image. I can use
actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();
actor.this.Actor.SetPosition(0.5, 0.9);
to place the image in the center of the window, but it's not center-aligned. The corner of the image is placed in the center. How can I center-align the image so that the center of the image is at the center of the window?
回答1:
I had this same problem.
This seems to solve it:
float height, width;
this->d_actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
this->d_actor->GetPositionCoordinate()->SetViewport(this); // Without this was getting weird results
height = this->d_actor->GetHeight();
width = this->d_actor->GetWidth();
this->d_actor->GetPositionCoordinate()->SetValue(.5 - width/2.0, .5 - height/2.0);
来源:https://stackoverflow.com/questions/15394359/centering-image-in-vtk-window