VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkHardwareSelector.h,v $ 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 vtkTypeRevisionMacro(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 00113 bool CaptureBuffers(); 00114 bool GetPixelInformation(unsigned int display_position[2], 00115 int& processId, 00116 vtkIdType& attrId, vtkProp*& prop); 00117 void ClearBuffers() 00118 { this->ReleasePixBuffers(); } 00120 00123 void RenderAttributeId(vtkIdType attribid); 00124 00127 int Render(vtkRenderer* renderer, vtkProp** propArray, int propArrayCount); 00128 00130 00132 void BeginRenderProp(); 00133 void EndRenderProp(); 00135 00137 00139 vtkSetMacro(ProcessID, int); 00140 vtkGetMacro(ProcessID, int); 00142 00144 00145 vtkGetMacro(CurrentPass, int); 00147 00148 //BTX 00149 enum PassTypes 00150 { 00151 PROCESS_PASS, 00152 ACTOR_PASS, 00153 ID_LOW24, 00154 ID_MID24, 00155 ID_HIGH16, 00156 MAX_KNOWN_PASS = ID_HIGH16, 00157 MIN_KNOWN_PASS = PROCESS_PASS 00158 }; 00159 protected: 00160 vtkHardwareSelector(); 00161 ~vtkHardwareSelector(); 00162 00163 static void Convert(int id, float tcoord[3]) 00164 { 00165 tcoord[0] = static_cast<float>((id & 0xff)/255.0); 00166 tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0); 00167 tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0); 00168 } 00169 00170 int Convert(unsigned long offset, unsigned char* pb) 00171 { 00172 if (!pb) 00173 { 00174 return 0; 00175 } 00176 00177 offset = offset * 3; 00178 unsigned char rgb[3]; 00179 rgb[0] = pb[offset]; 00180 rgb[1] = pb[offset+1]; 00181 rgb[2] = pb[offset+2]; 00182 int val = 0; 00183 val |= rgb[2]; 00184 val = val << 8; 00185 val |= rgb[1]; 00186 val = val << 8; 00187 val |= rgb[0]; 00188 return val; 00189 } 00190 00191 int Convert(int xx, int yy, unsigned char* pb) 00192 { 00193 if (!pb) 00194 { 00195 return 0; 00196 } 00197 int offset = (yy * (this->Area[2]-this->Area[0]) + xx) * 3; 00198 unsigned char rgb[3]; 00199 rgb[0] = pb[offset]; 00200 rgb[1] = pb[offset+1]; 00201 rgb[2] = pb[offset+2]; 00202 int val = 0; 00203 val |= rgb[2]; 00204 val = val << 8; 00205 val |= rgb[1]; 00206 val = val << 8; 00207 val |= rgb[0]; 00208 return val; 00209 } 00210 00211 vtkIdType GetID(int low24, int mid24, int high16) 00212 { 00213 vtkIdType val = 0; 00214 val |= high16; 00215 val = val << 24; 00216 val |= mid24; 00217 val = val << 24; 00218 val |= low24; 00219 return val; 00220 } 00221 00223 virtual bool PassRequired(int pass); 00224 00228 bool IsPropHit(int propid); 00229 00231 virtual vtkSelection* GenerateSelection(); 00232 00234 00235 virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop)) 00236 { return idx; } 00238 00239 virtual void BeginSelection(); 00240 virtual void EndSelection(); 00241 00242 void SavePixelBuffer(int passNo); 00243 void BuildPropHitList(unsigned char* rgbData); 00244 00246 00247 void ReleasePixBuffers(); 00248 vtkRenderer* Renderer; 00249 unsigned int Area[4]; 00250 int FieldAssociation; 00251 vtkIdType MaxAttributeId; 00253 00254 // At most 10 passes. 00255 unsigned char* PixBuffer[10]; 00256 int ProcessID; 00257 int CurrentPass; 00258 private: 00259 vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented. 00260 void operator=(const vtkHardwareSelector&); // Not implemented. 00261 00262 int PropID; 00263 class vtkInternals; 00264 vtkInternals* Internals; 00265 //ETX 00266 }; 00267 00268 #endif 00269 00270