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:
100  void PrintSelf(ostream& os, vtkIndent indent);
101 
103 
104  virtual void SetRenderer(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 
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]); }
213  unsigned int x1, unsigned int y1,
214  unsigned int x2, unsigned int y2);
216 
218 
223  int* polygonPoints, vtkIdType count);
225 
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 
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 
vtkHardwareSelector::PixelInformation::Valid
bool Valid
Definition: vtkHardwareSelector.h:82
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkHardwareSelector::GetPropFromID
vtkProp * GetPropFromID(int id)
vtkHardwareSelector::IsPropHit
bool IsPropHit(int propid)
vtkHardwareSelector::Convert
int Convert(unsigned long offset, unsigned char *pb)
Definition: vtkHardwareSelector.h:259
vtkgl::count
GLuint GLuint GLsizei count
Definition: vtkgl.h:11315
vtkHardwareSelector::Convert
int Convert(unsigned int pos[2], unsigned char *pb)
Definition: vtkHardwareSelector.h:281
vtkHardwareSelector::PixelInformation::Prop
vtkProp * Prop
Definition: vtkHardwareSelector.h:85
vtkSetVector3Macro
#define vtkSetVector3Macro(name, type)
Definition: vtkSetGet.h:287
vtkHardwareSelector::ID_LOW24
@ ID_LOW24
Definition: vtkHardwareSelector.h:236
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkHardwareSelector::PROCESS_PASS
@ PROCESS_PASS
Definition: vtkHardwareSelector.h:233
vtkHardwareSelector::New
static vtkHardwareSelector * New()
vtkHardwareSelector::CurrentPass
int CurrentPass
Definition: vtkHardwareSelector.h:348
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkHardwareSelector::ProcessID
int ProcessID
Definition: vtkHardwareSelector.h:347
vtkHardwareSelector::RenderCompositeIndex
virtual void RenderCompositeIndex(unsigned int index)
vtkHardwareSelector::PassRequired
virtual bool PassRequired(int pass)
vtkHardwareSelector::GetPropID
virtual int GetPropID(int idx, vtkProp *vtkNotUsed(prop))
Definition: vtkHardwareSelector.h:325
vtkHardwareSelector::ID_MID24
@ ID_MID24
Definition: vtkHardwareSelector.h:237
vtkHardwareSelector::GenerateSelection
virtual vtkSelection * GenerateSelection(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
vtkSelection
A node in a selection tree. Used to store selection results.
Definition: vtkSelection.h:45
vtkHardwareSelector::GenerateSelection
virtual vtkSelection * GenerateSelection()
Definition: vtkHardwareSelector.h:208
vtkHardwareSelector::PassTypes
PassTypes
Definition: vtkHardwareSelector.h:232
vtkHardwareSelector::ACTOR_PASS
@ ACTOR_PASS
Definition: vtkHardwareSelector.h:234
vtkHardwareSelector::FieldAssociation
int FieldAssociation
Definition: vtkHardwareSelector.h:340
vtkHardwareSelector::CaptureBuffers
virtual bool CaptureBuffers()
vtkHardwareSelector::EndRenderProp
virtual void EndRenderProp()
vtkHardwareSelector::Select
vtkSelection * Select()
vtkgl::val
GLuint GLfloat * val
Definition: vtkgl.h:13789
vtkHardwareSelector::BeginRenderProp
virtual void BeginRenderProp()
vtkHardwareSelector::~vtkHardwareSelector
~vtkHardwareSelector()
vtkNotUsed
#define vtkNotUsed(x)
Definition: vtkSetGet.h:557
vtkGetVector3Macro
#define vtkGetVector3Macro(name, type)
Definition: vtkSetGet.h:304
vtkHardwareSelector::ReleasePixBuffers
void ReleasePixBuffers()
vtkHardwareSelector::Renderer
vtkRenderer * Renderer
Definition: vtkHardwareSelector.h:338
vtkHardwareSelector::PixelInformation::PixelInformation
PixelInformation()
Definition: vtkHardwareSelector.h:88
vtkHardwareSelector::GetPixelInformation
PixelInformation GetPixelInformation(const unsigned int display_position[2])
Definition: vtkHardwareSelector.h:151
vtkHardwareSelector::BuildPropHitList
void BuildPropHitList(unsigned char *rgbData)
vtkHardwareSelector::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkHardwareSelector::GeneratePolygonSelection
virtual vtkSelection * GeneratePolygonSelection(int *polygonPoints, vtkIdType count)
vtkHardwareSelector
manager for OpenGL-based selection.
Definition: vtkHardwareSelector.h:76
vtkHardwareSelector::PixelInformation::AttributeID
vtkIdType AttributeID
Definition: vtkHardwareSelector.h:87
vtkHardwareSelector::GetPixelInformation
PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist, unsigned int selected_position[2])
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkRenderingCoreModule.h
vtkHardwareSelector::GenerateSelection
virtual vtkSelection * GenerateSelection(unsigned int r[4])
Definition: vtkHardwareSelector.h:210
vtkHardwareSelector::PropID
int PropID
Definition: vtkHardwareSelector.h:350
vtkgl::offset
GLintptr offset
Definition: vtkgl.h:11844
vtkHardwareSelector::EndRenderProp
virtual void EndRenderProp(vtkRenderWindow *)=0
vtkHardwareSelector::ID_HIGH16
@ ID_HIGH16
Definition: vtkHardwareSelector.h:238
vtkHardwareSelector::GetID
vtkIdType GetID(int low24, int mid24, int high16)
Definition: vtkHardwareSelector.h:304
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkHardwareSelector::COMPOSITE_INDEX_PASS
@ COMPOSITE_INDEX_PASS
Definition: vtkHardwareSelector.h:235
vtkHardwareSelector::Render
int Render(vtkRenderer *renderer, vtkProp **propArray, int propArrayCount)
vtkObject.h
vtkHardwareSelector::vtkHardwareSelector
vtkHardwareSelector()
vtkHardwareSelector::Convert
static void Convert(int id, float tcoord[3])
Definition: vtkHardwareSelector.h:243
vtkHardwareSelector::PixelInformation::PropID
int PropID
Definition: vtkHardwareSelector.h:84
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
vtkSetVector4Macro
#define vtkSetVector4Macro(name, type)
Definition: vtkSetGet.h:322
vtkHardwareSelector::Convert
int Convert(int xx, int yy, unsigned char *pb)
Definition: vtkHardwareSelector.h:283
vtkgl::index
GLuint index
Definition: vtkgl.h:11983
vtkHardwareSelector::SavePixelBuffer
virtual void SavePixelBuffer(int passNo)
vtkgl::r
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
vtkHardwareSelector::SetRenderer
virtual void SetRenderer(vtkRenderer *)
vtkHardwareSelector::InPropRender
int InPropRender
Definition: vtkHardwareSelector.h:349
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:64
vtkHardwareSelector::RenderAttributeId
virtual void RenderAttributeId(vtkIdType attribid)
vtkHardwareSelector::UseProcessIdFromData
bool UseProcessIdFromData
Definition: vtkHardwareSelector.h:341
vtkHardwareSelector::PixelInformation::ProcessID
int ProcessID
Definition: vtkHardwareSelector.h:83
VTKRENDERINGCORE_EXPORT
#define VTKRENDERINGCORE_EXPORT
Definition: vtkRenderingCoreModule.h:15
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:89
vtkHardwareSelector::PixelInformation::CompositeID
unsigned int CompositeID
Definition: vtkHardwareSelector.h:86
vtkHardwareSelector::BeginRenderProp
virtual void BeginRenderProp(vtkRenderWindow *)=0
vtkHardwareSelector::ClearBuffers
void ClearBuffers()
Definition: vtkHardwareSelector.h:157
vtkGetVector4Macro
#define vtkGetVector4Macro(name, type)
Definition: vtkSetGet.h:341
vtkHardwareSelector::MaxAttributeId
vtkIdType MaxAttributeId
Definition: vtkHardwareSelector.h:342
vtkHardwareSelector::RenderProcessId
virtual void RenderProcessId(unsigned int processid)
vtkHardwareSelector::EndSelection
virtual void EndSelection()
vtkHardwareSelector::PixelInformation
Definition: vtkHardwareSelector.h:81
vtkHardwareSelector::GetPixelInformation
PixelInformation GetPixelInformation(const unsigned int display_position[2], int maxDist)
Definition: vtkHardwareSelector.h:153
vtkHardwareSelector::BeginSelection
virtual void BeginSelection()