VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Rendering/Core/vtkHardwareSelector.h
Go to the documentation of this file.
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   virtual void RenderCompositeIndex(unsigned int index);
00172 
00175   virtual void RenderAttributeId(vtkIdType attribid);
00176 
00179   virtual 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   vtkGetVector3Macro(PropColorValue,float);
00202   vtkSetVector3Macro(PropColorValue,float);
00204 
00206 
00207   vtkGetMacro(CurrentPass, int);
00209 
00211 
00216   virtual vtkSelection* GenerateSelection()
00217     { return GenerateSelection(this->Area); }
00218   virtual vtkSelection* GenerateSelection(unsigned int r[4])
00219     { return GenerateSelection(r[0], r[1], r[2], r[3]); }
00220   virtual vtkSelection* GenerateSelection(
00221     unsigned int x1, unsigned int y1,
00222     unsigned int x2, unsigned int y2);
00224 
00226 
00230   virtual vtkSelection* GeneratePolygonSelection(
00231     int* polygonPoints, vtkIdType count);
00233 
00236   vtkProp* GetPropFromID(int id);
00237 
00238 //BTX
00239   enum PassTypes
00240     {
00241     PROCESS_PASS,
00242     ACTOR_PASS,
00243     COMPOSITE_INDEX_PASS,
00244     ID_LOW24,
00245     ID_MID24,
00246     ID_HIGH16,
00247     MAX_KNOWN_PASS = ID_HIGH16,
00248     MIN_KNOWN_PASS = PROCESS_PASS
00249     };
00250 
00251   static void Convert(int id, float tcoord[3])
00252     {
00253     tcoord[0] = static_cast<float>((id & 0xff)/255.0);
00254     tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
00255     tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
00256     }
00257 
00258 protected:
00259   vtkHardwareSelector();
00260   ~vtkHardwareSelector();
00261 
00262   // Called internally before and after each prop is rendered
00263   // for device specific configuration/preparation etc.
00264   virtual void BeginRenderProp(vtkRenderWindow *) = 0;
00265   virtual void EndRenderProp(vtkRenderWindow *) = 0;
00266 
00267   int Convert(unsigned long offset, unsigned char* pb)
00268     {
00269     if (!pb)
00270       {
00271       return 0;
00272       }
00273     offset = offset * 3;
00274     unsigned char rgb[3];
00275     rgb[0] = pb[offset];
00276     rgb[1] = pb[offset+1];
00277     rgb[2] = pb[offset+2];
00278     int val = 0;
00279     val |= rgb[2];
00280     val = val << 8;
00281     val |= rgb[1];
00282     val = val << 8;
00283     val |= rgb[0];
00284     return val;
00285     }
00286 
00288 
00289   int Convert(unsigned int pos[2], unsigned char* pb)
00290     { return this->Convert(pos[0], pos[1], pb); }
00291   int Convert(int xx, int yy, unsigned char* pb)
00292     {
00293     if (!pb)
00294       {
00295       return 0;
00296       }
00297     int offset = (yy * static_cast<int>(this->Area[2]-this->Area[0]+1) + xx) * 3;
00298     unsigned char rgb[3];
00299     rgb[0] = pb[offset];
00300     rgb[1] = pb[offset+1];
00301     rgb[2] = pb[offset+2];
00302     int val = 0;
00303     val |= rgb[2];
00304     val = val << 8;
00305     val |= rgb[1];
00306     val = val << 8;
00307     val |= rgb[0];
00308     return val;
00309     }
00311 
00312   vtkIdType GetID(int low24, int mid24, int high16)
00313     {
00314     vtkIdType val = 0;
00315     val |= high16;
00316     val = val << 24;
00317     val |= mid24;
00318     val = val << 24;
00319     val |= low24;
00320     return val;
00321     }
00322 
00324   virtual bool PassRequired(int pass);
00325 
00329   bool IsPropHit(int propid);
00330 
00332 
00333   virtual int GetPropID(int idx, vtkProp* vtkNotUsed(prop))
00334     { return idx; }
00336 
00337   virtual void BeginSelection();
00338   virtual void EndSelection();
00339 
00340   void SavePixelBuffer(int passNo);
00341   void BuildPropHitList(unsigned char* rgbData);
00342 
00344 
00345   void ReleasePixBuffers();
00346   vtkRenderer* Renderer;
00347   unsigned int Area[4];
00348   int FieldAssociation;
00349   bool UseProcessIdFromData;
00350   vtkIdType MaxAttributeId;
00352 
00353   // At most 10 passes.
00354   unsigned char* PixBuffer[10];
00355   int ProcessID;
00356   int CurrentPass;
00357   int InPropRender;
00358   int PropID;
00359   float PropColorValue[3];
00360 
00361 private:
00362   vtkHardwareSelector(const vtkHardwareSelector&); // Not implemented.
00363   void operator=(const vtkHardwareSelector&); // Not implemented.
00364 
00365   class vtkInternals;
00366   vtkInternals* Internals;
00367 //ETX
00368 };
00369 
00370 #endif
00371 
00372