vtkPropPicker.cxx 3.22 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPropPicker.cxx

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14 15

=========================================================================*/
#include "vtkPropPicker.h"
16

Will Schroeder's avatar
Will Schroeder committed
17
#include "vtkAssemblyNode.h"
18
#include "vtkAssemblyPath.h"
19
#include "vtkCommand.h"
20 21 22
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkWorldPointPicker.h"
23

Ken Martin's avatar
Ken Martin committed
24
vtkCxxRevisionMacro(vtkPropPicker, "1.23");
Brad King's avatar
Brad King committed
25
vtkStandardNewMacro(vtkPropPicker);
26

Will Schroeder's avatar
Will Schroeder committed
27 28 29 30 31 32 33 34 35 36
vtkPropPicker::vtkPropPicker()
{
  this->PickFromProps = NULL;
  this->WorldPointPicker = vtkWorldPointPicker::New();
}

vtkPropPicker::~vtkPropPicker()
{
  this->WorldPointPicker->Delete();
}
37 38 39 40

// set up for a pick
void vtkPropPicker::Initialize()
{
41
  this->vtkAbstractPropPicker::Initialize();
42 43
}

Bill Hoffman's avatar
Bill Hoffman committed
44
// Pick from the given collection
Ken Martin's avatar
Ken Martin committed
45 46
int vtkPropPicker::Pick(double selectionX, double selectionY, 
                        double vtkNotUsed(z), vtkRenderer *renderer)
Bill Hoffman's avatar
Bill Hoffman committed
47 48 49 50
{
  return this->PickProp(selectionX, selectionY, renderer);
}

51 52

// Pick from the given collection
Ken Martin's avatar
Ken Martin committed
53
int vtkPropPicker::PickProp(double selectionX, double selectionY,
54
                            vtkRenderer *renderer, vtkPropCollection* pickfrom)
55 56
{
  this->PickFromProps = pickfrom;
Bill Hoffman's avatar
Bill Hoffman committed
57
  int ret = this->PickProp(selectionX, selectionY, renderer);
58 59 60 61 62 63 64 65
  this->PickFromProps = NULL;
  return ret;
}



// Perform pick operation with selection point provided. The z location
// is recovered from the zBuffer. Always returns 0 since no actors are picked.
Ken Martin's avatar
Ken Martin committed
66
int vtkPropPicker::PickProp(double selectionX, double selectionY, 
67
                            vtkRenderer *renderer)
68 69
{
  //  Initialize picking process
Will Schroeder's avatar
Will Schroeder committed
70
  this->Initialize();
71 72 73 74
  this->Renderer = renderer;
  this->SelectionPoint[0] = selectionX;
  this->SelectionPoint[1] = selectionY;
  this->SelectionPoint[2] = 0;
Will Schroeder's avatar
Will Schroeder committed
75 76

  // Invoke start pick method if defined
77
  this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
78 79

  // Have the renderer do the hardware pick
Will Schroeder's avatar
Will Schroeder committed
80 81
  this->SetPath(
    renderer->PickPropFrom(selectionX, selectionY, this->PickFromProps));
82

Will Schroeder's avatar
Will Schroeder committed
83 84 85
  // If there was a pick then find the world x,y,z for the pick, and invoke
  // its pick method.
  if ( this->Path )
86
    {
Will Schroeder's avatar
Will Schroeder committed
87
    this->WorldPointPicker->Pick(selectionX, selectionY, 0, renderer);
88
    this->WorldPointPicker->GetPickPosition(this->PickPosition);
Will Schroeder's avatar
Will Schroeder committed
89
    this->Path->GetLastNode()->GetProp()->Pick();
90
    this->InvokeEvent(vtkCommand::PickEvent,NULL);
91
    } 
92

93
  this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
94 95

  // Call Pick on the Prop that was picked, and return 1 for success
Will Schroeder's avatar
Will Schroeder committed
96
  if ( this->Path )
97 98 99
    {
    return 1;
    }
Will Schroeder's avatar
Will Schroeder committed
100 101 102 103
  else
    {
    return 0;
    }
104 105
}

106
void vtkPropPicker::PrintSelf(ostream& os, vtkIndent indent)
107
{
Will Schroeder's avatar
Will Schroeder committed
108 109
  this->vtkAbstractPropPicker::PrintSelf(os, indent);

110 111
  if (this->PickFromProps)
    {
112
    os << indent << "PickFrom List: " << this->PickFromProps << endl;
113 114 115
    }
  else
    {
116
    os << indent << "PickFrom List: (none)" << endl;
117
    }
Will Schroeder's avatar
Will Schroeder committed
118

119
}