Adding a Module
In order to extend Voreen and integrate your own functionality, we recommend to add your own module, in which you organize all your classes. Modules are located in the directories src/modules resp. include/voreen/modules. Each module folder contains all files that belong to the module, as well as a special module class, which is derived from VoreenModule. This class is responsible for registering the module resources at run time, such that the Voreen framework can access them. In fact, most processors and data readers and writers are part of a module named base, of which the sources are located in src/modules/base.
In the following paragraphs, we describe how to create a new module named TestModule, which contains a simple image processor performing a gray scale conversion. On how to write a processor, please refer to the Adding a Processor tutorial.
0. Generate the Module Directories
All files you want to include with the module should be located in src/modules/test resp. include/voreen/modules/test.
1. Write the Module Class
The TestModule class is responsible for registering all classes contained in the module at run time. In our example it looks as follows:
include/voreen/modules/test/testmodule.h
#ifndef VRN_TESTMODULE_H
#define VRN_TESTMODULE_H
#include "voreen/core/voreenmodule.h"
namespace voreen {
class TestModule : public VoreenModule {
public:
TestModule();
virtual std::string getDescription() const {
return "My first test module.";
}
};
} // namespace
#endif // VRN_TESTMODULE_Hsrc/modules/test/testmodule.cpp
#include "voreen/modules/test/testmodule.h"
#include "voreen/modules/test/testprocessor.h"
namespace voreen {
TestModule::TestModule()
: VoreenModule()
{
// module name to be used in the GUI
setName("Test");
// each module processor needs to be registered
addProcessor(new TestProcessor());
// adds src/modules/test to the shader search path
addShaderPath(getModulesPath("test"));
}
} // namespace
2. Generate the Module Project Files
NOTE: This part has slightly changed since version 2.5.
Generate the files test_common.pri, which specifies the module availability macro and the module class, and test_core.pri, which references the remaining modul files contained in src/modules/test and include/voreen/modules/test.
src/modules/test/test_common.pri
# module availability macro DEFINES += VRN_MODULE_TEST # name of the module class VRN_MODULE_CLASSES += TestModule # module class header and source file. Paths are relative to # module base directories include/voreen/modules and src/modules, resp. VRN_MODULE_CLASS_HEADERS += test/testmodule.h VRN_MODULE_CLASS_SOURCES += test/testmodule.cpp
src/modules/test/test_core.pri
# processor headers
HEADERS += $${VRN_MODULE_INC_DIR}/test/testprocessor.h
# processor sources
SOURCES += $${VRN_MODULE_SRC_DIR}/test/testprocessor.cpp
# shaders
SHADER_SOURCES += $${VRN_MODULE_SRC_DIR}/test/test.frag
3. Activate the Module
To activate the module, add the following line to config.txt
VRN_MODULES += test
4. Rebuild the Project
Regenerate the project files and rebuild the project. See Build Instructions for further details.