VTK
|
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 "vtkCommonCoreModule.h" // For export macro 00033 #include "vtkObject.h" 00034 00035 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject 00036 { 00037 public: 00038 static vtkIdList *New(); 00039 00040 void Initialize(); 00041 00044 int Allocate(const vtkIdType sz, const int strategy=0); 00045 00046 vtkTypeMacro(vtkIdList,vtkObject); 00047 void PrintSelf(ostream& os, vtkIndent indent); 00048 00050 vtkIdType GetNumberOfIds() {return this->NumberOfIds;}; 00051 00053 vtkIdType GetId(const vtkIdType i) {return this->Ids[i];}; 00054 00057 void SetNumberOfIds(const vtkIdType number); 00058 00062 void SetId(const vtkIdType i, const vtkIdType vtkid) {this->Ids[i] = vtkid;}; 00063 00066 void InsertId(const vtkIdType i, const vtkIdType vtkid); 00067 00070 vtkIdType InsertNextId(const vtkIdType vtkid); 00071 00074 vtkIdType InsertUniqueId(const vtkIdType vtkid); 00075 00077 vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;}; 00078 00082 vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number); 00083 00085 void Reset() {this->NumberOfIds = 0;}; 00086 00088 void Squeeze() {this->Resize(this->NumberOfIds);}; 00089 00091 void DeepCopy(vtkIdList *ids); 00092 00095 void DeleteId(vtkIdType vtkid); 00096 00099 vtkIdType IsId(vtkIdType vtkid); 00100 00103 void IntersectWith(vtkIdList* otherIds); 00104 00105 //BTX 00106 // This method should become legacy 00107 void IntersectWith(vtkIdList& otherIds) { 00108 this->IntersectWith(&otherIds); }; 00109 //ETX 00110 00111 protected: 00112 vtkIdList(); 00113 ~vtkIdList(); 00114 00115 vtkIdType NumberOfIds; 00116 vtkIdType Size; 00117 vtkIdType *Ids; 00118 00119 vtkIdType *Resize(const vtkIdType sz); 00120 private: 00121 vtkIdList(const vtkIdList&); // Not implemented. 00122 void operator=(const vtkIdList&); // Not implemented. 00123 }; 00124 00125 // In-lined for performance 00126 inline vtkIdType vtkIdList::InsertNextId(const vtkIdType vtkid) 00127 { 00128 if ( this->NumberOfIds >= this->Size ) 00129 { 00130 this->Resize(this->NumberOfIds+1); 00131 } 00132 this->Ids[this->NumberOfIds++] = vtkid; 00133 return this->NumberOfIds-1; 00134 } 00135 00136 inline vtkIdType vtkIdList::IsId(vtkIdType vtkid) 00137 { 00138 vtkIdType *ptr, i; 00139 for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++) 00140 { 00141 if ( vtkid == *ptr ) 00142 { 00143 return i; 00144 } 00145 } 00146 return (-1); 00147 } 00148 00149 #endif