[vtkusers] Set position of vtkImageSlice

David Lonie david.lonie at kitware.com
Tue Nov 13 16:43:20 EST 2012


On Tue, Nov 13, 2012 at 4:41 PM, David Doria <daviddoria at gmail.com> wrote:
>> 2012/11/13 David Lonie <david.lonie at kitware.com>
> If you want to do it with the "change the position of the actor" technique,
> here is one way to make the view not update to always make the object look
> centered. I get the camera before adding the actor, add the actor (which
> changes the current camera, but not the one I deep copied previously), then
> set the camera to the one that was saved.
>
> (I just saw your reply - that is easier haha, but this might be good to know
> about too :) ).

Thanks for the tip -- that certainly would do the trick too :-)

Dave


> #include <vtkSphereSource.h>
>
> #include <vtkCamera.h>
>
> #include <vtkPolyData.h>
>
> #include <vtkSmartPointer.h>
>
> #include <vtkPolyDataMapper.h>
>
> #include <vtkActor.h>
>
> #include <vtkRenderWindow.h>
>
> #include <vtkRenderer.h>
>
> #include <vtkRenderWindowInteractor.h>
>
>
>
> int main(int, char *[])
>
> {
>
>   // Create a sphere
>
>   vtkSmartPointer<vtkSphereSource> sphereSource =
>
>     vtkSmartPointer<vtkSphereSource>::New();
>
>   sphereSource->SetCenter(0, 0, 0);
>
> //  sphereSource->SetCenter(0, -0.1, 0);
>
>   sphereSource->SetCenter(0.1, 0.1, 0);
>
>   sphereSource->SetRadius(0.1);
>
>
>   vtkSmartPointer<vtkPolyDataMapper> mapper =
>
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>
>   mapper->SetInputConnection(sphereSource->GetOutputPort());
>
>
>   vtkSmartPointer<vtkActor> actor =
>
>     vtkSmartPointer<vtkActor>::New();
>
>   actor->SetMapper(mapper);
>
>
>   vtkSmartPointer<vtkRenderer> renderer =
>
>     vtkSmartPointer<vtkRenderer>::New();
>
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>
>     vtkSmartPointer<vtkRenderWindow>::New();
>
>   renderWindow->AddRenderer(renderer);
>
>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>
>     vtkSmartPointer<vtkRenderWindowInteractor>::New();
>
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>
>
>   vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
>
>   camera->DeepCopy(renderer->GetActiveCamera());
>
>
>   renderer->AddActor(actor);
>
>
>   renderer->SetActiveCamera(camera);
>
>
>   renderWindowInteractor->Start();
>
>
>   return EXIT_SUCCESS;
>
> }
>
>
>
> David
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK 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