3#include <vtkInformation.h>
5#include <vtkDoubleArray.h>
6#include <vtkFieldData.h>
7#include <vtkImageData.h>
8#include <vtkMultiBlockDataSet.h>
9#include <vtkStringArray.h>
11#include <vtkXMLGenericDataObjectReader.h>
17 this->SetNumberOfInputPorts(1);
18 this->SetNumberOfOutputPorts(1);
23 vtkInformation *info) {
25 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkTable");
32 vtkInformation *info) {
34 info->Set(vtkDataObject::DATA_TYPE_NAME(),
"vtkMultiBlockDataSet");
40template <
class readerT>
42 vtkNew<readerT> &reader) {
43 reader->SetFileName(pathToFile.data());
45 if(reader->GetErrorCode() != 0)
50 result->ShallowCopy(reader->GetOutput());
57 if(pathToFile.substr(pathToFile.length() - 4, 4).compare(
".ttk") == 0) {
58 this->topologicalCompressionReader->SetDebugLevel(this->
debugLevel_);
59 return readFileLocal_(pathToFile, this->topologicalCompressionReader);
60 }
else if(pathToFile.substr(pathToFile.size() - 4) ==
".tif"
61 || pathToFile.substr(pathToFile.size() - 5) ==
".tiff") {
63 }
else if(pathToFile.substr(pathToFile.length() - 4, 4).compare(
".png")
68 std::ifstream is(pathToFile.data());
71 bool isXML = std::string(prefix).compare(
"<VTKFile ") == 0
72 || std::string(prefix).compare(
"<?xml ver") == 0;
76 return readFileLocal_(pathToFile, this->xmlGenericDataObjectReader);
87 auto objectAsMB = vtkMultiBlockDataSet::SafeDownCast(
object);
89 for(
size_t i = 0, j = objectAsMB->GetNumberOfBlocks(); i < j; i++)
92 auto ofd =
object->GetFieldData();
93 for(
size_t i = 0, j = fd->GetNumberOfArrays(); i < j; i++)
94 ofd->AddArray(fd->GetAbstractArray(i));
101 vtkInformationVector **inputVector,
102 vtkInformationVector *outputVector) {
106 auto inputTable = vtkTable::GetData(inputVector[0]);
108 auto outputMB = vtkMultiBlockDataSet::GetData(outputVector);
110 size_t n = inputTable->GetNumberOfRows();
111 size_t m = inputTable->GetNumberOfColumns();
114 {{
"#Files", std::to_string(n)}, {
"FILE Column", this->FilepathColumnName}});
120 auto paths = inputTable->GetColumnByName(this->FilepathColumnName.data());
122 this->
printErr(
"Table does not have column '" + this->FilepathColumnName
128 for(
size_t i = 0; i < n; i++) {
134 auto path = paths->GetVariantValue(i).ToString();
135 auto file = path.substr(path.find_last_of(
"/") + 1);
138 this->
printMsg(
"Reading (" + std::to_string(i + 1) +
"/"
139 + std::to_string(n) +
"): \"" + file +
"\"",
144 std::ifstream infile(path.data());
145 bool exists = infile.good();
147 this->
printErr(
"File does not exist.");
153 this->
printErr(
"Unable to read file.");
157 outputMB->SetBlock(i, readerOutput);
162 auto block = outputMB->GetBlock(i);
163 auto fieldData = block->GetFieldData();
164 for(
size_t j = 0; j < m; j++) {
165 auto columnName = inputTable->GetColumnName(j);
168 if(!fieldData->HasArray(columnName)
169 || columnName == this->FilepathColumnName) {
170 if(inputTable->GetColumn(j)->IsNumeric()) {
172 c->SetName(columnName);
173 c->SetNumberOfValues(1);
174 c->SetValue(0, inputTable->GetValue(i, j).ToDouble());
175 fieldData->AddArray(c);
178 c->SetName(columnName);
179 c->SetNumberOfValues(1);
180 c->SetValue(0, inputTable->GetValue(i, j).ToString());
181 fieldData->AddArray(c);
186 if(this->AddFieldDataRecursively)
189 this->
printMsg(
"Reading (" + std::to_string(i + 1) +
"/"
190 + std::to_string(n) +
"): \"" + file +
"\"",
198 this->
printMsg(
"Complete (#products: " + std::to_string(n) +
")", 1,
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
TTK VTK-filter that reads the data products that are referenced in a vtkTable.
int addFieldDataRecursively(vtkDataObject *object, vtkFieldData *fd)
vtkSmartPointer< vtkDataObject > readFileLocal(const std::string &pathToFile)
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
~ttkCinemaProductReader() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
void setDebugMsgPrefix(const std::string &prefix)
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) const
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
vtkStandardNewMacro(ttkCinemaProductReader)
vtkSmartPointer< vtkDataObject > readFileLocal_(const std::string &pathToFile, vtkNew< readerT > &reader)