VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkHardwareSelector.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00062 #ifndef __vtkHardwareSelector_h 00063 #define __vtkHardwareSelector_h 00064 00065 #include "vtkObject.h" 00066 00067 class vtkRenderer; 00068 class vtkSelection; 00069 class vtkProp; 00070 class vtkTextureObject; 00071 00072 class VTK_RENDERING_EXPORT vtkHardwareSelector : public vtkObject 00073 { 00074 public: 00076 00077 struct PixelInformation 00078 { 00079 bool Valid; 00080 int ProcessID; 00081 int PropID; 00082 vtkProp* Prop; 00083 unsigned int CompositeID; 00084 vtkIdType AttributeID; 00085 PixelInformation(): 00086 Valid(false), 00087 ProcessID(-1), 00088 Prop(NULL), 00089 CompositeID(0), 00090 AttributeID(-1) {} 00091 }; 00093 00094 public: 00095 static vtkHardwareSelector* New(); 00096 vtkTypeMacro(vtkHardwareSelector, vtkObject); 00097 void PrintSelf(ostream& os, vtkIndent indent); 00098 00100 00101 void SetRenderer(vtkRenderer*); 00102 vtkGetObjectMacro(Renderer, vtkRenderer); 00104 00106 00107 vtkSetVector4Macro(Area, unsigned int); 00108 vtkGetVector4Macro(Area, unsigned int); 00110 00112 00119 vtkSetMacro(FieldAssociation, int); 00120 vtkGetMacro(FieldAssociation, int); 00122 00125 vtkSelection* Select(); 00126 00128 00135 virtual bool CaptureBuffers(); 00136 PixelInformation GetPixelInformation(unsigned int display_position[2]) 00137 { return this->GetPixelInformation(display_position, 0); } 00138 PixelInformation GetPixelInformation(unsigned int display_position[2], 00139 int maxDist); 00140 void ClearBuffers() 00141 { this->ReleasePixBuffers(); } 00143 00145 00147 bool GetPixelInformation(unsigned int display_position[2], 00148 int& processId, vtkIdType& attrId, vtkProp*& prop); 00150 00152 00154 bool GetPixelInformation(unsigned int display_position[2], 00155 int& processId, vtkIdType& attrId, vtkProp*& prop, int maxDist); 00157 00160 void RenderCompositeIndex(unsigned int index); 00161 00164 void RenderAttributeId(vtkIdType attribid); 00165 00168 int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount); 00169 00171 00173 void BeginRenderProp(); 00174 void EndRenderProp(); 00176 00178 00180 vtkSetMacro(ProcessID, int); 00181 vtkGetMacro(ProcessID, int); 00183 00185 00186 vtkGetMacro(CurrentPass, int); 00188 00190 00195 virtual vtkSelection* GenerateSelection() 00196 { return GenerateSelection(this->Area); } 00197 virtual vtkSelection* GenerateSelection(unsigned int r[4]) 00198 { return GenerateSelection(r[0], r[1], r[2], r[3]); } 00199 virtual vtkSelection* GenerateSelection( 00200 unsigned int x1, unsigned int y1, 00201 unsigned int x2, unsigned int y2); 00203 00206 vtkProp* GetPropFromID(int id); 00207 00208 //BTX 00209 enum PassTypes 00210 { 00211 PROCESS_PASS, 00212 ACTOR_PASS, 00213 COMPOSITE_INDEX_PASS, 00214 ID_LOW24, 00215 ID_MID24, 00216 ID_HIGH16, 00217 MAX_KNOWN_PASS = ID_HIGH16, 00218 MIN_KNOWN_PASS = PROCESS_PASS 00219 }; 00220 protected: 00221 vtkHardwareSelector(); 00222 ~vtkHardwareSelector(); 00223 00224 static void Convert(int id, float tcoord[3]) 00225 { 00226 tcoord[0] = static_cast<float>((id & 0xff)/255.0); 00227 tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0); 00228 tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0); 00229 } 00230 00231 int Convert(unsigned long offset, unsigned char* pb) 00232 { 00233 if (!pb) 00234 { 00235 return 0; 00236 } 00237 00238 offset = offset * 3; 00239 unsigned char rgb[3]; 00240 rgb[0] = pb[offset]; 00241 rgb[1] = pb[offset+1]; 00242 rgb[2] = pb[offset+2]; 00243 int val = 0; 00244 val |= rgb[2]; 00245 val = val << 8; 00246 val |= rgb[1]; 00247 val = val << 8; 00248 val |= rgb[0]; 00249 return val; 00250 } 00251 00253 00254 int Convert(unsigned int pos[2], unsigned char* pb) 00255 { return this->Convert(pos[0], pos[1], pb); } 00256 int Convert(int xx, int yy, unsigned char* pb) 00257 { 00258 if (!pb) 00259 { 00260 return 0; 00261 } 00262 int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3; 00263 unsigned char rgb[3]; 00264 rgb[0] = pb[offset]; 00265 rgb[1] = pb[offset+1]; 00266 rgb[2] = pb[offset+2]; 00267 int val = 0; 00268 val |= rgb[2]; 00269 val = val << 8; 00270 val |= rgb[1]; 00271 val = val << 8; 00272 val |= rgb[0]; 00273 return val; 00274 } 00276 00277 vtkIdType GetID(int low24, int mid24, int high16) 00278 { 00279 vtkIdType val = 0; 00280 val |= high16; 00281 val = val << 24; 00282 val |= mid24; 00283 val = val << 24; 00284 val |= low24; 00285 return val; 00286 } 00287 00289 virtual bool PassRequired(int pass); 00290 00294 bool IsPropHit(int propid); 00295 00297 00298 virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop)) 00299 { return idx; } 00301 00302 virtual void BeginSelection(); 00303 virtual void EndSelection(); 00304 00305 void SavePixelBuffer(int passNo); 00306 void BuildPropHitList(unsigned char* rgbData); 00307 00309 00310 void ReleasePixBuffers(); 00311 vtkRenderer* Renderer; 00312 unsigned int Area[4]; 00313 int FieldAssociation; 00314 vtkIdType MaxAttributeId; 00316 00317 // At most 10 passes. 00318 unsigned char* PixBuffer[10]; 00319 int ProcessID; 00320 int CurrentPass; 00321 int InPropRender; 00322 private: 00323 vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented. 00324 void operator=(const vtkHardwareSelector&); // Not implemented. 00325 00326 int PropID; 00327 class vtkInternals; 00328 vtkInternals* Internals; 00329 //ETX 00330 }; 00331 00332 #endif 00333 00334