In the following chapter, we will merge our two modules
(SimpleAdd
and SimpleAverage
)
into one project, in the following steps:
Per project, one DLL (.DLL
/.dynlib
/.so
)
file is created and transferred, and the modules might share common includes etc.
within one project.
Therefore, this example is a showcase on how to build a larger library by augmenting an existing project.
In this example, we will merge the SimpleAverage
module into the SimpleAdd
project. For two modules, this is an arbitrary decision; for larger projects, always merge into the existing project.
Note | |
---|---|
The source code of this example is not delivered with MeVisLab, as it would lead to module name collisions with the examples above. If you want to implement this example, make sure to change the module names or to move the original modules to another folder. |
Copy the mlSimpleAverage.cpp
and mlSimpleAverage.h
files
to the source folder of SimpleAdd
.
Open the CMakeLists.txt
of your project in any text editor.
Add mlSimpleAverage.h
and mlSimpleAverage.cpp
to the target_sources
statement.
Resulting code (excerpt):
target_sources(MLSimpleAddExample PRIVATE mlSimpleAddExample.cpp mlSimpleAddExample.h mlSimpleAverage.cpp mlSimpleAverage.h MLSimpleAddExampleInit.cpp MLSimpleAddExampleInit.h MLSimpleAddExampleSystem.h )
Re-translate the CMakeLists.txt
file.
Open the SimpleAdd
project in your development environment.
Open SimpleAverage.h
.
Exchange the line
#include "MLSimpleAverageSystem.h"
by
#include "MLSimpleAddSystem.h"
Resulting in:
// Local includes
#include "MLSimpleAddSystem.h"
Exchange the macro in the class definition (this handles exporting symbols under Windows)
MLSIMPLEAVERAGE_EXPORT
by
MLSIMPLEADD_EXPORT
Resulting in:
//! Computes the average voxel value of an image.
class MLSIMPLEADD_EXPORT SimpleAverage : public Module
The new module in this project (i.e., SimpleAdd
) needs
to be initialized for the runtime-type system.
Open MLSimpleAddInit.cpp
.
Add the line
#include "mlSimpleAverage.h"
below the line
#include "mlSimpleAdd.h"
Resulting in:
// Include all module headers ...
#include "mlSimpleAdd.h"
#include "mlSimpleAverage.h"
Add the line
SimpleAverage::initClass();
below the line
SimpleAdd::initClass();
Resulting in:
SimpleAdd::initClass();
SimpleAverage::initClass();
This registers the classes to the ML runtime type system.
Recompile the project.
Note | |
---|---|
|
Copy the file SimpleAverage.script
to the folder containing the file SimpleAdd.def
.
Open the file MLSimpleAverage.def
in MATE.
Copy the definition of the module SimpleAverage
into the clipboard (this is at least from the line
MLModule SimpleAverage {to the last closing curly bracket (
}
)
Open the file MLSimpleAdd.def
.
Paste the definition of the SimpleAverage
module
below the definition of the SimpleAdd
module.
Exchange the line in the definition of the SimpleAverage module
DLL = "MLSimpleAverage"
by the line
DLL = "MLSimpleAdd"
Resulting code:
MLModule SimpleAdd {
DLL = MLSimpleAdd
genre = ""
author = "JDoe"
comment = "Adds a constant double value to each voxel."
keywords = ""
seeAlso = Arithmetic1
exampleNetwork = $(LOCAL)/networks/SimpleAddExample.mlab
externalDefinition = $(LOCAL)/SimpleAdd.script
}
MLModule SimpleAverage {
DLL = MLSimpleAdd
genre = ""
author = "JDoe"
comment = "Computes the average voxel value of an image."
keywords = "Statistics Average"
seeAlso = ""
exampleNetwork = $(LOCAL)/networks/SimpleAverageExample.mlab
externalDefinition = $(LOCAL)/SimpleAverage.script
}
Copy the example network and HTML documentation of the
SimpleAverage
module to the according folders
of the SimpleAdd
module. The paths to those files
should be relative, so they are still correct.
(Re)move the old files and folders of the SimpleAverage
module from the folders /Sources
and /Modules
so that no
conflicts arise.
(Re)start MeVisLab.
Both modules can now be added, for example via a quick search. However, you will find that in the About information, the same DLL will appear for both modules.
© 2024 MeVis Medical Solutions AG