Create Another#

Synopsis#

Copy/duplicate a filter

Results#

Output:

2

Code#

C++#

#include "itkAbsImageFilter.h"
#include "itkImage.h"

template <class TImage>
void
CreateImage(typename TImage::Pointer image)
{
  using ImageType = TImage;
  typename ImageType::IndexType start;
  start.Fill(0);

  typename ImageType::SizeType size;
  size.Fill(2);

  typename ImageType::RegionType region(start, size);

  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(-2);
}

int
main()
{
  constexpr unsigned int Dimension = 2;
  using PixelType = double;

  using ImageType = itk::Image<PixelType, Dimension>;

  using FilterType = itk::AbsImageFilter<ImageType, ImageType>;
  auto                filter = FilterType::New();
  FilterType::Pointer filter2 = dynamic_cast<FilterType *>(filter->CreateAnother().GetPointer());

  auto image = ImageType::New();
  CreateImage<ImageType>(image);

  filter2->SetInput(image);
  filter2->Update();

  itk::Index<Dimension> index;
  index.Fill(0);

  std::cout << filter2->GetOutput()->GetPixel(index) << std::endl;

  return EXIT_SUCCESS;
}

Classes demonstrated#

class Object : public itk::LightObject

Base class for most ITK classes.

Object is the second-highest level base class for most itk objects. It extends the base object functionality of LightObject by implementing callbacks (via object/observer), debug flags/methods, and modification time tracking. Most ITK classes should be a subclass of Object due to the need to keep track of modified time.

ITK Sphinx Examples:

Subclassed by itk::BinaryImageToLevelSetImageAdaptorBase< TInput, MalcolmSparseLevelSetImage< TInput::ImageDimension > >, itk::BinaryImageToLevelSetImageAdaptorBase< TInput, ShiSparseLevelSetImage< TInput::ImageDimension > >, itk::BinaryImageToLevelSetImageAdaptorBase< TInput, TOutput >, itk::BinaryImageToLevelSetImageAdaptorBase< TInput, WhitakerSparseLevelSetImage< TOutput, TInput::ImageDimension > >, itk::BinaryImageToLevelSetImageAdaptorBase< TInputImage, LevelSetDenseImage< TLevelSetImage > >, itk::CenteredTransformInitializer< VersorRigid3DTransform< double >, TFixedImage, TMovingImage >, itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >, itk::CostFunctionTemplate< TParametersValueType >, itk::DomainThreader< itk::ThreadedIndexedContainerPartitioner, itk::GradientDescentOptimizerBasev4Template >, itk::DomainThreader< itk::ThreadedIndexedContainerPartitioner, itk::QuasiNewtonOptimizerv4Template >, itk::DomainThreader< TDomainPartitioner, TImageToImageMetricv4 >, itk::DomainThreader< TDomainPartitioner, TJointHistogramMetric >, itk::DomainThreader< ThreadedImageRegionPartitioner< TImage::ImageDimension >, TLevelSetEvolution >, itk::DomainThreader< ThreadedImageRegionPartitioner< TImageToImageMetricv4::VirtualImageDimension >, TImageToImageMetricv4 >, itk::DomainThreader< ThreadedImageRegionPartitioner< TJointHistogramMetric::VirtualImageDimension >, TJointHistogramMetric >, itk::DomainThreader< ThreadedIndexedContainerPartitioner, GradientDescentOptimizerBasev4Template< TInternalComputationValueType > >, itk::DomainThreader< ThreadedIndexedContainerPartitioner, QuasiNewtonOptimizerv4Template< TInternalComputationValueType > >, itk::DomainThreader< ThreadedIndexedContainerPartitioner, TImageToImageMetricv4 >, itk::DomainThreader< ThreadedIndexedContainerPartitioner, TJointHistogramMetric >, itk::DomainThreader< ThreadedIteratorRangePartitioner< TLevelSetEvolution::DomainMapImageFilterType::DomainMapType::const_iterator >, TLevelSetEvolution >, itk::DomainThreader< ThreadedIteratorRangePartitioner< WhitakerSparseLevelSetImage< TOutput, VDimension >::LayerConstIterator >, TLevelSetEvolution >, itk::FunctionBase< Array< double >, double >, itk::FunctionBase< ContinuousIndex< TCoordRep, VSpaceDimension >, Array< double > >, itk::FunctionBase< double, double >, itk::FunctionBase< Point< float, TInputImage::ImageDimension >, TOutput >, itk::FunctionBase< Point< TCoordRep, TImageType ::ImageDimension >, NumericTraits< TImageType ::PixelType >::RealType >, itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, bool >, itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, NumericTraits< TInputImage::PixelType >::RealType >, itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, TInputImage::PixelType >, itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, TOutput >, itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, TOutputType >, itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, vnl_matrix< NumericTraits< TInputImage::PixelType::ValueType >::RealType > >, itk::FunctionBase< Point< TCoordRep, VSpaceDimension >, double >, itk::FunctionBase< Point< TOutput, TInputImage::ImageDimension >, SymmetricSecondRankTensor< TOutput, TInputImage::ImageDimension > >, itk::FunctionBase< Point< TOutput, TInputImage::ImageDimension >, TOutput >, itk::FunctionBase< Point< TOutput, TInputImage::ImageDimension >, Vector< TOutput, TInputImage::ImageDimension > >, itk::FunctionBase< TFunction::InputType, bool >, itk::FunctionBase< TInput, bool >, itk::FunctionBase< TInputPointSet::PointType, TOutput >, itk::FunctionBase< TMeasurementVector, double >, itk::FunctionBase< TMesh, TMesh::EdgeListPointerType >, itk::FunctionBase< TPointSet ::PointType, TOutput >, itk::FunctionBase< TRealValueType, TRealValueType >, itk::FunctionBase< TVector, double >, itk::GPUReduction< float >, itk::GPUReduction< int >, itk::HistogramAlgorithmBase< THistogram >, itk::ArchetypeSeriesFileNames, itk::BinaryImageToLevelSetImageAdaptorBase< TInputImage, TLevelSet >, itk::BoundingBox< TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer >, itk::BSplineTransformInitializer< TTransform, TImage >, itk::BuildInformation, itk::ByteSwapper< T >, itk::CastSpatialObjectFilter< ObjectDimension >, itk::CenteredTransformInitializer< TTransform, TFixedImage, TMovingImage >, itk::ColorTable< TPixel >, itk::Command, itk::CostFunctionTemplate< TInternalComputationValueType >, itk::CreateObjectFunctionBase, itk::DataObject, itk::Directory, itk::DomainThreader< TDomainPartitioner, TAssociate >, itk::DOMNode, itk::DOMNodeXMLReader, itk::DOMNodeXMLWriter, itk::DOMReader< TOutput >, itk::DOMWriter< TInput >, itk::DynamicLoader, itk::FastMarchingImageToNodePairContainerAdaptor< TInput, TOutput, TImage >, itk::FFTWGlobalConfiguration, itk::Function::ColormapFunction< TScalar, TRGBPixel >, itk::Function::ConvergenceMonitoringFunction< TScalar, TEnergyValue >, itk::FunctionBase< TInput, TOutput >, itk::GPUDataManager, itk::GPUReduction< TElement >, itk::HistogramAlgorithmBase< TInputHistogram >, itk::ImageContainerInterface< TElementIdentifier, TElement >, itk::ImageDuplicator< TInputImage >, itk::ImageIOFactory, itk::ImageMomentsCalculator< TImage >, itk::ImagePCADecompositionCalculator< TInputImage, TBasisImage >, itk::ImageRegionSplitterBase, itk::ImportImageContainer< TElementIdentifier, TElement >, itk::IndexedContainerInterface< TElementIdentifier, TElement >, itk::KappaSigmaThresholdImageCalculator< TInputImage, TMaskImage >, itk::LandmarkBasedTransformInitializer< TTransform, TFixedImage, TMovingImage >, itk::LevelSetContainerBase< TIdentifier, TLevelSet >, itk::LevelSetDomainPartitionBase< TDomain >, itk::LevelSetEquationContainer< TTermContainer >, itk::LevelSetEquationTermBase< TInputImage, TLevelSetContainer >, itk::LevelSetEquationTermContainer< TInputImage, TLevelSetContainer >, itk::LevelSetEvolutionBase< TEquationContainer, TLevelSet >, itk::LightProcessObject, itk::LoggerBase, itk::LoggerManager, itk::LogOutput, itk::MapContainer< TElementIdentifier, TElement >, itk::MeshIOFactory, itk::MetaConverterBase< VDimension >, itk::MetaSceneConverter< NDimensions, PixelType, TMeshTraits >, itk::MinimumMaximumImageCalculator< TInputImage >, itk::MRASlabIdentifier< TInputImage >, itk::MultiThreaderBase, itk::NumericSeriesFileNames, itk::ObjectFactoryBase, itk::ObjectStore< TObjectType >, itk::ObjectToObjectOptimizerBaseTemplate< TInternalComputationValueType >, itk::OctreeBase, itk::Optimizer, itk::OptimizerParameterScalesEstimatorTemplate< TInternalComputationValueType >, itk::OutputWindow, itk::PointsLocator< TPointsContainer >, itk::ProcessObject, itk::ProgressAccumulator, itk::QuadEdgeMeshDecimationCriterion< TMesh, TElement, TMeasure, TPriorityQueueWrapper >, itk::QuadEdgeMeshFunctionBase< TMesh, TOutput >, itk::QuadEdgeMeshTopologyChecker< TMesh >, itk::RealTimeClock, itk::RegularExpressionSeriesFileNames, itk::RingBuffer< TElement >, itk::RobustAutomaticThresholdCalculator< TInputImage, TGradientImage >, itk::SegmentationBorder, itk::SegmentationRegion, itk::SimplexMeshVolumeCalculator< TInputMesh >, itk::SparseFieldLayer< TNodeType >, itk::SpatialObjectDuplicator< TInputSpatialObject >, itk::SpatialObjectReader< NDimensions, PixelType, TMeshTraits >, itk::SpatialObjectToImageStatisticsCalculator< TInputImage, TInputSpatialObject, TSampleDimension >, itk::SpatialObjectWriter< NDimensions, PixelType, TMeshTraits >, itk::Statistics::DecisionRule, itk::Statistics::DenseFrequencyContainer2, itk::Statistics::ExpectationMaximizationMixtureModelEstimator< TSample >, itk::Statistics::KdTree< TSample >, itk::Statistics::KdTreeBasedKmeansEstimator< TKdTree >, itk::Statistics::KdTreeGenerator< TSample >, itk::Statistics::MixtureModelComponentBase< TSample >, itk::Statistics::ProbabilityDistribution, itk::Statistics::RandomVariateGeneratorBase, itk::Statistics::ScalarImageToHistogramGenerator< TImageType >, itk::Statistics::SparseFrequencyContainer2, itk::Statistics::SubsamplerBase< TSample >, itk::StoppingCriterionBase, itk::testhelper::ImageRegistrationMethodImageSource< TFixedPixelType, TMovingPixelType, NDimension >, itk::ThreadedDomainPartitioner< TDomain >, itk::ThreadPool, itk::TransformBaseTemplate< TParametersValueType >, itk::TransformIOFactoryTemplate< TParametersValueType >, itk::TransformParametersAdaptorBase< TTransform >, itk::UpdateMalcolmSparseLevelSet< VDimension, TEquationContainer >, itk::UpdateShiSparseLevelSet< VDimension, TEquationContainer >, itk::UpdateWhitakerSparseLevelSet< VDimension, TLevelSetValueType, TEquationContainer >, itk::ValarrayImageContainer< TElementIdentifier, TElement >, itk::VectorContainer< TElementIdentifier, TElement >, itk::Version, itk::VideoIOFactory, itk::VTKPolyDataWriter< TInputMesh >, itk::WarpHarmonicEnergyCalculator< TInputImage >, itk::LevelSetContainerBase< TIdentifier, LevelSetDenseImage< TImage > >, itk::LevelSetDomainPartitionBase< TImage >, itk::LevelSetDomainPartitionBase< TMesh >, itk::LevelSetEquationTermBase< TInput, TLevelSetContainer >, itk::LevelSetEvolutionBase< TEquationContainer, LevelSetDenseImage< TImage > >, itk::LevelSetEvolutionBase< TEquationContainer, MalcolmSparseLevelSetImage< VDimension > >, itk::LevelSetEvolutionBase< TEquationContainer, ShiSparseLevelSetImage< VDimension > >, itk::LevelSetEvolutionBase< TEquationContainer, WhitakerSparseLevelSetImage< TOutput, VDimension > >, itk::MetaConverterBase< NDimensions >, itk::ObjectToObjectOptimizerBaseTemplate< double >, itk::OptimizerParameterScalesEstimatorTemplate< TMetric::ParametersValueType >, itk::QuadEdgeMeshFunctionBase< TMesh, TQEType * >, itk::QuadEdgeMeshFunctionBase< TMesh, TQEType::OriginRefType >, itk::ThreadedDomainPartitioner< ImageRegion< VDimension > >, itk::ThreadedDomainPartitioner< Index< 2 > >, itk::ThreadedDomainPartitioner< ThreadedIteratorRangePartitionerDomain< TIterator > >, itk::TransformParametersAdaptorBase< Transform< TTransform::ScalarType, TTransform::InputSpaceDimension, TTransform::OutputSpaceDimension > >, itk::VectorContainer< TElementIdentifier, TElementWrapper >, itk::VTKPolyDataWriter< TMesh >

See itk::Object for additional documentation.