[vtkusers] vtkPropPicker pick coordinate problem

chasank chasank at gmail.com
Mon Jul 22 09:30:41 EDT 2013


Hi,

Whenever I click the regions which have minimum intensity values,
vtkPropPicker generates wrong coordinate values. When I look at the code of
Pick method of vtkPropPicker, I see that GetZ method of vtkRenderer returns
1.0 whenever I click the regions which have minimum intensity values. Is
there any other way to solve this problem? Here is our code.

/* In this part of code when user uses wheel forward, slice of image
changes. */
    if ( event == vtkCommand::MouseWheelForwardEvent)
    {
        imageSlice->GetMapper()->UpdateInformation();
        imageSlice->GetMapper()->Modified();
        vtkPlane *plane = imageSlice->GetMapper()->GetSlicePlane();
        double *origin = plane->GetOrigin();
        plane->SetOrigin(origin[0], origin[1], origin[2] +
imageData->GetSpacing()[2]);
        plane->Modified();
        plane->Print(std::cout);
        imageSlice->GetMapper()->UpdateInformation();
        imageSlice->GetMapper()->Modified();
        imageSlice->Update();
        imageSlice->Modified();

        renderWindow->Render();
    }

/* In this part, we are trying to find the coordinate where user clicked. */
    if ( event == vtkCommand::StartWindowLevelEvent )
    {
        initialLevel = imageProperty->GetColorLevel();
        initialWindow = imageProperty->GetColorWindow();

        double intensity = 0.0;
        double *position, *spacing, *origin;
        int indices[3];

        int *click = iren->GetEventPosition();
        picker->Pick(click[0], click[1], 0.0, renderer);

        std::cout << "Z buffer is : " << renderer->GetZ(click[0], click[1])
<< std::endl; //here is the problem we mentioned above.

        vtkSmartPointer<vtkAssemblyPath> path = picker->GetPath();
        bool validPick = false;

        if ( path != NULL) {
            path->InitTraversal();
            vtkSmartPointer<vtkAssemblyNode> node =
vtkSmartPointer<vtkAssemblyNode>::New();
            for ( int i = 0; i < path->GetNumberOfItems() && !validPick;
i++) {
                node = path->GetNextNode();
                if ( imageSlice ==
vtkImageSlice::SafeDownCast(node->GetViewProp()))
                {
                    validPick = true;
                }
            }
        }

        if ( !validPick ) {
            interactorStyle->OnMouseMove();
            return;
        }

        position = picker->GetPickPosition();
        std::cout << "Pick position : " << position[0] << ", " <<
position[1] << ", " << position[2] << std::endl;
        spacing = imageData->GetSpacing();
        origin = imageData->GetOrigin();

        for (int i = 0; i <= 2; i++)
        {
            indices[i] = static_cast< int >(( position[i] - origin[i] ) /
spacing[i] + 0.5 );
        }

        std::cout << "Transformed coordinates : " << indices[0] << ", " <<
indices[1] << ", " << indices[2] << std::endl;


        intensity = imageData->GetScalarComponentAsDouble(indices[0],
indices[1], indices[2], 0);
        this->RefreshIntensity(indices[0], indices[1], indices[2],
intensity);        
    }


Best regards.



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPropPicker-pick-coordinate-problem-tp5722113.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list