1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkPicker.h,v $
6 Date: $Date: 2002/08/26 02:31:16 $
7 Version: $Revision: 1.48 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkPicker - superclass for 3D geometric pickers (uses ray cast)
19 // .SECTION Description
20 // vtkPicker is used to select instances of vtkProp3D by shooting a ray
21 // into a graphics window and intersecting with the actor's bounding box.
22 // The ray is defined from a point defined in window (or pixel) coordinates,
23 // and a point located from the camera's position.
25 // vtkPicker may return more than one vtkProp3D, since more than one bounding
26 // box may be intersected. vtkPicker returns the list of props that were hit,
27 // the pick coordinates in world and untransformed mapper space, and the
28 // prop (vtkProp3D) and mapper that are "closest" to the camera. The closest
29 // prop is the one whose center point (i.e., center of bounding box)
30 // projected on the ray is closest to the camera.
33 // vtkPicker is used for quick geometric picking. If you desire to pick
34 // points or cells, use the subclass vtkPointPicker or vtkCellPicker,
35 // respectively. Or you may use hardware picking to pick any type of vtkProp
36 // - see vtkPropPicker or vtkWorldPointPicker.
41 #include "vtkAbstractPropPicker.h"
43 class vtkAbstractMapper3D;
46 class vtkActorCollection;
47 class vtkProp3DCollection;
50 class VTK_RENDERING_EXPORT vtkPicker : public vtkAbstractPropPicker
53 static vtkPicker *New();
54 vtkTypeRevisionMacro(vtkPicker,vtkAbstractPropPicker);
55 void PrintSelf(ostream& os, vtkIndent indent);
58 // Specify tolerance for performing pick operation. Tolerance is specified
59 // as fraction of rendering window size. (Rendering window size is measured
61 vtkSetMacro(Tolerance,float);
62 vtkGetMacro(Tolerance,float);
65 // Return position in mapper (i.e., non-transformed) coordinates of
67 vtkGetVectorMacro(MapperPosition,float,3);
70 // Return mapper that was picked (if any).
71 vtkGetObjectMacro(Mapper,vtkAbstractMapper3D);
74 // Get a pointer to the dataset that was picked (if any). If nothing
75 // was picked then NULL is returned.
76 vtkGetObjectMacro(DataSet,vtkDataSet);
79 // Return a collection of all the prop 3D's that were intersected
80 // by the pick ray. This collection is not sorted.
81 vtkProp3DCollection *GetProp3Ds() {return this->Prop3Ds;};
84 // Return a collection of all the actors that were intersected.
85 // This collection is not sorted. (This is a convenience method
86 // to maintain backward compatibility.)
87 vtkActorCollection *GetActors();
90 // Return a list of the points the the actors returned by GetActors
91 // were intersected at. The order of this list will match the order of
93 vtkPoints *GetPickedPositions() {return this->PickedPositions;};
96 // Perform pick operation with selection point provided. Normally the
97 // first two values for the selection point are x-y pixel coordinate, and
98 // the third value is =0. Return non-zero if something was successfully
100 virtual int Pick(float selectionX, float selectionY, float selectionZ,
101 vtkRenderer *renderer);
104 // Perform pick operation with selection point provided. Normally the first
105 // two values for the selection point are x-y pixel coordinate, and the
106 // third value is =0. Return non-zero if something was successfully picked.
107 int Pick(float selectionPt[3], vtkRenderer *ren)
108 {return this->Pick(selectionPt[0], selectionPt[1], selectionPt[2], ren);};
114 void MarkPicked(vtkAssemblyPath *path, vtkProp3D *p, vtkAbstractMapper3D *m,
115 float tMin, float mapperPos[3]);
116 virtual float IntersectWithLine(float p1[3], float p2[3], float tol,
117 vtkAssemblyPath *path, vtkProp3D *p,
118 vtkAbstractMapper3D *m);
119 virtual void Initialize();
121 float Tolerance; //tolerance for computation (% of window)
122 float MapperPosition[3]; //selection point in untransformed coordinates
124 vtkAbstractMapper3D *Mapper; //selected mapper (if the prop has a mapper)
125 vtkDataSet *DataSet; //selected dataset (if there is one)
127 float GlobalTMin; //parametric coordinate along pick ray where hit occured
128 vtkTransform *Transform; //use to perform ray transformation
129 vtkActorCollection *Actors; //candidate actors (based on bounding box)
130 vtkProp3DCollection *Prop3Ds; //candidate actors (based on bounding box)
131 vtkPoints *PickedPositions; // candidate positions
134 vtkPicker(const vtkPicker&); // Not implemented.
135 void operator=(const vtkPicker&); // Not implemented.