Commit 383f9e69 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: check whether SuperElastixFilter in/outputs match Sources/Sinks

parent 9547cce1
......@@ -413,7 +413,8 @@ TEST_F(WBIRDemoTest, elastix_BS_NCC)
superElastixFilter->SetInput("FixedImageSource", fixedImageReader->GetOutput());
superElastixFilter->SetInput("MovingImageSource", movingImageReader->GetOutput());
//resultImageWriter->SetInput(superElastixFilter->GetOutput<Image2DType>("ResultImageSink"));
resultImageWriter->SetInput(superElastixFilter->GetOutput<Image2DType>("ResultImageSink"));
//elastix component does not have an deformation output, but writes deformationfield to disk.
//vectorImageWriter->SetInput(superElastixFilter->GetOutput<VectorImage2DType>("ResultDisplacementFieldSink"));
baselineImageReader->SetFileName(dataManager->GetBaselineFile("elastix_BS_NCC_Image.mhd"));
......@@ -432,7 +433,7 @@ TEST_F(WBIRDemoTest, elastix_BS_NCC)
//superElastixFilter->Update();
// Update call on the writers triggers SuperElastix to configure and execute
//EXPECT_NO_THROW(resultImageWriter->Update());
EXPECT_NO_THROW(resultImageWriter->Update());
//EXPECT_NO_THROW(vectorImageWriter->Update());
EXPECT_NO_THROW(compareImageFilter->Update());
......@@ -509,7 +510,8 @@ TEST_F(WBIRDemoTest, elastix_BS_MSD)
superElastixFilter->SetInput("MovingImageSource", movingImageReader->GetOutput());
resultImageWriter->SetInput(superElastixFilter->GetOutput<Image2DType>("ResultImageSink"));
vectorImageWriter->SetInput(superElastixFilter->GetOutput<VectorImage2DType>("ResultDisplacementFieldSink"));
//elastix component does not have an deformation output, but writes deformationfield to disk.
//vectorImageWriter->SetInput(superElastixFilter->GetOutput<VectorImage2DType>("ResultDisplacementFieldSink"));
baselineImageReader->SetFileName(dataManager->GetBaselineFile("elastix_BS_MSD_Image.mhd"));
baselineVectorImageReader->SetFileName(dataManager->GetBaselineFile("elastix_BS_MSD_Displacement.mhd"));
......@@ -527,7 +529,7 @@ TEST_F(WBIRDemoTest, elastix_BS_MSD)
//superElastixFilter->Update();
// Update call on the writers triggers SuperElastix to configure and execute
//EXPECT_NO_THROW(resultImageWriter->Update());
EXPECT_NO_THROW(resultImageWriter->Update());
//EXPECT_NO_THROW(vectorImageWriter->Update());
EXPECT_NO_THROW(compareImageFilter->Update());
......
......@@ -72,6 +72,7 @@ private:
bool m_InputConnectionModified;
bool m_OutputConnectionModified;
bool m_BlueprintConnectionModified;
bool m_IsConnected;
};
} // namespace elx
......
......@@ -13,7 +13,7 @@ namespace selx
template< typename ComponentTypeList >
SuperElastixFilter< ComponentTypeList >
::SuperElastixFilter(void) : m_InputConnectionModified(true), m_OutputConnectionModified(true), m_BlueprintConnectionModified(true)
::SuperElastixFilter(void) : m_InputConnectionModified(true), m_OutputConnectionModified(true), m_BlueprintConnectionModified(true), m_IsConnected(false)
{
this->m_Overlord = std::unique_ptr<Overlord> (new Overlord());
......@@ -61,21 +61,59 @@ SuperElastixFilter< ComponentTypeList >
if ((m_InputConnectionModified == true) || (this->m_BlueprintConnectionModified == true))
{
auto usedInputs = this->GetInputNames();
Overlord::SourceInterfaceMapType sources = this->m_Overlord->GetSourceInterfaces();
for (const auto & nameAndInterface : sources)
{
auto foundIndex = std::find(usedInputs.begin(), usedInputs.end(), nameAndInterface.first);
if (foundIndex == usedInputs.end())
{
// or should we catch and rethrow nameAndInterface.second->SetMiniPipelineInput(this->GetInput(nameAndInterface.first)); ?
itkExceptionMacro(<< "SuperElastixFilter requires the input """ << nameAndInterface.first << """ for the Source Component with that name" )
}
nameAndInterface.second->SetMiniPipelineInput(this->GetInput(nameAndInterface.first));
usedInputs.erase(foundIndex);
}
if (usedInputs.size() > 0)
{
std::stringstream msg;
msg << "These inputs are connected, but not used by any Source Component: " << std::endl;
for (auto & unusedInput : usedInputs)
{
msg << unusedInput << std::endl;
}
itkExceptionMacro( << msg.str())
}
}
if ((m_OutputConnectionModified == true) || (this->m_BlueprintConnectionModified == true))
{
auto usedOutputs = this->GetOutputNames();
Overlord::SinkInterfaceMapType sinks = this->m_Overlord->GetSinkInterfaces();
for (const auto & nameAndInterface : sinks)
{
auto foundIndex = std::find(usedOutputs.begin(), usedOutputs.end(), nameAndInterface.first);
if (foundIndex == usedOutputs.end())
{
// or should we catch and rethrow nameAndInterface.second->SetMiniPipelineOutput(this->GetOutput(nameAndInterface.first)); ?
itkExceptionMacro(<< "SuperElastixFilter requires the output """ << nameAndInterface.first << """ for the Sink Component with that name")
}
nameAndInterface.second->SetMiniPipelineOutput(this->GetOutput(nameAndInterface.first));
usedOutputs.erase(foundIndex);
}
if (usedOutputs.size() > 0)
{
std::stringstream msg;
msg << "These outputs are connected, but not used by any Sink Component: " << std::endl;
for (auto & unusedOutput : usedOutputs)
{
msg << unusedOutput << std::endl;
}
itkExceptionMacro(<< msg.str())
}
}
if (allUniqueComponents == false) // by setting inputs and outputs, settings could be derived to uniquely select the other components
......@@ -85,9 +123,10 @@ SuperElastixFilter< ComponentTypeList >
bool isSuccess(false);
if (allUniqueComponents)
if (allUniqueComponents && !this->m_IsConnected)
{
isSuccess = this->m_Overlord->ConnectComponents();
this->m_IsConnected = true;
}
std::cout << "Connecting Components: " << (isSuccess ? "succeeded" : "failed") << std::endl;
......@@ -97,9 +136,9 @@ SuperElastixFilter< ComponentTypeList >
Overlord::SinkInterfaceMapType sinks = this->m_Overlord->GetSinkInterfaces();
for (const auto & nameAndInterface : sinks)
{
// TODO this Update seems needed, but I would expect that UpdateOutputInformation should be enough
//nameAndInterface.second->GetMiniPipelineOutput()->Update();
// Update information: ask the mini pipeline what the size of the data will be
nameAndInterface.second->GetMiniPipelineOutput()->UpdateOutputInformation();
// Put the information into the Filter's output Objects by grafting
this->GetOutput(nameAndInterface.first)->Graft(nameAndInterface.second->GetMiniPipelineOutput());
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment