1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkXMLTreeReader.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 Copyright 2008 Sandia Corporation. 17 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 18 the U.S. Government retains certain rights in this software. 19 -------------------------------------------------------------------------*/ 20 /** 21 * @class vtkXMLTreeReader 22 * @brief reads an XML file into a vtkTree 23 * 24 * 25 * vtkXMLTreeReader parses an XML file and uses the nesting structure of the 26 * XML tags to generate a tree. Node attributes are assigned to node arrays, 27 * and the special arrays .tagname and .chardata contain the tag type and the 28 * text internal to the tag, respectively. The arrays are of type 29 * vtkStringArray. There is an array for each attribute type in the XML file, 30 * even if it appears in only one tag. If an attribute is missing from a tag, 31 * its value is the empty string. 32 * 33 * If MaskArrays is on (the default is off), the filter will additionally make bit 34 * arrays whose names are prepended with ".valid." which are 1 if the element 35 * contains that attribute, and 0 otherwise. 36 * 37 * For example, the XML file containing the text: 38 * <pre> 39 * <node name="jeff" age="26"> 40 * this is text in jeff's node 41 * <node name="joe"> 42 * <node name="al" initials="amb" other="something"/> 43 * <node name="dave" age="30"/> 44 * </node> 45 * <node name="lisa">this is text in lisa's node</node> 46 * <node name="darlene" age="29"/> 47 * </node> 48 * </pre> 49 * 50 * would be parsed into a tree with the following node IDs and structure: 51 * 52 * <pre> 53 * 0 (jeff) - children: 1 (joe), 4 (lisa), 5 (darlene) 54 * 1 (joe) - children: 2 (al), 3 (dave) 55 * 2 (al) 56 * 3 (dave) 57 * 4 (lisa) 58 * 5 (darlene) 59 * </pre> 60 * 61 * and the node data arrays would be as follows: 62 * 63 * <pre> 64 * name initials other age .tagname .chardata 65 * ------------------------------------------------------------------------------------------------ 66 * jeff (empty) (empty) 26 node " this is text in jeff's node\n \n \n \n" 67 * joe (empty) (empty) (empty) node "\n \n \n " 68 * al amb something (empty) node (empty) 69 * dave (empty) (empty) 30 node (empty) 70 * lisa (empty) (empty) (empty) node "this is text in lisa's node" 71 * darlene (empty) (empty) 29 node (empty) 72 * </pre> 73 * 74 * There would also be the following bit arrays if MaskArrays is on: 75 * 76 * <pre> 77 * .valid.name .valid.initials .valid.other .valid.age 78 * --------------------------------------------------------- 79 * 1 0 0 1 80 * 1 0 0 0 81 * 1 1 1 0 82 * 1 0 0 1 83 * 1 0 0 0 84 * 1 0 0 1 85 * </pre> 86 */ 87 88 #ifndef vtkXMLTreeReader_h 89 #define vtkXMLTreeReader_h 90 91 #include "vtkIOInfovisModule.h" // For export macro 92 #include "vtkTreeAlgorithm.h" 93 94 class VTKIOINFOVIS_EXPORT vtkXMLTreeReader : public vtkTreeAlgorithm 95 { 96 public: 97 static vtkXMLTreeReader* New(); 98 vtkTypeMacro(vtkXMLTreeReader, vtkTreeAlgorithm); 99 void PrintSelf(ostream& os, vtkIndent indent) override; 100 101 ///@{ 102 /** 103 * If set, reads in the XML file specified. 104 */ 105 vtkGetFilePathMacro(FileName); 106 vtkSetFilePathMacro(FileName); 107 ///@} 108 109 ///@{ 110 /** 111 * If set, and FileName is not set, reads in the XML string. 112 */ 113 vtkGetStringMacro(XMLString); 114 vtkSetStringMacro(XMLString); 115 ///@} 116 117 ///@{ 118 /** 119 * The name of the edge pedigree ids. Default is "edge id". 120 */ 121 vtkGetStringMacro(EdgePedigreeIdArrayName); 122 vtkSetStringMacro(EdgePedigreeIdArrayName); 123 ///@} 124 125 ///@{ 126 /** 127 * The name of the vertex pedigree ids. Default is "vertex id". 128 */ 129 vtkGetStringMacro(VertexPedigreeIdArrayName); 130 vtkSetStringMacro(VertexPedigreeIdArrayName); 131 ///@} 132 133 ///@{ 134 /** 135 * Set whether to use an property from the XML file as pedigree ids (off), 136 * or generate a new array with integer values starting at zero (on). 137 * Default is on. 138 */ 139 vtkSetMacro(GenerateEdgePedigreeIds, bool); 140 vtkGetMacro(GenerateEdgePedigreeIds, bool); 141 vtkBooleanMacro(GenerateEdgePedigreeIds, bool); 142 vtkSetMacro(GenerateVertexPedigreeIds, bool); 143 vtkGetMacro(GenerateVertexPedigreeIds, bool); 144 vtkBooleanMacro(GenerateVertexPedigreeIds, bool); 145 ///@} 146 147 ///@{ 148 /** 149 * If on, makes bit arrays for each attribute with name .valid.attribute_name 150 * for each attribute. Default is off. 151 */ 152 vtkGetMacro(MaskArrays, bool); 153 vtkSetMacro(MaskArrays, bool); 154 vtkBooleanMacro(MaskArrays, bool); 155 ///@} 156 157 ///@{ 158 /** 159 * If on, stores the XML character data (i.e. textual data between tags) 160 * into an array named CharDataField, otherwise this field is skipped. 161 * Default is off. 162 */ 163 vtkGetMacro(ReadCharData, bool); 164 vtkSetMacro(ReadCharData, bool); 165 vtkBooleanMacro(ReadCharData, bool); 166 ///@} 167 168 ///@{ 169 /** 170 * If on, stores the XML tag name data in a field called .tagname 171 * otherwise this field is skipped. 172 * Default is on. 173 */ 174 vtkGetMacro(ReadTagName, bool); 175 vtkSetMacro(ReadTagName, bool); 176 vtkBooleanMacro(ReadTagName, bool); 177 ///@} 178 179 static const char* TagNameField; 180 static const char* CharDataField; 181 182 protected: 183 vtkXMLTreeReader(); 184 ~vtkXMLTreeReader() override; 185 char* FileName; 186 char* XMLString; 187 bool ReadCharData; 188 bool ReadTagName; 189 bool MaskArrays; 190 char* EdgePedigreeIdArrayName; 191 char* VertexPedigreeIdArrayName; 192 bool GenerateEdgePedigreeIds; 193 bool GenerateVertexPedigreeIds; 194 195 int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; 196 197 private: 198 vtkXMLTreeReader(const vtkXMLTreeReader&) = delete; 199 void operator=(const vtkXMLTreeReader&) = delete; 200 }; 201 202 #endif 203