ITK/Examples/Cxx/Developer/ImageSource
From KitwarePublic
< ITK | Examples
Jump to navigationJump to search
Revision as of 19:27, 7 November 2010 by Daviddoria (talk | contribs) (Created page with "==ImageSourceExample.cxx== <source lang="cp"> #include "itkImage.h" #include "itkImageFileWriter.h" #include "ImageFilter.h" int main(int, char*[]) { // Setup types typedef...")
ImageSourceExample.cxx
<source lang="cp">
- include "itkImage.h"
- include "itkImageFileWriter.h"
- include "ImageFilter.h"
int main(int, char*[]) {
// Setup types typedef itk::Image<unsigned char, 2> ImageType; typedef itk::ImageFilter<ImageType> FilterType;
// Create and the filter FilterType::Pointer filter = FilterType::New(); filter->Update(); typedef itk::ImageFileWriter< ImageType > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName("Test.jpg"); writer->SetInput(filter->GetOutput()); writer->Update(); return EXIT_SUCCESS;
} </source>
ImageSource.h
<source lang="cp">
- ifndef __itkImageFilter_h
- define __itkImageFilter_h
- include "itkImageSource.h"
namespace itk { template< class TOutputImage> class ImageFilter:public ImageSource< TOutputImage > { public:
/** Standard class typedefs. */ typedef ImageFilter Self; typedef ImageSource< TOutputImage > Superclass; typedef SmartPointer< Self > Pointer;
/** Method for creation through the object factory. */ itkNewMacro(Self);
/** Run-time type information (and related methods). */ itkTypeMacro(ImageFilter, ImageSource);
protected:
ImageFilter(){} ~ImageFilter(){}
/** Does the real work. */ virtual void GenerateData();
private:
ImageFilter(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented
}; } //namespace ITK
- ifndef ITK_MANUAL_INSTANTIATION
- include "ImageFilter.txx"
- endif
- endif // __itkImageFilter_h
</source>
ImageSource.txx
<source lang="cp">
- ifndef __itkImageFilter_txx
- define __itkImageFilter_txx
- include "ImageFilter.h"
- include "itkObjectFactory.h"
namespace itk {
template< class TOutputImage> void ImageFilter< TOutputImage>
- GenerateData()
{
typename TOutputImage::Pointer output = this->GetOutput(); typename TOutputImage::RegionType region; typename TOutputImage::IndexType start; start[0] = 0; start[1] = 0;
typename TOutputImage::SizeType size; size[0] = 200; size[1] = 300;
region.SetSize(size); region.SetIndex(start);
output->SetRegions(region); output->Allocate();
itk::ImageRegionIterator<TOutputImage> imageIterator(output,output->GetLargestPossibleRegion());
while(!imageIterator.IsAtEnd()) { if(imageIterator.GetIndex()[0] == imageIterator.GetIndex()[1]) { imageIterator.Set(255); } else { imageIterator.Set(0); }
++imageIterator; }
}
}// end namespace
- endif
</source>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
PROJECT(ImageSource)
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(ImageSource ImageSourceExample.cxx) TARGET_LINK_LIBRARIES(ImageSource ITKBasicFilters ITKIO ITKCommon)
</source>