[vtkusers] iren->Set*PickMethod() obsoleted?

Denis Shamonin dshamoni at science.uva.nl
Tue Apr 22 13:56:19 EDT 2003


Bruce.Lamond at ed.ac.uk wrote:

>Hi there,
>I'm trying to use VTK to return (x,y,z) coordinate corresponding to the cursor
>position when 'p' is pressed. I thought this might involve using the
>iren->Set*PickMethod() but see that this is not to be used in future. Does
>anyone know how I should go about getting the coordinate corresponding to a pick
>event?
>cheers
>Bruce Lamond
>  
>
Depend. If you will make pick operation you will get not a point (xyz) 
but vector.
This vector will start from XY on the X window which should be converted 
to world coordinats like
//---
float* YouClass::ComputeWorldCoordinate(float x,float y,float z)
{
  float *WorldCoordinate;
  vtkCoordinate *Coordinate = vtkCoordinate::New();
   Coordinate->SetCoordinateSystem(VTK_DISPLAY);
   Coordinate->SetValue(x,y,z);
   WorldCoordinate = Coordinate->GetComputedWorldValue(ren);
 
  return WorldCoordinate;
}

if you know XY on you X window use it like
//---
float *t;
t = this->ComputeWorldCoordinate((float)X1,(float)Y1,0.0);

Then end will be clipping rage of the camera->GetClippingRange(), or *inf*.
You can use this for calculate end point:
//---
void YouClass::EndPoint(float Point[3], float EndPoint[3])
{
  float cameraPos[4], cameraFP[4];
  float cameraDOP[3];
  float ray[3], rayLength;
  double *clipRange;
  float tF, tB;
  float p2World[4];
  int i;

  vtkCamera *camera = this->ren->GetActiveCamera();
  camera->GetPosition((float *)cameraPos); cameraPos[3] = 1.0;
  camera->GetFocalPoint((float *)cameraFP); cameraFP[3] = 1.0;  

  for (i=0; i<3; i++)
  {
   ray[i] = Point[i] - cameraPos[i];
  }
 
  for (i=0; i<3; i++)
  {
   cameraDOP[i] = cameraFP[i] - cameraPos[i];
  }
  
  vtkMath::Normalize(cameraDOP);
 
  if (( rayLength = vtkMath::Dot(cameraDOP,ray)) == 0.0 )
    {
     vtkErrorMacro(<< "Cannot process points");
    }

  clipRange = camera->GetClippingRange();

  if ( camera->GetParallelProjection() )
    {
    tF = clipRange[0] - rayLength;
    tB = clipRange[1] - rayLength;
    for (i=0; i<3; i++)
      {
       p2World[i] = Point[i] + tB*cameraDOP[i];
      }
    }
  else
    {
    tF = clipRange[0] / rayLength;
    tB = clipRange[1] / rayLength;
    for (i=0; i<3; i++)
      {
       p2World[i] = cameraPos[i] + tB*ray[i];
      }
    }

  p2World[3] = 1.0;
 
  for (i=0; i<3; i++)
  {
   EndPoint[i] = p2World[i];
  }
}

Then you can calculate vector. If you know how :)

-- 
Denis Shamonin
Address       : Section Computational Science
                University of Amsterdam
                Kruislaan 403, 1098 SJ Amsterdam
                the Netherlands

E-mail        : dshamoni at science.uva.nl
URL           : http://www.science.uva.nl/~dshamoni/






More information about the vtkusers mailing list