In the example above, the change in length will be translated into an overall change with the center of rotation as overall center. However, it might be preferable to keep the tip in place and change the length of the shaft into the other direction.
Basically, this is the same problem as in the length calculation we made in the Python script. However, instead of calculating it in the macro scripting, we can also use a module for the calculation.
For this, the following modules need to be added:
SoCalculator
: For calculating
the length of the shaft.
SoComposeVec3f
: For applying
the translation of the float value to the vector of the overall
translation in TranslationApplicator
.
The SoCalculator
module offers
input and output of floating values and vectors.
Some important points:
In the Expression
field, mathematic formulas can be
entered; the name of the input values and the name of the output have
to be given.
More than one expression can be entered. For that, end each line with a semicolon ;
For the expression to be calculated, you need to click Apply.
For calculating the translation from the input values of cone and
shaft height, use the SoCalculator
module
and set up parameter connections
Connect SoCylinder.height
to
SoCalculator.a
Connect SoCone.height
to
SoCalculator.b
Enter the calculation: oa = - (0.5*a+0.5*b)
(a
negative sign needs to be added; otherwise, the end of the applicator
is fixed and the tip side grows).
To apply the new translation, we need another SoComposeVec3f
module. It allows for converting
the float value y into a vector translation in y direction. For this, it
needs to receive the output of SoCalculator
and deliver the input for the
SoTranslation
module.
Connect SoCalculator.oa
to
SoComposeVec3f1.y
Connect SoComposeVec3f1.vector
to SoTranslation.translation
Tip | |
---|---|
You can find the names of the connected parameters by right-clicking the parameter connections. For an overview of all parameter connections in a network, use the Parameter Connections Inspector View. |
The resulting macro network looks as follows:
When to choose calculating values in scripts and when via modules? This is not an easy question.
The advantage of the script is that it is easily changed and extended. This might be harder with modules.
The main advantage of using script is that the setting of parameter field values or the triggering of a (re-)computation is much more controlled. Using parameter field connections can easily lead to unwanted notification avalanches.
The advantage of the modules is that the connections between modules are visible as parameter connections (which can be changed and removed).
In the end, it comes down to your current network and your design
decisions which way to choose. Or you might combine them, like we did in
our ApplicatorMacro
network.
What else could you do now? You could, for example, make sure that the shaft length cannot be shorter than the tip length (which looks strange in the Open Inventor scene). You could also make the colors parametrizable, or add new features for the applicator.
This is the end of this example.
Tip | |
---|---|
This example is delivered with MeVisLab ( |
© 2024 MeVis Medical Solutions AG