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 vtkSelection;
71 class vtkProp;
72 class vtkTextureObject;
73 
74 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject
75 {
76 public:
78 
80  {
81  bool Valid;
82  int ProcessID;
83  int PropID;
85  unsigned int CompositeID;
88  Valid(false),
89  ProcessID(-1),
90  Prop(NULL),
91  CompositeID(0),
92  AttributeID(-1) {}
93  };
95 
96 public:
97  static vtkHardwareSelector* New();
99  void PrintSelf(ostream& os, vtkIndent indent);
100 
102 
103  void SetRenderer(vtkRenderer*);
104  vtkGetObjectMacro(Renderer, vtkRenderer);
106 
108 
109  vtkSetVector4Macro(Area, unsigned int);
110  vtkGetVector4Macro(Area, unsigned int);
112 
114 
121  vtkSetMacro(FieldAssociation, int);
122  vtkGetMacro(FieldAssociation, int);
124 
126 
129  vtkSetMacro(UseProcessIdFromData, bool);
130  vtkGetMacro(UseProcessIdFromData, bool);
132 
135  vtkSelection* Select();
136 
138 
145  virtual bool CaptureBuffers();
146  PixelInformation GetPixelInformation(unsigned int display_position[2])
147  { return this->GetPixelInformation(display_position, 0); }
148  PixelInformation GetPixelInformation(unsigned int display_position[2],
149  int maxDist);
150  void ClearBuffers()
151  { this->ReleasePixBuffers(); }
153 
155 
157  bool GetPixelInformation(unsigned int display_position[2],
158  int& processId, vtkIdType& attrId, vtkProp*& prop);
160 
162 
164  bool GetPixelInformation(unsigned int display_position[2],
165  int& processId, vtkIdType& attrId, vtkProp*& prop, int maxDist);
167 
170  void RenderCompositeIndex(unsigned int index);
171 
174  void RenderAttributeId(vtkIdType attribid);
175 
178  void RenderProcessId(unsigned int processid);
179 
182  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
183 
185 
187  void BeginRenderProp();
188  void EndRenderProp();
190 
192 
194  vtkSetMacro(ProcessID, int);
195  vtkGetMacro(ProcessID, int);
197 
199 
200  vtkGetMacro(CurrentPass, int);
202 
204 
209  virtual vtkSelection* GenerateSelection()
210  { return GenerateSelection(this->Area); }
211  virtual vtkSelection* GenerateSelection(unsigned int r[4])
212  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
213  virtual vtkSelection* GenerateSelection(
214  unsigned int x1, unsigned int y1,
215  unsigned int x2, unsigned int y2);
217 
220  vtkProp* GetPropFromID(int id);
221 
222 //BTX
224  {
231  MAX_KNOWN_PASS = ID_HIGH16,
232  MIN_KNOWN_PASS = PROCESS_PASS
233  };
234 protected:
237 
238  static void Convert(int id, float tcoord[3])
239  {
240  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
241  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
242  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
243  }
244 
245  int Convert(unsigned long offset, unsigned char* pb)
246  {
247  if (!pb)
248  {
249  return 0;
250  }
251 
252  offset = offset * 3;
253  unsigned char rgb[3];
254  rgb[0] = pb[offset];
255  rgb[1] = pb[offset+1];
256  rgb[2] = pb[offset+2];
257  int val = 0;
258  val |= rgb[2];
259  val = val << 8;
260  val |= rgb[1];
261  val = val << 8;
262  val |= rgb[0];
263  return val;
264  }
265 
267 
268  int Convert(unsigned int pos[2], unsigned char* pb)
269  { return this->Convert(pos[0], pos[1], pb); }
270  int Convert(int xx, int yy, unsigned char* pb)
271  {
272  if (!pb)
273  {
274  return 0;
275  }
276  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
277  unsigned char rgb[3];
278  rgb[0] = pb[offset];
279  rgb[1] = pb[offset+1];
280  rgb[2] = pb[offset+2];
281  int val = 0;
282  val |= rgb[2];
283  val = val << 8;
284  val |= rgb[1];
285  val = val << 8;
286  val |= rgb[0];
287  return val;
288  }
290 
291  vtkIdType GetID(int low24, int mid24, int high16)
292  {
293  vtkIdType val = 0;
294  val |= high16;
295  val = val << 24;
296  val |= mid24;
297  val = val << 24;
298  val |= low24;
299  return val;
300  }
301 
303  virtual bool PassRequired(int pass);
304 
308  bool IsPropHit(int propid);
309 
311 
312  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
313  { return idx; }
315 
316  virtual void BeginSelection();
317  virtual void EndSelection();
318 
319  void SavePixelBuffer(int passNo);
320  void BuildPropHitList(unsigned char* rgbData);
321 
323 
324  void ReleasePixBuffers();
326  unsigned int Area[4];
331 
332  // At most 10 passes.
333  unsigned char* PixBuffer[10];
337 private:
338  vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented.
339  void operator=(const vtkHardwareSelector&); // Not implemented.
340 
341  int PropID;
342  class vtkInternals;
343  vtkInternals* Internals;
344 //ETX
345 };
346 
347 #endif
348 
349