ITK/Examples/Cxx/Developer/ImageSource: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
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...") |
Daviddoria (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
==ImageSourceExample.cxx== | ==ImageSourceExample.cxx== | ||
<source lang=" | <source lang="cpp"> | ||
#include "itkImage.h" | #include "itkImage.h" | ||
#include "itkImageFileWriter.h" | #include "itkImageFileWriter.h" | ||
Line 27: | Line 27: | ||
==ImageSource.h== | ==ImageSource.h== | ||
<source lang=" | <source lang="cpp"> | ||
#ifndef __itkImageFilter_h | #ifndef __itkImageFilter_h | ||
#define __itkImageFilter_h | #define __itkImageFilter_h | ||
Line 74: | Line 74: | ||
==ImageSource.txx== | ==ImageSource.txx== | ||
<source lang=" | <source lang="cpp"> | ||
#ifndef __itkImageFilter_txx | #ifndef __itkImageFilter_txx | ||
#define __itkImageFilter_txx | #define __itkImageFilter_txx |
Revision as of 19:28, 7 November 2010
ImageSourceExample.cxx
<source lang="cpp">
- 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="cpp">
- 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="cpp">
- 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>