VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  void RenderCompositeIndex(unsigned int index);
172 
175  void RenderAttributeId(vtkIdType attribid);
176 
179  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  vtkGetMacro(CurrentPass, int);
203 
205 
211  { return GenerateSelection(this->Area); }
212  virtual vtkSelection* GenerateSelection(unsigned int r[4])
213  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
214  virtual vtkSelection* GenerateSelection(
215  unsigned int x1, unsigned int y1,
216  unsigned int x2, unsigned int y2);
218 
220 
224  virtual vtkSelection* GeneratePolygonSelection(
225  int* polygonPoints, vtkIdType count);
227 
230  vtkProp* GetPropFromID(int id);
231 
232 //BTX
234  {
241  MAX_KNOWN_PASS = ID_HIGH16,
242  MIN_KNOWN_PASS = PROCESS_PASS
243  };
244 protected:
247 
248  // Called internally before and after each prop is rendered
249  // for device specific configuration/preparation etc.
250  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
251  virtual void EndRenderProp(vtkRenderWindow *) = 0;
252 
253  static void Convert(int id, float tcoord[3])
254  {
255  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
256  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
257  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
258  }
259 
260  int Convert(unsigned long offset, unsigned char* pb)
261  {
262  if (!pb)
263  {
264  return 0;
265  }
266  offset = offset * 3;
267  unsigned char rgb[3];
268  rgb[0] = pb[offset];
269  rgb[1] = pb[offset+1];
270  rgb[2] = pb[offset+2];
271  int val = 0;
272  val |= rgb[2];
273  val = val << 8;
274  val |= rgb[1];
275  val = val << 8;
276  val |= rgb[0];
277  return val;
278  }
279 
281 
282  int Convert(unsigned int pos[2], unsigned char* pb)
283  { return this->Convert(pos[0], pos[1], pb); }
284  int Convert(int xx, int yy, unsigned char* pb)
285  {
286  if (!pb)
287  {
288  return 0;
289  }
290  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
291  unsigned char rgb[3];
292  rgb[0] = pb[offset];
293  rgb[1] = pb[offset+1];
294  rgb[2] = pb[offset+2];
295  int val = 0;
296  val |= rgb[2];
297  val = val << 8;
298  val |= rgb[1];
299  val = val << 8;
300  val |= rgb[0];
301  return val;
302  }
304 
305  vtkIdType GetID(int low24, int mid24, int high16)
306  {
307  vtkIdType val = 0;
308  val |= high16;
309  val = val << 24;
310  val |= mid24;
311  val = val << 24;
312  val |= low24;
313  return val;
314  }
315 
317  virtual bool PassRequired(int pass);
318 
322  bool IsPropHit(int propid);
323 
325 
326  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
327  { return idx; }
329 
330  virtual void BeginSelection();
331  virtual void EndSelection();
332 
333  void SavePixelBuffer(int passNo);
334  void BuildPropHitList(unsigned char* rgbData);
335 
337 
338  void ReleasePixBuffers();
340  unsigned int Area[4];
345 
346  // At most 10 passes.
347  unsigned char* PixBuffer[10];
351 private:
352  vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented.
353  void operator=(const vtkHardwareSelector&); // Not implemented.
354 
355  int PropID;
356  class vtkInternals;
357  vtkInternals* Internals;
358 //ETX
359 };
360 
361 #endif
362 
363 
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:47
abstract base class for most VTK objects
Definition: vtkObject.h:61
GLuint index
Definition: vtkgl.h:11983
GLintptr offset
Definition: vtkgl.h:11844
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:268
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual int GetPropID(int idx, vtkProp *vtkNotUsed(prop))
static void Convert(int id, float tcoord[3])
int Convert(int xx, int yy, unsigned char *pb)
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])
int Convert(unsigned long offset, unsigned char *pb)
GLuint GLfloat * val
Definition: vtkgl.h:13789
int Convert(unsigned int pos[2], unsigned char *pb)