1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkXMLHyperTreeGridWriter.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 vtkXMLHyperTreeGridWriter 17 * @brief Write VTK XML HyperTreeGrid files. 18 * 19 * vtkXMLHyperTreeGridWriter writes the VTK XML HyperTreeGrid file 20 * format. The standard extension for this writer's file format is "htg". 21 * 22 * Note for developers: 23 * The VTK XML HyperTreeGrid file format is versioned. 24 * Any evolution of the format must lead to: 25 * - a move to a higher major version number, X+1.0, if the evolution is 26 * incompatible with the previous versions either at the level of the 27 * description of the information or the semantic understanding made by 28 * the reader; 29 * - a move to a higher minor version number, X.y+1, if its consists of 30 * adding information without calling into question the general 31 * interpretation. 32 * 33 * Version 0.0 (P. Fasel and D. DeMarle) 34 * ... 35 * Version 1.0 (J-B Lekien CEA, DAM, DIF, F-91297 Arpajon, France) 36 * - writing by HyperTree description and fields; 37 * - saving the minimal tree (a hidden refined node becomes a hidden leaf node); 38 * - saving the tree by level of refinement (course in width); 39 * - the last null values in the binary description of the tree or mask (if 40 * defined) may not / are not explicitly described. The size of the table 41 * given elsewhere is authentic; 42 * - all fields are copied to be saved in the implicit order, so even 43 * if an explicit global index map exists, it disappears; 44 * - writing in this version requires more memory and CPU; 45 * - reading of a part is accelerated (non iterative construction of the tree) 46 * and consumes potentially less memory (suppression of the global index 47 * map explicit); 48 * - expanded possibility at the reader level, today these options allow to 49 * accelerate the obtaining of a result which will be less precise and to 50 * allow the loading of a part of a mesh which would not hold in memory: 51 * - loading by limiting the maximum level to load; 52 * - loading by selecting (differentes description possibilities are 53 * offered) the HTs to take into account. 54 * 55 * The default version of the VTK XML HyperTreeGrid file format is the latest 56 * version, now version 1.0. 57 * 58 * For developpers: 59 * To ensure the durability of this storage format over time, at least, the drive 60 * must continue to support playback of previous format. 61 */ 62 63 #ifndef vtkXMLHyperTreeGridWriter_h 64 #define vtkXMLHyperTreeGridWriter_h 65 66 #include "vtkIOXMLModule.h" // For export macro 67 #include "vtkSmartPointer.h" // For internal attributes 68 #include "vtkXMLWriter.h" 69 70 #include <vector> // std::vector 71 72 class OffsetsManagerGroup; 73 class OffsetsManagerArray; 74 class vtkBitArray; 75 class vtkIdList; 76 class vtkHyperTree; 77 class vtkHyperTreeGrid; 78 class vtkHyperTreeGridNonOrientedCursor; 79 class vtkTypeInt64Array; 80 class vtkTypeUInt32Array; 81 82 class VTKIOXML_EXPORT vtkXMLHyperTreeGridWriter : public vtkXMLWriter 83 { 84 public: 85 vtkTypeMacro(vtkXMLHyperTreeGridWriter, vtkXMLWriter); 86 void PrintSelf(ostream& os, vtkIndent indent) override; 87 static vtkXMLHyperTreeGridWriter* New(); 88 89 /** 90 * Get/Set the writer's input. 91 */ 92 vtkHyperTreeGrid* GetInput(); 93 94 /** 95 * Get the default file extension for files written by this writer. 96 */ 97 const char* GetDefaultFileExtension() override; 98 99 /** 100 * Methods to define the file's major and minor version numbers. 101 * Major version incremented since v0.1 hypertreegrid data readers 102 * cannot read the files written by this new reader. 103 * A version is defined by defect, so there is no need to call 104 * this function. 105 * The default choice is usually the best choice. 106 */ 107 vtkSetMacro(DataSetMajorVersion, int); 108 vtkSetMacro(DataSetMinorVersion, int); 109 110 protected: 111 vtkXMLHyperTreeGridWriter(); 112 ~vtkXMLHyperTreeGridWriter() override; 113 114 const char* GetDataSetName() override; 115 116 /** 117 * Methods to define the file's major and minor version numbers. 118 * Major version incremented since v0.1 hypertreegrid data readers 119 * cannot read the files written by this new reader. 120 * Actually, the default version is 1.0 121 */ GetDataSetMajorVersion()122 int GetDataSetMajorVersion() override { return DataSetMajorVersion; } GetDataSetMinorVersion()123 int GetDataSetMinorVersion() override { return DataSetMinorVersion; } 124 125 // Specify that we require HyperTreeGrid input 126 int FillInputPortInformation(int port, vtkInformation* info) override; 127 128 // The most important method, make the XML file for my input. 129 int WriteData() override; 130 131 // <HyperTreeGrid ... 132 int StartPrimaryElement(vtkIndent); 133 134 // ... dim, size, origin> 135 void WritePrimaryElementAttributes(ostream&, vtkIndent) override; 136 137 // Grid coordinates and mask 138 int WriteGrid(vtkIndent); 139 140 // Tree Descriptor and CellData 141 int WriteTrees_0(vtkIndent); 142 int WriteTrees_1(vtkIndent); 143 int WriteTrees_2(vtkIndent); 144 145 // </HyperTreeGrid> 146 int FinishPrimaryElement(vtkIndent); 147 148 // Descriptors for individual hypertrees 149 std::vector<vtkSmartPointer<vtkBitArray>> Descriptors; 150 151 // Descriptors for individual hypertrees 152 std::vector<vtkSmartPointer<vtkTypeInt64Array>> NbVerticesByLevels; 153 154 // Masks for individual hypertrees 155 std::vector<vtkSmartPointer<vtkBitArray>> Masks; 156 157 // Ids (index selection) for individual hypertrees 158 std::vector<vtkSmartPointer<vtkIdList>> Ids; 159 160 // Helper to simplify writing appended array data 161 void WriteAppendedArrayDataHelper(vtkAbstractArray* array, OffsetsManager& offsets); 162 163 void WriteCellDataAppendedArrayDataHelper(vtkAbstractArray* array, vtkIdType numberOfVertices, 164 OffsetsManager& offsets, vtkHyperTree* tree); 165 166 struct HyperTreeGridMetaDataForVersion2 167 { 168 void Initialize(); 169 170 vtkSmartPointer<vtkBitArray> Descriptors; 171 vtkSmartPointer<vtkTypeInt64Array> TreeIds; 172 vtkSmartPointer<vtkTypeInt64Array> NumberOfVerticesPerDepth; 173 vtkSmartPointer<vtkIdList> BreadthFirstIdMap; 174 vtkSmartPointer<vtkTypeUInt32Array> DepthPerTree; 175 } MetaDataForVersion2; 176 177 OffsetsManagerGroup* CoordsOMG; 178 OffsetsManagerGroup* DescriptorOMG; 179 OffsetsManagerGroup* NbVerticesByLevelOMG; 180 OffsetsManagerGroup* MaskOMG; 181 OffsetsManagerGroup* CellDataOMG; 182 OffsetsManagerGroup* TreeIdsOMG; 183 OffsetsManagerGroup* DepthPerTreeOMG; 184 185 int NumberOfTrees; 186 187 // Default choice 188 int DataSetMajorVersion; 189 int DataSetMinorVersion; 190 191 private: 192 vtkXMLHyperTreeGridWriter(const vtkXMLHyperTreeGridWriter&) = delete; 193 void operator=(const vtkXMLHyperTreeGridWriter&) = delete; 194 }; 195 196 #endif 197