AW: [vtkusers] vtkPointPicker sample/question/problem

de Boer Ingo I.deBoer at polytec.de
Thu Dec 11 06:13:26 EST 2003


This doesn't work either :(
Isn't there any 'correct' method/version or whatsoever
which works ?

greets
  Ingo

/////////////////////////////////
#include "vtkActor.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkPointPicker.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyDataMapper.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkShrinkFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkIdList.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"

#include <stdio.h>

static void PickCells(void *arg)
{
  vtkPointPicker *picker = (vtkPointPicker *)arg;
  cout << "Point id: " << picker->GetPointId() << "\n";
}

int main( int argc, char *argv[] )
{
  int i;
  static float x[8][3]={{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0},
                        {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1}};
  static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4},
                        {1,2,6,5}, {2,3,7,6}, {3,0,4,7}};
  
  // We'll create the building blocks of polydata including data attributes.
  vtkPolyData *cube = vtkPolyData::New();
  vtkPoints *points = vtkPoints::New();
  vtkCellArray *polys = vtkCellArray::New();
  vtkFloatArray *scalars = vtkFloatArray::New();

  // Load the point, cell, and data attributes.
  for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
  for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
  for (i=0; i<8; i++) scalars->InsertTuple1(i,i);

  // We now assign the pieces to the vtkPolyData.
  cube->SetPoints(points);
  points->Delete();
  cube->SetPolys(polys);
  polys->Delete();
  cube->GetPointData()->SetScalars(scalars);
  scalars->Delete();

  // Now we'll look at it.
  vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
      cubeMapper->SetInput(cube);
      cubeMapper->SetScalarRange(0,7);
  vtkActor *cubeActor = vtkActor::New();
      cubeActor->SetMapper(cubeMapper);

  // The usual rendering stuff.
  vtkCamera *camera = vtkCamera::New();
      camera->SetPosition(1,1,1);
      camera->SetFocalPoint(0,0,0);

  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);

  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

  renderer->AddActor(cubeActor);
      renderer->SetActiveCamera(camera);
      renderer->ResetCamera();
      renderer->SetBackground(1,1,1);
  
  renWin->SetSize(300,300);

  // start renderer
  renWin->Render();
  
  // init picker
  vtkPointPicker *picker = vtkPointPicker::New();
  picker->SetTolerance(0.01);
  iren->SetPicker(picker);

  // init callback
  picker->SetEndPickMethod(PickCells,(void *)picker);

  // start interaction
  iren->Start();

  // Clean up
  picker->Delete();
  cube->Delete();
  cubeMapper->Delete();
  cubeActor->Delete();
  camera->Delete();
  renderer->Delete();
  renWin->Delete();
  iren->Delete();

  return 0;
}




More information about the vtkusers mailing list