------------------------------------------------------------------------------
| 2034 | |
| 2035 | //------------------------------------------------------------------------------ |
| 2036 | void vtkXMLWriter::WriteArrayHeader(vtkAbstractArray* a, vtkIndent indent, |
| 2037 | const char* alternateName, int writeNumTuples, int timestep) |
| 2038 | { |
| 2039 | ostream& os = *(this->Stream); |
| 2040 | if (vtkArrayDownCast<vtkDataArray>(a)) |
| 2041 | { |
| 2042 | os << indent << "<DataArray"; |
| 2043 | } |
| 2044 | else |
| 2045 | { |
| 2046 | os << indent << "<Array"; |
| 2047 | } |
| 2048 | this->WriteWordTypeAttribute("type", a->GetDataType()); |
| 2049 | if (a->GetDataType() == VTK_ID_TYPE) |
| 2050 | { |
| 2051 | this->WriteScalarAttribute("IdType", 1); |
| 2052 | } |
| 2053 | if (alternateName) |
| 2054 | { |
| 2055 | this->WriteStringAttribute("Name", alternateName); |
| 2056 | } |
| 2057 | else if (const char* arrayName = a->GetName()) |
| 2058 | { |
| 2059 | this->WriteStringAttribute("Name", arrayName); |
| 2060 | } |
| 2061 | else |
| 2062 | { |
| 2063 | // Generate a name for this array. |
| 2064 | std::ostringstream name; |
| 2065 | void* p = a; |
| 2066 | name << "Array " << p; |
| 2067 | this->WriteStringAttribute("Name", name.str().c_str()); |
| 2068 | } |
| 2069 | if (a->GetNumberOfComponents() > 1) |
| 2070 | { |
| 2071 | this->WriteScalarAttribute("NumberOfComponents", a->GetNumberOfComponents()); |
| 2072 | } |
| 2073 | |
| 2074 | // always write out component names, even if only 1 component |
| 2075 | std::ostringstream buff; |
| 2076 | const char* compName = nullptr; |
| 2077 | for (int i = 0; i < a->GetNumberOfComponents(); ++i) |
| 2078 | { |
| 2079 | // get the component names |
| 2080 | buff << "ComponentName" << i; |
| 2081 | compName = a->GetComponentName(i); |
| 2082 | if (compName) |
| 2083 | { |
| 2084 | this->WriteStringAttribute(buff.str().c_str(), compName); |
| 2085 | compName = nullptr; |
| 2086 | } |
| 2087 | buff.str(""); |
| 2088 | buff.clear(); |
| 2089 | } |
| 2090 | |
| 2091 | if (this->NumberOfTimeSteps > 1) |
| 2092 | { |
| 2093 | this->WriteScalarAttribute("TimeStep", timestep); |
no test coverage detected