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  PropID(-1),
97  Prop(nullptr),
98  CompositeID(0),
99  AttributeID(-1) {}
100  };
102 
103 public:
104  static vtkHardwareSelector* New();
106  void PrintSelf(ostream& os, vtkIndent indent) override;
107 
109 
112  virtual void SetRenderer(vtkRenderer*);
113  vtkGetObjectMacro(Renderer, vtkRenderer);
115 
117 
120  vtkSetVector4Macro(Area, unsigned int);
121  vtkGetVector4Macro(Area, unsigned int);
123 
125 
135  vtkSetMacro(FieldAssociation, int);
136  vtkGetMacro(FieldAssociation, int);
138 
140 
145  vtkSetMacro(UseProcessIdFromData, bool);
146  vtkGetMacro(UseProcessIdFromData, bool);
148 
153  vtkSelection* Select();
154 
156 
169  virtual bool CaptureBuffers();
170  PixelInformation GetPixelInformation(const unsigned int display_position[2])
171  { return this->GetPixelInformation(display_position, 0); }
172  PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
173  { unsigned int temp[2]; return this->GetPixelInformation(display_position, maxDist, temp); }
174  PixelInformation GetPixelInformation(const unsigned int display_position[2],
175  int maxDist, unsigned int selected_position[2]);
177  { this->ReleasePixBuffers(); }
179 
184  virtual void RenderCompositeIndex(unsigned int index);
185 
189  virtual void RenderAttributeId(vtkIdType attribid);
190 
195  virtual void RenderProcessId(unsigned int processid);
196 
201  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
202 
204 
208  virtual void BeginRenderProp();
209  virtual void EndRenderProp();
211 
213 
217  vtkSetMacro(ProcessID, int);
218  vtkGetMacro(ProcessID, int);
220 
222 
225  vtkGetVector3Macro(PropColorValue,float);
226  vtkSetVector3Macro(PropColorValue,float);
228 
230 
233  vtkGetMacro(CurrentPass, int);
235 
245  { return GenerateSelection(this->Area); }
246  virtual vtkSelection* GenerateSelection(unsigned int r[4])
247  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
248  virtual vtkSelection* GenerateSelection(
249  unsigned int x1, unsigned int y1,
250  unsigned int x2, unsigned int y2);
251 
258  virtual vtkSelection* GeneratePolygonSelection(
259  int* polygonPoints, vtkIdType count);
260 
265  vtkProp* GetPropFromID(int id);
266 
268  {
275  MAX_KNOWN_PASS = ID_HIGH16,
276  MIN_KNOWN_PASS = PROCESS_PASS
277  };
278 
282  std::string PassTypeToString(PassTypes type);
283 
284  static void Convert(int id, float tcoord[3])
285  {
286  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
287  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
288  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
289  }
290 
291 protected:
293  ~vtkHardwareSelector() override;
294 
295  // Used to notify subclasses when a capture pass is occurring.
296  virtual void PreCapturePass(int pass) { (void)pass; }
297  virtual void PostCapturePass(int pass) { (void)pass; }
298 
299  // Called internally before and after each prop is rendered
300  // for device specific configuration/preparation etc.
301  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
302  virtual void EndRenderProp(vtkRenderWindow *) = 0;
303 
304  int Convert(unsigned long offset, unsigned char* pb)
305  {
306  if (!pb)
307  {
308  return 0;
309  }
310  offset = offset * 3;
311  unsigned char rgb[3];
312  rgb[0] = pb[offset];
313  rgb[1] = pb[offset+1];
314  rgb[2] = pb[offset+2];
315  int val = 0;
316  val |= rgb[2];
317  val = val << 8;
318  val |= rgb[1];
319  val = val << 8;
320  val |= rgb[0];
321  return val;
322  }
323 
325 
328  int Convert(unsigned int pos[2], unsigned char* pb)
329  { return this->Convert(pos[0], pos[1], pb); }
330  int Convert(int xx, int yy, unsigned char* pb)
331  {
332  if (!pb)
333  {
334  return 0;
335  }
336  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
337  unsigned char rgb[3];
338  rgb[0] = pb[offset];
339  rgb[1] = pb[offset+1];
340  rgb[2] = pb[offset+2];
341  int val = 0;
342  val |= rgb[2];
343  val = val << 8;
344  val |= rgb[1];
345  val = val << 8;
346  val |= rgb[0];
347  return val;
348  }
350 
351  vtkIdType GetID(int low24, int mid24, int high16)
352  {
353  vtkIdType val = 0;
354  val |= high16;
355  val = val << 24;
356  val |= mid24;
357  val = val << 24;
358  val |= low24;
359  return val;
360  }
361 
365  virtual bool PassRequired(int pass);
366 
372  bool IsPropHit(int propid);
373 
377  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
378  { return idx; }
379 
380  virtual void BeginSelection();
381  virtual void EndSelection();
382 
383  virtual void SavePixelBuffer(int passNo);
384  void BuildPropHitList(unsigned char* rgbData);
385 
387 
390  void ReleasePixBuffers();
392  unsigned int Area[4];
397 
398  // At most 10 passes.
399  unsigned char* PixBuffer[10];
403  int PropID;
404  float PropColorValue[3];
405 
406 private:
407  vtkHardwareSelector(const vtkHardwareSelector&) = delete;
408  void operator=(const vtkHardwareSelector&) = delete;
409 
410  class vtkInternals;
411  vtkInternals* Internals;
412 
413 };
414 
415 #endif
416 
417 
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
virtual void PostCapturePass(int pass)
abstract base class for most VTK objects
Definition: vtkObject.h:59
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.
virtual void PreCapturePass(int pass)
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:63
virtual vtkSelection * GenerateSelection(unsigned int r[4])
A node in a selection tree.
Definition: vtkSelection.h:43
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:39
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->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->Area.
VTKACCELERATORSVTKM_EXPORT vtkm::cont::Field Convert(vtkDataArray *input, int association)