|
|
Line 1: |
Line 1: |
| ==Description== | | {{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 releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}} |
| This example demonstrates how to throw an exception.
| |
| | |
| ==ITK Classes Demonstrated==
| |
| | |
| ==Exceptions.cxx==
| |
| <source lang="cpp">
| |
| #include "itkImage.h"
| |
| #include "itkImageFileReader.h"
| |
| #include "itkImageFileWriter.h"
| |
| | |
| #include "ImageSource.h"
| |
| | |
| int main(int, char*[])
| |
| {
| |
| // Setup types
| |
| typedef itk::Image<unsigned char, 2> ImageType;
| |
| ImageType::Pointer image = ImageType::New();
| |
|
| |
| // Create and the filter
| |
| typedef itk::ImageFilter<ImageType> FilterType;
| |
| FilterType::Pointer filter = FilterType::New();
| |
| filter->SetInput(image);
| |
| filter->Update();
| |
| | |
| return EXIT_SUCCESS;
| |
| }
| |
| </source>
| |
| | |
| ==ImageSource.h==
| |
| <source lang="cpp">
| |
| #ifndef __itkImageFilter_h
| |
| #define __itkImageFilter_h
| |
| | |
| #include "itkImageToImageFilter.h"
| |
| | |
| #include <set>
| |
| | |
| namespace itk
| |
| {
| |
| template< class TImage>
| |
| class ImageFilter:public ImageToImageFilter< TImage, TImage >
| |
| {
| |
| public:
| |
| | |
| /** Standard class typedefs. */
| |
| typedef ImageFilter Self;
| |
| typedef ImageToImageFilter< TImage, TImage > Superclass;
| |
| typedef SmartPointer< Self > Pointer;
| |
| | |
| /** Method for creation through the object factory. */
| |
| itkNewMacro(Self);
| |
| | |
| /** Run-time type information (and related methods). */
| |
| itkTypeMacro(ImageFilter, ImageToImageFilter); | |
| | |
| 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 __itkImageSource_hxx
| |
| #define __itkImageSource_hxx
| |
| | |
| #include "ImageSource.h"
| |
| #include "itkObjectFactory.h"
| |
| #include "itkImageRegionIterator.h"
| |
| #include "itkImageRegionConstIterator.h"
| |
| | |
| namespace itk
| |
| {
| |
| | |
| template< class TImage>
| |
| void ImageFilter< TImage>
| |
| ::GenerateData()
| |
| {
| |
| double a = 2.1;
| |
| itkExceptionMacro ("Here is a variable: " << a << " and then more text.");
| |
| }
| |
| | |
| }// end namespace
| |
| | |
| | |
| #endif
| |
| </source>
| |
| | |
| {{ITKCMakeLists|{{SUBPAGENAME}}}}
| |