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 =========================================================================*/
63 #ifndef vtkHardwareSelector_h
64 #define vtkHardwareSelector_h
65 
66 #include "vtkRenderingCoreModule.h" // For export macro
67 #include "vtkObject.h"
68 
69 class vtkRenderer;
70 class vtkRenderWindow;
71 class vtkSelection;
72 class vtkProp;
73 class vtkTextureObject;
74 
76 {
77 public:
79 
81  {
82  bool Valid;
83  int ProcessID;
84  int PropID;
86  unsigned int CompositeID;
89  Valid(false),
90  ProcessID(-1),
91  Prop(NULL),
92  CompositeID(0),
93  AttributeID(-1) {}
94  };
96 
97 public:
98  static vtkHardwareSelector* New();
100  void PrintSelf(ostream& os, vtkIndent indent);
101 
103 
104  virtual void SetRenderer(vtkRenderer*);
105  vtkGetObjectMacro(Renderer, vtkRenderer);
107 
109 
110  vtkSetVector4Macro(Area, unsigned int);
111  vtkGetVector4Macro(Area, unsigned int);
113 
115 
122  vtkSetMacro(FieldAssociation, int);
123  vtkGetMacro(FieldAssociation, int);
125 
127 
130  vtkSetMacro(UseProcessIdFromData, bool);
131  vtkGetMacro(UseProcessIdFromData, bool);
133 
136  vtkSelection* Select();
137 
139 
146  virtual bool CaptureBuffers();
147  PixelInformation GetPixelInformation(unsigned int display_position[2])
148  { return this->GetPixelInformation(display_position, 0); }
149  PixelInformation GetPixelInformation(unsigned int display_position[2],
150  int maxDist);
152  { this->ReleasePixBuffers(); }
154 
156 
158  VTK_LEGACY(bool GetPixelInformation(unsigned int display_position[2],
159  int& processId, vtkIdType& attrId, vtkProp*& prop));
161 
163 
165  VTK_LEGACY(bool GetPixelInformation(unsigned int display_position[2],
166  int& processId, vtkIdType& attrId, vtkProp*& prop, int maxDist));
168 
171  virtual void RenderCompositeIndex(unsigned int index);
172 
175  virtual void RenderAttributeId(vtkIdType attribid);
176 
179  virtual void RenderProcessId(unsigned int processid);
180 
183  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
184 
186 
188  virtual void BeginRenderProp();
189  virtual void EndRenderProp();
191 
193 
195  vtkSetMacro(ProcessID, int);
196  vtkGetMacro(ProcessID, int);
198 
200 
201  vtkGetVector3Macro(PropColorValue,float);
202  vtkSetVector3Macro(PropColorValue,float);
204 
206 
207  vtkGetMacro(CurrentPass, int);
209 
211 
217  { return GenerateSelection(this->Area); }
218  virtual vtkSelection* GenerateSelection(unsigned int r[4])
219  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
220  virtual vtkSelection* GenerateSelection(
221  unsigned int x1, unsigned int y1,
222  unsigned int x2, unsigned int y2);
224 
226 
230  virtual vtkSelection* GeneratePolygonSelection(
231  int* polygonPoints, vtkIdType count);
233 
236  vtkProp* GetPropFromID(int id);
237 
238 //BTX
240  {
247  MAX_KNOWN_PASS = ID_HIGH16,
248  MIN_KNOWN_PASS = PROCESS_PASS
249  };
250 
251  static void Convert(int id, float tcoord[3])
252  {
253  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
254  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
255  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
256  }
257 
258 protected:
261 
262  // Called internally before and after each prop is rendered
263  // for device specific configuration/preparation etc.
264  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
265  virtual void EndRenderProp(vtkRenderWindow *) = 0;
266 
267  int Convert(unsigned long offset, unsigned char* pb)
268  {
269  if (!pb)
270  {
271  return 0;
272  }
273  offset = offset * 3;
274  unsigned char rgb[3];
275  rgb[0] = pb[offset];
276  rgb[1] = pb[offset+1];
277  rgb[2] = pb[offset+2];
278  int val = 0;
279  val |= rgb[2];
280  val = val << 8;
281  val |= rgb[1];
282  val = val << 8;
283  val |= rgb[0];
284  return val;
285  }
286 
288 
289  int Convert(unsigned int pos[2], unsigned char* pb)
290  { return this->Convert(pos[0], pos[1], pb); }
291  int Convert(int xx, int yy, unsigned char* pb)
292  {
293  if (!pb)
294  {
295  return 0;
296  }
297  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
298  unsigned char rgb[3];
299  rgb[0] = pb[offset];
300  rgb[1] = pb[offset+1];
301  rgb[2] = pb[offset+2];
302  int val = 0;
303  val |= rgb[2];
304  val = val << 8;
305  val |= rgb[1];
306  val = val << 8;
307  val |= rgb[0];
308  return val;
309  }
311 
312  vtkIdType GetID(int low24, int mid24, int high16)
313  {
314  vtkIdType val = 0;
315  val |= high16;
316  val = val << 24;
317  val |= mid24;
318  val = val << 24;
319  val |= low24;
320  return val;
321  }
322 
324  virtual bool PassRequired(int pass);
325 
329  bool IsPropHit(int propid);
330 
332 
333  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
334  { return idx; }
336 
337  virtual void BeginSelection();
338  virtual void EndSelection();
339 
340  void SavePixelBuffer(int passNo);
341  void BuildPropHitList(unsigned char* rgbData);
342 
344 
345  void ReleasePixBuffers();
347  unsigned int Area[4];
352 
353  // At most 10 passes.
354  unsigned char* PixBuffer[10];
358  int PropID;
359  float PropColorValue[3];
360 
361 private:
362  vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented.
363  void operator=(const vtkHardwareSelector&); // Not implemented.
364 
365  class vtkInternals;
366  vtkInternals* Internals;
367 //ETX
368 };
369 
370 #endif
371 
372 
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
#define vtkNotUsed(x)
Definition: vtkSetGet.h:547
abstract base class for most VTK objects
Definition: vtkObject.h:61
GLuint index
Definition: vtkgl.h:11983
GLintptr offset
Definition: vtkgl.h:11844
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
GLuint GLuint GLsizei count
Definition: vtkgl.h:11315
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual vtkSelection * GenerateSelection(unsigned int r[4])
A node in a selection tree. Used to store selection results.
Definition: vtkSelection.h:44
int vtkIdType
Definition: vtkType.h:281
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:632
virtual void PrintSelf(ostream &os, vtkIndent indent)
#define vtkSetVector4Macro(name, type)
Definition: vtkSetGet.h:312
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual int GetPropID(int idx, vtkProp *vtkNotUsed(prop))
#define vtkGetVector3Macro(name, type)
Definition: vtkSetGet.h:294
static void Convert(int id, float tcoord[3])
#define vtkGetVector4Macro(name, type)
Definition: vtkSetGet.h:331
int Convert(int xx, int yy, unsigned char *pb)
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:222
#define VTK_LEGACY(method)
Definition: vtkSetGet.h:800
abstracts an OpenGL texture object.
vtkIdType GetID(int low24, int mid24, int high16)
create a window for renderers to draw into
#define VTKRENDERINGCORE_EXPORT
virtual vtkSelection * GenerateSelection()
manager for OpenGL-based selection.
static vtkObject * New()
PixelInformation GetPixelInformation(unsigned int display_position[2])
#define vtkSetVector3Macro(name, type)
Definition: vtkSetGet.h:277
int Convert(unsigned long offset, unsigned char *pb)
GLuint GLfloat * val
Definition: vtkgl.h:13789
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69
int Convert(unsigned int pos[2], unsigned char *pb)