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
|
#ifndef f3d_reader_h
#define f3d_reader_h
#include <vtkAlgorithm.h>
#include <vtkImporter.h>
#include <vtkSmartPointer.h>
#include <algorithm>
#include <cctype>
#include <map>
#include <string>
#include <vector>
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 - generally according its extension
*/
virtual bool canRead(const std::string& fileName) 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();
return std::any_of(
extensions.begin(), extensions.end(), [&](const std::string& s) { return s == ext; });
}
/**
* 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;
}
/**
* Apply custom code for the reader
*/
virtual void applyCustomReader(vtkAlgorithm*, const std::string&) 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;
}
/**
* Apply custom code for the importer
*/
virtual void applyCustomImporter(vtkImporter*, const std::string&) const
{
}
/**
* 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()
{
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
|