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 =========================================================================*/
61 #ifndef vtkHardwareSelector_h
62 #define vtkHardwareSelector_h
63 
64 #include "vtkRenderingCoreModule.h" // For export macro
65 #include "vtkObject.h"
66 
67 #include <string> // for std::string
68 
69 class vtkRenderer;
70 class vtkRenderWindow;
71 class vtkSelection;
72 class vtkProp;
73 class vtkTextureObject;
74 
75 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject
76 {
77 public:
79 
83  {
84  bool Valid;
85  int ProcessID;
86  int PropID;
88  unsigned int CompositeID;
91  Valid(false),
92  ProcessID(-1),
93  Prop(NULL),
94  CompositeID(0),
95  AttributeID(-1) {}
96  };
98 
99 public:
100  static vtkHardwareSelector* New();
102  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
103 
105 
108  virtual void SetRenderer(vtkRenderer*);
109  vtkGetObjectMacro(Renderer, vtkRenderer);
111 
113 
116  vtkSetVector4Macro(Area, unsigned int);
117  vtkGetVector4Macro(Area, unsigned int);
119 
121 
131  vtkSetMacro(FieldAssociation, int);
132  vtkGetMacro(FieldAssociation, int);
134 
136 
141  vtkSetMacro(UseProcessIdFromData, bool);
142  vtkGetMacro(UseProcessIdFromData, bool);
144 
149  vtkSelection* Select();
150 
152 
165  virtual bool CaptureBuffers();
166  PixelInformation GetPixelInformation(const unsigned int display_position[2])
167  { return this->GetPixelInformation(display_position, 0); }
168  PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
169  { unsigned int temp[2]; return this->GetPixelInformation(display_position, maxDist, temp); }
170  PixelInformation GetPixelInformation(const unsigned int display_position[2],
171  int maxDist, unsigned int selected_position[2]);
173  { this->ReleasePixBuffers(); }
175 
180  virtual void RenderCompositeIndex(unsigned int index);
181 
185  virtual void RenderAttributeId(vtkIdType attribid);
186 
191  virtual void RenderProcessId(unsigned int processid);
192 
197  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
198 
200 
204  virtual void BeginRenderProp();
205  virtual void EndRenderProp();
207 
209 
213  vtkSetMacro(ProcessID, int);
214  vtkGetMacro(ProcessID, int);
216 
218 
221  vtkGetVector3Macro(PropColorValue,float);
222  vtkSetVector3Macro(PropColorValue,float);
224 
226 
229  vtkGetMacro(CurrentPass, int);
231 
241  { return GenerateSelection(this->Area); }
242  virtual vtkSelection* GenerateSelection(unsigned int r[4])
243  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
244  virtual vtkSelection* GenerateSelection(
245  unsigned int x1, unsigned int y1,
246  unsigned int x2, unsigned int y2);
247 
254  virtual vtkSelection* GeneratePolygonSelection(
255  int* polygonPoints, vtkIdType count);
256 
261  vtkProp* GetPropFromID(int id);
262 
264  {
271  MAX_KNOWN_PASS = ID_HIGH16,
272  MIN_KNOWN_PASS = PROCESS_PASS
273  };
274 
278  std::string PassTypeToString(PassTypes type);
279 
280  static void Convert(int id, float tcoord[3])
281  {
282  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
283  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
284  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
285  }
286 
287 protected:
289  ~vtkHardwareSelector() VTK_OVERRIDE;
290 
291  // Used to notify subclasses when a capture pass is occurring.
292  virtual void PreCapturePass(int pass) { (void)pass; }
293  virtual void PostCapturePass(int pass) { (void)pass; }
294 
295  // Called internally before and after each prop is rendered
296  // for device specific configuration/preparation etc.
297  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
298  virtual void EndRenderProp(vtkRenderWindow *) = 0;
299 
300  int Convert(unsigned long offset, unsigned char* pb)
301  {
302  if (!pb)
303  {
304  return 0;
305  }
306  offset = offset * 3;
307  unsigned char rgb[3];
308  rgb[0] = pb[offset];
309  rgb[1] = pb[offset+1];
310  rgb[2] = pb[offset+2];
311  int val = 0;
312  val |= rgb[2];
313  val = val << 8;
314  val |= rgb[1];
315  val = val << 8;
316  val |= rgb[0];
317  return val;
318  }
319 
321 
324  int Convert(unsigned int pos[2], unsigned char* pb)
325  { return this->Convert(pos[0], pos[1], pb); }
326  int Convert(int xx, int yy, unsigned char* pb)
327  {
328  if (!pb)
329  {
330  return 0;
331  }
332  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
333  unsigned char rgb[3];
334  rgb[0] = pb[offset];
335  rgb[1] = pb[offset+1];
336  rgb[2] = pb[offset+2];
337  int val = 0;
338  val |= rgb[2];
339  val = val << 8;
340  val |= rgb[1];
341  val = val << 8;
342  val |= rgb[0];
343  return val;
344  }
346 
347  vtkIdType GetID(int low24, int mid24, int high16)
348  {
349  vtkIdType val = 0;
350  val |= high16;
351  val = val << 24;
352  val |= mid24;
353  val = val << 24;
354  val |= low24;
355  return val;
356  }
357 
361  virtual bool PassRequired(int pass);
362 
368  bool IsPropHit(int propid);
369 
373  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
374  { return idx; }
375 
376  virtual void BeginSelection();
377  virtual void EndSelection();
378 
379  virtual void SavePixelBuffer(int passNo);
380  void BuildPropHitList(unsigned char* rgbData);
381 
383 
386  void ReleasePixBuffers();
388  unsigned int Area[4];
393 
394  // At most 10 passes.
395  unsigned char* PixBuffer[10];
399  int PropID;
400  float PropColorValue[3];
401 
402 private:
403  vtkHardwareSelector(const vtkHardwareSelector&) VTK_DELETE_FUNCTION;
404  void operator=(const vtkHardwareSelector&) VTK_DELETE_FUNCTION;
405 
406  class vtkInternals;
407  vtkInternals* Internals;
408 
409 };
410 
411 #endif
412 
413 
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:44
virtual void PostCapturePass(int pass)
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Struct used to return information about a pixel location.
vtkIdType MaxAttributeId
Clears all pixel buffers.
PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
It is possible to use the vtkHardwareSelector for a custom picking.
abstract specification for renderers
Definition: vtkRenderer.h:57
virtual vtkSelection * GenerateSelection(unsigned int r[4])
A node in a selection tree.
Definition: vtkSelection.h:37
int vtkIdType
Definition: vtkType.h:345
bool UseProcessIdFromData
Clears all pixel buffers.
int FieldAssociation
Clears all pixel buffers.
a simple class to control print indentation
Definition: vtkIndent.h:33
virtual int GetPropID(int idx, vtkProp *vtkNotUsed(prop))
Return a unique ID for the prop.
static void Convert(int id, float tcoord[3])
void ClearBuffers()
It is possible to use the vtkHardwareSelector for a custom picking.
int Convert(int xx, int yy, unsigned char *pb)
pos must be relative to the lower-left corner of this-&gt;Area.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstracts an OpenGL texture object.
vtkIdType GetID(int low24, int mid24, int high16)
create a window for renderers to draw into
vtkRenderer * Renderer
Clears all pixel buffers.
PixelInformation GetPixelInformation(const unsigned int display_position[2])
It is possible to use the vtkHardwareSelector for a custom picking.
virtual vtkSelection * GenerateSelection()
Generates the vtkSelection from pixel buffers.
manager for OpenGL-based selection.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
int Convert(unsigned long offset, unsigned char *pb)
int Convert(unsigned int pos[2], unsigned char *pb)
pos must be relative to the lower-left corner of this-&gt;Area.
VTKACCELERATORSVTKM_EXPORT vtkm::cont::Field Convert(vtkDataArray *input, int association)