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 vtkSelection; 00071 class vtkProp; 00072 class vtkTextureObject; 00073 00074 class VTKRENDERINGCORE_EXPORT vtkHardwareSelector : public vtkObject 00075 { 00076 public: 00078 00079 struct PixelInformation 00080 { 00081 bool Valid; 00082 int ProcessID; 00083 int PropID; 00084 vtkProp* Prop; 00085 unsigned int CompositeID; 00086 vtkIdType AttributeID; 00087 PixelInformation(): 00088 Valid(false), 00089 ProcessID(-1), 00090 Prop(NULL), 00091 CompositeID(0), 00092 AttributeID(-1) {} 00093 }; 00095 00096 public: 00097 static vtkHardwareSelector* New(); 00098 vtkTypeMacro(vtkHardwareSelector, vtkObject); 00099 void PrintSelf(ostream& os, vtkIndent indent); 00100 00102 00103 void SetRenderer(vtkRenderer*); 00104 vtkGetObjectMacro(Renderer, vtkRenderer); 00106 00108 00109 vtkSetVector4Macro(Area, unsigned int); 00110 vtkGetVector4Macro(Area, unsigned int); 00112 00114 00121 vtkSetMacro(FieldAssociation, int); 00122 vtkGetMacro(FieldAssociation, int); 00124 00126 00129 vtkSetMacro(UseProcessIdFromData, bool); 00130 vtkGetMacro(UseProcessIdFromData, bool); 00132 00135 vtkSelection* Select(); 00136 00138 00145 virtual bool CaptureBuffers(); 00146 PixelInformation GetPixelInformation(unsigned int display_position[2]) 00147 { return this->GetPixelInformation(display_position, 0); } 00148 PixelInformation GetPixelInformation(unsigned int display_position[2], 00149 int maxDist); 00150 void ClearBuffers() 00151 { this->ReleasePixBuffers(); } 00153 00155 00157 VTK_LEGACY(bool GetPixelInformation(unsigned int display_position[2], 00158 int& processId, vtkIdType& attrId, vtkProp*& prop)); 00160 00162 00164 VTK_LEGACY(bool GetPixelInformation(unsigned int display_position[2], 00165 int& processId, vtkIdType& attrId, vtkProp*& prop, int maxDist)); 00167 00170 void RenderCompositeIndex(unsigned int index); 00171 00174 void RenderAttributeId(vtkIdType attribid); 00175 00178 void RenderProcessId(unsigned int processid); 00179 00182 int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount); 00183 00185 00187 void BeginRenderProp(); 00188 void EndRenderProp(); 00190 00192 00194 vtkSetMacro(ProcessID, int); 00195 vtkGetMacro(ProcessID, int); 00197 00199 00200 vtkGetMacro(CurrentPass, int); 00202 00204 00209 virtual vtkSelection* GenerateSelection() 00210 { return GenerateSelection(this->Area); } 00211 virtual vtkSelection* GenerateSelection(unsigned int r[4]) 00212 { return GenerateSelection(r[0], r[1], r[2], r[3]); } 00213 virtual vtkSelection* GenerateSelection( 00214 unsigned int x1, unsigned int y1, 00215 unsigned int x2, unsigned int y2); 00217 00219 00223 virtual vtkSelection* GeneratePolygonSelection( 00224 int* polygonPoints, vtkIdType count); 00226 00229 vtkProp* GetPropFromID(int id); 00230 00231 //BTX 00232 enum PassTypes 00233 { 00234 PROCESS_PASS, 00235 ACTOR_PASS, 00236 COMPOSITE_INDEX_PASS, 00237 ID_LOW24, 00238 ID_MID24, 00239 ID_HIGH16, 00240 MAX_KNOWN_PASS = ID_HIGH16, 00241 MIN_KNOWN_PASS = PROCESS_PASS 00242 }; 00243 protected: 00244 vtkHardwareSelector(); 00245 ~vtkHardwareSelector(); 00246 00247 static void Convert(int id, float tcoord[3]) 00248 { 00249 tcoord[0] = static_cast<float>((id & 0xff)/255.0); 00250 tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0); 00251 tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0); 00252 } 00253 00254 int Convert(unsigned long offset, unsigned char* pb) 00255 { 00256 if (!pb) 00257 { 00258 return 0; 00259 } 00260 00261 offset = offset * 3; 00262 unsigned char rgb[3]; 00263 rgb[0] = pb[offset]; 00264 rgb[1] = pb[offset+1]; 00265 rgb[2] = pb[offset+2]; 00266 int val = 0; 00267 val |= rgb[2]; 00268 val = val << 8; 00269 val |= rgb[1]; 00270 val = val << 8; 00271 val |= rgb[0]; 00272 return val; 00273 } 00274 00276 00277 int Convert(unsigned int pos[2], unsigned char* pb) 00278 { return this->Convert(pos[0], pos[1], pb); } 00279 int Convert(int xx, int yy, unsigned char* pb) 00280 { 00281 if (!pb) 00282 { 00283 return 0; 00284 } 00285 int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3; 00286 unsigned char rgb[3]; 00287 rgb[0] = pb[offset]; 00288 rgb[1] = pb[offset+1]; 00289 rgb[2] = pb[offset+2]; 00290 int val = 0; 00291 val |= rgb[2]; 00292 val = val << 8; 00293 val |= rgb[1]; 00294 val = val << 8; 00295 val |= rgb[0]; 00296 return val; 00297 } 00299 00300 vtkIdType GetID(int low24, int mid24, int high16) 00301 { 00302 vtkIdType val = 0; 00303 val |= high16; 00304 val = val << 24; 00305 val |= mid24; 00306 val = val << 24; 00307 val |= low24; 00308 return val; 00309 } 00310 00312 virtual bool PassRequired(int pass); 00313 00317 bool IsPropHit(int propid); 00318 00320 00321 virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop)) 00322 { return idx; } 00324 00325 virtual void BeginSelection(); 00326 virtual void EndSelection(); 00327 00328 void SavePixelBuffer(int passNo); 00329 void BuildPropHitList(unsigned char* rgbData); 00330 00332 00333 void ReleasePixBuffers(); 00334 vtkRenderer* Renderer; 00335 unsigned int Area[4]; 00336 int FieldAssociation; 00337 bool UseProcessIdFromData; 00338 vtkIdType MaxAttributeId; 00340 00341 // At most 10 passes. 00342 unsigned char* PixBuffer[10]; 00343 int ProcessID; 00344 int CurrentPass; 00345 int InPropRender; 00346 private: 00347 vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented. 00348 void operator=(const vtkHardwareSelector&); // Not implemented. 00349 00350 int PropID; 00351 class vtkInternals; 00352 vtkInternals* Internals; 00353 //ETX 00354 }; 00355 00356 #endif 00357 00358