You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Example 1: Creating a New ML Module for Adding Values"
11
+
title: "Example 1: Creating a New ML Module for Adding a Value to Each Voxel"
12
12
weight: 602
13
13
parent: "cpp"
14
14
---
15
15
16
-
# Example 1: Creating a New ML Module for Adding Values
16
+
# Example 1: Creating a New ML Module for Adding a Value to Each Voxel
17
17
18
18
## Precondition
19
19
Make sure to have [cmake](https://cmake.org/download) installed. This example has been created using CMake Legacy Release (3.31.11).
20
20
21
21
## Introduction
22
-
In this example, we develop our own C++ ML module which adds a constant value to each voxel of the given input image.
22
+
In this example, we develop our own C++ ML module, which adds a constant value to each voxel of the given input image.
23
23
24
24
## Steps to Do
25
25
### Create a new ML Module
26
26
Before creating the module, make sure to have your own user package available. See [Package creation](tutorials/basicmechanisms/macromodules/package/) for details about Packages.
27
27
28
-
Use the *Project Wizard* via menu entry {{< menuitem "File" "Run Project Wizard ..." >}} to create a new ML module. Select *ML Module* and click *Run Wizard*.
28
+
Use the *Project Wizard* via the menu entry {{< menuitem "File" "Run Project Wizard ..." >}} to create a new ML module. Select *ML Module* and click *Run Wizard*.
Enter properties of your new module and give your module the name `SimpleAdd`. Make sure to select your user package and name your project *SimpleAdd*.
Click *Next*. The next screen of the wizard allows you to define the inputs and outputs of your module. Select *Module Type* as *New style ML Module*, make sure to have one in- and one output and leave the rest of the settings unchanged.
36
+
Click *Next*. The next screen of the Wizard allows you to define the inputs and outputs of your module. Select *Module Type* as *New style ML Module*, make sure to have one input and one output and leave the rest of the settings unchanged.
Click *Next*. On the next screen, we can define some additional properties of our module. Select *Add activateAttachments()*, unselect *Acc configuration hints* and select *Add MDL window with fields*.
40
+
Click *Next*. On the next screen, we can define some additional properties of our module. Select *Add activateAttachments()*, unselect *Add configuration hints* and select *Add MDL window with fields*.
@@ -49,7 +49,7 @@ Click *Next*. The Module Field Interface allows you to define additional fields
49
49
50
50

51
51
52
-
Click *Create*. You see a screen showing the results of the module creation process. In case the Wizard finished succesfully, you can close the window. Additionally an explorer window opens showing the created folder containing your sources and the *CMakeLists.txt*.
52
+
Click *Create*. You see a screen showing the results of the module creation process. In the case the Wizard finished succesfully, you can close the window. Additionally, an explorer window opens showing the created folder containing your sources and the *CMakeLists.txt*.
53
53
54
54
The foundation of the module has been created with the Wizard. From here on, the programming starts.
55
55
@@ -62,13 +62,13 @@ Just make sure that the MLAB_ROOT environment variable is set on your system and
62
62
63
63
Open a commandline and change to your current module directory (the directory containing your *CMakeLists.txt* file). Enter **cmake . -G "Visual Studio 17"**. After execution, a lot of files are generated by CMake.
64
64
65
-
For further documentation about our use of CMake see: [CMake for MeVisLab - Documentation](https://mevislabdownloads.mevis.de/docs/current/MeVisLab/Resources/Documentation/Publish/SDK/CMakeManual/#mainBook).
65
+
For further documentation about our use of CMake, see: [CMake for MeVisLab - Documentation](https://mevislabdownloads.mevis.de/docs/current/MeVisLab/Resources/Documentation/Publish/SDK/CMakeManual/#mainBook).
66
66
67
67
### Programming the Functions of the ML Module
68
-
Open the file *ALL_BUILD.vcxproj* in your preferred C++ development environment. Select the file *mlSimpleAdd.cpp*.
68
+
Open the file *ALL_BUILD.vcxproj* in your preferred C++ development environment. Select the file *mlSimpleAdd.cpp*.
69
69
70
70
{{<alertclass="info"caption="Note">}}
71
-
In the following code examples, the comment lines already available in the created .cpp file are added for better overview.
71
+
In the following code examples, the comment lines already available in the created *.cpp* file are added for better overview.
*outputIndex* is the index number of the output connector. It is commented out in this example, because we only defined one output. In case of more than one outputs, uncomment this parameter.
114
+
*outputIndex* is the index number of the output connector. It is commented out in this example, because we only defined one output. In the case of more than one outputs, uncomment this parameter.
115
115
{{</alert>}}
116
116
117
117
#### Implementing *typedCalculateOutputSubImage*
@@ -124,7 +124,7 @@ Next, we are going to finally change the voxel values of the image. Open the fil
124
124
```
125
125
{{</highlight>}}
126
126
127
-
Then change the inner line of the loop, so that the constant value is added to the value of the input voxel:
127
+
Then, change the inner line of the loop, so that the constant value is added to the value of the input voxel:
@@ -136,20 +136,20 @@ Then change the inner line of the loop, so that the constant value is added to t
136
136
```
137
137
{{</highlight>}}
138
138
139
-
Compile the project (this includes all module files) in the development environment. Make sure to select a *Release* build.
139
+
Compile the project in the development environment. Make sure to select a *Release* build.
140
140
141
-
### Use your module in MeVisLab
142
-
Your compiled *.dll is available in your project directory under *Sources/lib*. In order to use it in MeVisLab, it needs to be copied to the *lib* folder of your user package.
141
+
### Use Your Module in MeVisLab
142
+
Your compiled **.dll* is available in your project directory under *Sources/lib*. In order to use it in MeVisLab, it needs to be copied to the *lib* folder of your user package.
143
143
144
144
You can either do this manually or via PostBuild step.
145
145
146
-
In case MeVisLab was running during development, restart MeVisLab and use your new module.
146
+
In the case MeVisLab was running during development, restart MeVisLab and use your new module.
147
147
148
148
For testing purposes, you can use a `LocalImage` module and two `View2D` modules. Connect the `SimpleAdd` module to the second `View2D` and change the <field>Constant Value</field> field.
The output image of the module `SimpleAdd` is automatically re-calculated on changing the field <field>Constant Value</field>. This is already implemented in the generated code of the file below:
152
+
The output image of the module `SimpleAdd` is automatically recalculated on changing the field <field>Constant Value</field>. This is already implemented in the generated code of the file below:
153
153
154
154
{{< highlight filename="mlSimpleAdd.cpp" >}}
155
155
```c++
@@ -177,5 +177,5 @@ The output image of the module `SimpleAdd` is automatically re-calculated on cha
177
177
178
178
## Summary
179
179
* MeVisLab allows to develop your own C++ modules.
180
-
* The Project Wizard already generates all necessary *.cpp and *.h files and a loop through all voxels of the input image.
181
-
* Changes of userdefined fields automatically lead to a recalculation of the input image.
180
+
* The Project Wizard already generates all necessary \**.cpp* and \**.h* files and a loop through all voxels of the input image.
181
+
* Changes of user-defined fields automatically lead to a recalculation of the input image.
Make sure to use a compiler that is compatible to your currently installed MeVisLab version.
22
22
{{</alert>}}
23
23
24
-
### ML modules on the C++ level
24
+
### ML Modules on the C++ Level
25
25
* Image processing modules are objects derived from class Module defined in the ML library and therefore are also called ML modules.
26
26
* Image inputs and outputs are connectors to objects of class PagedImage, which are defined in the ML library.
27
27
* Inputs and outputs for abstract data structures are connectors to pointers of objects derived from class Base and are called Base objects.
28
28
29
-
### Inventor modules on the C++-level:
30
-
* Most Inventor modules are objects derived from class SoNode defined in the Open Inventor library.
31
-
* Inventor inputs and outputs are connectors to objects derived from class SoNode defined in the Open Inventor library. Many Inventor modules will return themselves as outputs (“self”). On inputs, they may have connectors to child Inventor modules.
32
-
* Some Inventor modules are objects derived from class SoEngine. They are used for calculations and return their output not via output connectors but via fields.
33
-
* Inventor modules may also have input and output connectors to Base objects and Image objects.
34
-
* All standard Inventor nodes defined in the Open Inventor library are available in MeVisLab as Inventor modules.
29
+
### Open Inventor Modules on the C++ Level
30
+
* Most Open Inventor modules are objects derived from class SoNode defined in the Open Inventor library.
31
+
*Open Inventor inputs and outputs are connectors to objects derived from class SoNode defined in the Open Inventor library. Many Open Inventor modules will return themselves as outputs (“self”). On inputs, they may have connectors to child Open Inventor modules.
32
+
* Some Open Inventor modules are objects derived from class SoEngine. They are used for calculations and return their output not via output connectors but via fields.
33
+
*Open Inventor modules may also have input and output connectors to Base objects and Image objects.
34
+
* All standard Open Inventor nodes defined in the Open Inventor library are available in MeVisLab as Open Inventor modules.
35
35
36
-
This chapter describes some examples for developing your own ML and Inventor modules.
36
+
This chapter describes some examples for developing your own ML and Open Inventor modules.
37
37
38
38
## Some Tips for Module Design
39
39
### Macro Modules or C++ Modules?
@@ -46,23 +46,20 @@ In [Example 2: Macro Modules](tutorials/basicmechanisms/macromodules/), we alrea
46
46
* scripting possible on the module or network level
47
47
* scripting supported by the Scripting Assistant View (basically a recorder for actions performed on the network)
48
48
49
-
**Disadvantages:**
50
-
* With macros, only existing functionalities and algorithms can be used.
51
-
52
49
**Conclusion:**
53
50
* For rapid prototyping based on existing image processing algorithms, use macros.
54
51
* For implementing new image processing, write new ML or Open Inventor modules.
55
52
56
53
### Combining Functionalities
57
54
It is possible to have ML and Open Inventor connectors in the same module. Two cases are possible:
58
55
* Type 1: **ML -> visualization:** Image data or properties are displayed by a visualization module. Usually a <field>SoSFXVImage</field> field gets random access to an ML image by *getTile()*. Examples: `SoView2D`, `GlobalStatistics`.
59
-
* Type 2: **visualization -> ML:** Modules generate an ML image from an Inventor scene. Examples: `VoxelizeInventorScene`, `SoExaminerViewer` (hidden functionality).
56
+
* Type 2: **visualization -> ML:** Modules generate an ML image from an Open Inventor scene. Examples: `VoxelizeInventorScene`, `SoExaminerViewer` (hidden functionality).
60
57
61
58
Generally, however, it is not always a good solution to combine that, as the processes of image processing and image visualization are usually separated.
62
59
63
60
Therefore, rather separate the ML and Open Inventor functionalities into two modules. This way,
64
61
* functionality is encapsulated and can be reused as module
65
62
* modules for the single steps may already be available in MeVisLab and spare you a new development
66
63
67
-
## Code examples
68
-
In addition to the tutorials in this chapter, you can find additional code examples in your MeVisLab installation directory.
64
+
## Code Examples
65
+
In addition to the tutorials in this chapter, you can find additional code examples in your MeVisLab installation directory.
0 commit comments