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 =========================================================================*/
53 #ifndef vtkHardwareSelector_h
54 #define vtkHardwareSelector_h
55 
56 #include "vtkRenderingCoreModule.h" // For export macro
57 #include "vtkObject.h"
58 
59 #include <string> // for std::string
60 
61 class vtkRenderer;
62 class vtkRenderWindow;
63 class vtkSelection;
64 class vtkProp;
65 class vtkTextureObject;
66 
67 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject
68 {
69 public:
71 
75  {
76  bool Valid;
77  int ProcessID;
78  int PropID;
80  unsigned int CompositeID;
83  Valid(false),
84  ProcessID(-1),
85  PropID(-1),
86  Prop(nullptr),
87  CompositeID(0),
88  AttributeID(-1) {}
89  };
91 
92 public:
93  static vtkHardwareSelector* New();
95  void PrintSelf(ostream& os, vtkIndent indent) override;
96 
98 
101  virtual void SetRenderer(vtkRenderer*);
102  vtkGetObjectMacro(Renderer, vtkRenderer);
104 
106 
109  vtkSetVector4Macro(Area, unsigned int);
110  vtkGetVector4Macro(Area, unsigned int);
112 
114 
124  vtkSetMacro(FieldAssociation, int);
125  vtkGetMacro(FieldAssociation, int);
127 
129 
134  vtkSetMacro(UseProcessIdFromData, bool);
135  vtkGetMacro(UseProcessIdFromData, bool);
137 
142  vtkSelection* Select();
143 
145 
158  virtual bool CaptureBuffers();
159  PixelInformation GetPixelInformation(const unsigned int display_position[2])
160  { return this->GetPixelInformation(display_position, 0); }
161  PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
162  { unsigned int temp[2]; return this->GetPixelInformation(display_position, maxDist, temp); }
163  PixelInformation GetPixelInformation(const unsigned int display_position[2],
164  int maxDist, unsigned int selected_position[2]);
166  { this->ReleasePixBuffers(); }
168 
173  virtual void RenderCompositeIndex(unsigned int index);
174 
178  virtual void RenderAttributeId(vtkIdType attribid);
179 
184  virtual void RenderProcessId(unsigned int processid);
185 
190  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
191 
193 
197  virtual void BeginRenderProp();
198  virtual void EndRenderProp();
200 
202 
206  vtkSetMacro(ProcessID, int);
207  vtkGetMacro(ProcessID, int);
209 
211 
214  vtkGetVector3Macro(PropColorValue,float);
215  vtkSetVector3Macro(PropColorValue,float);
217 
219 
222  vtkGetMacro(CurrentPass, int);
224 
234  { return GenerateSelection(this->Area); }
235  virtual vtkSelection* GenerateSelection(unsigned int r[4])
236  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
237  virtual vtkSelection* GenerateSelection(
238  unsigned int x1, unsigned int y1,
239  unsigned int x2, unsigned int y2);
240 
247  virtual vtkSelection* GeneratePolygonSelection(
248  int* polygonPoints, vtkIdType count);
249 
254  vtkProp* GetPropFromID(int id);
255 
257  {
264  MAX_KNOWN_PASS = ID_HIGH16,
265  MIN_KNOWN_PASS = PROCESS_PASS
266  };
267 
271  std::string PassTypeToString(PassTypes type);
272 
273  static void Convert(int id, float tcoord[3])
274  {
275  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
276  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
277  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
278  }
279 
280 protected:
282  ~vtkHardwareSelector() override;
283 
284  // Used to notify subclasses when a capture pass is occurring.
285  virtual void PreCapturePass(int pass) { (void)pass; }
286  virtual void PostCapturePass(int pass) { (void)pass; }
287 
288  // Called internally before and after each prop is rendered
289  // for device specific configuration/preparation etc.
290  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
291  virtual void EndRenderProp(vtkRenderWindow *) = 0;
292 
293  int Convert(unsigned long offset, unsigned char* pb)
294  {
295  if (!pb)
296  {
297  return 0;
298  }
299  offset = offset * 3;
300  unsigned char rgb[3];
301  rgb[0] = pb[offset];
302  rgb[1] = pb[offset+1];
303  rgb[2] = pb[offset+2];
304  int val = 0;
305  val |= rgb[2];
306  val = val << 8;
307  val |= rgb[1];
308  val = val << 8;
309  val |= rgb[0];
310  return val;
311  }
312 
314 
317  int Convert(unsigned int pos[2], unsigned char* pb)
318  { return this->Convert(pos[0], pos[1], pb); }
319  int Convert(int xx, int yy, unsigned char* pb)
320  {
321  if (!pb)
322  {
323  return 0;
324  }
325  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
326  unsigned char rgb[3];
327  rgb[0] = pb[offset];
328  rgb[1] = pb[offset+1];
329  rgb[2] = pb[offset+2];
330  int val = 0;
331  val |= rgb[2];
332  val = val << 8;
333  val |= rgb[1];
334  val = val << 8;
335  val |= rgb[0];
336  return val;
337  }
339 
340  vtkIdType GetID(int low24, int mid24, int high16)
341  {
342  vtkIdType val = 0;
343  val |= high16;
344  val = val << 24;
345  val |= mid24;
346  val = val << 24;
347  val |= low24;
348  return val;
349  }
350 
354  virtual bool PassRequired(int pass);
355 
361  bool IsPropHit(int propid);
362 
366  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
367  { return idx; }
368 
369  virtual void BeginSelection();
370  virtual void EndSelection();
371 
372  virtual void SavePixelBuffer(int passNo);
373  void BuildPropHitList(unsigned char* rgbData);
374 
376 
379  void ReleasePixBuffers();
381  unsigned int Area[4];
386 
387  // At most 10 passes.
388  unsigned char* PixBuffer[10];
392  int PropID;
393  float PropColorValue[3];
394 
395 private:
396  vtkHardwareSelector(const vtkHardwareSelector&) = delete;
397  void operator=(const vtkHardwareSelector&) = delete;
398 
399  class vtkInternals;
400  vtkInternals* Internals;
401 
402 };
403 
404 #endif
405 
406 
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.
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)