<commit_before>/*=========================================================================
 *
 *  Copyright Leiden University Medical Center, Erasmus University Medical
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include "selxDisplacementFieldNiftiToItkImageSinkComponent.h"
#include "selxCheckTemplateProperties.h"

namespace selx
{
template< int Dimensionality, class TPixel >
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::DisplacementFieldNiftiToItkImageSinkComponent( const std::string & name, LoggerImpl & logger ) : 
  Superclass( name, logger ), m_NetworkBuilderOutputImage( nullptr ), m_DisplacementFieldInterface( nullptr ), m_ImageDomainInterface( nullptr )
{
  m_MiniPipelineOutputImage = ItkDisplacementFieldType::New(); // this is just an empty image for we have a SmartPointer we can pass around downstream. The actual image data will be grafted into this image.
  m_ImportFilter            = ImportFilterType::New();
}


template< int Dimensionality, class TPixel >
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::~DisplacementFieldNiftiToItkImageSinkComponent()
{
}


template< int Dimensionality, class TPixel >
int
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::Accept( typename NiftiDisplacementFieldInterfaceType::Pointer other )
{
  // Store pointer to the m_WarpedImageInterface for getting the result image after in has been generated (registration).
  // TODO: sanity check that m_WarpedImageInterface was Null to detect if Set was called more than once erroneously.
  this->m_DisplacementFieldInterface = other;
  return 0;
}


template< int Dimensionality, class TPixel >
int
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::Accept( typename ItkImageDomainInterfaceType::Pointer other )
{
  // Store pointer to the m_ImageDomainInterface for getting the result image after in has been generated (registration).
  // TODO: sanity check that m_ImageDomainInterface was Null to detect if Set was called more than once erroneously.
  m_MiniPipelineOutputImage->SetRegions( other->GetItkImageDomainFixed()->GetLargestPossibleRegion() );
  //this->m_ImageDomainInterface = other;
  return 0;
}


template< int Dimensionality, class TPixel >
void
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::SetMiniPipelineOutput( itk::DataObject::Pointer NetworkBuilderOutput )
{
  /** Tries to cast the NetworkBuilderOutput to an image (data object) and stores the result.
  *  The resulting output image will be grafted into when the sink component is connected to an other component.
  * */
  //
  /*
  this->m_NetworkBuilderOutputImage = dynamic_cast< ItkImageType * >(NetworkBuilderOutput.GetPointer());
  if (this->m_NetworkBuilderOutputImage == nullptr)
  {
    throw std::runtime_error("DisplacementFieldNiftiToItkImageSinkComponent cannot cast the NetworkBuilder's Output to the required type");
  }
  this->m_MiniPipelineOutputImage = this->m_NetworkBuilderOutputImage;
  */
}


template< int Dimensionality, class TPixel >
typename itk::DataObject::Pointer
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::GetMiniPipelineOutput()<commit_msg>BUG: Fix Nifty to ITK displacement field missing world coordinates<commit_after>/*=========================================================================
 *
 *  Copyright Leiden University Medical Center, Erasmus University Medical
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include "selxDisplacementFieldNiftiToItkImageSinkComponent.h"
#include "selxCheckTemplateProperties.h"

namespace selx
{
template< int Dimensionality, class TPixel >
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::DisplacementFieldNiftiToItkImageSinkComponent( const std::string & name, LoggerImpl & logger ) : 
  Superclass( name, logger ), m_NetworkBuilderOutputImage( nullptr ), m_DisplacementFieldInterface( nullptr ), m_ImageDomainInterface( nullptr )
{
  m_MiniPipelineOutputImage = ItkDisplacementFieldType::New(); // this is just an empty image for we have a SmartPointer we can pass around downstream. The actual image data will be grafted into this image.
  m_ImportFilter            = ImportFilterType::New();
}


template< int Dimensionality, class TPixel >
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::~DisplacementFieldNiftiToItkImageSinkComponent()
{
}


template< int Dimensionality, class TPixel >
int
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::Accept( typename NiftiDisplacementFieldInterfaceType::Pointer other )
{
  // Store pointer to the m_WarpedImageInterface for getting the result image after in has been generated (registration).
  // TODO: sanity check that m_WarpedImageInterface was Null to detect if Set was called more than once erroneously.
  this->m_DisplacementFieldInterface = other;
  return 0;
}


template< int Dimensionality, class TPixel >
int
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::Accept( typename ItkImageDomainInterfaceType::Pointer other )
{
  // Store pointer to the m_ImageDomainInterface for getting the result image after in has been generated (registration).
  // TODO: sanity check that m_ImageDomainInterface was Null to detect if Set was called more than once erroneously.
  this->m_MiniPipelineOutputImage->SetRegions( other->GetItkImageDomainFixed()->GetLargestPossibleRegion() );
  this->m_MiniPipelineOutputImage->CopyInformation( other->GetItkImageDomainFixed());
  //this->m_ImageDomainInterface = other;
  return 0;
}


template< int Dimensionality, class TPixel >
void
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::SetMiniPipelineOutput( itk::DataObject::Pointer NetworkBuilderOutput )
{
  /** Tries to cast the NetworkBuilderOutput to an image (data object) and stores the result.
  *  The resulting output image will be grafted into when the sink component is connected to an other component.
  * */
  //
  /*
  this->m_NetworkBuilderOutputImage = dynamic_cast< ItkImageType * >(NetworkBuilderOutput.GetPointer());
  if (this->m_NetworkBuilderOutputImage == nullptr)
  {
    throw std::runtime_error("DisplacementFieldNiftiToItkImageSinkComponent cannot cast the NetworkBuilder's Output to the required type");
  }
  this->m_MiniPipelineOutputImage = this->m_NetworkBuilderOutputImage;
  */
}


template< int Dimensionality, class TPixel >
typename itk::DataObject::Pointer
DisplacementFieldNiftiToItkImageSinkComponent< Dimensionality, TPixel >::GetMiniPipelineOutput()
{'fraction_non_alphanumeric': 0.10783938814531549, 'fraction_numerical': 0.0015296367112810707, 'mean_word_length': 5.846422338568935, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5221663', 'n_tokens_mistral': 2087, 'n_tokens_neox': 2043, 'n_words': 682}