ITK/Examples/Utilities/CreateImageWithSameType: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Deprecated content that is moved to sphinx)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
==CreateImageWithSameType.cxx==
{{warning|1=The media wiki content on this page is no longer maintained.  The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
<source lang="cpp">
#include "itkImage.h"
 
typedef itk::Image<float,2> FloatScalarImageType;
 
itk::ImageBase<2>::Pointer CreateImageWithSameType(const itk::ImageBase<2>* input);
void OutputImageType(const itk::ImageBase<2>* input);
 
int main(int argc, char *argv[])
{
  FloatScalarImageType::Pointer floatImage = FloatScalarImageType::New();
  itk::ImageBase<2>::Pointer floatCopy = CreateImageWithSameType(floatImage);
  OutputImageType(floatCopy);
 
  return EXIT_SUCCESS;
}
 
itk::ImageBase<2>::Pointer CreateImageWithSameType(const itk::ImageBase<2>* input)
{
  OutputImageType(input);
  itk::LightObject::Pointer objectCopyLight = input->CreateAnother();
 
  itk::ImageBase<2>::Pointer objectCopy = dynamic_cast<itk::ImageBase<2>*>(objectCopyLight.GetPointer());
   OutputImageType(objectCopy);
  return objectCopy;
}
 
void OutputImageType(const itk::ImageBase<2>* input)
{
  if(dynamic_cast<const FloatScalarImageType*>(input))
    {
    std::cout << "Image type FloatScalarImageType" << std::endl;
    }
  else
    {
    std::cout << "Image is Invalid type!" << std::endl;
    }
}
 
</source>
 
{{ITKCMakeLists|CreateImageWithSameType}}

Latest revision as of 20:25, 6 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.