00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ImageToImagePairOperator_H
00012 #define ImageToImagePairOperator_H
00013
00014 #include <iostream>
00015 #include "ImageOperator.h"
00016
00017 namespace puma2
00018 {
00019
00026 template <class InputClass, class OutputClass1, class OutputClass2 > class ImageToImagePairOperator
00027 : public ImageOperator
00028 {
00029 public:
00030
00034 ImageToImagePairOperator();
00035
00039 virtual ~ImageToImagePairOperator();
00040
00042 virtual void operator() ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 );
00043
00044 protected:
00046 virtual void apply ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 ) = 0;
00047
00063 virtual void checkArgument ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 );
00064
00065 public:
00066
00067 static void checkImageArgument ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 );
00068
00069 };
00070
00071
00072 template <class InputClass, class OutputClass1, class OutputClass2>
00073 ImageToImagePairOperator<InputClass, OutputClass1, OutputClass2>::ImageToImagePairOperator()
00074 {
00075 }
00076
00077 template <class InputClass, class OutputClass1, class OutputClass2>
00078 ImageToImagePairOperator<InputClass, OutputClass1, OutputClass2>::~ImageToImagePairOperator()
00079 {
00080 };
00081
00082 template <class InputClass, class OutputClass1, class OutputClass2>
00083 void ImageToImagePairOperator<InputClass, OutputClass1, OutputClass2>::operator()
00084 ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 )
00085 {
00086 checkArgument ( inputImage, outputImage1, outputImage2 );
00087 apply ( inputImage, outputImage1, outputImage2 );
00088 }
00089
00090
00091 template <class InputClass, class OutputClass1, class OutputClass2>
00092 void ImageToImagePairOperator<InputClass, OutputClass1, OutputClass2>::checkArgument
00093 ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 )
00094 {
00095 checkImageArgument ( inputImage, outputImage1, outputImage2 );
00096 }
00097
00098 template <class InputClass, class OutputClass1, class OutputClass2>
00099 void ImageToImagePairOperator<InputClass, OutputClass1, OutputClass2>::checkImageArgument
00100 ( const InputClass & inputImage, OutputClass1 & outputImage1, OutputClass2 & outputImage2 )
00101 {
00102 if ( outputImage1.getWidth() != 0 )
00103 {
00104 if ( ( outputImage1.getWidth() != outputImage2.getWidth() ) || ( outputImage1.getHeight() != outputImage2.getHeight() ) ||
00105 ( outputImage1.getWidth() != inputImage.getWidth() ) || ( outputImage1.getHeight() != inputImage.getHeight() ) )
00106 {
00107 throw "Image size missmatch";
00108 }
00109 }
00110 else
00111 {
00112 if ( ( reinterpret_cast<const void*> ( &inputImage ) == reinterpret_cast<const void*> ( &outputImage1 ) ) ||
00113 ( reinterpret_cast<const void*> ( &inputImage ) == reinterpret_cast<const void*> ( &outputImage2 ) ) )
00114 {
00115 throw "Inplace operation of image operator not possible";
00116 }
00117 outputImage1.resize ( inputImage.getWidth(), inputImage.getHeight() );
00118 outputImage2.resize ( inputImage.getWidth(), inputImage.getHeight() );
00119 }
00120 }
00121
00122 }
00123
00124 #endif