1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkCompositeDataSet.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 vtkCompositeDataSet 17 * @brief abstract superclass for composite 18 * (multi-block or AMR) datasets 19 * 20 * vtkCompositeDataSet is an abstract class that represents a collection 21 * of datasets (including other composite datasets). It 22 * provides an interface to access the datasets through iterators. 23 * vtkCompositeDataSet provides methods that are used by subclasses to store the 24 * datasets. 25 * vtkCompositeDataSet provides the datastructure for a full tree 26 * representation. Subclasses provide the semantics for it and control how 27 * this tree is built. 28 * 29 * @sa 30 * vtkCompositeDataIterator 31 */ 32 33 #ifndef vtkCompositeDataSet_h 34 #define vtkCompositeDataSet_h 35 36 #include "vtkCommonDataModelModule.h" // For export macro 37 #include "vtkDataObject.h" 38 39 #include <vector> // For GetDataSets 40 41 class vtkCompositeDataIterator; 42 class vtkCompositeDataSetInternals; 43 class vtkDataSet; 44 class vtkInformation; 45 class vtkInformationStringKey; 46 class vtkInformationIntegerKey; 47 48 class VTKCOMMONDATAMODEL_EXPORT vtkCompositeDataSet : public vtkDataObject 49 { 50 public: 51 vtkTypeMacro(vtkCompositeDataSet, vtkDataObject); 52 void PrintSelf(ostream& os, vtkIndent indent) override; 53 54 /** 55 * Return a new iterator (the iterator has to be deleted by user). 56 */ 57 virtual VTK_NEWINSTANCE vtkCompositeDataIterator* NewIterator() = 0; 58 59 /** 60 * Return class name of data type (see vtkType.h for 61 * definitions). 62 */ GetDataObjectType()63 int GetDataObjectType() override { return VTK_COMPOSITE_DATA_SET; } 64 65 /** 66 * Copies the tree structure from the input. All pointers to non-composite 67 * data objects are initialized to nullptr. This also shallow copies the meta data 68 * associated with all the nodes. 69 */ 70 virtual void CopyStructure(vtkCompositeDataSet* input); 71 72 /** 73 * Sets the data set at the location pointed by the iterator. 74 * The iterator does not need to be iterating over this dataset itself. It can 75 * be any composite datasite with similar structure (achieved by using 76 * CopyStructure). 77 */ 78 virtual void SetDataSet(vtkCompositeDataIterator* iter, vtkDataObject* dataObj) = 0; 79 80 /** 81 * Returns the dataset located at the positiong pointed by the iterator. 82 * The iterator does not need to be iterating over this dataset itself. It can 83 * be an iterator for composite dataset with similar structure (achieved by 84 * using CopyStructure). 85 */ 86 virtual vtkDataObject* GetDataSet(vtkCompositeDataIterator* iter) = 0; 87 88 /** 89 * Return the actual size of the data in kibibytes (1024 bytes). This number 90 * is valid only after the pipeline has updated. 91 */ 92 unsigned long GetActualMemorySize() override; 93 94 ///@{ 95 /** 96 * Retrieve an instance of this class from an information object. 97 */ 98 static vtkCompositeDataSet* GetData(vtkInformation* info); 99 static vtkCompositeDataSet* GetData(vtkInformationVector* v, int i = 0); 100 ///@} 101 102 /** 103 * Restore data object to initial state, 104 */ 105 void Initialize() override; 106 107 ///@{ 108 /** 109 * Shallow and Deep copy. 110 */ 111 void ShallowCopy(vtkDataObject* src) override; 112 void DeepCopy(vtkDataObject* src) override; 113 ///@} 114 115 /** 116 * For historical reasons, `vtkCompositeDataSet::ShallowCopy` simply pass 117 * pointers to the leaf non-composite datasets. In some cases, we truly want 118 * to shallow copy those leaf non-composite datasets as well. For those cases, 119 * use this method. 120 */ 121 virtual void RecursiveShallowCopy(vtkDataObject* src) = 0; 122 123 /** 124 * Returns the total number of points of all blocks. This will 125 * iterate over all blocks and call GetNumberOfPoints() so it 126 * might be expensive. 127 */ 128 virtual vtkIdType GetNumberOfPoints(); 129 130 /** 131 * Returns the total number of cells of all blocks. This will 132 * iterate over all blocks and call GetNumberOfPoints() so it 133 * might be expensive. 134 */ 135 virtual vtkIdType GetNumberOfCells(); 136 137 /** 138 * Get the number of elements for a specific attribute type (POINT, CELL, etc.). 139 */ 140 vtkIdType GetNumberOfElements(int type) override; 141 142 /** 143 * Return the geometric bounding box in the form (xmin,xmax, ymin,ymax, 144 * zmin,zmax). Note that if the composite dataset contains abstract types 145 * (i.e., non vtkDataSet types) such as tables these will be ignored by the 146 * method. In cases where no vtkDataSet is contained in the composite 147 * dataset then the returned bounds will be undefined. THIS METHOD IS 148 * THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND THE DATASET IS NOT 149 * MODIFIED. 150 */ 151 void GetBounds(double bounds[6]); 152 153 /** 154 * Key used to put node name in the meta-data associated with a node. 155 */ 156 static vtkInformationStringKey* NAME(); 157 158 /** 159 * Key used to indicate that the current process can load the data 160 * in the node. Used for parallel readers where the nodes are assigned 161 * to the processes by the reader to indicate further down the pipeline 162 * which nodes will be on which processes. 163 * ***THIS IS AN EXPERIMENTAL KEY SUBJECT TO CHANGE WITHOUT NOTICE*** 164 */ 165 static vtkInformationIntegerKey* CURRENT_PROCESS_CAN_LOAD_BLOCK(); 166 167 /** 168 * Extract datasets from the given data object. This method returns a vector 169 * of DataSetT* from the `dobj`. If dobj is a DataSetT, the returned 170 * vector will have just 1 DataSetT. If dobj is a vtkCompositeDataSet, then 171 * we iterate over it and add all non-null leaf nodes to the returned vector. 172 * 173 * If `preserveNull` is true (defaults to false), then `nullptr` place holders 174 * are added as placeholders when leaf node dataset type does not match the 175 * requested or is nullptr to begin with. 176 */ 177 template <class DataSetT = vtkDataSet> 178 static std::vector<DataSetT*> GetDataSets(vtkDataObject* dobj, bool preserveNull = false); 179 180 protected: 181 vtkCompositeDataSet(); 182 ~vtkCompositeDataSet() override; 183 184 private: 185 vtkCompositeDataSet(const vtkCompositeDataSet&) = delete; 186 void operator=(const vtkCompositeDataSet&) = delete; 187 }; 188 189 #include "vtkCompositeDataSet.txx" // for template implementations 190 191 #endif 192