CTL
0.6.1
Computed Tomography Library
|
The ClFileLoader class provides the ability to load files with OpenCL C source code. More...
#include <clfileloader.h>
Public Member Functions | |
ClFileLoader (const char *fileName) | |
ClFileLoader (std::string fileName) | |
ClFileLoader (const QString &fileName) | |
void | setFileName (const char *fileName) |
void | setFileName (std::string fileName) |
void | setFileName (const QString &fileName) |
const std::string & | fileName () const |
bool | isValid () const |
std::string | loadSourceCode () const |
Static Public Member Functions | |
static std::string | loadExternalSourceCode (const char *absoluteFilePath) |
static std::string | loadExternalSourceCode (const std::string &absoluteFilePath) |
static std::string | loadExternalSourceCode (const QString &absoluteFilePath) |
static void | setOpenCLSourceDir (const char *path) |
static void | setOpenCLSourceDir (const QString &path) |
static void | setOpenCLSourceDir (QString &&path) |
static void | setOpenCLSourceDir (const std::string &path) |
static const QString & | openCLSourceDir () |
Static Private Member Functions | |
static const QString & | absoluteOpenCLSourceDir () |
Private Attributes | |
std::string | _fn |
Static Private Attributes | |
static QString | _oclSourceDir |
The ClFileLoader class provides the ability to load files with OpenCL C source code.
OpenCL C source code needs to be available at runtime. Therefore, it will be collected in .cl files within the "cl_src" directory, which is located in the path of the executable (copied from the "ocl" folder of the repository by the qmake build system; see "ocl_config.pri"). The ClFileLoader provides the method loadSourceCode() that loads a file from the "cl_src" folder and return the content as a std::string. The file name of a .cl file is passed by the constructor or the setFileName() method as a relative path wrt the "cl_src" folder, e.g. "projectors/external_raycaster.cl". Moreover, the ClFileLoader allows to check beforehand if a certain .cl file is readable by using isValid().
NOTE: The internal determination of the absolute path of the "cl_src" folder can only work correctly if the main function of the program instantiate a QCoreApplication (or derived classes) as in the following snippet:
If no QCoreApplication has been instantiated:
The ClFileLoader can only use the relative path to the OpenCL sources wrt to the executable. This requires that the current directory (from where the program was started) is equal to the directory of the executable. Should this not be the case, the ClFileLoader is not able to locate the .cl files, i.e. isValid() will return false
and loadSourceCode() will return an empty string. Alternatively, the path to the "cl_src" folder can be set during run time using the static method setOpenCLSourceDir().
|
explicit |
Constructs a ClFileLoader object using fileName as the path of the .cl file.
|
explicit |
Constructs a ClFileLoader object using fileName as the path of the .cl file.
|
explicit |
Constructs a ClFileLoader object using fileName as the path of the .cl file.
|
staticprivate |
Returns the absolute path to the "ocl_src" directory. If no OpenCL source directory has been set, it determines the absolute path "<executable's directory>/cl_src" in a platform-independent way provided that QCoreApplication
has been instatiated in the main() of the application. In case CTL_LIBRARY was defined (CTL as pre-compiled library), the macro OCL_SOURCE_DIR is used.
const std::string & CTL::ClFileLoader::fileName | ( | ) | const |
Returns the relative path within the "cl_src" directory to the .cl file set by setFileName() or a constructor.
bool CTL::ClFileLoader::isValid | ( | ) | const |
Returns true if the .cl file is readable, otherwise false.
|
static |
Returns the content of an .cl file specified by an absolute path absoluteFilePath. This convenience function allows using OpenCL kernel files that are not located in the "cl_src" folder.
|
static |
Returns the content of an .cl file specified by an absolute path absoluteFilePath. This convenience function allows using OpenCL kernel files that are not located in the "cl_src" folder.
|
static |
Returns the content of an .cl file specified by an absolute path absoluteFilePath. This convenience function allows using OpenCL kernel files that are not located in the "cl_src" folder.
std::string CTL::ClFileLoader::loadSourceCode | ( | ) | const |
Returns the content of the .cl file as a std::string.
|
static |
Returns the path to the OpenCL directory, where OpenCL C kernel files are stored. This could be the default path ("cl_src" next to the executable or specified by OCL_SOURCE_DIR) or the path that has been set by setOpenCLSourceDir().
void CTL::ClFileLoader::setFileName | ( | const char * | fileName | ) |
void CTL::ClFileLoader::setFileName | ( | std::string | fileName | ) |
(Re)sets the path of the .cl file. The fileName shall be passed to this method by the relative path wrt the "cl_src" directory.
void CTL::ClFileLoader::setFileName | ( | const QString & | fileName | ) |
|
static |
Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable).
|
static |
Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable), or, in case CTL_LIBRARY was defined, the macro OCL_SOURCE_DIR is used.
|
static |
Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable), or, in case CTL_LIBRARY was defined, the macro OCL_SOURCE_DIR is used.
|
static |
Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable), or, in case CTL_LIBRARY was defined, the macro OCL_SOURCE_DIR is used.