VTK
9.3.1
|
Helper class for readers and importer that need to load more than one resource. More...
#include <vtkURILoader.h>
Public Types | |
typedef vtkObject | Superclass |
Public Member Functions | |
virtual vtkTypeBool | IsA (const char *type) |
Return 1 if this class is the same type of (or a subclass of) the named class. More... | |
vtkURILoader * | NewInstance () const |
void | PrintSelf (ostream &os, vtkIndent indent) override |
Methods invoked by print to print information about the object including superclasses. More... | |
vtkURI * | GetBaseURI () const |
Get base URI. More... | |
bool | HasBaseURI () const |
Check if loader as a base URI. More... | |
bool | SetBaseFileName (VTK_FILEPATH const std::string &filepath) |
Higher level way to set the base URI to an existing file. More... | |
bool | SetBaseDirectory (VTK_FILEPATH const std::string &dirpath) |
Higher level way to set the base URI to an existing directory. More... | |
vtkSmartPointer< vtkURI > | Resolve (const vtkURI *uri) |
Resolve URI from base URI. More... | |
vtkSmartPointer< vtkResourceStream > | Load (const std::string &uri) |
Load a resource referenced by an URI. More... | |
vtkSmartPointer< vtkResourceStream > | Load (const char *uri, std::size_t size) |
Load a resource referenced by an URI. More... | |
vtkSmartPointer< vtkResourceStream > | Load (const vtkURI *uri) |
Try to resolve given URI from base URI, using vtkURI::Resolve . More... | |
vtkSmartPointer< vtkResourceStream > | LoadResolved (const vtkURI *uri) |
Load a resource from a full URI. More... | |
bool | SetBaseURI (const std::string &uri) |
Set base URI to use. More... | |
bool | SetBaseURI (vtkURI *uri) |
Set base URI to use. More... | |
![]() | |
vtkBaseTypeMacro (vtkObject, vtkObjectBase) | |
virtual void | DebugOn () |
Turn debugging output on. More... | |
virtual void | DebugOff () |
Turn debugging output off. More... | |
bool | GetDebug () |
Get the value of the debug flag. More... | |
void | SetDebug (bool debugFlag) |
Set the value of the debug flag. More... | |
virtual void | Modified () |
Update the modification time for this object. More... | |
virtual vtkMTimeType | GetMTime () |
Return this object's modified time. More... | |
void | RemoveObserver (unsigned long tag) |
void | RemoveObservers (unsigned long event) |
void | RemoveObservers (const char *event) |
void | RemoveAllObservers () |
vtkTypeBool | HasObserver (unsigned long event) |
vtkTypeBool | HasObserver (const char *event) |
vtkTypeBool | InvokeEvent (unsigned long event) |
vtkTypeBool | InvokeEvent (const char *event) |
std::string | GetObjectDescription () const override |
The object description printed in messages and PrintSelf output. More... | |
unsigned long | AddObserver (unsigned long event, vtkCommand *, float priority=0.0f) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
unsigned long | AddObserver (const char *event, vtkCommand *, float priority=0.0f) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
vtkCommand * | GetCommand (unsigned long tag) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
void | RemoveObserver (vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
void | RemoveObservers (unsigned long event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
void | RemoveObservers (const char *event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
vtkTypeBool | HasObserver (unsigned long event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
vtkTypeBool | HasObserver (const char *event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. More... | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f) |
Overloads to AddObserver that allow developers to add class member functions as callbacks for events. More... | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f) |
Overloads to AddObserver that allow developers to add class member functions as callbacks for events. More... | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f) |
Allow user to set the AbortFlagOn() with the return value of the callback method. More... | |
vtkTypeBool | InvokeEvent (unsigned long event, void *callData) |
This method invokes an event and return whether the event was aborted or not. More... | |
vtkTypeBool | InvokeEvent (const char *event, void *callData) |
This method invokes an event and return whether the event was aborted or not. More... | |
virtual void | SetObjectName (const std::string &objectName) |
Set/get the name of this object for reporting purposes. More... | |
virtual std::string | GetObjectName () const |
Set/get the name of this object for reporting purposes. More... | |
![]() | |
const char * | GetClassName () const |
Return the class name as a string. More... | |
virtual vtkIdType | GetNumberOfGenerationsFromBase (const char *name) |
Given the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). More... | |
virtual void | Delete () |
Delete a VTK object. More... | |
virtual void | FastDelete () |
Delete a reference to this object. More... | |
void | InitializeObjectBase () |
void | Print (ostream &os) |
Print an object to an ostream. More... | |
virtual void | Register (vtkObjectBase *o) |
Increase the reference count (mark as used by another object). More... | |
virtual void | UnRegister (vtkObjectBase *o) |
Decrease the reference count (release by another object). More... | |
int | GetReferenceCount () |
Return the current reference count of this object. More... | |
void | SetReferenceCount (int) |
Sets the reference count. More... | |
bool | GetIsInMemkind () const |
A local state flag that remembers whether this object lives in the normal or extended memory space. More... | |
virtual void | PrintHeader (ostream &os, vtkIndent indent) |
Methods invoked by print to print information about the object including superclasses. More... | |
virtual void | PrintTrailer (ostream &os, vtkIndent indent) |
Methods invoked by print to print information about the object including superclasses. More... | |
virtual bool | UsesGarbageCollector () const |
Indicate whether the class uses vtkGarbageCollector or not. More... | |
Static Public Member Functions | |
static vtkTypeBool | IsTypeOf (const char *type) |
static vtkURILoader * | SafeDownCast (vtkObjectBase *o) |
static vtkURILoader * | New () |
![]() | |
static vtkObject * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. More... | |
static void | BreakOnError () |
This method is called when vtkErrorMacro executes. More... | |
static void | SetGlobalWarningDisplay (vtkTypeBool val) |
This is a global flag that controls whether any debug, warning or error messages are displayed. More... | |
static void | GlobalWarningDisplayOn () |
This is a global flag that controls whether any debug, warning or error messages are displayed. More... | |
static void | GlobalWarningDisplayOff () |
This is a global flag that controls whether any debug, warning or error messages are displayed. More... | |
static vtkTypeBool | GetGlobalWarningDisplay () |
This is a global flag that controls whether any debug, warning or error messages are displayed. More... | |
![]() | |
static vtkTypeBool | IsTypeOf (const char *name) |
Return 1 if this class type is the same type of (or a subclass of) the named class. More... | |
static vtkIdType | GetNumberOfGenerationsFromBaseType (const char *name) |
Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). More... | |
static vtkObjectBase * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. More... | |
static void | SetMemkindDirectory (const char *directoryname) |
The name of a directory, ideally mounted -o dax, to memory map an extended memory space within. More... | |
static bool | GetUsingMemkind () |
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) or within the extended memory space. More... | |
Protected Member Functions | |
virtual vtkObjectBase * | NewInstanceInternal () const |
vtkURILoader () | |
Constructor. More... | |
~vtkURILoader () override | |
vtkURILoader (const vtkURILoader &)=delete | |
vtkURILoader & | operator= (const vtkURILoader &)=delete |
virtual vtkSmartPointer< vtkResourceStream > | DoLoad (const vtkURI &uri) |
Load a resource from a full URI. More... | |
vtkSmartPointer< vtkResourceStream > | LoadFile (const vtkURI &uri) |
Load a resource from a file URI. More... | |
vtkSmartPointer< vtkResourceStream > | LoadData (const vtkURI &uri) |
Load a resource from a data URI. More... | |
![]() | |
vtkObject () | |
~vtkObject () override | |
void | RegisterInternal (vtkObjectBase *, vtkTypeBool check) override |
void | UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) override |
void | InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr) |
These methods allow a command to exclusively grab all events. More... | |
void | InternalReleaseFocus () |
These methods allow a command to exclusively grab all events. More... | |
![]() | |
vtkObjectBase () | |
virtual | ~vtkObjectBase () |
virtual void | ReportReferences (vtkGarbageCollector *) |
vtkObjectBase (const vtkObjectBase &) | |
void | operator= (const vtkObjectBase &) |
Additional Inherited Members | |
![]() | |
static vtkMallocingFunction | GetCurrentMallocFunction () |
static vtkReallocingFunction | GetCurrentReallocFunction () |
static vtkFreeingFunction | GetCurrentFreeFunction () |
static vtkFreeingFunction | GetAlternateFreeFunction () |
![]() | |
bool | Debug |
vtkTimeStamp | MTime |
vtkSubjectHelper * | SubjectHelper |
std::string | ObjectName |
![]() | |
std::atomic< int32_t > | ReferenceCount |
vtkWeakPointerBase ** | WeakPointers |
Helper class for readers and importer that need to load more than one resource.
vtkURILoader
is a class that will load URIs, giving vtkResourceStream
s from resolved resource. URI logic (parsing, resolution) is implemented in vtkURI
.
Some formats, such as GLTF, may refer to external resources through URIs. This URI loader can be used to solve this problem.
vtkURILoader
provides "file" and "data" URIs loading. "file" URIs loading only supports localhost. More schemes may be supported in future versions.
Base URI, specified in RFC3986#5, is a concept that enable URIs to refer to relative resources from a base resource. For example, you can have a file that needs to look for another file next to it. The best way to implement this, is to have the first file as the base URI, and the referenced file as a relative reference.
To set a local file as base URI, you should use SetBaseFileName
, and for a local directory, you should use SetBaseDirectory
. These functions generate a "file" URI from given path. For example, calling SetBaseFileName(".")
will generate the following URI: "file:///\<absolute-current-working-directory\>/."
. These functions should be used because they handle some platform specific details, such as adding a /
at the beginning of the path on Windows, percent-encoding, resolving relative paths, "." and "..", checking that path exists and actual filesystem entry type is coherent.
If the loader has no base URI, it can only load full URIs. See vtkURI
for more informations.
Here is a basic exemple of vtkURILoader
usage:
```cpp vtkNew<vtkURILoader> loader; loader->SetBaseFileName("."); // Set current working directory as the base URI // This Load call will parse the string to a vtkURI. In that case, the URI only has a path. // Then it will be resolved from base URI. In that case, the current working directory: // "file:///<cwd>/." + "example.txt" == "file:///<cwd>/example.txt" // Then it will call the DoLoad
function. This DoLoad function will check URI scheme, // here "file", and call the right loading function. In that case LoadFile will be called. // LoadFile will create a vtkFileResourceStream and open it on URI path. auto stream = loader->Load("example.txt"); // stream is opened on ./example.txt... Or it is null, in case of error.
// When loading a full URI, base URI is ignored (see vtkURI::Resolve and RFC specs) auto other = loader->Load("data:;base64,AAAA"); // other is a vtkMemoryResourceStream on the decoded base64 data. Here, 3 bytes, all equal to 0.
```
Note that in previous example, loader->Load()
actually returns a vtkResourceStream
, the real type can be accessed through SafeDownCast
.
When implementing a reader, you should use vtkURILoader
if the format can contain URIs. Here are the global guidelines of URI loader support in a reader:
SetURILoader
.SetFileName
function, the reader should internally open a vtkFileResourceStream
on the file and create a vtkURILoader
with a base URI set to FileName
, then use the same code as the resource stream based reading. This prevents code duplication.vtkURILoader::DoLoad
is reponsible of actually loading a full URI. It is a virtual function, so it can be reimplemented to let the user support additional schemes. In case you want do support additional scheme, URI scheme and host should be case-insensitive as specified in RFC3986#6.2.2.1.
vtkURILoader::LoadFile
and vtkURILoader::LoadData
are the actual implementation of "file" and "data" URI loading.
Definition at line 99 of file vtkURILoader.h.
typedef vtkObject vtkURILoader::Superclass |
Definition at line 101 of file vtkURILoader.h.
|
protected |
Constructor.
Default constructed vtkURILoader has no base URI.
|
overrideprotected |
|
protecteddelete |
|
static |
|
virtual |
Return 1 if this class is the same type of (or a subclass of) the named class.
Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.
Reimplemented from vtkObjectBase.
|
static |
|
protectedvirtual |
vtkURILoader* vtkURILoader::NewInstance | ( | ) | const |
|
overridevirtual |
|
static |
bool vtkURILoader::SetBaseURI | ( | const std::string & | uri | ) |
Set base URI to use.
URI must be an absolute URI. It will be used by Resolve
and Load(const vtkURI*)
functions to resolve relative references.
It may be nullptr
. HasBaseURI
is a more explicit way to check that.
SetBaseURI(const std::string& uri)
parses the URI from a string and then do the same as SetBaseURI(vtkURI* uri)
.
Base URI is manipulated as a non-const vtkURI
because loader keep a owning reference on it.
uri | A string to parse, or an existing URI. Empty string is the same as nullptr. Existing URI Reference count will be increased. |
true
if uri is a suitable base URI (i.e. is absolute
). bool vtkURILoader::SetBaseURI | ( | vtkURI * | uri | ) |
Set base URI to use.
URI must be an absolute URI. It will be used by Resolve
and Load(const vtkURI*)
functions to resolve relative references.
It may be nullptr
. HasBaseURI
is a more explicit way to check that.
SetBaseURI(const std::string& uri)
parses the URI from a string and then do the same as SetBaseURI(vtkURI* uri)
.
Base URI is manipulated as a non-const vtkURI
because loader keep a owning reference on it.
uri | A string to parse, or an existing URI. Empty string is the same as nullptr. Existing URI Reference count will be increased. |
true
if uri is a suitable base URI (i.e. is absolute
). vtkURI* vtkURILoader::GetBaseURI | ( | ) | const |
Get base URI.
|
inline |
Check if loader as a base URI.
Definition at line 140 of file vtkURILoader.h.
bool vtkURILoader::SetBaseFileName | ( | VTK_FILEPATH const std::string & | filepath | ) |
Higher level way to set the base URI to an existing file.
This generates a file URI on the absolute path of the specified filepath. filepath
must refer to an existing file.
filepath | File path to use as base URI. filepath may be relative, it will be automatically transformed into an absolute path. |
bool vtkURILoader::SetBaseDirectory | ( | VTK_FILEPATH const std::string & | dirpath | ) |
Higher level way to set the base URI to an existing directory.
This generates a file URI on the absolute path of the specified directory "."
file. path
must refer to an existing directory.
dirpath | File path to use as base URI. dirpath may be relative, it will be automatically transformed into an absolute path. |
vtkSmartPointer<vtkURI> vtkURILoader::Resolve | ( | const vtkURI * | uri | ) |
Resolve URI from base URI.
|
inline |
Load a resource referenced by an URI.
Perform as if by calling this->Load(uri.data(), uri.size())
.
uri | URI string representation, may be empty. |
vtkResourceStream
on the loaded resource on success, nullptr otherwise. Definition at line 180 of file vtkURILoader.h.
vtkSmartPointer<vtkResourceStream> vtkURILoader::Load | ( | const char * | uri, |
std::size_t | size | ||
) |
Load a resource referenced by an URI.
Try to parse an URI from given string using vtkURI::Parse
. If parsing fails, returns nullptr immediately, otherwise, performs as if by calling Load(const vtkURI*)
with parsed URI.
uri | An URI string representation, may be nullptr if size is 0 . |
size | Size of uri string, may be 0 . |
vtkResourceStream
on the loaded resource on success, nullptr otherwise. vtkSmartPointer<vtkResourceStream> vtkURILoader::Load | ( | const vtkURI * | uri | ) |
Try to resolve given URI from base URI, using vtkURI::Resolve
.
If resolution fails, returns nullptr. Otherwise, performs as if by calling LoadResolved(const vtkURI*)
with resolved URI.
uri | A vtkURI , must be a relative reference. |
vtkResourceStream
on the loaded resource on success, nullptr otherwise. vtkSmartPointer<vtkResourceStream> vtkURILoader::LoadResolved | ( | const vtkURI * | uri | ) |
Load a resource from a full URI.
Checks if URI is suitable for loading (i.e. is a full URI), then calls DoLoad(uri)
.
uri | A vtkURI , must be a full URI |
vtkResourceStream
on the loaded resource on success, nullptr otherwise.
|
protecteddelete |
|
protectedvirtual |
Load a resource from a full URI.
Dispatch, depending on uri scheme:
LoadFile
if scheme == "file"LoadData
if scheme == "data" If scheme is not one of these, returns nullptr and generates an error.This function is virtual and may be reimplemented to support additional schemes or disable some schemes.
uri | A vtkURI , must be a full URI |
vtkResourceStream
on the loaded resource on success, nullptr otherwise.
|
protected |
Load a resource from a file URI.
Current implementation only supports localhost authority. Returned stream is a vtkFileResourceStream
on URI path. Query and fragment are ignored.
uri | A vtkURI , must be a full file URI |
vtkResourceStream
on the loaded resource on success, nullptr otherwise.
|
protected |
Load a resource from a data URI.
Authority is ignored. Supports raw (percent-encoded) and base64-encoded data URI. If an error occurs during data decoding, returns nullptr. Query and fragment are ignored.
Returned stream is a vtkMemoryResourceStream
on decoded data. The streams owns the data.
uri | A vtkURI , must be a full data URI |
vtkResourceStream
on the loaded resource on success, nullptr otherwise.