[vtkusers] vtkImageSlice and vtkImageReslice Mapper

Sahithya Wintrich s.prakash at csuohio.edu
Fri Nov 9 16:53:44 EST 2012


I want to select points and add a connecting line through the points on the
axial slice. Adding an mouse interaction to the modified code from
VTK/ImageProcessing/Python/ImageInteractorReslice.py causes the axial slice
not be "static" anymore. Meaning if I hold down the left mouse button and
drag my mouse around the mouse pad, I am able to visualize the remaining
volume. I would like to prevent this from happening. Is there are
workaround to this? (my code below)

class Interaction: public vtkInteractorStyleTrackballCamera
{
  public:
    static Interaction* New();
    vtkTypeMacro(Interaction, vtkInteractorStyleTrackballCamera);

    void Initiliaze();

    virtual void OnLeftButtonDown()
    {
        cout << "Picking pixel: " <<
this->Interactor->GetEventPosition()[0] << " " <<
this->Interactor->GetEventPosition()[1] << std::endl;

this->Interactor->GetPicker()->Pick(this->Interactor->GetEventPosition()[0],

                            this->Interactor->GetEventPosition()[1],
                            0,  // always zero.

this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
        double picked[3];
        this->Interactor->GetPicker()->GetPickPosition(picked);
        cout << "Picked value: " << picked[0] << " " << picked[1] << " " <<
picked[2] << std::endl;

        AddSelectedPoint(picked);

        // code to display the picked values and  locations
        vtkSmartPointer<vtkRegularPolygonSource> circle =
vtkSmartPointer<vtkRegularPolygonSource>::New();
        circle->SetNumberOfSides(50);
        circle->SetRadius(1);
        circle->SetCenter(picked[0], picked[1], picked[2]);
        circle->Update();

        vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputConnection(circle->GetOutputPort());
        mapper->Modified();

        vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
        vtkSmartPointer<vtkProperty> circleProperty =
vtkSmartPointer<vtkProperty>::New();
        circleProperty->SetColor(1, 1, 0);
        //circleProperty->SetOpacity(0.0);
        circleProperty->EdgeVisibilityOn();
        circleProperty->SetEdgeColor(1, 0, 0);
        actor->SetMapper(mapper);
        actor->SetProperty(circleProperty);

this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(actor);

this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->Render();

        // Forward events
        vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
     };


  private:
      void AddSelectedPoint(double point[]);



};

main.cpp

  vtkSmartPointer<Interaction> mouseStyle =
vtkSmartPointer<Interaction>::New();
  mouseStyle->Initiliaze();
  mouseStyle->SetDefaultRenderer(renderer);

  iren->SetInteractorStyle( mouseStyle );

Thanks for any help!

Sahithya



On Fri, Nov 2, 2012 at 6:03 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Sahithya,
>
> The following example comes with the VTK source code:
>
> VTK/ImageProcessing/Python/ImageInteractorReslice.py
>
> Note that you cannot use SetSlicePlane() together with
> SliceFacesCameraOn() and SliceAtFocalPointOn(),
> because when the latter two methods are used, the slice
> plane will be automatically set from the camera parameters
> and any value you set with SetSlicePlane() will be ignored.
>
>  - David
>
>
> On Fri, Nov 2, 2012 at 3:39 PM, Sahithya Wintrich <s.prakash at csuohio.edu>
> wrote:
> > Hello,
> >
> > I am new to VTK and visualization in general. I am trying to extract a 2D
> > slice from a 3D volume. The classes I use are as follows:
> >
> > vtkImageReader - reads the stack of 2D CT images
> > vtkVolumeTextureMapper2D - Maps the volume
> >
> > in order to get a slice defined by a vtkPlane with origin and normal
> > corresponding to the slice of interest, I use:
> >
> >     mapper = vtkImageResliceMapper::New();
> >     mapper->SetInputConnection(
> > reader->GetOuputPort());
> >     mapper->SetSlicePlane(plane);
> >
> >     slice = vtkImageSlice::New();
> >     slice->SetMapper(mapper);
> >
> >     renderer->AddViewProp(slice);
> >
> > I understand that the vtkImageSlice is a 3D prop and I tried using
> > suggestions to change the position and focal point of the camera.
> However,
> > this is still displayed in a 3D space. I need to display this as a 2D
> slice
> > with a correct view (for oblique slices as well) and prevent the user
> from
> > rotating the slice.
> >
> > Any help would be greatly appreciated!
> >
> > Sahithya
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121109/52ce7fe3/attachment.htm>


More information about the vtkusers mailing list