VTK
dox/Common/vtkIdList.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkIdList.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 =========================================================================*/
00029 #ifndef __vtkIdList_h
00030 #define __vtkIdList_h
00031 
00032 #include "vtkObject.h"
00033 
00034 class VTK_COMMON_EXPORT vtkIdList : public vtkObject
00035 {
00036 public:
00037   static vtkIdList *New();
00038 
00039   void Initialize();
00040   int Allocate(const vtkIdType sz, const int strategy=0);
00041   vtkTypeMacro(vtkIdList,vtkObject);
00042   void PrintSelf(ostream& os, vtkIndent indent);
00043 
00045   vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
00046   
00048   vtkIdType GetId(const vtkIdType i) {return this->Ids[i];};
00049   
00052   void SetNumberOfIds(const vtkIdType number);
00053 
00057   void SetId(const vtkIdType i, const vtkIdType vtkid) {this->Ids[i] = vtkid;};
00058 
00061   void InsertId(const vtkIdType i, const vtkIdType vtkid);
00062 
00065   vtkIdType InsertNextId(const vtkIdType vtkid);
00066 
00069   vtkIdType InsertUniqueId(const vtkIdType vtkid);
00070 
00072   vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
00073 
00077   vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
00078 
00080   void Reset() {this->NumberOfIds = 0;};
00081 
00083   void Squeeze() {this->Resize(this->NumberOfIds);};
00084 
00086   void DeepCopy(vtkIdList *ids);
00087 
00090   void DeleteId(vtkIdType vtkid);
00091 
00094   vtkIdType IsId(vtkIdType vtkid);
00095 
00098   void IntersectWith(vtkIdList* otherIds);
00099 
00100   //BTX
00101   // This method should become legacy
00102   void IntersectWith(vtkIdList& otherIds) {
00103     return this->IntersectWith(&otherIds); };
00104   //ETX
00105 
00106 protected:
00107   vtkIdList();
00108   ~vtkIdList();
00109 
00110   vtkIdType NumberOfIds;
00111   vtkIdType Size; 
00112   vtkIdType *Ids;
00113 
00114   vtkIdType *Resize(const vtkIdType sz);
00115 private:
00116   vtkIdList(const vtkIdList&);  // Not implemented.
00117   void operator=(const vtkIdList&);  // Not implemented.
00118 };
00119 
00120 // In-lined for performance
00121 inline vtkIdType vtkIdList::InsertNextId(const vtkIdType vtkid)
00122 {
00123   if ( this->NumberOfIds >= this->Size )
00124     {
00125     this->Resize(this->NumberOfIds+1);
00126     }
00127   this->Ids[this->NumberOfIds++] = vtkid;
00128   return this->NumberOfIds-1;
00129 }
00130 
00131 inline vtkIdType vtkIdList::IsId(vtkIdType vtkid)
00132 {
00133   vtkIdType *ptr, i;
00134   for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
00135     {
00136     if ( vtkid == *ptr )
00137       {
00138       return i;
00139       }
00140     }
00141   return (-1);
00142 }
00143 
00144 #endif