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 00107 vtkIdType *Resize(const vtkIdType sz); 00108 00109 //BTX 00110 // This method should become legacy 00111 void IntersectWith(vtkIdList& otherIds) { 00112 this->IntersectWith(&otherIds); }; 00113 //ETX 00114 00115 protected: 00116 vtkIdList(); 00117 ~vtkIdList(); 00118 00119 vtkIdType NumberOfIds; 00120 vtkIdType Size; 00121 vtkIdType *Ids; 00122 00123 private: 00124 vtkIdList(const vtkIdList&); // Not implemented. 00125 void operator=(const vtkIdList&); // Not implemented. 00126 }; 00127 00128 // In-lined for performance 00129 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid) 00130 { 00131 if (i >= this->Size) 00132 { 00133 this->Resize(i + 1); 00134 } 00135 this->Ids[i] = vtkid; 00136 if (i >= this->NumberOfIds) 00137 { 00138 this->NumberOfIds = i + 1; 00139 } 00140 } 00141 00142 // In-lined for performance 00143 inline vtkIdType vtkIdList::InsertNextId(const vtkIdType vtkid) 00144 { 00145 if ( this->NumberOfIds >= this->Size ) 00146 { 00147 this->Resize(this->NumberOfIds+1); 00148 } 00149 this->Ids[this->NumberOfIds++] = vtkid; 00150 return this->NumberOfIds-1; 00151 } 00152 00153 inline vtkIdType vtkIdList::IsId(vtkIdType vtkid) 00154 { 00155 vtkIdType *ptr, i; 00156 for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++) 00157 { 00158 if ( vtkid == *ptr ) 00159 { 00160 return i; 00161 } 00162 } 00163 return (-1); 00164 } 00165 00166 #endif