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: 00075 static vtkHardwareSelector* New(); 00076 vtkTypeMacro(vtkHardwareSelector, vtkObject); 00077 void PrintSelf(ostream& os, vtkIndent indent); 00078 00080 00081 void SetRenderer(vtkRenderer*); 00082 vtkGetObjectMacro(Renderer, vtkRenderer); 00084 00086 00087 vtkSetVector4Macro(Area, unsigned int); 00088 vtkGetVector4Macro(Area, unsigned int); 00090 00092 00099 vtkSetMacro(FieldAssociation, int); 00100 vtkGetMacro(FieldAssociation, int); 00102 00105 vtkSelection* Select(); 00106 00108 00115 bool CaptureBuffers(); 00116 bool GetPixelInformation(unsigned int display_position[2], 00117 int& processId, 00118 vtkIdType& attrId, vtkProp*& prop) 00119 { return this->GetPixelInformation(display_position, processId, attrId, prop, 0); } 00120 bool GetPixelInformation(unsigned int display_position[2], 00121 int& processId, 00122 vtkIdType& attrId, vtkProp*& prop, int maxDist); 00123 void ClearBuffers() 00124 { this->ReleasePixBuffers(); } 00126 00129 void RenderAttributeId(vtkIdType attribid); 00130 00133 int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount); 00134 00136 00138 void BeginRenderProp(); 00139 void EndRenderProp(); 00141 00143 00145 vtkSetMacro(ProcessID, int); 00146 vtkGetMacro(ProcessID, int); 00148 00150 00151 vtkGetMacro(CurrentPass, int); 00153 00155 00160 virtual vtkSelection* GenerateSelection() 00161 { return GenerateSelection(this->Area); } 00162 virtual vtkSelection* GenerateSelection(unsigned int r[4]) 00163 { return GenerateSelection(r[0], r[1], r[2], r[3]); } 00164 virtual vtkSelection* GenerateSelection( 00165 unsigned int x1, unsigned int y1, 00166 unsigned int x2, unsigned int y2); 00168 00169 //BTX 00170 enum PassTypes 00171 { 00172 PROCESS_PASS, 00173 ACTOR_PASS, 00174 ID_LOW24, 00175 ID_MID24, 00176 ID_HIGH16, 00177 MAX_KNOWN_PASS = ID_HIGH16, 00178 MIN_KNOWN_PASS = PROCESS_PASS 00179 }; 00180 protected: 00181 vtkHardwareSelector(); 00182 ~vtkHardwareSelector(); 00183 00184 static void Convert(int id, float tcoord[3]) 00185 { 00186 tcoord[0] = static_cast<float>((id & 0xff)/255.0); 00187 tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0); 00188 tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0); 00189 } 00190 00191 int Convert(unsigned long offset, unsigned char* pb) 00192 { 00193 if (!pb) 00194 { 00195 return 0; 00196 } 00197 00198 offset = offset * 3; 00199 unsigned char rgb[3]; 00200 rgb[0] = pb[offset]; 00201 rgb[1] = pb[offset+1]; 00202 rgb[2] = pb[offset+2]; 00203 int val = 0; 00204 val |= rgb[2]; 00205 val = val << 8; 00206 val |= rgb[1]; 00207 val = val << 8; 00208 val |= rgb[0]; 00209 return val; 00210 } 00211 00212 int Convert(int xx, int yy, unsigned char* pb) 00213 { 00214 if (!pb) 00215 { 00216 return 0; 00217 } 00218 int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3; 00219 unsigned char rgb[3]; 00220 rgb[0] = pb[offset]; 00221 rgb[1] = pb[offset+1]; 00222 rgb[2] = pb[offset+2]; 00223 int val = 0; 00224 val |= rgb[2]; 00225 val = val << 8; 00226 val |= rgb[1]; 00227 val = val << 8; 00228 val |= rgb[0]; 00229 return val; 00230 } 00231 00232 vtkIdType GetID(int low24, int mid24, int high16) 00233 { 00234 vtkIdType val = 0; 00235 val |= high16; 00236 val = val << 24; 00237 val |= mid24; 00238 val = val << 24; 00239 val |= low24; 00240 return val; 00241 } 00242 00244 virtual bool PassRequired(int pass); 00245 00249 bool IsPropHit(int propid); 00250 00252 00253 virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop)) 00254 { return idx; } 00256 00257 virtual void BeginSelection(); 00258 virtual void EndSelection(); 00259 00260 void SavePixelBuffer(int passNo); 00261 void BuildPropHitList(unsigned char* rgbData); 00262 00264 00265 void ReleasePixBuffers(); 00266 vtkRenderer* Renderer; 00267 unsigned int Area[4]; 00268 int FieldAssociation; 00269 vtkIdType MaxAttributeId; 00271 00272 // At most 10 passes. 00273 unsigned char* PixBuffer[10]; 00274 int ProcessID; 00275 int CurrentPass; 00276 private: 00277 vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented. 00278 void operator=(const vtkHardwareSelector&); // Not implemented. 00279 00280 int PropID; 00281 class vtkInternals; 00282 vtkInternals* Internals; 00283 //ETX 00284 }; 00285 00286 #endif 00287 00288