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 =========================================================================*/
62 #ifndef __vtkHardwareSelector_h
63 #define __vtkHardwareSelector_h
64 
65 #include "vtkObject.h"
66 
67 class vtkRenderer;
68 class vtkSelection;
69 class vtkProp;
70 class vtkTextureObject;
71 
73 {
74 public:
76 
78  {
79  bool Valid;
80  int ProcessID;
81  int PropID;
83  unsigned int CompositeID;
86  Valid(false),
87  ProcessID(-1),
88  Prop(NULL),
89  CompositeID(0),
90  AttributeID(-1) {}
91  };
93 
94 public:
95  static vtkHardwareSelector* New();
97  void PrintSelf(ostream& os, vtkIndent indent);
98 
100 
101  void SetRenderer(vtkRenderer*);
102  vtkGetObjectMacro(Renderer, vtkRenderer);
104 
106 
107  vtkSetVector4Macro(Area, unsigned int);
108  vtkGetVector4Macro(Area, unsigned int);
110 
112 
119  vtkSetMacro(FieldAssociation, int);
120  vtkGetMacro(FieldAssociation, int);
122 
125  vtkSelection* Select();
126 
128 
135  virtual bool CaptureBuffers();
136  PixelInformation GetPixelInformation(unsigned int display_position[2])
137  { return this->GetPixelInformation(display_position, 0); }
138  PixelInformation GetPixelInformation(unsigned int display_position[2],
139  int maxDist);
141  { this->ReleasePixBuffers(); }
143 
145 
147  bool GetPixelInformation(unsigned int display_position[2],
148  int& processId, vtkIdType& attrId, vtkProp*& prop);
150 
152 
154  bool GetPixelInformation(unsigned int display_position[2],
155  int& processId, vtkIdType& attrId, vtkProp*& prop, int maxDist);
157 
160  void RenderCompositeIndex(unsigned int index);
161 
164  void RenderAttributeId(vtkIdType attribid);
165 
168  int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount);
169 
171 
173  void BeginRenderProp();
174  void EndRenderProp();
176 
178 
180  vtkSetMacro(ProcessID, int);
181  vtkGetMacro(ProcessID, int);
183 
185 
186  vtkGetMacro(CurrentPass, int);
188 
190 
196  { return GenerateSelection(this->Area); }
197  virtual vtkSelection* GenerateSelection(unsigned int r[4])
198  { return GenerateSelection(r[0], r[1], r[2], r[3]); }
199  virtual vtkSelection* GenerateSelection(
200  unsigned int x1, unsigned int y1,
201  unsigned int x2, unsigned int y2);
203 
206  vtkProp* GetPropFromID(int id);
207 
208 //BTX
210  {
217  MAX_KNOWN_PASS = ID_HIGH16,
218  MIN_KNOWN_PASS = PROCESS_PASS
219  };
220 protected:
223 
224  static void Convert(int id, float tcoord[3])
225  {
226  tcoord[0] = static_cast<float>((id & 0xff)/255.0);
227  tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
228  tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
229  }
230 
231  int Convert(unsigned long offset, unsigned char* pb)
232  {
233  if (!pb)
234  {
235  return 0;
236  }
237 
238  offset = offset * 3;
239  unsigned char rgb[3];
240  rgb[0] = pb[offset];
241  rgb[1] = pb[offset+1];
242  rgb[2] = pb[offset+2];
243  int val = 0;
244  val |= rgb[2];
245  val = val << 8;
246  val |= rgb[1];
247  val = val << 8;
248  val |= rgb[0];
249  return val;
250  }
251 
253 
254  int Convert(unsigned int pos[2], unsigned char* pb)
255  { return this->Convert(pos[0], pos[1], pb); }
256  int Convert(int xx, int yy, unsigned char* pb)
257  {
258  if (!pb)
259  {
260  return 0;
261  }
262  int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
263  unsigned char rgb[3];
264  rgb[0] = pb[offset];
265  rgb[1] = pb[offset+1];
266  rgb[2] = pb[offset+2];
267  int val = 0;
268  val |= rgb[2];
269  val = val << 8;
270  val |= rgb[1];
271  val = val << 8;
272  val |= rgb[0];
273  return val;
274  }
276 
277  vtkIdType GetID(int low24, int mid24, int high16)
278  {
279  vtkIdType val = 0;
280  val |= high16;
281  val = val << 24;
282  val |= mid24;
283  val = val << 24;
284  val |= low24;
285  return val;
286  }
287 
289  virtual bool PassRequired(int pass);
290 
294  bool IsPropHit(int propid);
295 
297 
298  virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
299  { return idx; }
301 
302  virtual void BeginSelection();
303  virtual void EndSelection();
304 
305  void SavePixelBuffer(int passNo);
306  void BuildPropHitList(unsigned char* rgbData);
307 
309 
310  void ReleasePixBuffers();
312  unsigned int Area[4];
316 
317  // At most 10 passes.
318  unsigned char* PixBuffer[10];
322 private:
323  vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented.
324  void operator=(const vtkHardwareSelector&); // Not implemented.
325 
326  int PropID;
327  class vtkInternals;
328  vtkInternals* Internals;
329 //ETX
330 };
331 
332 #endif
333 
334