STYLE: Call SetNthOutput(i, MakeOutput(i)) in a for loop#4687
STYLE: Call SetNthOutput(i, MakeOutput(i)) in a for loop#4687N-Dekker wants to merge 1 commit intoInsightSoftwareConsortium:masterfrom
SetNthOutput(i, MakeOutput(i)) in a for loop#4687Conversation
Reduced duplicate code by replacing manual `SetNthOutput(i, MakeOutput(i)` calls for i = 0, 1, 2 with the corresponding `for` loops.
SetNthOutput(i, MakeOutput(i) in a for loopSetNthOutput(i, MakeOutput(i)) in a for loop
|
@blowekamp Following our discussion at #4654 (comment) I'm still trying to get clear in which particular scenario's |
|
OK, so this could be a nice use case, being able to call |
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 Note: An incorrectly casted image type can work a surprising long time as the wrong type. |
It is also used here: Which indirectly gets called when operations the "ReleaseDataFlagOn" or "DisconnectPipeline" are called and the output created in the constructor is created again. |
Interesting, thanks! Apparently |
| // distance map, voronoi map, distance vectors | ||
| for (unsigned int i{}; i < numberOfRequiredOutputs; ++i) | ||
| { | ||
| ProcessObject::SetNthOutput(i, Self::MakeOutput(i)); | ||
| } |
There was a problem hiding this comment.
Maybe we can make this more generic, like:
ProcessObject::SetRequiredOutputs(*this, numberOfRequiredOutputs);
This new function, SetRequiredOutputs would then set the numberOfRequiredOutputs and do the for loop. What do you think?
There was a problem hiding this comment.
For the constructors we are in a bit of a hard place where the methods called be the constructor should not be virtual. That is the virtual MakeOutput should not be called by base classes in the constructor.
This is more of a design issue, maybe the output should only be created on demand? or Maybe a separate "virtual Initialize" method is needed.
Then there is the idea of having a base class take multiple template parameters for inputs and outputs.... But for the few filters it's likely not worth the refactor.
|
Reduced duplicate code by replacing manual
SetNthOutput(i, MakeOutput(i))calls for i = 0, 1, 2 with the correspondingforloops.