VTK
vtkHardwareSelector.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkHardwareSelector.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
64 #ifndef vtkHardwareSelector_h
65 #define vtkHardwareSelector_h
66 
67 #include "vtkRenderingCoreModule.h" // For export macro
68 #include "vtkObject.h"
69 
70 #include <string> // for std::string
71 
72 class vtkRenderer;
73 class vtkRenderWindow;
74 class vtkSelection;
75 class vtkProp;
76 class vtkTextureObject;
77 
78 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject
79 {
80 public:
82 
86  {
87  bool Valid;
88  int ProcessID;
89  int PropID;
91  unsigned int CompositeID;
94  Valid(false),
95  ProcessID(-1),
96  Prop(NULL),
97  CompositeID(0),
98  AttributeID(-1) {}
99  };
101 
102 public:
105  void PrintSelf(ostream& os, vtkIndent indent);
106 
108 
111  virtual void SetRenderer(vtkRenderer*);
112  vtkGetObjectMacro(Renderer, vtkRenderer);
114 
116 
119  vtkSetVector4Macro(Area, unsigned int);
120  vtkGetVector4Macro(Area, unsigned int);
122 
124 
134  vtkSetMacro(FieldAssociation, int);
135  vtkGetMacro(FieldAssociation, int);
137 
139 
144  vtkSetMacro(UseProcessIdFromData, bool);
145  vtkGetMacro(UseProcessIdFromData, bool);
147 
153 
155 
168  virtual bool CaptureBuffers();
169  PixelInformation GetPixelInformation(const unsigned int display_position[2])
170  { return this->GetPixelInformation(display_position, 0); }
171  PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
172  { unsigned int temp[2]; return this->GetPixelInformation(display_position, maxDist, temp); }
173  PixelInformation GetPixelInformation(const unsigned int display_position[2],
174  int maxDist, unsigned int selected_position[2]);
176  { this->ReleasePixBuffers(); }
178 
183  virtual void RenderCompositeIndex(unsigned int index);
184 
188  virtual void RenderAttributeId(vtkIdType attribid);
189 
194  virtual void RenderProcessId(unsigned int processid);
195 
200  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
201 
203 
207  virtual void BeginRenderProp();
208  virtual void EndRenderProp();
210 
212 
216  vtkSetMacro(ProcessID, int);
217  vtkGetMacro(ProcessID, int);
219 
221 
224  vtkGetVector3Macro(PropColorValue,float);
225  vtkSetVector3Macro(PropColorValue,float);
227 
229 
232  vtkGetMacro(CurrentPass, int);
234 
244  { return GenerateSelection(this->Area); }
245  virtual vtkSelection* GenerateSelection(unsigned int r[4])
246  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
248  unsigned int x1, unsigned int y1,
249  unsigned int x2, unsigned int y2);
250 
258  int* polygonPoints, vtkIdType count);
259 
265 
267  {
274  MAX_KNOWN_PASS = ID_HIGH16,
275  MIN_KNOWN_PASS = PROCESS_PASS
276  };
277 
282 
283  static void Convert(int id, float tcoord[3])
284  {
285  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
286  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
287  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
288  }
289 
290 protected:
293 
294  // Used to notify subclasses when a capture pass is occuring.
295  virtual void PreCapturePass(int pass) { (void)pass; }
296  virtual void PostCapturePass(int pass) { (void)pass; }
297 
298  // Called internally before and after each prop is rendered
299  // for device specific configuration/preparation etc.
300  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
301  virtual void EndRenderProp(vtkRenderWindow *) = 0;
302 
303  int Convert(unsigned long offset, unsigned char* pb)
304  {
305  if (!pb)
306  {
307  return 0;
308  }
309  offset = offset * 3;
310  unsigned char rgb[3];
311  rgb[0] = pb[offset];
312  rgb[1] = pb[offset+1];
313  rgb[2] = pb[offset+2];
314  int val = 0;
315  val |= rgb[2];
316  val = val << 8;
317  val |= rgb[1];
318  val = val << 8;
319  val |= rgb[0];
320  return val;
321  }
322 
324 
327  int Convert(unsigned int pos[2], unsigned char* pb)
328  { return this->Convert(pos[0], pos[1], pb); }
329  int Convert(int xx, int yy, unsigned char* pb)
330  {
331  if (!pb)
332  {
333  return 0;
334  }
335  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
336  unsigned char rgb[3];
337  rgb[0] = pb[offset];
338  rgb[1] = pb[offset+1];
339  rgb[2] = pb[offset+2];
340  int val = 0;
341  val |= rgb[2];
342  val = val << 8;
343  val |= rgb[1];
344  val = val << 8;
345  val |= rgb[0];
346  return val;
347  }
349 
350  vtkIdType GetID(int low24, int mid24, int high16)
351  {
352  vtkIdType val = 0;
353  val |= high16;
354  val = val << 24;
355  val |= mid24;
356  val = val << 24;
357  val |= low24;
358  return val;
359  }
360 
364  virtual bool PassRequired(int pass);
365 
371  bool IsPropHit(int propid);
372 
376  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
377  { return idx; }
378 
379  virtual void BeginSelection();
380  virtual void EndSelection();
381 
382  virtual void SavePixelBuffer(int passNo);
383  void BuildPropHitList(unsigned char* rgbData);
384 
386 
391  unsigned int Area[4];
396 
397  // At most 10 passes.
398  unsigned char* PixBuffer[10];
402  int PropID;
403  float PropColorValue[3];
404 
405 private:
406  vtkHardwareSelector(const vtkHardwareSelector&) VTK_DELETE_FUNCTION;
407  void operator=(const vtkHardwareSelector&) VTK_DELETE_FUNCTION;
408 
409  class vtkInternals;
410  vtkInternals* Internals;
411 
412 };
413 
414 #endif
415 
416 
vtkHardwareSelector::PixelInformation::Valid
bool Valid
Definition: vtkHardwareSelector.h:87
vtkHardwareSelector::GetPropFromID
vtkProp * GetPropFromID(int id)
returns the prop associated with a ID.
vtkHardwareSelector::IsPropHit
bool IsPropHit(int propid)
After the ACTOR_PASS this return true or false depending upon whether the prop was hit in the ACTOR_P...
vtkHardwareSelector::Convert
int Convert(unsigned long offset, unsigned char *pb)
Definition: vtkHardwareSelector.h:303
vtkHardwareSelector::Convert
int Convert(unsigned int pos[2], unsigned char *pb)
pos must be relative to the lower-left corner of this->Area.
Definition: vtkHardwareSelector.h:327
vtkHardwareSelector::PixelInformation::Prop
vtkProp * Prop
Definition: vtkHardwareSelector.h:90
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkHardwareSelector::ID_LOW24
@ ID_LOW24
Definition: vtkHardwareSelector.h:271
vtkIdType
int vtkIdType
Definition: vtkType.h:287
vtkHardwareSelector::PROCESS_PASS
@ PROCESS_PASS
Definition: vtkHardwareSelector.h:268
vtkHardwareSelector::New
static vtkHardwareSelector * New()
vtkHardwareSelector::CurrentPass
int CurrentPass
Definition: vtkHardwareSelector.h:400
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkHardwareSelector::ProcessID
int ProcessID
Definition: vtkHardwareSelector.h:399
vtkHardwareSelector::RenderCompositeIndex
virtual void RenderCompositeIndex(unsigned int index)
Called by any vtkMapper or vtkProp subclass to render a composite-index.
vtkHardwareSelector::PassRequired
virtual bool PassRequired(int pass)
Returns is the pass indicated is needed.
vtkHardwareSelector::GetPropID
virtual int GetPropID(int idx, vtkProp *vtkNotUsed(prop))
Return a unique ID for the prop.
Definition: vtkHardwareSelector.h:376
vtkHardwareSelector::ID_MID24
@ ID_MID24
Definition: vtkHardwareSelector.h:272
vtkHardwareSelector::GenerateSelection
virtual vtkSelection * GenerateSelection(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
vtkSelection
A node in a selection tree.
Definition: vtkSelection.h:44
vtkHardwareSelector::GenerateSelection
virtual vtkSelection * GenerateSelection()
Generates the vtkSelection from pixel buffers.
Definition: vtkHardwareSelector.h:243
vtkHardwareSelector::PassTypes
PassTypes
Definition: vtkHardwareSelector.h:267
vtkHardwareSelector::ACTOR_PASS
@ ACTOR_PASS
Definition: vtkHardwareSelector.h:269
vtkHardwareSelector::FieldAssociation
int FieldAssociation
Definition: vtkHardwareSelector.h:392
vtkHardwareSelector::CaptureBuffers
virtual bool CaptureBuffers()
It is possible to use the vtkHardwareSelector for a custom picking.
vtkHardwareSelector::EndRenderProp
virtual void EndRenderProp()
vtkHardwareSelector::Select
vtkSelection * Select()
Perform the selection.
vtkHardwareSelector::BeginRenderProp
virtual void BeginRenderProp()
Called by the mapper (vtkHardwareSelectionPolyDataPainter) before and after rendering each prop.
vtkHardwareSelector::PassTypeToString
std::string PassTypeToString(PassTypes type)
Convert a PassTypes enum value to a human readable string.
vtkHardwareSelector::~vtkHardwareSelector
~vtkHardwareSelector()
vtkHardwareSelector::ReleasePixBuffers
void ReleasePixBuffers()
Clears all pixel buffers.
vtkHardwareSelector::Renderer
vtkRenderer * Renderer
Definition: vtkHardwareSelector.h:390
vtkHardwareSelector::PixelInformation::PixelInformation
PixelInformation()
Definition: vtkHardwareSelector.h:93
vtkX3D::offset
@ offset
Definition: vtkX3D.h:438
vtkHardwareSelector::GetPixelInformation
PixelInformation GetPixelInformation(const unsigned int display_position[2])
Definition: vtkHardwareSelector.h:169
vtkHardwareSelector::BuildPropHitList
void BuildPropHitList(unsigned char *rgbData)
vtkHardwareSelector::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkHardwareSelector::GeneratePolygonSelection
virtual vtkSelection * GeneratePolygonSelection(int *polygonPoints, vtkIdType count)
Generates the vtkSelection from pixel buffers.
vtkHardwareSelector
manager for OpenGL-based selection.
Definition: vtkHardwareSelector.h:79
vtkHardwareSelector::PixelInformation::AttributeID
vtkIdType AttributeID
Definition: vtkHardwareSelector.h:92
vtkHardwareSelector::GetPixelInformation
PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist, unsigned int selected_position[2])
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:41
vtkHardwareSelector::GenerateSelection
virtual vtkSelection * GenerateSelection(unsigned int r[4])
Definition: vtkHardwareSelector.h:245
vtkHardwareSelector::PropID
int PropID
Definition: vtkHardwareSelector.h:402
vtkHardwareSelector::EndRenderProp
virtual void EndRenderProp(vtkRenderWindow *)=0
vtkHardwareSelector::ID_HIGH16
@ ID_HIGH16
Definition: vtkHardwareSelector.h:273
vtkHardwareSelector::GetID
vtkIdType GetID(int low24, int mid24, int high16)
Definition: vtkHardwareSelector.h:350
vtkHardwareSelector::COMPOSITE_INDEX_PASS
@ COMPOSITE_INDEX_PASS
Definition: vtkHardwareSelector.h:270
vtkHardwareSelector::Render
int Render(vtkRenderer *renderer, vtkProp **propArray, int propArrayCount)
Called by vtkRenderer to render the selection pass.
vtkHardwareSelector::PreCapturePass
virtual void PreCapturePass(int pass)
Definition: vtkHardwareSelector.h:295
vtkObject.h
vtkHardwareSelector::vtkHardwareSelector
vtkHardwareSelector()
vtkHardwareSelector::Convert
static void Convert(int id, float tcoord[3])
Definition: vtkHardwareSelector.h:283
vtkHardwareSelector::PixelInformation::PropID
int PropID
Definition: vtkHardwareSelector.h:89
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:48
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkHardwareSelector::Convert
int Convert(int xx, int yy, unsigned char *pb)
Definition: vtkHardwareSelector.h:329
vtkHardwareSelector::SavePixelBuffer
virtual void SavePixelBuffer(int passNo)
vtkHardwareSelector::SetRenderer
virtual void SetRenderer(vtkRenderer *)
Get/Set the renderer to perform the selection on.
vtkHardwareSelector::InPropRender
int InPropRender
Definition: vtkHardwareSelector.h:401
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:64
vtkHardwareSelector::RenderAttributeId
virtual void RenderAttributeId(vtkIdType attribid)
Called by any vtkMapper or vtkProp subclass to render an attribute's id.
vtkHardwareSelector::UseProcessIdFromData
bool UseProcessIdFromData
Definition: vtkHardwareSelector.h:393
vtkHardwareSelector::PixelInformation::ProcessID
int ProcessID
Definition: vtkHardwareSelector.h:88
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:87
vtkHardwareSelector::PixelInformation::CompositeID
unsigned int CompositeID
Definition: vtkHardwareSelector.h:91
vtkHardwareSelector::BeginRenderProp
virtual void BeginRenderProp(vtkRenderWindow *)=0
vtkHardwareSelector::ClearBuffers
void ClearBuffers()
Definition: vtkHardwareSelector.h:175
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkHardwareSelector::MaxAttributeId
vtkIdType MaxAttributeId
Definition: vtkHardwareSelector.h:394
vtkHardwareSelector::RenderProcessId
virtual void RenderProcessId(unsigned int processid)
Called by any vtkMapper or subclass to render process id.
vtkHardwareSelector::EndSelection
virtual void EndSelection()
vtkHardwareSelector::PixelInformation
Struct used to return information about a pixel location.
Definition: vtkHardwareSelector.h:86
vtkHardwareSelector::GetPixelInformation
PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
Definition: vtkHardwareSelector.h:171
vtkHardwareSelector::PostCapturePass
virtual void PostCapturePass(int pass)
Definition: vtkHardwareSelector.h:296
vtkHardwareSelector::BeginSelection
virtual void BeginSelection()