|
44 | 44 | #include <vtkInformationVector.h> |
45 | 45 |
|
46 | 46 | #include <Base/Console.h> |
| 47 | +#include <Base/Reader.h> |
47 | 48 |
|
48 | 49 | #include "FemMesh.h" |
49 | 50 | #include "FemMeshObject.h" |
@@ -130,10 +131,10 @@ bool FemPostPipeline::canRead(Base::FileInfo File) |
130 | 131 | { |
131 | 132 |
|
132 | 133 | // from FemResult only unstructural mesh is supported in femvtktoools.cpp |
133 | | - return File.hasExtension({"vtk", "vtp", "vts", "vtr", "vti", "vtu", "pvtu", "vtm"}); |
| 134 | + return File.hasExtension({"vtk", "vtp", "vts", "vtr", "vti", "vtu", "pvtu", "vtm", "pvd"}); |
134 | 135 | } |
135 | 136 |
|
136 | | -vtkSmartPointer<vtkDataObject> FemPostPipeline::dataObjectFromFile(Base::FileInfo File) |
| 137 | +vtkSmartPointer<vtkDataObject> FemPostPipeline::dataObjectFromFile(const Base::FileInfo& File) |
137 | 138 | { |
138 | 139 | // checking on the file |
139 | 140 | if (!File.isReadable()) { |
@@ -164,10 +165,55 @@ vtkSmartPointer<vtkDataObject> FemPostPipeline::dataObjectFromFile(Base::FileInf |
164 | 165 | else if (File.hasExtension("vtm")) { |
165 | 166 | return readXMLFile<vtkXMLMultiBlockDataReader>(File.filePath()); |
166 | 167 | } |
| 168 | + else if (File.hasExtension("pvd")) { |
| 169 | + return readPVD(File); |
| 170 | + } |
167 | 171 |
|
168 | 172 | throw Base::FileException("Unknown extension"); |
169 | 173 | } |
170 | 174 |
|
| 175 | +vtkSmartPointer<vtkDataObject> FemPostPipeline::readPVD(const Base::FileInfo& file) |
| 176 | +{ |
| 177 | + std::string path = file.filePath(); |
| 178 | + |
| 179 | + std::ifstream ifstr(path, std::ios::in | std::ios::binary); |
| 180 | + Base::XMLReader reader(path.c_str(), ifstr); |
| 181 | + reader.readElement("DataSet"); |
| 182 | + std::map<double, std::string> values; |
| 183 | + std::vector<std::string> files; |
| 184 | + while (strcmp(reader.localName(), "DataSet") == 0) { |
| 185 | + values.emplace(std::make_pair(reader.getAttribute<double>("timestep"), |
| 186 | + reader.getAttribute<std::string>("file"))); |
| 187 | + reader.readNextElement(); |
| 188 | + } |
| 189 | + |
| 190 | + auto timeInfo = vtkSmartPointer<vtkStringArray>::New(); |
| 191 | + timeInfo->SetName("TimeInfo"); |
| 192 | + timeInfo->InsertNextValue("TimeStep"); |
| 193 | + // set unit to empty string |
| 194 | + timeInfo->InsertNextValue(""); |
| 195 | + |
| 196 | + auto multiBlock = vtkSmartPointer<vtkMultiBlockDataSet>::New(); |
| 197 | + multiBlock->GetFieldData()->AddArray(timeInfo); |
| 198 | + |
| 199 | + int i = 0; |
| 200 | + std::string dir = file.dirPath(); |
| 201 | + for (auto v : values) { |
| 202 | + Base::FileInfo fi(dir + "/" + v.second); |
| 203 | + auto data = dataObjectFromFile(fi); |
| 204 | + auto time = vtkSmartPointer<vtkFloatArray>::New(); |
| 205 | + time->SetName("TimeValue"); |
| 206 | + time->InsertNextValue(v.first); |
| 207 | + data->GetFieldData()->AddArray(time); |
| 208 | + data->GetFieldData()->AddArray(timeInfo); |
| 209 | + |
| 210 | + multiBlock->SetBlock(i, data); |
| 211 | + ++i; |
| 212 | + } |
| 213 | + |
| 214 | + return multiBlock; |
| 215 | +} |
| 216 | + |
171 | 217 | void FemPostPipeline::read(Base::FileInfo File) |
172 | 218 | { |
173 | 219 | Data.setValue(dataObjectFromFile(File)); |
|
0 commit comments