TTK
Loading...
Searching...
No Matches
ttkCinemaReader.cpp
Go to the documentation of this file.
1#include <ttkCinemaReader.h>
2
3#include <vtkInformation.h>
4#include <vtkObjectFactory.h>
5
6#include <vtkDelimitedTextReader.h>
7#include <vtkFieldData.h>
8#include <vtkSmartPointer.h>
9#include <vtkStringArray.h>
10#include <vtkTable.h>
11
12#include <ttkUtils.h>
13
15
17 this->setDebugMsgPrefix("CinemaReader");
18
19 this->SetNumberOfInputPorts(0);
20 this->SetNumberOfOutputPorts(1);
21}
22
24
25int ttkCinemaReader::FillOutputPortInformation(int port, vtkInformation *info) {
26 if(port == 0)
27 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTable");
28 else
29 return 0;
30 return 1;
31}
32
34 if(this->DatabasePath.length() < 4
35 || this->DatabasePath.substr(this->DatabasePath.length() - 4, 4)
36 .compare(".cdb")
37 != 0) {
38 this->printErr("Database path has to end with '.cdb'.");
39 return 0;
40 }
41
42 return 1;
43}
44
45int ttkCinemaReader::RequestData(vtkInformation *ttkNotUsed(request),
46 vtkInformationVector **ttkNotUsed(inputVector),
47 vtkInformationVector *outputVector) {
48 ttk::Timer timer;
49
50 // print input
51 this->printMsg({
52 {"Database", this->GetDatabasePath()},
53 {"FILE Columns", this->GetFilePathColumnNames()},
54 });
56
57 if(!this->validateDatabasePath())
58 return 0;
59
60 this->printMsg("Reading CSV file", 0, ttk::debug::LineMode::REPLACE);
61
62 // get output
63 auto outTable = vtkTable::GetData(outputVector);
64
65 // read CSV file which is in Spec D format
66 {
68 reader->SetFileName((this->GetDatabasePath() + "/data.csv").data());
69 reader->DetectNumericColumnsOn();
70 reader->SetHaveHeaders(true);
71 reader->SetFieldDelimiterCharacters(",");
72 reader->Update();
73
74 if(reader->GetLastError().compare("") != 0)
75 return 0;
76
77 // copy information to output
78 outTable->ShallowCopy(reader->GetOutput());
79
80 // prepend database path to FILE column
81 std::vector<std::string> filePathColumnNames;
83 this->GetFilePathColumnNames(), filePathColumnNames);
84
85 for(size_t j = 0; j < filePathColumnNames.size(); j++) {
86 auto filepathColumn = vtkStringArray::SafeDownCast(
87 outTable->GetColumnByName(filePathColumnNames[j].data()));
88 if(filepathColumn) {
89 size_t const n = filepathColumn->GetNumberOfValues();
90 for(size_t i = 0; i < n; i++)
91 filepathColumn->SetValue(
92 i, this->GetDatabasePath() + "/" + filepathColumn->GetValue(i));
93 } else {
94 this->printErr("Input table does not have column '"
95 + filePathColumnNames[j]
96 + "' or is not of type 'vtkStringArray'.");
97 return 0;
98 }
99 }
100
101 this->printMsg("Reading CSV file", 1, timer.getElapsedTime());
102 }
103
104 // print stats
106 this->printMsg(
107 "Complete (#rows: " + std::to_string(outTable->GetNumberOfRows()) + ")", 1,
108 timer.getElapsedTime());
110
111 return 1;
112}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
TTK VTK-filter that reads a Cinema Spec D Database.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
virtual std::string GetFilePathColumnNames()
virtual std::string GetDatabasePath()
~ttkCinemaReader() override
static int stringListToVector(const std::string &iString, std::vector< std::string > &v)
Definition ttkUtils.cpp:115
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
double getElapsedTime()
Definition Timer.h:15
vtkStandardNewMacro(ttkCinemaReader)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)