[vtkusers] Getting point value on picking besides the coordinates
abhinay
abhinaynagpal at gmail.com
Sat Nov 20 21:49:05 EST 2010
HI
I have a vtkwidget which i am using to show k means clustering in 3d , I am
stuck with getting the value of the point which was clicked I am just able
to get the value of the pixel. Here is what I do
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint ( 0.0, 0.0, 0.0 );
points->InsertNextPoint ( 3.0, 3.0, 3.0 );
points->InsertNextPoint ( 0.1, 0.1, 0.1 );
.
.
//get the points into the format needed for KMeans
vtkSmartPointer<vtkTable> inputData =
vtkSmartPointer<vtkTable>::New();
//display
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(polydata->GetProducerPort());
glyphFilter->Update();
//Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(glyphFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetPointSize(3);
//Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
vtkSmartPointer<MouseInteractorStylePP> style =
vtkSmartPointer<MouseInteractorStylePP>::New();
renderWindowInteractor->SetInteractorStyle( style );
Now in the mouse interactor I have the following :
class MouseInteractorStylePP : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStylePP* New();
vtkTypeMacro(MouseInteractorStylePP, vtkInteractorStyleTrackballCamera);
MouseInteractorStylePP()
{
this->SelectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
this->SelectedActor = vtkSmartPointer<vtkActor>::New();
this->SelectedActor->SetMapper(SelectedMapper);
}
virtual void OnLeftButtonDown()
{
std::cout << "Picking pixel: " <<
this->Interactor->GetEventPosition()[0] << " " <<
this->Interactor->GetEventPosition()[1]<< " " <<
this->Interactor->GetEventPosition()[2] << std::endl;
this->Interactor->GetPicker()->Pick(this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1],
this->Interactor->GetEventPosition()[2], // always
zero.
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
double picked[3],data;
this->Interactor->GetPicker()->GetPickPosition(picked);
std::cout << "Picked value: " << picked[0] << " " << picked[1] << " "
<< picked[2] << std::endl;
how do i get the polydata value associated with this pixel at the time
of the click?
====
Am i supposed to do something like th following? (and how?)
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(extractGeometry->GetOutputPort());
glyphFilter->Update();
vtkPolyData* selected = glyphFilter->GetOutput();
std::cout << "Selected " << selected->GetNumberOfPoints() << "
points." << std::endl;
std::cout << "Selected " << selected->GetNumberOfCells() << "
cells." << std::endl;
this->SelectedMapper->SetInput(selected);
Please advise
Thanks and best regards
abhinay
--
View this message in context: http://vtk.1045678.n5.nabble.com/Getting-point-value-on-picking-besides-the-coordinates-tp3274056p3274056.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list