1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkGenericAttributeCollection.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /** 16 * @class vtkGenericAttributeCollection 17 * @brief a collection of attributes 18 * 19 * vtkGenericAttributeCollection is a class that collects attributes 20 * (represented by vtkGenericAttribute). 21 */ 22 23 #ifndef vtkGenericAttributeCollection_h 24 #define vtkGenericAttributeCollection_h 25 26 #include "vtkCommonDataModelModule.h" // For export macro 27 #include "vtkObject.h" 28 29 class vtkGenericAttributeInternalVector; 30 class vtkIntInternalVector; 31 class vtkGenericAttribute; 32 33 class VTKCOMMONDATAMODEL_EXPORT vtkGenericAttributeCollection : public vtkObject 34 { 35 public: 36 /** 37 * Create an empty collection. 38 */ 39 static vtkGenericAttributeCollection *New(); 40 41 //@{ 42 /** 43 * Standard type definition and print methods for a VTK class. 44 */ 45 vtkTypeMacro(vtkGenericAttributeCollection,vtkObject); 46 void PrintSelf(ostream& os, vtkIndent indent) override; 47 //@} 48 49 /** 50 * Return the number of attributes (e.g., instances of vtkGenericAttribute) 51 * in the collection. 52 * \post positive_result: result>=0 53 */ 54 int GetNumberOfAttributes(); 55 56 /** 57 * Return the number of components. This is the sum of all components 58 * found in all attributes. 59 * \post positive_result: result>=0 60 */ 61 int GetNumberOfComponents(); 62 63 /** 64 * Return the number of components. This is the sum of all components 65 * found in all point centered attributes. 66 * \post positive_result: result>=0 67 */ 68 int GetNumberOfPointCenteredComponents(); 69 70 /** 71 * Maximum number of components encountered among all attributes. 72 * \post positive_result: result>=0 73 * \post valid_result: result<=GetNumberOfComponents() 74 */ 75 int GetMaxNumberOfComponents(); 76 77 /** 78 * Actual size of the data in kibibytes (1024 bytes); only valid after the pipeline has 79 * updated. It is guaranteed to be greater than or equal to the memory 80 * required to represent the data. 81 */ 82 unsigned long GetActualMemorySize(); 83 84 /** 85 * Indicate whether the collection contains any attributes. 86 * \post definition: result==(GetNumberOfAttributes()==0) 87 */ 88 int IsEmpty(); 89 90 /** 91 * Return a pointer to the ith instance of vtkGenericAttribute. 92 * \pre not_empty: !IsEmpty() 93 * \pre valid_i: i>=0 && i<GetNumberOfAttributes() 94 * \post result_exists: result!=0 95 */ 96 vtkGenericAttribute *GetAttribute(int i); 97 98 /** 99 * Return the index of the attribute named `name'. Return the non-negative 100 * index if found. Return -1 otherwise. 101 * \pre name_exists: name!=0 102 * \post valid_result: (result==-1) || (result>=0) && (result<=GetNumberOfAttributes()) 103 */ 104 int FindAttribute(const char *name); 105 106 /** 107 * Return the index of the first component of attribute `i' in an array of 108 * format attrib0comp0 attrib0comp1 ... attrib4comp0 ... 109 * \pre valid_i: i>=0 && i<GetNumberOfAttributes() 110 * \pre is_point_centered: GetAttribute(i)->GetCentering()==vtkPointCentered 111 */ 112 int GetAttributeIndex(int i); 113 114 /** 115 * Add the attribute `a' to the end of the collection. 116 * \pre a_exists: a!=0 117 * \post more_items: GetNumberOfAttributes()==old GetNumberOfAttributes()+1 118 * \post a_is_set: GetAttribute(GetNumberOfAttributes()-1)==a 119 */ 120 void InsertNextAttribute(vtkGenericAttribute *a); 121 122 /** 123 * Replace the attribute at index `i' by `a'. 124 * \pre not_empty: !IsEmpty() 125 * \pre a_exists: a!=0 126 * \pre valid_i: i>=0 && i<GetNumberOfAttributes() 127 * \post same_size: GetNumberOfAttributes()==old GetNumberOfAttributes() 128 * \post item_is_set: GetAttribute(i)==a 129 */ 130 void InsertAttribute(int i, vtkGenericAttribute *a); 131 132 /** 133 * Remove the attribute at `i'. 134 * \pre not_empty: !IsEmpty() 135 * \pre valid_i: i>=0 && i<GetNumberOfAttributes() 136 * \post fewer_items: GetNumberOfAttributes()==old GetNumberOfAttributes()-1 137 */ 138 void RemoveAttribute(int i); 139 140 /** 141 * Remove all attributes. 142 * \post is_empty: GetNumberOfAttributes()==0 143 */ 144 void Reset(); 145 146 /** 147 * Copy, without reference counting, the other attribute array. 148 * \pre other_exists: other!=0 149 * \pre not_self: other!=this 150 * \post same_size: GetNumberOfAttributes()==other->GetNumberOfAttributes() 151 */ 152 void DeepCopy(vtkGenericAttributeCollection *other); 153 154 /** 155 * Copy, via reference counting, the other attribute array. 156 * \pre other_exists: other!=0 157 * \pre not_self: other!=this 158 * \post same_size: GetNumberOfAttributes()==other->GetNumberOfAttributes() 159 */ 160 void ShallowCopy(vtkGenericAttributeCollection *other); 161 162 /** 163 * vtkAttributeCollection is a composite object and needs to check each 164 * member of its collection for modified time. 165 */ 166 vtkMTimeType GetMTime() override; 167 168 // *** ALL THE FOLLOWING METHODS SHOULD BE REMOVED WHEN when the 169 // new pipeline update mechanism is checked in. 170 // *** BEGIN 171 172 //@{ 173 /** 174 * Index of the attribute to be processed (not necessarily scalar). 175 * \pre not_empty: !IsEmpty() 176 * \post valid_result: result>=0 && result<GetNumberOfAttributes() 177 */ 178 vtkGetMacro(ActiveAttribute, int); 179 //@} 180 181 //@{ 182 /** 183 * Component of the active attribute to be processed. -1 means module. 184 * \pre not_empty: GetNumberOfAttributes()>0 185 * \post valid_result: result>=-1 && 186 * result<GetAttribute(GetActiveAttribute())->GetNumberOfComponents() 187 */ 188 vtkGetMacro(ActiveComponent, int); 189 //@} 190 191 /** 192 * Set the scalar attribute to be processed. -1 means module. 193 * \pre not_empty: !IsEmpty() 194 * \pre valid_attribute: attribute>=0 && attribute<GetNumberOfAttributes() 195 * \pre valid_component: component>=-1 && 196 * component<GetAttribute(attribute)->GetNumberOfComponents() 197 * \post is_set: GetActiveAttribute()==attribute && 198 * GetActiveComponent()==component 199 */ 200 void SetActiveAttribute(int attribute, int component = 0); 201 202 //@{ 203 /** 204 * Number of attributes to interpolate. 205 * \pre not_empty: !IsEmpty() 206 * \post positive_result: result>=0 207 */ 208 vtkGetMacro(NumberOfAttributesToInterpolate, int); 209 //@} 210 211 /** 212 * Indices of attributes to interpolate. 213 * \pre not_empty: !IsEmpty() 214 * \post valid_result: GetNumberOfAttributesToInterpolate()>0 215 */ 216 int *GetAttributesToInterpolate(); 217 218 /** 219 * Does the array `attributes' of size `size' have `attribute'? 220 * \pre positive_size: size>=0 221 * \pre valid_attributes: size>0 implies attributes!=0 222 */ 223 int HasAttribute(int size, int *attributes, int attribute); 224 225 //@{ 226 /** 227 * Set the attributes to interpolate. 228 * \pre not_empty: !IsEmpty() 229 * \pre positive_size: size>=0 230 * \pre valid_attributes: size>0 implies attributes!=0 231 * \pre valid_attributes_contents: attributes!=0 implies 232 * !HasAttributes(size,attributes,GetActiveAttribute()) 233 * \post is_set: (GetNumberOfAttributesToInterpolate()==size)&& 234 * (GetAttributesToInterpolate()==attributes) 235 */ 236 void SetAttributesToInterpolate(int size, int *attributes); 237 void SetAttributesToInterpolateToAll(); 238 //@} 239 240 protected: 241 /** 242 * Default constructor: empty collection. 243 */ 244 vtkGenericAttributeCollection(); 245 246 /** 247 * Destructor. 248 */ 249 ~vtkGenericAttributeCollection() override; 250 251 /** 252 * STL vector for storing attributes 253 */ 254 vtkGenericAttributeInternalVector* AttributeInternalVector; 255 /** 256 * STL vector for storing index of point centered attributes 257 */ 258 vtkIntInternalVector *AttributeIndices; 259 260 int ActiveAttribute; 261 int ActiveComponent; 262 int NumberOfAttributesToInterpolate; 263 int AttributesToInterpolate[10]; 264 265 int NumberOfComponents; // cache 266 int NumberOfPointCenteredComponents; // cache 267 int MaxNumberOfComponents; // cache 268 unsigned long ActualMemorySize; // cache 269 vtkTimeStamp ComputeTime; // cache time stamp 270 271 /** 272 * Compute number of components, max number of components and actual 273 * memory size. 274 */ 275 void ComputeNumbers(); 276 277 private: 278 vtkGenericAttributeCollection(const vtkGenericAttributeCollection &) = delete; 279 void operator=(const vtkGenericAttributeCollection &) = delete; 280 }; 281 #endif 282