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 
150  virtual bool CaptureBuffers();
151  PixelInformation GetPixelInformation(const unsigned int display_position[2])
152  { return this->GetPixelInformation(display_position, 0); }
153  PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
154  { unsigned int temp[2]; return this->GetPixelInformation(display_position, maxDist, temp); }
155  PixelInformation GetPixelInformation(const unsigned int display_position[2],
156  int maxDist, unsigned int selected_position[2]);
158  { this->ReleasePixBuffers(); }
160 
163  virtual void RenderCompositeIndex(unsigned int index);
164 
167  virtual void RenderAttributeId(vtkIdType attribid);
168 
171  virtual void RenderProcessId(unsigned int processid);
172 
175  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
176 
178 
180  virtual void BeginRenderProp();
181  virtual void EndRenderProp();
183 
185 
187  vtkSetMacro(ProcessID, int);
188  vtkGetMacro(ProcessID, int);
190 
192 
193  vtkGetVector3Macro(PropColorValue,float);
194  vtkSetVector3Macro(PropColorValue,float);
196 
198 
199  vtkGetMacro(CurrentPass, int);
201 
203 
209  { return GenerateSelection(this->Area); }
210  virtual vtkSelection* GenerateSelection(unsigned int r[4])
211  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
212  virtual vtkSelection* GenerateSelection(
213  unsigned int x1, unsigned int y1,
214  unsigned int x2, unsigned int y2);
216 
218 
222  virtual vtkSelection* GeneratePolygonSelection(
223  int* polygonPoints, vtkIdType count);
225 
228  vtkProp* GetPropFromID(int id);
229 
230 //BTX
232  {
239  MAX_KNOWN_PASS = ID_HIGH16,
240  MIN_KNOWN_PASS = PROCESS_PASS
241  };
242 
243  static void Convert(int id, float tcoord[3])
244  {
245  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
246  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
247  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
248  }
249 
250 protected:
253 
254  // Called internally before and after each prop is rendered
255  // for device specific configuration/preparation etc.
256  virtual void BeginRenderProp(vtkRenderWindow *) = 0;
257  virtual void EndRenderProp(vtkRenderWindow *) = 0;
258 
259  int Convert(unsigned long offset, unsigned char* pb)
260  {
261  if (!pb)
262  {
263  return 0;
264  }
265  offset = offset * 3;
266  unsigned char rgb[3];
267  rgb[0] = pb[offset];
268  rgb[1] = pb[offset+1];
269  rgb[2] = pb[offset+2];
270  int val = 0;
271  val |= rgb[2];
272  val = val << 8;
273  val |= rgb[1];
274  val = val << 8;
275  val |= rgb[0];
276  return val;
277  }
278 
280 
281  int Convert(unsigned int pos[2], unsigned char* pb)
282  { return this->Convert(pos[0], pos[1], pb); }
283  int Convert(int xx, int yy, unsigned char* pb)
284  {
285  if (!pb)
286  {
287  return 0;
288  }
289  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
290  unsigned char rgb[3];
291  rgb[0] = pb[offset];
292  rgb[1] = pb[offset+1];
293  rgb[2] = pb[offset+2];
294  int val = 0;
295  val |= rgb[2];
296  val = val << 8;
297  val |= rgb[1];
298  val = val << 8;
299  val |= rgb[0];
300  return val;
301  }
303 
304  vtkIdType GetID(int low24, int mid24, int high16)
305  {
306  vtkIdType val = 0;
307  val |= high16;
308  val = val << 24;
309  val |= mid24;
310  val = val << 24;
311  val |= low24;
312  return val;
313  }
314 
316  virtual bool PassRequired(int pass);
317 
321  bool IsPropHit(int propid);
322 
324 
325  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
326  { return idx; }
328 
329  virtual void BeginSelection();
330  virtual void EndSelection();
331 
332  virtual void SavePixelBuffer(int passNo);
333  void BuildPropHitList(unsigned char* rgbData);
334 
336 
337  void ReleasePixBuffers();
339  unsigned int Area[4];
344 
345  // At most 10 passes.
346  unsigned char* PixBuffer[10];
350  int PropID;
351  float PropColorValue[3];
352 
353 private:
354  vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented.
355  void operator=(const vtkHardwareSelector&); // Not implemented.
356 
357  class vtkInternals;
358  vtkInternals* Internals;
359 //ETX
360 };
361 
362 #endif
363 
364 
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:52
abstract base class for most VTK objects
Definition: vtkObject.h:61
PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
abstract specification for renderers
Definition: vtkRenderer.h:62
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:247
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
PixelInformation GetPixelInformation(const unsigned int display_position[2])
virtual vtkSelection * GenerateSelection()
manager for OpenGL-based selection.
static vtkObject * New()
int Convert(unsigned long offset, unsigned char *pb)
int Convert(unsigned int pos[2], unsigned char *pb)