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 =========================================================================*/
50 #ifndef vtkHardwareSelector_h
51 #define vtkHardwareSelector_h
52 
53 #include "vtkRenderingCoreModule.h" // For export macro
54 #include "vtkObject.h"
55 
56 #include <string> // for std::string
57 
58 class vtkRenderer;
59 class vtkRenderWindow;
60 class vtkSelection;
61 class vtkProp;
62 class vtkTextureObject;
63 
64 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject
65 {
66 public:
68 
72  {
73  bool Valid;
74  int ProcessID;
75  int PropID;
77  unsigned int CompositeID;
80  Valid(false),
81  ProcessID(-1),
82  PropID(-1),
83  Prop(nullptr),
84  CompositeID(0),
85  AttributeID(-1) {}
86  };
88 
89 public:
90  static vtkHardwareSelector* New();
92  void PrintSelf(ostream& os, vtkIndent indent) override;
93 
95 
98  virtual void SetRenderer(vtkRenderer*);
99  vtkGetObjectMacro(Renderer, vtkRenderer);
101 
103 
106  vtkSetVector4Macro(Area, unsigned int);
107  vtkGetVector4Macro(Area, unsigned int);
109 
111 
121  vtkSetMacro(FieldAssociation, int);
122  vtkGetMacro(FieldAssociation, int);
124 
126 
131  vtkSetMacro(UseProcessIdFromData, bool);
132  vtkGetMacro(UseProcessIdFromData, bool);
134 
139  vtkSelection* Select();
140 
142 
155  virtual bool CaptureBuffers();
156  PixelInformation GetPixelInformation(const unsigned int display_position[2])
157  { return this->GetPixelInformation(display_position, 0); }
158  PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
159  { unsigned int temp[2]; return this->GetPixelInformation(display_position, maxDist, temp); }
160  PixelInformation GetPixelInformation(const unsigned int display_position[2],
161  int maxDist, unsigned int selected_position[2]);
163  { this->ReleasePixBuffers(); }
165 
170  virtual void RenderCompositeIndex(unsigned int index);
171 
175  virtual void RenderAttributeId(vtkIdType attribid);
176 
181  virtual void RenderProcessId(unsigned int processid);
182 
187  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
188 
190 
194  virtual void BeginRenderProp();
195  virtual void EndRenderProp();
197 
199 
203  vtkSetMacro(ProcessID, int);
204  vtkGetMacro(ProcessID, int);
206 
208 
211  vtkGetVector3Macro(PropColorValue,float);
212  vtkSetVector3Macro(PropColorValue,float);
214 
216 
219  vtkGetMacro(CurrentPass, int);
221 
231  { return GenerateSelection(this->Area); }
232  virtual vtkSelection* GenerateSelection(unsigned int r[4])
233  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
234  virtual vtkSelection* GenerateSelection(
235  unsigned int x1, unsigned int y1,
236  unsigned int x2, unsigned int y2);
237 
244  virtual vtkSelection* GeneratePolygonSelection(
245  int* polygonPoints, vtkIdType count);
246 
251  vtkProp* GetPropFromID(int id);
252 
254  {
261  MAX_KNOWN_PASS = ID_HIGH16,
262  MIN_KNOWN_PASS = PROCESS_PASS
263  };
264 
268  std::string PassTypeToString(PassTypes type);
269 
270  static void Convert(int id, float tcoord[3])
271  {
272  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
273  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
274  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
275  }
276 
277 protected:
279  ~vtkHardwareSelector() override;
280 
281  // Used to notify subclasses when a capture pass is occurring.
282  virtual void PreCapturePass(int pass) { (void)pass; }
283  virtual void PostCapturePass(int pass) { (void)pass; }
284 
285  // Called internally before and after each prop is rendered
286  // for device specific configuration/preparation etc.
287  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
288  virtual void EndRenderProp(vtkRenderWindow *) = 0;
289 
290  int Convert(unsigned long offset, unsigned char* pb)
291  {
292  if (!pb)
293  {
294  return 0;
295  }
296  offset = offset * 3;
297  unsigned char rgb[3];
298  rgb[0] = pb[offset];
299  rgb[1] = pb[offset+1];
300  rgb[2] = pb[offset+2];
301  int val = 0;
302  val |= rgb[2];
303  val = val << 8;
304  val |= rgb[1];
305  val = val << 8;
306  val |= rgb[0];
307  return val;
308  }
309 
311 
314  int Convert(unsigned int pos[2], unsigned char* pb)
315  { return this->Convert(pos[0], pos[1], pb); }
316  int Convert(int xx, int yy, unsigned char* pb)
317  {
318  if (!pb)
319  {
320  return 0;
321  }
322  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
323  unsigned char rgb[3];
324  rgb[0] = pb[offset];
325  rgb[1] = pb[offset+1];
326  rgb[2] = pb[offset+2];
327  int val = 0;
328  val |= rgb[2];
329  val = val << 8;
330  val |= rgb[1];
331  val = val << 8;
332  val |= rgb[0];
333  return val;
334  }
336 
337  vtkIdType GetID(int low24, int mid24, int high16)
338  {
339  vtkIdType val = 0;
340  val |= high16;
341  val = val << 24;
342  val |= mid24;
343  val = val << 24;
344  val |= low24;
345  return val;
346  }
347 
351  virtual bool PassRequired(int pass);
352 
358  bool IsPropHit(int propid);
359 
363  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
364  { return idx; }
365 
366  virtual void BeginSelection();
367  virtual void EndSelection();
368 
369  virtual void SavePixelBuffer(int passNo);
370  void BuildPropHitList(unsigned char* rgbData);
371 
373 
376  void ReleasePixBuffers();
378  unsigned int Area[4];
383 
384  // At most 10 passes.
385  unsigned char* PixBuffer[10];
389  int PropID;
390  float PropColorValue[3];
391 
392 private:
393  vtkHardwareSelector(const vtkHardwareSelector&) = delete;
394  void operator=(const vtkHardwareSelector&) = delete;
395 
396  class vtkInternals;
397  vtkInternals* Internals;
398 
399 };
400 
401 #endif
402 
403 
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.
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: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->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)