-
-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy pathreader.h
More file actions
229 lines (202 loc) · 5.47 KB
/
Copy pathreader.h
File metadata and controls
229 lines (202 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef f3d_reader_h
#define f3d_reader_h
#include <vtkAlgorithm.h>
#include <vtkFileResourceStream.h>
#include <vtkImporter.h>
#include <vtkSmartPointer.h>
#include "../public/reader_types.h"
#include <algorithm>
#include <cctype>
#include <map>
#include <optional>
#include <string>
#include <vector>
class vtkResourceStream;
namespace f3d
{
/**
* @class reader
* @brief The basis reader class
*
* `reader` is the basic class for every file format readers.
* It must provide information about its name and descriptions, the managed
* file formats, and must be able to produce either a VTK reader or a VTK importer.
* Every reader must be registered to the `factory` singleton. This is
* automatically done when the plugin is loaded by CMake when declaring every reader
* with the f3d_plugin_declare_reader() macro.
*
* @warning This file is used internally by the plugin SDK, it is not intended to be included
* directly by libf3d users.
*/
class reader
{
public:
reader() = default;
virtual ~reader() = default;
/**
* Get the name of this reader
*/
virtual const std::string getName() const = 0;
/**
* Get the short description of this reader
*/
virtual const std::string getShortDescription() const = 0;
/**
* Get the long description of this reader
*/
virtual const std::string getLongDescription() const
{
return this->getShortDescription();
}
/**
* Get the extensions supported by this reader
*/
virtual const std::vector<std::string> getExtensions() const = 0;
/**
* Get the mimetypes supported by this reader
*/
virtual const std::vector<std::string> getMimeTypes() const = 0;
/**
* Check if this reader can read the given filename - according to its extension and file content
*/
virtual bool canRead(const std::string& fileName, const std::optional<bool> skipContentCheck,
reader_types::file_availability& availability) const
{
std::string ext = fileName.substr(fileName.find_last_of(".") + 1);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
const std::vector<std::string>& extensions = this->getExtensions();
if (std::any_of(
extensions.begin(), extensions.end(), [&](const std::string& s) { return s == ext; }))
{
vtkNew<vtkFileResourceStream> stream;
if (skipContentCheck.has_value() && skipContentCheck.value() == true)
{
availability = reader_types::file_availability::AVAILABLE;
return true;
}
else if (stream->Open(fileName.c_str()))
{
if (this->canRead(stream))
{
availability = reader_types::file_availability::AVAILABLE;
return true;
}
else
{
availability = reader_types::file_availability::UNSUPPORTED_CONTENT;
}
}
}
return false;
}
/**
* Should return true if this reader could be able to read provided stream,
* false if it is sure it cannot.
*/
virtual bool canRead(vtkResourceStream*) const = 0;
/**
* Get the score of this reader.
* The score is used in case several readers are able to read the file.
* The reader having the highest score (from 0 to 100) is used to read the file.
* Default is 50.
*/
virtual int getScore() const
{
return 50;
}
/**
* Return true if this reader can create a geometry reader
* false otherwise
*/
virtual bool hasGeometryReader()
{
return false;
}
/**
* Create the geometry reader (VTK reader) for the given filename
*/
virtual vtkSmartPointer<vtkAlgorithm> createGeometryReader(const std::string&) const
{
return nullptr;
}
/**
* Create the geometry reader (VTK reader) for the given stream
*/
virtual vtkSmartPointer<vtkAlgorithm> createGeometryReader(vtkResourceStream*) const
{
return nullptr;
}
/**
* Apply custom code for the reader
*/
virtual void applyCustomReader(vtkAlgorithm*, const std::string&, vtkResourceStream*) const
{
}
/**
* Return true if this reader can create a scene reader
* false otherwise
*/
virtual bool hasSceneReader()
{
return false;
}
/**
* Create the scene reader (VTK importer) for the given filename
*/
virtual vtkSmartPointer<vtkImporter> createSceneReader(const std::string&) const
{
return nullptr;
}
/**
* Create the scene reader (VTK importer) for the given stream
*/
virtual vtkSmartPointer<vtkImporter> createSceneReader(vtkResourceStream*) const
{
return nullptr;
}
/**
* Apply custom code for the importer
*/
virtual void applyCustomImporter(vtkImporter*, const std::string&, vtkResourceStream*) const
{
}
/**
* Return true if this reader supports stream
* false otherwise
*/
virtual bool supportsStream() const
{
return false;
}
/**
* Set a reader option
* Return true if the option was found (and set), false otherwise
*/
bool setReaderOption(const std::string& name, const std::string& value)
{
auto iter = this->ReaderOptions.find(name);
if (iter == this->ReaderOptions.end())
{
return false;
}
iter->second = value;
return true;
}
/**
* Return the list of all reader option names
*/
std::vector<std::string> getAllReaderOptionNames() const
{
std::vector<std::string> keys;
keys.reserve(this->ReaderOptions.size());
for (const auto& [key, value] : this->ReaderOptions)
{
keys.push_back(key);
}
return keys;
}
protected:
std::map<std::string, std::string> ReaderOptions;
};
}
#endif