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 =========================================================================*/ 00063 #ifndef __vtkHardwareSelector_h 00064 #define __vtkHardwareSelector_h 00065 00066 #include "vtkRenderingCoreModule.h" // For export macro 00067 #include "vtkObject.h" 00068 00069 class vtkRenderer; 00070 class vtkRenderWindow; 00071 class vtkSelection; 00072 class vtkProp; 00073 class vtkTextureObject; 00074 00075 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject 00076 { 00077 public: 00079 00080 struct PixelInformation 00081 { 00082 bool Valid; 00083 int ProcessID; 00084 int PropID; 00085 vtkProp* Prop; 00086 unsigned int CompositeID; 00087 vtkIdType AttributeID; 00088 PixelInformation(): 00089 Valid(false), 00090 ProcessID(-1), 00091 Prop(NULL), 00092 CompositeID(0), 00093 AttributeID(-1) {} 00094 }; 00096 00097 public: 00098 static vtkHardwareSelector* New(); 00099 vtkTypeMacro(vtkHardwareSelector, vtkObject); 00100 void PrintSelf(ostream& os, vtkIndent indent); 00101 00103 00104 virtual void SetRenderer(vtkRenderer*); 00105 vtkGetObjectMacro(Renderer, vtkRenderer); 00107 00109 00110 vtkSetVector4Macro(Area, unsigned int); 00111 vtkGetVector4Macro(Area, unsigned int); 00113 00115 00122 vtkSetMacro(FieldAssociation, int); 00123 vtkGetMacro(FieldAssociation, int); 00125 00127 00130 vtkSetMacro(UseProcessIdFromData, bool); 00131 vtkGetMacro(UseProcessIdFromData, bool); 00133 00136 vtkSelection* Select(); 00137 00139 00146 virtual bool CaptureBuffers(); 00147 PixelInformation GetPixelInformation(unsigned int display_position[2]) 00148 { return this->GetPixelInformation(display_position, 0); } 00149 PixelInformation GetPixelInformation(unsigned int display_position[2], 00150 int maxDist); 00151 void ClearBuffers() 00152 { this->ReleasePixBuffers(); } 00154 00156 00158 VTK_LEGACY(bool GetPixelInformation(unsigned int display_position[2], 00159 int& processId, vtkIdType& attrId, vtkProp*& prop)); 00161 00163 00165 VTK_LEGACY(bool GetPixelInformation(unsigned int display_position[2], 00166 int& processId, vtkIdType& attrId, vtkProp*& prop, int maxDist)); 00168 00171 void RenderCompositeIndex(unsigned int index); 00172 00175 void RenderAttributeId(vtkIdType attribid); 00176 00179 void RenderProcessId(unsigned int processid); 00180 00183 int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount); 00184 00186 00188 virtual void BeginRenderProp(); 00189 virtual void EndRenderProp(); 00191 00193 00195 vtkSetMacro(ProcessID, int); 00196 vtkGetMacro(ProcessID, int); 00198 00200 00201 vtkGetMacro(CurrentPass, int); 00203 00205 00210 virtual vtkSelection* GenerateSelection() 00211 { return GenerateSelection(this->Area); } 00212 virtual vtkSelection* GenerateSelection(unsigned int r[4]) 00213 { return GenerateSelection(r[0], r[1], r[2], r[3]); } 00214 virtual vtkSelection* GenerateSelection( 00215 unsigned int x1, unsigned int y1, 00216 unsigned int x2, unsigned int y2); 00218 00220 00224 virtual vtkSelection* GeneratePolygonSelection( 00225 int* polygonPoints, vtkIdType count); 00227 00230 vtkProp* GetPropFromID(int id); 00231 00232 //BTX 00233 enum PassTypes 00234 { 00235 PROCESS_PASS, 00236 ACTOR_PASS, 00237 COMPOSITE_INDEX_PASS, 00238 ID_LOW24, 00239 ID_MID24, 00240 ID_HIGH16, 00241 MAX_KNOWN_PASS = ID_HIGH16, 00242 MIN_KNOWN_PASS = PROCESS_PASS 00243 }; 00244 protected: 00245 vtkHardwareSelector(); 00246 ~vtkHardwareSelector(); 00247 00248 // Called internally before and after each prop is rendered 00249 // for device specific configuration/preparation etc. 00250 virtual void BeginRenderProp(vtkRenderWindow *) = 0; 00251 virtual void EndRenderProp(vtkRenderWindow *) = 0; 00252 00253 static void Convert(int id, float tcoord[3]) 00254 { 00255 tcoord[0] = static_cast<float>((id & 0xff)/255.0); 00256 tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0); 00257 tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0); 00258 } 00259 00260 int Convert(unsigned long offset, unsigned char* pb) 00261 { 00262 if (!pb) 00263 { 00264 return 0; 00265 } 00266 offset = offset * 3; 00267 unsigned char rgb[3]; 00268 rgb[0] = pb[offset]; 00269 rgb[1] = pb[offset+1]; 00270 rgb[2] = pb[offset+2]; 00271 int val = 0; 00272 val |= rgb[2]; 00273 val = val << 8; 00274 val |= rgb[1]; 00275 val = val << 8; 00276 val |= rgb[0]; 00277 return val; 00278 } 00279 00281 00282 int Convert(unsigned int pos[2], unsigned char* pb) 00283 { return this->Convert(pos[0], pos[1], pb); } 00284 int Convert(int xx, int yy, unsigned char* pb) 00285 { 00286 if (!pb) 00287 { 00288 return 0; 00289 } 00290 int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3; 00291 unsigned char rgb[3]; 00292 rgb[0] = pb[offset]; 00293 rgb[1] = pb[offset+1]; 00294 rgb[2] = pb[offset+2]; 00295 int val = 0; 00296 val |= rgb[2]; 00297 val = val << 8; 00298 val |= rgb[1]; 00299 val = val << 8; 00300 val |= rgb[0]; 00301 return val; 00302 } 00304 00305 vtkIdType GetID(int low24, int mid24, int high16) 00306 { 00307 vtkIdType val = 0; 00308 val |= high16; 00309 val = val << 24; 00310 val |= mid24; 00311 val = val << 24; 00312 val |= low24; 00313 return val; 00314 } 00315 00317 virtual bool PassRequired(int pass); 00318 00322 bool IsPropHit(int propid); 00323 00325 00326 virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop)) 00327 { return idx; } 00329 00330 virtual void BeginSelection(); 00331 virtual void EndSelection(); 00332 00333 void SavePixelBuffer(int passNo); 00334 void BuildPropHitList(unsigned char* rgbData); 00335 00337 00338 void ReleasePixBuffers(); 00339 vtkRenderer* Renderer; 00340 unsigned int Area[4]; 00341 int FieldAssociation; 00342 bool UseProcessIdFromData; 00343 vtkIdType MaxAttributeId; 00345 00346 // At most 10 passes. 00347 unsigned char* PixBuffer[10]; 00348 int ProcessID; 00349 int CurrentPass; 00350 int InPropRender; 00351 private: 00352 vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented. 00353 void operator=(const vtkHardwareSelector&); // Not implemented. 00354 00355 int PropID; 00356 class vtkInternals; 00357 vtkInternals* Internals; 00358 //ETX 00359 }; 00360 00361 #endif 00362 00363