Closed N-Dekker closed 1 week ago
@blowekamp Following our discussion at https://github.com/InsightSoftwareConsortium/ITK/pull/4654#discussion_r1596759648 I'm still trying to get clear in which particular scenario's MakeOutput(i)
is actually useful, within a default-constructor. Is this an example use case? I mean, the ability to call it iteratively in a for
loop?
OK, so this could be a nice use case, being able to call Self::MakeOutput(i)
is a for
loop. Still I'm interested to hear if calling Self::MakeOutput(i)
is also useful outside the constructor of a class (the class Self
).
@blowekamp Following our discussion at #4654 (comment) I'm still trying to get clear in which particular scenario's
MakeOutput(i)
is actually useful, within a default-constructor. Is this an example use case? I mean, the ability to call it iteratively in afor
loop?
Thanks for the continued investigation and the discussion. These filters have multiple outputs of different types. These different output types are not represented by the template parameters. Hence the MakeOutput
method has been overloaded to create the correct "nth" output. This is important because the base class ImageSource
just creates all outputs of the same type. Having the correctly typed output was a hard issue to track down with forced casted and failed dynamic casts. The pattern used in as many places possible was to use the MakeOutput method as the generic way to create the outputs.
Note: An incorrectly casted image type can work a surprising long time as the wrong type.
Still I'm interested to hear if calling
Self::MakeOutput(i)
is also useful outside the constructor of a class (the classSelf
).
It is also used here: https://github.com/InsightSoftwareConsortium/ITK/blob/8e5abbd87129e1cba589d5999b28957802ca28c0/Modules/Core/Common/src/itkProcessObject.cxx#L464
Which indirectly gets called when operations the "ReleaseDataFlagOn" or "DisconnectPipeline" are called and the output created in the constructor is created again.
It is also used here:
Interesting, thanks! Apparently SetOutput(name, output)
creates a new output by calling MakeOutput
, if the output
argument passed by the user is NULL. I did not know that. 🤷
Reduced duplicate code by replacing manual
SetNthOutput(i, MakeOutput(i))
calls for i = 0, 1, 2 with the correspondingfor
loops.